From 62dbf14a306c9feb008ca6cd561cc1669fb870f2 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 7 Nov 2023 21:34:42 -0800 Subject: gcc: put environment variables in drvAttrs.env --- pkgs/development/compilers/gcc/default.nix | 90 ++++++++++++++++-------------- 1 file changed, 47 insertions(+), 43 deletions(-) (limited to 'pkgs/development/compilers') diff --git a/pkgs/development/compilers/gcc/default.nix b/pkgs/development/compilers/gcc/default.nix index 01f172513080..57141ba23e2e 100644 --- a/pkgs/development/compilers/gcc/default.nix +++ b/pkgs/development/compilers/gcc/default.nix @@ -259,7 +259,6 @@ lib.pipe ((callFile ./common/builder.nix {}) ({ else [ "out" "lib" "man" "info" ]; setOutputFlags = false; - NIX_NO_SELF_RPATH = true; libc_dev = stdenv.cc.libc_dev; @@ -353,44 +352,55 @@ lib.pipe ((callFile ./common/builder.nix {}) ({ # https://gcc.gnu.org/PR109898 enableParallelInstalling = false; - # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 - ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; - - # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the - # library headers and binaries, regarless of the language being compiled. - # - # Note: When building the Java AWT GTK peer, the build system doesn't honor - # `--with-gmp' et al., e.g., when building - # `libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c', so we just add - # them to $CPATH and $LIBRARY_PATH in this case. - # - # Likewise, the LTO code doesn't find zlib. - # - # Cross-compiling, we need gcc not to read ./specs in order to build the g++ - # compiler (after the specs for the cross-gcc are created). Having - # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. - - CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] - ++ optional (zlib != null) zlib - ++ optional langJava boehmgc - ++ optionals javaAwtGtk xlibs - ++ optionals javaAwtGtk [ gmp mpfr ] - )); - - LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath ( - optional (zlib != null) zlib - ++ optional langJava boehmgc - ++ optionals javaAwtGtk xlibs - ++ optionals javaAwtGtk [ gmp mpfr ] - )); - - inherit (callFile ./common/extra-target-flags.nix { }) - EXTRA_FLAGS_FOR_TARGET - EXTRA_LDFLAGS_FOR_TARGET - ; + env = mapAttrs (_: v: toString v) ({ + + NIX_NO_SELF_RPATH = true; + + # https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210 + ${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64"; + + # Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the + # library headers and binaries, regarless of the language being compiled. + # + # Note: When building the Java AWT GTK peer, the build system doesn't honor + # `--with-gmp' et al., e.g., when building + # `libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c', so we just add + # them to $CPATH and $LIBRARY_PATH in this case. + # + # Likewise, the LTO code doesn't find zlib. + # + # Cross-compiling, we need gcc not to read ./specs in order to build the g++ + # compiler (after the specs for the cross-gcc are created). Having + # LIBRARY_PATH= makes gcc read the specs from ., and the build breaks. + + CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([] + ++ optional (zlib != null) zlib + ++ optional langJava boehmgc + ++ optionals javaAwtGtk xlibs + ++ optionals javaAwtGtk [ gmp mpfr ] + )); + + LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath ( + optional (zlib != null) zlib + ++ optional langJava boehmgc + ++ optionals javaAwtGtk xlibs + ++ optionals javaAwtGtk [ gmp mpfr ] + )); + + inherit (callFile ./common/extra-target-flags.nix { }) + EXTRA_FLAGS_FOR_TARGET + EXTRA_LDFLAGS_FOR_TARGET + ; + } // optionalAttrs is7 { + NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument"; + } // optionalAttrs (!atLeast7) { + inherit langJava; + } // optionalAttrs atLeast6 { + NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; + }); passthru = { - inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD version; + inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version; isGNU = true; } // lib.optionalAttrs (!atLeast12) { hardeningUnsupportedFlags = lib.optionals is48 [ "stackprotector" ] ++ [ "fortify3" ]; @@ -411,17 +421,11 @@ lib.pipe ((callFile ./common/builder.nix {}) ({ } // lib.optionalAttrs (!atLeast11) { badPlatforms = if !(is48 || is49) then [ "aarch64-darwin" ] else lib.platforms.darwin; }; -} // optionalAttrs is7 { - env.NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument"; } // lib.optionalAttrs (!atLeast10 && stdenv.hostPlatform.isDarwin) { # GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools. preBuild = '' makeFlagsArray+=('STRIP=${lib.getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip') ''; -} // optionalAttrs (!atLeast7) { - env.langJava = langJava; -} // optionalAttrs atLeast6 { - NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; } // optionalAttrs (!atLeast8) { doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv } // optionalAttrs enableMultilib { -- cgit 1.4.1