Skip to content

stdenv: make -nostdinc work as intended - #91974

Merged
Ericson2314 merged 1 commit into
NixOS:stagingfrom
Mic92:nostdinc
Jul 28, 2020
Merged

Ericson2314 merged 1 commit into
NixOS:stagingfrom
Mic92:nostdinc

Conversation

@Mic92

@Mic92 Mic92 commented Jul 1, 2020 •

Copy link
Copy Markdown
Member

Right now we add glibc to search path also -nostdinc was provided,
which breaks projects providing their own gcc.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Mic92
Mic92 requested a review from Ericson2314 as a code owner July 1, 2020 20:57
@Mic92
Mic92 requested a review from matthewbauer July 1, 2020 20:59
Comment thread pkgs/test/cc-wrapper/default.nix Resolved
@Mic92
Mic92 marked this pull request as draft July 1, 2020 22:06
@ofborg ofborg Bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jul 2, 2020
@Mic92
Mic92 force-pushed the nostdinc branch 3 times, most recently from b78a55d to d4f4506 Compare July 2, 2020 09:14
@Mic92
Mic92 marked this pull request as ready for review July 2, 2020 09:41
@Mic92

Mic92 commented Jul 2, 2020

Copy link
Copy Markdown
Member Author

Until this hits master, the following solution also works:

with import <nixpkgs> {};
let
  libcPattern =
    builtins.replaceStrings ["/"] ["\\/"] "${gcc.libc_dev}/include";
  gcc' = wrapCCWith {
    cc = gcc.cc;
    bintools = binutils;
    extraBuildCommands = ''
      cat >> $out/nix-support/add-flags.sh <<'EOF'
      if [[ "$@" = *-nostdinc* ]]; then
          NIX_CFLAGS_COMPILE_${gcc.suffixSalt}=''${NIX_CFLAGS_COMPILE_${gcc.suffixSalt}//-idirafter ${libcPattern}/}
      fi
      EOF
    '';
  };
in (overrideCC stdenv gcc').mkDerivation {
  name = "env";
  buildInputs = [
    bashInteractive
  ];
}

@Mic92

Mic92 commented Jul 2, 2020

Copy link
Copy Markdown
Member Author

@GrahamcOfBorg build stdenv

@Ericson2314

Copy link
Copy Markdown
Member

Oh this looks great to me; I had tried something similar at one point when adding those new files.

Do note when you fix conflicts that we now touch all the flags files so downstream can unconditionally cat them.

@Ericson2314

Copy link
Copy Markdown
Member

CC @aaronjanse just in case anything special needs to be done for relibc's crt0.

Comment thread pkgs/test/cc-wrapper/stdio.h Resolved
@aaronjanse

Copy link
Copy Markdown
Member

CC @aaronjanse just in case anything special needs to be done for relibc's crt0.

I don't know enough to understand this PR well, but I've locally verified that these changes don't break relibc 👍

Right now we add glibc to search path also -nostdinc was provided,
which breaks projects providing their own gcc.
@Ericson2314

Copy link
Copy Markdown
Member

Oh i missed the conflicts were fixed. Let's ship!

@Ericson2314
Ericson2314 merged commit cd719c1 into NixOS:staging Jul 28, 2020
@Mic92
Mic92 deleted the nostdinc branch July 29, 2020 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants