linux: un-simplify toolchain selection

This reverts commit 70cc251554.

This commit caused gcc to be pulled in as a target compiler for
pkgsLLVM.

Co-authored-by: Tristan Ross <tristan.ross@midstall.com>
This commit is contained in:
Julian Stecklina
2025-03-19 12:26:02 +01:00
committed by Tristan Ross
parent a155990361
commit e9b2edb491
4 changed files with 56 additions and 23 deletions
@@ -525,7 +525,9 @@ let
DRM_AMD_DC_DCN = lib.mkIf (with stdenv.hostPlatform; isx86 || isPower64) (
whenBetween "5.11" "6.4" yes
);
DRM_AMD_DC_FP = whenAtLeast "6.4" yes;
# Not available when using clang
# See: https://github.com/torvalds/linux/blob/172a9d94339cea832d89630b89d314e41d622bd8/drivers/gpu/drm/amd/display/Kconfig#L14
DRM_AMD_DC_FP = lib.mkIf (!stdenv.cc.isClang) (whenAtLeast "6.4" yes);
DRM_AMD_DC_HDCP = whenBetween "5.5" "6.4" yes;
DRM_AMD_DC_SI = whenAtLeast "5.10" yes;
@@ -0,0 +1,34 @@
{
lib,
stdenv,
buildPackages,
extraMakeFlags ? [ ],
}:
# Absolute paths for compilers avoid any PATH-clobbering issues.
[
#
# We use the unwrapped compiler, because the clang-wrapper doesn't like -target.
"CC=${lib.getExe stdenv.cc.cc}"
# The wrapper for ld.lld breaks linking the kernel. We use the unwrapped linker as workaround. See:
# https://github.com/NixOS/nixpkgs/issues/321667
"LD=${lib.getExe' stdenv.cc.bintools.bintools "${stdenv.cc.targetPrefix}ld"}"
"AR=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}ar"}"
"NM=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}nm"}"
"STRIP=${lib.getExe' stdenv.cc.bintools.bintools "${stdenv.cc.targetPrefix}strip"}"
"OBJCOPY=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}objcopy"}"
"OBJDUMP=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}objdump"}"
"READELF=${lib.getExe' stdenv.cc "${stdenv.cc.targetPrefix}readelf"}"
"HOSTCC=${lib.getExe' buildPackages.stdenv.cc "${buildPackages.stdenv.cc.targetPrefix}cc"}"
"HOSTCXX=${lib.getExe' buildPackages.stdenv.cc "${buildPackages.stdenv.cc.targetPrefix}c++"}"
"HOSTAR=${lib.getExe' buildPackages.stdenv.cc.bintools "${buildPackages.stdenv.cc.targetPrefix}ar"}"
"HOSTLD=${lib.getExe' buildPackages.stdenv.cc.bintools "${buildPackages.stdenv.cc.targetPrefix}ld"}"
"ARCH=${stdenv.hostPlatform.linuxArch}"
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
]
# Add the built in headers the kernel needs
++ lib.optionals (stdenv.cc.isClang) [
"CFLAGS_MODULE=-I${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include"
"CFLAGS_KERNEL=-I${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include"
]
++ (stdenv.hostPlatform.linux-kernel.makeFlags or [ ])
++ extraMakeFlags
+9 -6
View File
@@ -191,7 +191,7 @@ let
++ lib.optional (lib.versionAtLeast version "5.2") pahole
++ lib.optionals withRust [
rust-bindgen
rustc
rustc.unwrapped
];
RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc;
@@ -201,11 +201,14 @@ let
kernelBaseConfig =
if defconfig != null then defconfig else stdenv.hostPlatform.linux-kernel.baseConfig;
makeFlags =
lib.optionals (
stdenv.hostPlatform.linux-kernel ? makeFlags
) stdenv.hostPlatform.linux-kernel.makeFlags
++ extraMakeFlags;
makeFlags = import ./common-flags.nix {
inherit
lib
stdenv
buildPackages
extraMakeFlags
;
};
postPatch = kernel.postPatch + ''
# Patch kconfig to print "###" after every question so that
+10 -16
View File
@@ -170,7 +170,7 @@ lib.makeOverridable (
++ optional (lib.versionAtLeast version "5.13") zstd
++ optionals withRust [
rustc
rust-bindgen
rust-bindgen.unwrapped
];
in
@@ -230,7 +230,7 @@ lib.makeOverridable (
]
++ optionals withRust [
rustc
rust-bindgen
rust-bindgen.unwrapped
];
RUST_LIB_SRC = lib.optionalString withRust rustPlatform.rustLibSrc;
@@ -531,20 +531,14 @@ lib.makeOverridable (
// extraMeta;
};
# Absolute paths for compilers avoid any PATH-clobbering issues.
commonMakeFlags = [
"ARCH=${stdenv.hostPlatform.linuxArch}"
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
]
++ lib.optionals (stdenv.isx86_64 && stdenv.cc.bintools.isLLVM) [
# The wrapper for ld.lld breaks linking the kernel. We use the
# unwrapped linker as workaround. See:
#
# https://github.com/NixOS/nixpkgs/issues/321667
"LD=${stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ld"
]
++ (stdenv.hostPlatform.linux-kernel.makeFlags or [ ])
++ extraMakeFlags;
commonMakeFlags = import ./common-flags.nix {
inherit
lib
stdenv
buildPackages
extraMakeFlags
;
};
in
stdenv.mkDerivation (