-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Remove NIX_CFLAGS_COMPILE where possible #79303
Comments
Note that many of these are actually upstream bugs so in addition to changing the expressions, we should report the issues. See, for example, #36468 |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
I was just about to copy one such instance of $ rg 'NIX_CFLAGS_COMPILE' | wc -l
705 |
@blaggacao Yes, it is a very common hack. It would still be better if maintainers went upstream for their packages and opened issues or merge requests with a proper fix, like we do with #36468. |
Often it's also not an upstream problem but straight-out unnecessarily done in nixpkgs, as described in the |
@nh2 Would you want to do a regex mass commit (quickly) that at least prepends the ocurrances with a comment and link to this issue? That would at least stop further propagation. Good/bad idea? |
@blaggacao That sounds like a great idea to me! |
I'm not convinced getting rid of |
@edolstra Is there a way a consistent policy can be drafted that does justice to the motivations of the author and also to the inherent values of the flag? Maybe such draft could be the comment to be regex-commited and further if not avoidance, but so awareness. (Blindly copy in my opinion is something that is happening — it happend to me) |
@edolstra Well, my argument in the issue description is exactly the opposite: By sneaking flags past the build system, things actually stop working as expected. I've lost many working days figuring out why some programs don't link, only to find out that one of my dependencies snuck an (Also, if we followed your argument all the way through, we might as well get rid of
Is that really a practical problem? Most build systems make it straightforward to do this today (and for the big ones like Autoconf, CMake, and Meson I've written in the description what the straightforward way is). It's similarly easy for non-C toolchains that may invoke C compilers on the way, like Haskell. Also, this issue is not suggesting to outright forbid the use of |
@nh2 Maybe you would be able to use |
(Also, if we followed your argument all the way through, we might as well get rid of `buildInputs`, the `pkgconfig` hook and so on, and sneak _all_ the dependencies past the build systems whose job it is to manage them.)
Not buildInputs, because the main thing it does is setting NIX_CFLAGS_COMPILE and NIX_LDFLAGS. Which it ususally does correctly and it is enough, but some build systems fail at noticing the dependencies are already available and need pkgconfig hooks.
|
I am actually completely with @edolstra on this subject. I just spent half a day trying to build sqlite DSO's with Don't get me wrong. Using the capabilities of the build system first is a good thing. And I am all-in for removing |
Yup. Last week I had to pass a #define to a glibc source file. I could have spent a few hours figuring out glibc's build system, patch the makefiles and configure scripts, etc. - or just add a line to set |
I haven't decided if |
Interestingly, |
As for |
I've been thinking about this a little recently, and I personally don't have any issue with the
the resulting
As you can see, we are getting all the
which evaluates to
On my current system. It would be nice to add these to |
OK, so adding these to |
From: chaincodelabs/libmultiprocess#75 (comment)
In light of this example I fail to see how the use of Using it locally to solve temporary problems is completely understandable but those changes, once submitted, compromise the environment of depending packages which seems to go against the Nix philosophy. |
Well, Nixpkgs is about building the software even if upstream build system assumes too much, not about making the packagers suffer because upstream developers can't be bothered. Also it looks like |
See NixOS#79303. Avoids warnings about -fpermissive not being a valid C flag.
Nixpkgs is not only used for packaging software for Nixpkgs, it is also used for obtaining development environments with nix-shell, for developing software that might be used on non-Nix platforms. In this case, the compiler implicitly finding headers due to |
An environment tuned to a specific choice of buildsystem is a useful thing, but it probably should be defined separately per-build-system, and it is a different thing from To go to an extreme example, we suppress some |
I don't think the distinction in the above 2 posts matters for what I'm proposing: That if there's a cleaner way to pass something to the build system, use that instead of the In cases where there is no other way, using the So there should be no difference in buildability. The point of my issue description is that there are many cases in nixpkgs where the hack is used unnecessarily, and that that leads to the hack being copy-pasted around too much. |
It does. Given that build systems are complicated, messy, and when they change they change more dramatically than the actual code, |
This misses @nh2 's point which is that those usages should be removed when they are not necessary. Your point seems to be that |
No it doesn't. Even if it is strictly speaking not necessary, but making things work without it takes two hours of debugging instead of ten minutes, and this exercise will need to be repeated once a year instead of once in five years — let's not jump the hoops when we have a tool to just demolish them.
Well, if the most obvious thing that comes to mind literally in the first minute of looking at the expression works fine from at most the second attempt, sure, let's use it instead of |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/single-cmakebuildtype-shared-between-derivation-and-dependency/35184/5 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/single-cmakebuildtype-shared-between-derivation-and-dependency/35184/6 |
While I understand the arguments for not using |
I don't think anybody is suggesting for this feature to be removed. The idea is that if there's a clean way to pass an option to the build system, that should be the default. |
Is there a correct way to disable includes getting added to NIX_CFLAGS_COMPILE for buildInputs in a stdenv or in a derivation? I'm working on packaging rocm 6.2.2. I'd like to turn off the automatic include paths since cmake and pkg-config should be handling all that anyway - in practice we just get a giant pile of duplicate includes passed to clang. So far I didn't find the correct way to turn it off. I'm assuming there is one since nix hook stuff is pretty flexible and I'm just doing it wrong. Adding this to the compiler wrapper allows turning it off for that specific wrapper but it's super jank :(
|
Problem
NIX_CFLAGS_COMPILE
is a low-level hack that sneaks compiler arguments past packages' build systems.It has various drawbacks:
.pc
files, may lack the necessary entries, making problems for downstream packagesBecause many packages use
NIX_CFLAGS_COMPILE
, more packages get it added when people copy this style.Solution
It is better to pass
CFLAGS
,CXXFLAGS
and so on directly to the build system via the method intended to pass compiler flags, for example (feel free to edit this to add more build systems):CFLAGS
before the./configure
invocation (e.g. by writingCFLAGS = "...";
intomkDerivation
)CFLAGS
before thecmake
invocation (see also cmake setup hook: Allow passing environment variables to cmake invocation #79302)-Dc_args
(see also cinnamon.nemo: init at 4.4.1 #77979 (comment) and Report undeclared gio-unix-2.0 upstream #36468 (comment))Delivery
I think we should run a nixpkgs-wide sprint (like #79064) to do this switch for as many packages as possible.
We should also update the documentation to recommend better alternatives to this hack (like above).
The text was updated successfully, but these errors were encountered: