Add support for overriding default compiler flags with '.nim.cfg' and '.nims' configuration files #54
Replies: 3 comments 5 replies
-
@SekouDiaoNlp excellent write-up! I think that between all of the available options, the switches.py should be removed since I have seen most people get confused with it and I think for good reason. Originally I had intended that to be easier to use than other methods of overriding the compiler switches but now it just seems to be in the way. Other than that the proposed solution looks fantastic! :) |
Beta Was this translation helpful? Give feedback.
-
Hey @Pebaz , what's up? I started implementing the fix for the lto flag on macOS and I am about to write some tests to check if everything is ok. I can test all my changes locally, but as I don't have a mac handy, I use the same workflow file you use to automate testing via GitHub Actions. I wanted to check the logs of your latest builds through Github Actions but the logs have been deleted as they are too old. Could you please re-run some of the latest jobs, so that I can check them out and compare them with mine please?
That would be awesome. Cheers. |
Beta Was this translation helpful? Give feedback.
-
Hi @Pebaz and all.
In response to issue #51 regarding the inability to override nimporter's default compiler flags, I have been investigating the issue.
Basically it should be possible to override nimporter's default list of flags
NIM_CLI_ARGS
with values taken from a configuration file other thanswitches.py
.According to the nim compiler documentation, the compiler can be configured via both
.nim.cfg
and.nims
files.One relevant bit of the documentation is:
At the moment
NimCompiler.compile_nim_extension()
andNimCompiler.compile_nim_code()
don't check if there is a.nim.cfg
or.nims
file in the target directory, and because command-line settings have priority over configuration file settings, once nimporter callsnimble
ornim
with it's default flags on the cli, the flags inNIM_CLI_ARGS
have priority over any flags the user might have defined in a.nim.cfg
or.nims
. This means that flags specified outside ofswitches.py
are actually ignored by bothnimble
andnim
.Proposed solution:
After a bit of testing with both 'nim_1.5' and 'nim_1.6' it appears that the compiler first checks the presence of a
.nim.cfg
file, and if not found then checks for the presence of a.nims
file.The solution I propose is to parallel this behaviour. Forward the default cli settings only if no suitable config file has been found, this way the default values in
NIM_CLI_ARGS
won't interfere with user defined flags.Modify
NimCompiler.compile_nim_extension()
andNimCompiler.compile_nim_code()
to:.nim.cfg
file: If found, don't passNIM_CLI_ARGS
tonim_args
. (new behaviour)..nims
file: If found, don't passNIM_CLI_ARGS
tonim_args
. (new behaviour)switches.py
file: If found call get_swiches() and passswitches['bundle']
tonim_args
. (current behaviour)NIM_CLI_ARGS
tonim_args
. (current behaviour)Let me know if you have any suggestions or comments I should be able to start implementing the changes tomorrow or on Tuesday.
Cheers,
SekouDiaoNlp.
Beta Was this translation helpful? Give feedback.
All reactions