From 95c818bff4bcbb74ebaf04c48ea62dcb1cd1177d Mon Sep 17 00:00:00 2001 From: Saem Ghani Date: Fri, 9 Feb 2024 11:57:47 -0800 Subject: [PATCH] std: `compilesettings` show CLI compile/link flags Summary ======= `compilersettings` now includes compiler and linker options that are set via the command-line `--passc/passl` flags. Details ===== Prior to this change only pragma based compiler and linker options were shown, via `{.passC: "...".}` or `{.passL:"...".}`. Now `vmops`, which implements the compile time querying, uses compiler and link option construction procedures from `extccomp` module, which orchestrates C compilation and linking, to fulfill the query. As part of this change the `tcompilesetting` test has been updated to ensure these continue to work. Note: the `compilesettings` query for compile options does _not_ include module specific compile options, set via `{.localPassc: "...".}` pragma. This could be implemented, but that would likely require further changes, like introducing a new query to get all file compiler options vs file specific. --- compiler/backend/extccomp.nim | 4 ++-- compiler/vm/vmops.nim | 6 ++++-- tests/vm/tcompilesetting.nim | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/backend/extccomp.nim b/compiler/backend/extccomp.nim index 0fa36f9f241..5371ef08fe6 100644 --- a/compiler/backend/extccomp.nim +++ b/compiler/backend/extccomp.nim @@ -484,7 +484,7 @@ proc cFileSpecificOptions(conf: ConfigRef; nimname, fullNimFile: string): string addOpt(result, conf.cfileSpecificOptions.getOrDefault(fullNimFile)) -proc getCompileOptions(conf: ConfigRef): string = +proc getCompileOptions*(conf: ConfigRef): string = result = cFileSpecificOptions(conf, "__dummy__", "__dummy__") proc vccplatform(conf: ConfigRef): string = @@ -499,7 +499,7 @@ proc vccplatform(conf: ConfigRef): string = of cpuAmd64: " --platform:amd64" else: "" -proc getLinkOptions(conf: ConfigRef): string = +proc getLinkOptions*(conf: ConfigRef): string = result = conf.linkOptions & " " & conf.linkOptionsCmd.join(" ") & " " for linkedLib in items(conf.cLinkedLibs): result.add(CC[conf.cCompiler].linkLibCmd % linkedLib.quoteShell) diff --git a/compiler/vm/vmops.nim b/compiler/vm/vmops.nim index a5cd6c80073..e938b897eb1 100644 --- a/compiler/vm/vmops.nim +++ b/compiler/vm/vmops.nim @@ -38,6 +38,8 @@ import results ] +from compiler/backend/extccomp import getCompileOptions, getLinkOptions + from compiler/front/msgs import localReport # xxx: reports are a code smell meaning data types are misplaced @@ -203,8 +205,8 @@ when defined(nimHasInvariant): of SingleValueSetting.projectFull: result = conf.projectFull.string of SingleValueSetting.command: result = conf.command of SingleValueSetting.commandLine: result = conf.commandLine - of SingleValueSetting.linkOptions: result = conf.linkOptions - of SingleValueSetting.compileOptions: result = conf.compileOptions + of SingleValueSetting.linkOptions: result = conf.getLinkOptions() + of SingleValueSetting.compileOptions: result = conf.getCompileOptions() of SingleValueSetting.ccompilerPath: result = conf.cCompilerPath of SingleValueSetting.backend: result = $conf.backend of SingleValueSetting.libPath: result = conf.libpath.string diff --git a/tests/vm/tcompilesetting.nim b/tests/vm/tcompilesetting.nim index 5bf559c745a..b8a988b7d22 100644 --- a/tests/vm/tcompilesetting.nim +++ b/tests/vm/tcompilesetting.nim @@ -1,9 +1,9 @@ discard """ -cmd: "nim c --nimcache:build/myNimCache --nimblePath:myNimblePath $file" +matrix: "--nimcache:build/myNimCache --nimblePath:myNimblePath --passc:'-fmax-errors=4' --passl:'-u dummysymboldoesnotexist'" joinable: false """ -import std/[strutils,compilesettings] +import std/[strutils, compilesettings] from std/os import fileExists, `/` template main = @@ -12,6 +12,8 @@ template main = doAssert "myNimblePath" in nimblePaths.querySettingSeq[0] doAssert querySetting(backend) == "c" doAssert fileExists(libPath.querySetting / "system.nim") + doAssert "-fmax-errors=4" in querySetting(compileOptions) + doAssert "-u dummysymboldoesnotexist" in querySetting(linkOptions), querySetting(linkOptions) static: main() main()