Skip to content

Commit

Permalink
std: compilesettings show CLI compile/link flags
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
saem committed Feb 9, 2024
1 parent cef64c4 commit 95c818b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions compiler/backend/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions compiler/vm/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/vm/tcompilesetting.nim
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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()

0 comments on commit 95c818b

Please sign in to comment.