linux: fix compiler selection (#402198)

authored by Tristan Ross and committed by GitHub ef90270c 35892605

+97 -31
+1 -4
pkgs/development/compilers/gcc/common/configure-flags.nix
··· 20 enablePlugin, 21 disableGdbPlugin ? !enablePlugin, 22 enableShared, 23 24 langC, 25 langCC, ··· 58 crossMingw = (!lib.systems.equals targetPlatform hostPlatform) && targetPlatform.isMinGW; 59 crossDarwin = 60 (!lib.systems.equals targetPlatform hostPlatform) && targetPlatform.libc == "libSystem"; 61 - 62 - targetPrefix = lib.optionalString ( 63 - !lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform 64 - ) "${stdenv.targetPlatform.config}-"; 65 66 crossConfigureFlags = 67 # Ensure that -print-prog-name is able to find the correct programs.
··· 20 enablePlugin, 21 disableGdbPlugin ? !enablePlugin, 22 enableShared, 23 + targetPrefix, 24 25 langC, 26 langCC, ··· 59 crossMingw = (!lib.systems.equals targetPlatform hostPlatform) && targetPlatform.isMinGW; 60 crossDarwin = 61 (!lib.systems.equals targetPlatform hostPlatform) && targetPlatform.libc == "libSystem"; 62 63 crossConfigureFlags = 64 # Ensure that -print-prog-name is able to find the correct programs.
+6 -1
pkgs/development/compilers/gcc/common/meta.nix
··· 1 - { lib, version }: 2 3 let 4 inherit (lib) ··· 24 25 platforms = platforms.unix; 26 teams = [ teams.gcc ]; 27 28 }
··· 1 + { 2 + lib, 3 + version, 4 + targetPrefix, 5 + }: 6 7 let 8 inherit (lib) ··· 28 29 platforms = platforms.unix; 30 teams = [ teams.gcc ]; 31 + mainProgram = "${targetPrefix}gcc"; 32 33 }
+7 -2
pkgs/development/compilers/gcc/default.nix
··· 119 !lib.systems.equals targetPlatform hostPlatform 120 ) "${targetPlatform.config}${stageNameAddon}-"; 121 122 callFile = callPackageWith { 123 # lets 124 inherit ··· 340 "target" 341 ]; 342 343 - configureFlags = callFile ./common/configure-flags.nix { }; 344 345 inherit targetConfig; 346 ··· 449 inherit enableShared enableMultilib; 450 451 meta = { 452 - inherit (callFile ./common/meta.nix { }) 453 homepage 454 license 455 description 456 longDescription 457 platforms 458 teams 459 ; 460 } 461 // optionalAttrs (!atLeast11) {
··· 119 !lib.systems.equals targetPlatform hostPlatform 120 ) "${targetPlatform.config}${stageNameAddon}-"; 121 122 + targetPrefix = lib.optionalString ( 123 + !lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform 124 + ) "${stdenv.targetPlatform.config}-"; 125 + 126 callFile = callPackageWith { 127 # lets 128 inherit ··· 344 "target" 345 ]; 346 347 + configureFlags = callFile ./common/configure-flags.nix { inherit targetPrefix; }; 348 349 inherit targetConfig; 350 ··· 453 inherit enableShared enableMultilib; 454 455 meta = { 456 + inherit (callFile ./common/meta.nix { inherit targetPrefix; }) 457 homepage 458 license 459 description 460 longDescription 461 platforms 462 teams 463 + mainProgram 464 ; 465 } 466 // optionalAttrs (!atLeast11) {
+5 -1
pkgs/development/compilers/zig/cc.nix
··· 14 runCommand "zig-cc-${zig.version}" 15 { 16 pname = "zig-cc"; 17 - inherit (zig) version meta; 18 19 nativeBuildInputs = [ makeWrapper ]; 20 ··· 24 }; 25 26 inherit zig; 27 } 28 '' 29 mkdir -p $out/bin
··· 14 runCommand "zig-cc-${zig.version}" 15 { 16 pname = "zig-cc"; 17 + inherit (zig) version; 18 19 nativeBuildInputs = [ makeWrapper ]; 20 ··· 24 }; 25 26 inherit zig; 27 + 28 + meta = zig.meta // { 29 + mainProgram = "${targetPrefix}clang"; 30 + }; 31 } 32 '' 33 mkdir -p $out/bin
+3 -1
pkgs/os-specific/linux/kernel/common-config.nix
··· 525 DRM_AMD_DC_DCN = lib.mkIf (with stdenv.hostPlatform; isx86 || isPower64) ( 526 whenBetween "5.11" "6.4" yes 527 ); 528 - DRM_AMD_DC_FP = whenAtLeast "6.4" yes; 529 DRM_AMD_DC_HDCP = whenBetween "5.5" "6.4" yes; 530 DRM_AMD_DC_SI = whenAtLeast "5.10" yes; 531
··· 525 DRM_AMD_DC_DCN = lib.mkIf (with stdenv.hostPlatform; isx86 || isPower64) ( 526 whenBetween "5.11" "6.4" yes 527 ); 528 + # Not available when using clang 529 + # See: https://github.com/torvalds/linux/blob/172a9d94339cea832d89630b89d314e41d622bd8/drivers/gpu/drm/amd/display/Kconfig#L14 530 + DRM_AMD_DC_FP = lib.mkIf (!stdenv.cc.isClang) (whenAtLeast "6.4" yes); 531 DRM_AMD_DC_HDCP = whenBetween "5.5" "6.4" yes; 532 DRM_AMD_DC_SI = whenAtLeast "5.10" yes; 533
+34
pkgs/os-specific/linux/kernel/common-flags.nix
···
··· 1 + { 2 + lib, 3 + stdenv, 4 + buildPackages, 5 + extraMakeFlags ? [ ], 6 + }: 7 + # Absolute paths for compilers avoid any PATH-clobbering issues. 8 + [ 9 + # 10 + # We use the unwrapped compiler, because the clang-wrapper doesn't like -target. 11 + "CC=${lib.getExe stdenv.cc.cc}" 12 + # The wrapper for ld.lld breaks linking the kernel. We use the unwrapped linker as workaround. See: 13 + # https://github.com/NixOS/nixpkgs/issues/321667 14 + "LD=${lib.getExe' stdenv.cc.bintools.bintools "${stdenv.cc.targetPrefix}ld"}" 15 + "AR=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}ar"}" 16 + "NM=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}nm"}" 17 + "STRIP=${lib.getExe' stdenv.cc.bintools.bintools "${stdenv.cc.targetPrefix}strip"}" 18 + "OBJCOPY=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}objcopy"}" 19 + "OBJDUMP=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}objdump"}" 20 + "READELF=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}readelf"}" 21 + "HOSTCC=${lib.getExe' buildPackages.stdenv.cc "${buildPackages.stdenv.cc.targetPrefix}cc"}" 22 + "HOSTCXX=${lib.getExe' buildPackages.stdenv.cc "${buildPackages.stdenv.cc.targetPrefix}c++"}" 23 + "HOSTAR=${lib.getExe' buildPackages.stdenv.cc.bintools "${buildPackages.stdenv.cc.targetPrefix}ar"}" 24 + "HOSTLD=${lib.getExe' buildPackages.stdenv.cc.bintools "${buildPackages.stdenv.cc.targetPrefix}ld"}" 25 + "ARCH=${stdenv.hostPlatform.linuxArch}" 26 + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" 27 + ] 28 + # Add the built in headers the kernel needs 29 + ++ lib.optionals (stdenv.cc.isClang) [ 30 + "CFLAGS_MODULE=-I${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include" 31 + "CFLAGS_KERNEL=-I${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include" 32 + ] 33 + ++ (stdenv.hostPlatform.linux-kernel.makeFlags or [ ]) 34 + ++ extraMakeFlags
+27 -6
pkgs/os-specific/linux/kernel/generic.nix
··· 191 ++ lib.optional (lib.versionAtLeast version "5.2") pahole 192 ++ lib.optionals withRust [ 193 rust-bindgen 194 - rustc 195 ]; 196 197 RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc; ··· 201 kernelBaseConfig = 202 if defconfig != null then defconfig else stdenv.hostPlatform.linux-kernel.baseConfig; 203 204 - makeFlags = 205 - lib.optionals ( 206 - stdenv.hostPlatform.linux-kernel ? makeFlags 207 - ) stdenv.hostPlatform.linux-kernel.makeFlags 208 - ++ extraMakeFlags; 209 210 postPatch = kernel.postPatch + '' 211 # Patch kconfig to print "###" after every question so that ··· 233 KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \ 234 PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. MAKE_FLAGS="$makeFlags" \ 235 perl -w $generateConfig 236 ''; 237 238 installPhase = "mv $buildRoot/.config $out";
··· 191 ++ lib.optional (lib.versionAtLeast version "5.2") pahole 192 ++ lib.optionals withRust [ 193 rust-bindgen 194 + rustc.unwrapped 195 ]; 196 197 RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc; ··· 201 kernelBaseConfig = 202 if defconfig != null then defconfig else stdenv.hostPlatform.linux-kernel.baseConfig; 203 204 + makeFlags = import ./common-flags.nix { 205 + inherit 206 + lib 207 + stdenv 208 + buildPackages 209 + extraMakeFlags 210 + ; 211 + }; 212 213 postPatch = kernel.postPatch + '' 214 # Patch kconfig to print "###" after every question so that ··· 236 KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \ 237 PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. MAKE_FLAGS="$makeFlags" \ 238 perl -w $generateConfig 239 + '' 240 + + lib.optionalString stdenv.cc.isClang '' 241 + if ! grep -Fq CONFIG_CC_IS_CLANG=y $buildRoot/.config; then 242 + echo "Kernel config didn't recognize the clang compiler?" 243 + exit 1 244 + fi 245 + '' 246 + + lib.optionalString stdenv.cc.bintools.isLLVM '' 247 + if ! grep -Fq CONFIG_LD_IS_LLD=y $buildRoot/.config; then 248 + echo "Kernel config didn't recognize the LLVM linker?" 249 + exit 1 250 + fi 251 + '' 252 + + lib.optionalString withRust '' 253 + if ! grep -Fq CONFIG_RUST_IS_AVAILABLE=y $buildRoot/.config; then 254 + echo "Kernel config didn't find Rust toolchain?" 255 + exit 1 256 + fi 257 ''; 258 259 installPhase = "mv $buildRoot/.config $out";
+10 -16
pkgs/os-specific/linux/kernel/manual-config.nix
··· 170 ++ optional (lib.versionAtLeast version "5.13") zstd 171 ++ optionals withRust [ 172 rustc 173 - rust-bindgen 174 ]; 175 176 in ··· 230 ] 231 ++ optionals withRust [ 232 rustc 233 - rust-bindgen 234 ]; 235 236 RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc; ··· 531 // extraMeta; 532 }; 533 534 - # Absolute paths for compilers avoid any PATH-clobbering issues. 535 - commonMakeFlags = [ 536 - "ARCH=${stdenv.hostPlatform.linuxArch}" 537 - "CROSS_COMPILE=${stdenv.cc.targetPrefix}" 538 - ] 539 - ++ lib.optionals (stdenv.isx86_64 && stdenv.cc.bintools.isLLVM) [ 540 - # The wrapper for ld.lld breaks linking the kernel. We use the 541 - # unwrapped linker as workaround. See: 542 - # 543 - # https://github.com/NixOS/nixpkgs/issues/321667 544 - "LD=${stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ld" 545 - ] 546 - ++ (stdenv.hostPlatform.linux-kernel.makeFlags or [ ]) 547 - ++ extraMakeFlags; 548 in 549 550 stdenv.mkDerivation (
··· 170 ++ optional (lib.versionAtLeast version "5.13") zstd 171 ++ optionals withRust [ 172 rustc 173 + rust-bindgen.unwrapped 174 ]; 175 176 in ··· 230 ] 231 ++ optionals withRust [ 232 rustc 233 + rust-bindgen.unwrapped 234 ]; 235 236 RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc; ··· 531 // extraMeta; 532 }; 533 534 + commonMakeFlags = import ./common-flags.nix { 535 + inherit 536 + lib 537 + stdenv 538 + buildPackages 539 + extraMakeFlags 540 + ; 541 + }; 542 in 543 544 stdenv.mkDerivation (
+1
pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.cxx.nix
··· 102 license = licenses.gpl3Plus; 103 teams = [ teams.minimal-bootstrap ]; 104 platforms = platforms.unix; 105 }; 106 } 107 ''
··· 102 license = licenses.gpl3Plus; 103 teams = [ teams.minimal-bootstrap ]; 104 platforms = platforms.unix; 105 + mainProgram = "gcc"; 106 }; 107 } 108 ''
+1
pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.nix
··· 84 license = licenses.gpl3Plus; 85 teams = [ teams.minimal-bootstrap ]; 86 platforms = platforms.unix; 87 }; 88 } 89 ''
··· 84 license = licenses.gpl3Plus; 85 teams = [ teams.minimal-bootstrap ]; 86 platforms = platforms.unix; 87 + mainProgram = "gcc"; 88 }; 89 } 90 ''
+1
pkgs/os-specific/linux/minimal-bootstrap/gcc/8.nix
··· 101 license = licenses.gpl3Plus; 102 teams = [ teams.minimal-bootstrap ]; 103 platforms = platforms.unix; 104 }; 105 } 106 ''
··· 101 license = licenses.gpl3Plus; 102 teams = [ teams.minimal-bootstrap ]; 103 platforms = platforms.unix; 104 + mainProgram = "gcc"; 105 }; 106 } 107 ''
+1
pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix
··· 100 license = licenses.gpl3Plus; 101 teams = [ teams.minimal-bootstrap ]; 102 platforms = platforms.unix; 103 }; 104 } 105 ''
··· 100 license = licenses.gpl3Plus; 101 teams = [ teams.minimal-bootstrap ]; 102 platforms = platforms.unix; 103 + mainProgram = "gcc"; 104 }; 105 } 106 ''