Skip to content
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

cc-wrapper: conditionalize the nonexistent sysroot hack #213738

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
, buildPackages ? {}
, libcxx ? null
, enableNonExistentSysroot ? false
}:

with lib;
Expand Down Expand Up @@ -343,10 +344,18 @@ stdenv.mkDerivation {
# compile, because it uses "#include_next <limits.h>" to find the
# limits.h file in ../includes-fixed. To remedy the problem,
# another -idirafter is necessary to add that directory again.
#
# We use --sysroot=/nix/store/does/not/exist to drop embedded default
# path to glibc headers gcc was built against. Without it -idirafter
# only appends to the list and outdated glibc headers end up being
# used. 'cc-cflags-before' is used to allow user's --sysroot= option
# to override our default.
+ optionalString (libc != null) (''
touch "$out/nix-support/libc-cflags"
touch "$out/nix-support/libc-ldflags"
echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-crt1-cflags
'' + optionalString enableNonExistentSysroot ''
echo "--sysroot=/nix/store/does/not/exist" >> $out/nix-support/cc-cflags-before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in #213185 blanket --sysroot= changes library search path in transitive libraries. As a result we get linkage failures in dmd, d-seams, llvmPackages_rocm.compiler-rt. Conditional or not it's breaking real packages. The intent in the comment was only attempting to change header search path and not library search path.

For just headers there is an -isysroot flag. But it has it's own caveats as blanket --sysroot= also exposed failures in ipxe and wimboot. Those show that existing -idirafter sequence is incorrectly overridden in nixpkgs. It has to be fixed by chaning a priority.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional is only enabled for xgcc, which is never used to compile any of those packages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion would be to explore ways to add the flag locally to the place where it's intended to be used instead of changing the driver. I still think it's too heavy a hammer even for gcc.

'' + optionalString (!(cc.langD or false)) ''
echo "-idirafter ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
'' + optionalString (isGNU && (!(cc.langD or false))) ''
Expand Down