cc-wrapper/setup-hook.sh: remove duplicate flags in NIX_CFLAGS_COMPILE#191724
Conversation
|
This needs to go to staging, please rebase. |
There was a problem hiding this comment.
No opinion on the changes (sorry, not my area of expertise), but the commit message should be made a bit more clear (we have a lot of setup hooks):
- setup-hook.sh: remove duplicate flags in NIX_CFLAGS_COMPILE
+ cc-wrapper: don't add duplicate flags to NIX_CFLAGS_COMPILE(I reworded it a bit, feel free to play around with it, though.)
4b20142 to
9402e62
Compare
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
For later: I wonder if there's a more central place to remove duplicates, and whether we should do it there? E.g., what about |
e53c0f0 to
c27315b
Compare
vcunat
left a comment
There was a problem hiding this comment.
Sounds OK, but I haven't tested anything.
Nit suggestions:
-Ffor grep to get more precision of matching (and perhaps faster)-qfor grep instead of redirection, maybe?
c27315b to
529c715
Compare
|
@vcunat: Good suggestions! Have updated. Rebuilding now to make sure everything still works |
|
everything looks good. |
|
Why do you grep for |
|
You are totally right! Thanks for catching that @vcunat |
529c715 to
0bea4a1
Compare
|
I think |
|
This imprecision seems not easy to fix completely, I'm afraid. |
|
Actually yes, we could |
In NixOS#197798 (comment) we noticed that `eduke32` fails to build as: source/build/include/sdl_inc.h:17:12: fatal error: SDL2/SDL.h: No such file or directory 17 | # include <SDL2/SDL.h> | ^~~~~~~~~~~~ It statred after NixOS#191724 where `NIX_CFLAGS_COMPILE` entries were cleaned up slightly. This change works build failure around. But I think it's a good change: there should be no reason to set SDL2 offset via forced include paths.
|
Doesn't |
|
Oops... correction: |
|
I had a failure like the I don't think this PR was a good idea. The only reason we have multiple entries is because of |
|
Can you expand on how |
|
|
|
From that it doesn't sound to me that |
|
Ah, the |
|
OK, I suppose it will be better to revert until we have a better version of this deduplication. Any preliminary comments on this approach? ccWrapper_addCVars () {
# See ../setup-hooks/role.bash
local role_post
getHostRoleEnvHook
# Avoid adding non-existent directories and duplicates.
local CFLAGS_varname="NIX_CFLAGS_COMPILE${role_post}"
if [ -d "$1/include" ] \
&& (! printf %s " ${!CFLAGS_varname} " | grep -q -F " $1/include " ); then
export ${CFLAGS_varname}+=" -isystem $1/include"
fi
if [ -d "$1/Library/Frameworks" ] \
&& (! printf %s " ${!CFLAGS_varname} " | grep -q -F " $1/Library/Frameworks " ); then
export ${CFLAGS_varname}+=" -iframework $1/Library/Frameworks"
fi
}
|
|
I guess because we are appending, this is safe with respect to search path order? If so, the new version is good. |
Always set `SRCTOP`, set it with abs path llvmPackages: Bump minimum version for FreeBSD llvmPackages_*, libgcc, compiler_rt: Hack in enough libs that one can compiler C freebsd.compat: Rename some things to work around cc-wrapper change 0bea4a1 / NixOS#191724 in particular
|
Sorry, just catching up on this. These deep files are hard, but so interesting to hack on 😅 |
|
I was waiting anyway, as it felt better not to hurry with this into 21.11 release and wait for forking it off. |
|
We could just revert if that is what we think is best. Duplicates aren't a huge deal. I thought it would be an easy fix, but clearly there was some subtlety that I missed |
|
Right now it is reverted on all platforms (for a week or two, see above). |
|
sorry, I was unclear. I meant to say that I would be fine with not dealing with the duplicates after 22.11 if it is going to be complicated to get working. If you and Ericson2314 have it sorted now, then everything is good! I need to learn more about cross compiling .... |
|
I'd hope that the suggestion above will work well, but we can only be really sure after it's spent months in nixpkgs master (after it switches to 23.05). |
Always set `SRCTOP`, set it with abs path llvmPackages: Bump minimum version for FreeBSD llvmPackages_*, libgcc, compiler_rt: Hack in enough libs that one can compiler C freebsd.compat: Rename some things to work around cc-wrapper change 0bea4a1 / NixOS#191724 in particular
Description of changes
Currently, nix build environments have duplicate flags in
NIX_CFLAGS_COMPILE. For example, consider the followingshell.nix:which gives us
It is easy to remove this duplication by making
ccWrapper_addCVarsidempotent. After this change, we haveThis is mostly a cosmetic change, and will trigger a rebuild of the entire universe. I did so for the standard environment today and everything works fine. It has been bugging me since I started doing C++ dev on nix, especially for cmake projects with a lot of dependencies where I use
NIX_CFLAGS_COMPILEto generate acompile_commands.jsonThings done
Make
ccWrapper_addCVarsidempotent.sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes