diff options
author | John Ericson <git@JohnEricson.me> | 2020-04-13 20:44:43 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-22 04:24:44 +0000 |
commit | f3f7612a409e4ebbec634ab7f20e094f206d396a (patch) | |
tree | 58131834c6a8decb3a33bf3cb59dd3860cdca39c /pkgs/build-support | |
parent | e00d4d60214e04ba75d19870000e55b8ac4ed4dc (diff) |
C++ Compilers: Systematize handling of standard libraries
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/cc-wrapper/add-flags.sh | 8 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/cc-wrapper.sh | 2 | ||||
-rw-r--r-- | pkgs/build-support/cc-wrapper/default.nix | 61 |
3 files changed, 55 insertions, 16 deletions
diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh index 3398f11e8c215..04be3f408ee1b 100644 --- a/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/pkgs/build-support/cc-wrapper/add-flags.sh @@ -37,6 +37,14 @@ if [ -e @out@/nix-support/libc-cflags ]; then NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@" fi +if [ -e @out@/nix-support/libcxx-cxxflags ]; then + NIX_CXXSTDLIB_COMPILE_@suffixSalt@+=" $(< @out@/nix-support/libcxx-cxxflags)" +fi + +if [ -e @out@/nix-support/libcxx-ldflags ]; then + NIX_CXXSTDLIB_LINK_@suffixSalt@+=" $(< @out@/nix-support/libcxx-ldflags)" +fi + if [ -e @out@/nix-support/cc-cflags ]; then NIX_CFLAGS_COMPILE_@suffixSalt@="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE_@suffixSalt@" fi diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index cf00202221e6b..3f9f099f3bc1f 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -129,7 +129,7 @@ fi if [[ "$isCpp" = 1 ]]; then if [[ "$cppInclude" = 1 ]]; then - NIX_CFLAGS_COMPILE_@suffixSalt@+=" ${NIX_CXXSTDLIB_COMPILE_@suffixSalt@:-@default_cxx_stdlib_compile@}" + NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" fi NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" fi diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index da16a23f9dff3..e23d1c6dd4e6f 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -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,7 +62,7 @@ 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"; @@ -76,7 +70,7 @@ let 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 |