-
-
Notifications
You must be signed in to change notification settings - Fork 18k
C++ compilers: Be sane with standard libraries #85189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,12 +48,6 @@ let | |
| # The wrapper scripts use 'cat' and 'grep', so we may need coreutils. | ||
| coreutils_bin = if nativeTools then "" else getBin coreutils; | ||
|
|
||
| default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then | ||
| "-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/${targetPlatform.config}" | ||
| else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then | ||
| "-isystem ${libcxx}/include/c++/v1" | ||
| else ""; | ||
|
|
||
| # The "suffix salt" is a arbitrary string added in the end of env vars | ||
| # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used | ||
| # without interfering. For the moment, it is defined as the target triple, | ||
|
|
@@ -68,15 +62,15 @@ let | |
|
|
||
| # older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu | ||
| isGccArchSupported = arch: | ||
| if cc.isGNU or false then | ||
| if isGNU then | ||
| { skylake = versionAtLeast ccVersion "6.0"; | ||
| skylake-avx512 = versionAtLeast ccVersion "6.0"; | ||
| cannonlake = versionAtLeast ccVersion "8.0"; | ||
| icelake-client = versionAtLeast ccVersion "8.0"; | ||
| icelake-server = versionAtLeast ccVersion "8.0"; | ||
| knm = versionAtLeast ccVersion "8.0"; | ||
| }.${arch} or true | ||
| else if cc.isClang or false then | ||
| else if isClang then | ||
| { cannonlake = versionAtLeast ccVersion "5.0"; | ||
| icelake-client = versionAtLeast ccVersion "7.0"; | ||
| icelake-server = versionAtLeast ccVersion "7.0"; | ||
|
|
@@ -116,7 +110,7 @@ stdenv.mkDerivation { | |
| # Binutils, and Apple's "cctools"; "bintools" as an attempt to find an | ||
| # unused middle-ground name that evokes both. | ||
| inherit bintools; | ||
| inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile; | ||
|
||
| inherit libc nativeTools nativeLibc nativePrefix isGNU isClang; | ||
|
||
|
|
||
| emacsBufferSetup = pkgs: '' | ||
| ; We should handle propagation here too | ||
|
|
@@ -173,8 +167,6 @@ stdenv.mkDerivation { | |
| export named_cc=${targetPrefix}cc | ||
| export named_cxx=${targetPrefix}c++ | ||
|
|
||
| export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}" | ||
|
|
||
| if [ -e $ccPath/${targetPrefix}gcc ]; then | ||
| wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc | ||
| ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc | ||
|
|
@@ -226,7 +218,7 @@ stdenv.mkDerivation { | |
|
|
||
| strictDeps = true; | ||
| propagatedBuildInputs = [ bintools ] ++ extraTools ++ optionals cc.langD or false [ zlib ]; | ||
| depsTargetTargetPropagated = extraPackages; | ||
| depsTargetTargetPropagated = optional (libcxx != null) libcxx ++ extraPackages; | ||
|
|
||
| wrapperName = "CC_WRAPPER"; | ||
|
|
||
|
|
@@ -250,6 +242,24 @@ stdenv.mkDerivation { | |
| fi | ||
| '' | ||
|
|
||
| + optionalString isClang '' | ||
| ## | ||
| ## General Clang support | ||
| ## | ||
|
|
||
| echo "-target ${targetPlatform.config}" >> $out/nix-support/cc-cflags | ||
| '' | ||
|
|
||
| + optionalString (isClang && libcxx == null && cc ? gcc) '' | ||
| ## | ||
| ## GCC libs for non-GCC support | ||
| ## | ||
|
|
||
| echo "-B${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-cflags | ||
| echo "-L${cc.gcc}/lib/gcc/${targetPlatform.config}/${cc.gcc.version}" >> $out/nix-support/cc-ldflags | ||
| echo "-L${cc.gcc.lib}/${targetPlatform.config}/lib" >> $out/nix-support/cc-ldflags | ||
| '' | ||
|
|
||
| + optionalString (libc != null) ('' | ||
| ## | ||
| ## General libc support | ||
|
|
@@ -279,6 +289,27 @@ stdenv.mkDerivation { | |
| echo "${libc_dev}" > $out/nix-support/orig-libc-dev | ||
| '') | ||
|
|
||
| + '' | ||
| ## | ||
| ## General libc++ support | ||
| ## | ||
|
|
||
| '' | ||
| + optionalString (libcxx == null && cc ? gcc) '' | ||
| for dir in ${cc.gcc}/include/c++/*; do | ||
| echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags | ||
| done | ||
| for dir in ${cc.gcc}/include/c++/*/${targetPlatform.config}; do | ||
| echo "-isystem $dir" >> $out/nix-support/libcxx-cxxflags | ||
| done | ||
| '' | ||
| + optionalString (libcxx.isLLVM or false) ('' | ||
| echo "-isystem ${libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags | ||
| echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags | ||
| '' + stdenv.lib.optionalString stdenv.targetPlatform.isLinux '' | ||
| echo "-lc++abi" >> $out/nix-support/libcxx-ldflags | ||
| '') | ||
|
|
||
| + optionalString (!nativeTools) '' | ||
| ## | ||
| ## Initial CFLAGS | ||
|
|
@@ -389,9 +420,9 @@ stdenv.mkDerivation { | |
| # There are a few tools (to name one libstdcxx5) which do not work | ||
| # well with multi line flags, so make the flags single line again | ||
| + '' | ||
| if [ -e "$out/nix-support/libc-cflags" ]; then | ||
| substituteInPlace "$out/nix-support/libc-cflags" --replace $'\n' ' ' | ||
| fi | ||
| for flags in "$out/nix-support"/*flags; do | ||
| substituteInPlace "$flags" --replace $'\n' ' ' | ||
| done | ||
|
|
||
| substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh | ||
| substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just expose all of these flags in the cc-wrapper ? Something like
stdenv.cc.cflags_compileandstdenv.cc.ld_flagsUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is the pre-substituted values since we don't know the actual values at evaluation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to uses more Nix so we did know the values. (e.g. have a nix boolean and then assert at run-time it was correct.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that requires Nix-level setup-hooks to work correctly. I think that might be too ambitious for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking something like
/nix-support/get-cflags.shwhich does all of this for you.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well getting all the -I flags for other packaged requires that, but not just the std library stuff I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right these should just need the basic c/c++ headers and library paths.