Skip to content

Commit

Permalink
fix nim-lang#14272 nim-lang#12349 -d:release -d:danger -d:nimLto -d:n…
Browse files Browse the repository at this point in the history
…imStrip honor user config
  • Loading branch information
timotheecour committed Oct 27, 2020
1 parent ea6c282 commit 7c003cf
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 84 deletions.
10 changes: 9 additions & 1 deletion compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,17 @@ proc handleStdinInput*(conf: ConfigRef) =

proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
conf: ConfigRef) =
let switch2 = switch.normalize
if conf.switchesProcessed.contains switch2:
if conf.switchesProcessedLazy:
# eg: if -d:danger sets stacktrace:off but some config already set `stacktrace`, skip
return
else:
conf.switchesProcessed.add switch2

var
key, val: string
case switch.normalize
case switch2
of "path", "p":
expectArg(conf, switch, arg, pass, info)
for path in nimbleSubs(conf, arg):
Expand Down
28 changes: 23 additions & 5 deletions compiler/nimconf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,34 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef; idgen:
if cfg == DefaultConfig:
runNimScriptIfExists(pd / DefaultConfigNims)

for filename in configFiles:
# delayed to here so that `hintConf` is honored
rawMessage(conf, hintConf, filename.string)

let scriptFile = conf.projectFull.changeFileExt("nims")
let isMain = scriptFile == conf.projectFull

template epilogue() =
if optSkipSystemConfigFile notin conf.globalOptions:
conf.switchesProcessedLazy = true
readConfigFile(getSystemConfigPath(conf, DefaultConfigEpilogue))
conf.switchesProcessedLazy = false

template showConf() =
for filename in configFiles:
# delayed to here so that `hintConf` is honored
rawMessage(conf, hintConf, filename.string)
configFiles.setLen 0

if isMain:
showConf()
epilogue() # likely not significant for nimscript

if conf.command != "nimsuggest":
runNimScriptIfExists(scriptFile)
else:
if scriptFile != conf.projectFull:
if not isMain:
runNimScriptIfExists(scriptFile)
else:
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file
discard

if not isMain:
epilogue()
showConf()
3 changes: 3 additions & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ type
cmdlineNotes*: TNoteKinds # notes that have been set/unset from cmdline
foreignPackageNotes*: TNoteKinds
notes*: TNoteKinds # notes after resolving all logic(defaults, verbosity)/cmdline/configs
switchesProcessed*: seq[string]
switchesProcessedLazy*: bool
warningAsErrors*: TNoteKinds
mainPackageNotes*: TNoteKinds
mainPackageId*: int
Expand Down Expand Up @@ -550,6 +552,7 @@ const
TexExt* = "tex"
IniExt* = "ini"
DefaultConfig* = RelativeFile"nim.cfg"
DefaultConfigEpilogue* = RelativeFile"nim_epilogue.cfg"
DefaultConfigNims* = RelativeFile"config.nims"
DocConfig* = RelativeFile"nimdoc.cfg"
DocTexConfig* = RelativeFile"nimdoc.tex.cfg"
Expand Down
78 changes: 0 additions & 78 deletions config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,6 @@ path="$lib/pure"
nimblepath="$home/.nimble/pkgs/"
@end

@if danger or quick:
obj_checks:off
field_checks:off
range_checks:off
bound_checks:off
overflow_checks:off
assertions:off
stacktrace:off
linetrace:off
debugger:off
line_dir:off
dead_code_elim:on
@if nimHasNilChecks:
nilchecks:off
@end
@end

@if release or danger:
stacktrace:off
excessiveStackTrace:off
linetrace:off
debugger:off
line_dir:off
opt:speed
define:release
@end

@if false: # not danger: # this does not work yet.
clang.options.always %= "${clang.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
gcc.options.always %= "${gcc.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
@end

@if unix and mingw:
# Cross compile for Windows from Linux/OSX using MinGW
i386.windows.gcc.exe = "i686-w64-mingw32-gcc"
Expand Down Expand Up @@ -259,20 +227,6 @@ clang.options.always = "-w -ferror-limit=3"
clang.options.speed = "-O3"
clang.options.size = "-Os"

@if windows:
clang_cl.cpp.options.always %= "${clang_cl.options.always} /EHsc"
@if not release and not safety and not danger:
clang_cl.options.linker = "/Z7"
clang_cl.cpp.options.linker = "/Z7"
@end
clang.options.debug = "-g -gcodeview"
clang.cpp.options.debug = "-g -gcodeview"
@if not release and not safety and not danger:
clang.options.linker = "-g"
clang.cpp.options.linker = "-g"
@end
@end

# Configuration for the Visual C/C++ compiler:
# VCCEXE is a tool that invokes the Visual Studio Developer Command Prompt
# before calling the compiler.
Expand Down Expand Up @@ -327,35 +281,3 @@ tcc.options.always = "-w"
--define:nimOldCaseObjects
--define:nimOldShiftRight
@end

@if lto or lto_incremental:
@if lto_incremental:
vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL /Gw /Gy"
vcc.options.linker %= "${vcc.options.linker} /link /LTCG:incremental"
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG:incremental"
@else:
vcc.options.always%= "${vcc.options.always} /GL"
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL"
vcc.options.linker %= "${vcc.options.linker} /link /LTCG"
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG"
@end
clang_cl.options.always%= "${clang_cl.options.always} -flto"
clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto"
clang.options.always%= "${clang.options.always} -flto"
clang.cpp.options.always%= "${clang.cpp.options.always} -flto"
icl.options.always %= "${icl.options.always} /Qipo"
icl.cpp.options.always %= "${icl.cpp.options.always} /Qipo"
gcc.options.always %= "${gcc.options.always} -flto"
gcc.cpp.options.always %= "${gcc.cpp.options.always} -flto"
clang.options.linker %= "${clang.options.linker} -fuse-ld=lld -flto"
clang.cpp.options.linker %= "${clang.cpp.options.linker} -fuse-ld=lld -flto"
gcc.options.linker %= "${gcc.options.linker} -flto"
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -flto"
@end
@if strip:
gcc.options.linker %= "${gcc.options.linker} -s"
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -s"
clang.options.linker %= "${clang.options.linker} -s"
clang.cpp.options.linker %= "${clang.cpp.options.linker} -s"
@end
79 changes: 79 additions & 0 deletions config/nim_epilogue.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@if danger or quick:
obj_checks:off
field_checks:off
range_checks:off
bound_checks:off
overflow_checks:off
assertions:off
stacktrace:off
linetrace:off
debugger:off
line_dir:off
dead_code_elim:on
@if nimHasNilChecks:
nilchecks:off
@end
@end

@if release or danger:
stacktrace:off
excessiveStackTrace:off
linetrace:off
debugger:off
line_dir:off
opt:speed
define:release
@end

@if windows:
clang_cl.cpp.options.always %= "${clang_cl.options.always} /EHsc"
@if not release and not safety and not danger:
clang_cl.options.linker = "/Z7"
clang_cl.cpp.options.linker = "/Z7"
@end
clang.options.debug = "-g -gcodeview"
clang.cpp.options.debug = "-g -gcodeview"
@if not release and not safety and not danger:
clang.options.linker = "-g"
clang.cpp.options.linker = "-g"
@end
@end

@if false: # not danger: # this does not work yet.
clang.options.always %= "${clang.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
gcc.options.always %= "${gcc.options.always} -fsanitize=null -fsanitize-undefined-trap-on-error"
@end

@if nimLto or nimLto_incremental or lto or lto_incremental:
@if nimLto_incremental or lto_incremental:
vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL /Gw /Gy"
vcc.options.linker %= "${vcc.options.linker} /link /LTCG:incremental"
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG:incremental"
@else:
vcc.options.always%= "${vcc.options.always} /GL"
vcc.cpp.options.always%= "${vcc.cpp.options.always} /GL"
vcc.options.linker %= "${vcc.options.linker} /link /LTCG"
vcc.cpp.options.linker %= "${vcc.cpp.options.linker} /link /LTCG"
@end
clang_cl.options.always%= "${clang_cl.options.always} -flto"
clang_cl.cpp.options.always%= "${clang.cpp.options.always} -flto"
clang.options.always%= "${clang.options.always} -flto"
clang.cpp.options.always%= "${clang.cpp.options.always} -flto"
icl.options.always %= "${icl.options.always} /Qipo"
icl.cpp.options.always %= "${icl.cpp.options.always} /Qipo"
gcc.options.always %= "${gcc.options.always} -flto"
gcc.cpp.options.always %= "${gcc.cpp.options.always} -flto"
clang.options.linker %= "${clang.options.linker} -fuse-ld=lld -flto"
clang.cpp.options.linker %= "${clang.cpp.options.linker} -fuse-ld=lld -flto"
gcc.options.linker %= "${gcc.options.linker} -flto"
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -flto"
@end

@if nimStrip or strip:
gcc.options.linker %= "${gcc.options.linker} -s"
gcc.cpp.options.linker %= "${gcc.cpp.options.linker} -s"
clang.options.linker %= "${clang.options.linker} -s"
clang.cpp.options.linker %= "${clang.cpp.options.linker} -s"
@end

0 comments on commit 7c003cf

Please sign in to comment.