-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-d:release -d:danger don't work as expected in user configs #14272
Comments
shell script to reproduce (run this in an empty directory) set -x
if [ ! -f main.nim ]; then
cat << DONK > main.nim
echo "yardanico made me do it"
DONK
fi
if [ -f nim.cfg ]; then
mv nim.cfg nim.cfg.off
fi
if [ ! -f nim.cfg.off ]; then
cat << DONK > nim.cfg.off
-d:danger
DONK
fi
nim c -o:test-inline -d:danger main.nim
mv nim.cfg.off nim.cfg
nim c -o:test-cfg main.nim
du -sh test-cfg test-inline |
I discovered this when trying to minimise binary size:
|
This is caused by the fact that https://github.com/nim-lang/Nim/blob/devel/config/nim.cfg is now read before the project .cfg file. |
Even simpler way to reproduce: # a.nim
proc a =
raise newException(ValueError, "test")
a() Compile with
Now do P.S: If you do it in |
Also this is not a regression :p |
Seems to be documented in https://nim-lang.org/docs/nims.html only but it's just a note |
So I guess there are two approaches - make this actually work or document it in an obvious place and optionally add a warning so when Nim sees -d:danger or -d:release in user config files it shows a warning |
I see a few ways to implement this:
If we were to implement something like this, I'd personally prefer the first proposal, as it's easier to implement/understand IMO, though it might cause trouble with configurations that can have side effects (ie. nimscript's |
I would figure the config files were the same as if the lines were added to
the command line, since they’re sort of patterned after @-files like this.
Then defines should work in the order they were read, with an undefined
added to the CLI so config files closer to the module being compiled have
an opportunity to unset anything the workspace set above them.
|
That's the solution I had in mind. |
Yeah, I think that making release and danger special would make the most sense |
Making Also, the user could have a global user cfg with other defines and |
this would be fixed via #15614 (comment), see RFC nim-lang/RFCs#278 EDIT: see #15742 |
…imStrip honor user config
Fixed by #18051 |
The problem is that currently the Nim compiler evaluates user configs last, so if a user puts
-d:release
or-d:danger
in theirown config file, it won't have any effect on the actual compiler switches because the user config file will be evaluated last.
This can be quite unexpected for newbies since there are no warnings/hints about this behaviour at all. If you put these in your config file it'll compile just fine,
defined(release)
will returntrue
, but the switches like--opt:speed
won't get activated.The text was updated successfully, but these errors were encountered: