-
-
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
wrapCC, wrapBintools: use absolute paths #314920
base: staging
Are you sure you want to change the base?
Conversation
9ef79e4
to
75b959d
Compare
75b959d
to
22b3600
Compare
Rebuild from
|
Looks like some unrelated commits have found their way in. |
@alyssais, I don’t think so? The main change is in 3b6195a82ee60f528852b34e097c0582734deb1e with other commits mostly fixing occasional $CC references introduced by package build systems. I’ll try to merge these separately (hence the draft status for now), but they are still required for this PR, especially stdenv stuff like gnumake and gawk. |
ah right, I missed the prerequisites mention in the PR body |
Uh, I think we have a problem, looks like At b1a4e83 (master branch) on
Note that we use stripped down version of Output:
So, stdenv overrides work fine, we get the correct What would be the right path to move forward with this PR? I’d really like to avoid diving even deeper down this rabbit hole and focus on a single issue at hand 😬 |
Yeah, I'm not a big fan of absolute paths as they tend to leak everywhere as you have discovered and sometimes are not even supported by the build systems. But if there is no better solution then it might be a reasonable workaround. Ideally I would say that |
Nixpkgs platforms can be configured in so many different ways (microarchitectures, compiler flags, etc) that IMO the only reasonable encoding is a hash of all parameters, which we already have in a form of absolute paths in Nix store 😅 |
I wouldn’t say it’s that bad. I feel like so far most of the time on this PR I’ve spent debugging issues with things like Paths leaks are relatively easy to fix by patching source code, removing references from output or setting fixed values at build time. Most build systems are fine with absolute paths too. There are some commits for bespoke configure scripts in this PR, but these are also easy to fix. Again, if possible, I’ll try to merge each change set separately since fixes for absolute paths can be merged before actually using them (see Prerequisites in the description for a list of split PRs). |
I think in the past both this and putting the target prefix on native binaries have both been half-attempted. |
I remember some time ago that was cited Exherbo employed something like always prefixing the target on the name of CC. Edit: links |
We do prefix target when target ≠ host, but the PATH lookup is still ambiguous in many cases. For example, I recently had to add a workaround for this issue because a package required Aside from occasional reference leaks, I think that using absolute paths is better than prefixing toolchain (i.e. using Nix store paths instead of target prefixes). That is because nativeBuildInputs and other flags from mkDerivation arguments take precedence over defaults and we also embed some platform-specific options in the wrapper itself. Fixing unwanted references is easy in most cases and is a common task for Nixpkgs contributors, but I start questioning my sanity every time the build uses wrong toolchain because of PATH lookup. FWIW, some packages already set these variables to absolute paths for non-trivial builds, e.g.
|
Why not to generalize it? Regardless the need of absolute paths, I think we should begin to treat cross-compilation as first class and native compilation as a particular case of it. (I hope this is not too off-topic. If so, feel free to ignore it.) |
Yes, I completely agree with this! Unfortunately, GCC and the existing C ecosystem makes it much harder than it should be, and potentially having multiple matching binaries on the search path doesn’t help that… On that note, we’ve had several PRs recently that added useful information to the stdenv (e.g. #290081), so perhaps we can also warn about binaries under the same name present in multiple PATH entries 🤔 |
Just had another weird issue while working on #329721 where configure script does not detect $ echo $AR
aarch64-unknown-linux-musl-ar
$ AR=$AR ./configure $confugureFlags | fgrep 'checking for ar'
checking for ar... no
$ AR=$NIX_CC/bin/$AR ./configure $confugureFlags | fgrep 'checking for ar'
checking for ar... /nix/store/zzaivbdjmarqdcsfia9g5zfs8mgdhj9q-aarch64-unknown-linux-musl-gcc-wrapper-13.3.0/bin/aarch64-unknown-linux-musl-ar |
Relevant to the prefixing discussion: #44583. |
Note: the PR is not stale and I still think there aren’t any better solutions compared to using absolute paths. I’ll try to squeeze in some time for a rebase in a week or so. |
It is important to use absolute paths to support compiling for different platforms with the same target prefix (e.g. otherwise identical but statically linked platform, or enabling some CPU extensions for host platform that build platform does not support). For example, it is common to set ```nix depsBuildBuild = [ buildPackages.stdenv.cc ]; ``` and we don’t want to use CC{,_FOR_BUILD} from PATH lookup in such cases. See also doc/stdenv/cross-compilation.chapter.md.
C/C++ toolchain variables use absolute paths now, so no need to add workarounds for these in libgcc.
This change supresses error when $bintools/nix-support/libc-ldflags-before file does not exist and also avoids resetting ld flags when setting dynamic linker (this seems to be the correct behavior and doesn’t look like it breaks anything else).
Discovered by accident when building without strip program that we actually need these variables to avoid building GCC with debug information (these variables default to `-g -O2`). Note that GCC 5 has been removed from Nixpkgs in 20.03 release (see nixos/doc/manual/release-notes/rl-2003.section.md).
These are not needed now that we set CC/CXX to absolute paths.
c3e8c3e
to
d6d72d1
Compare
Description of changes
This change sets {CC,CXX,LD,etc…}{,_FOR_BUILD,_FOR_TARGET} variables to absolute paths in cc-wrapper and bintools-wrapper setup hooks.
It’s common to set
when cross-compiling (see doc/stdenv/cross-compilation.chapter.md), however, cc/bintools wrapper setup hook currently sets these variables to program name instead of absolute path. That obviously doesn’t work e.g. when build and host platform have the same C compiler name because only the first program from PATH is used (for example, this is part of the reason why static glibc doesn’t work in Nixpkgs and we have pkgsStatic use musl that has different target prefix).
Prerequisites:
postgresql: remove unnecessary store references #322025postgresql: split -lib and -dev outputs cleanly #294504
Note: I’ll be adding new PRs split from this one to the list above.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.