linux: fix compiler selection (#402198)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
enablePlugin,
|
||||
disableGdbPlugin ? !enablePlugin,
|
||||
enableShared,
|
||||
targetPrefix,
|
||||
|
||||
langC,
|
||||
langCC,
|
||||
@@ -59,10 +60,6 @@ let
|
||||
crossDarwin =
|
||||
(!lib.systems.equals targetPlatform hostPlatform) && targetPlatform.libc == "libSystem";
|
||||
|
||||
targetPrefix = lib.optionalString (
|
||||
!lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform
|
||||
) "${stdenv.targetPlatform.config}-";
|
||||
|
||||
crossConfigureFlags =
|
||||
# Ensure that -print-prog-name is able to find the correct programs.
|
||||
[
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{ lib, version }:
|
||||
{
|
||||
lib,
|
||||
version,
|
||||
targetPrefix,
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
@@ -24,5 +28,6 @@ in
|
||||
|
||||
platforms = platforms.unix;
|
||||
teams = [ teams.gcc ];
|
||||
mainProgram = "${targetPrefix}gcc";
|
||||
|
||||
}
|
||||
|
||||
@@ -119,6 +119,10 @@ let
|
||||
!lib.systems.equals targetPlatform hostPlatform
|
||||
) "${targetPlatform.config}${stageNameAddon}-";
|
||||
|
||||
targetPrefix = lib.optionalString (
|
||||
!lib.systems.equals stdenv.targetPlatform stdenv.hostPlatform
|
||||
) "${stdenv.targetPlatform.config}-";
|
||||
|
||||
callFile = callPackageWith {
|
||||
# lets
|
||||
inherit
|
||||
@@ -340,7 +344,7 @@ pipe
|
||||
"target"
|
||||
];
|
||||
|
||||
configureFlags = callFile ./common/configure-flags.nix { };
|
||||
configureFlags = callFile ./common/configure-flags.nix { inherit targetPrefix; };
|
||||
|
||||
inherit targetConfig;
|
||||
|
||||
@@ -449,13 +453,14 @@ pipe
|
||||
inherit enableShared enableMultilib;
|
||||
|
||||
meta = {
|
||||
inherit (callFile ./common/meta.nix { })
|
||||
inherit (callFile ./common/meta.nix { inherit targetPrefix; })
|
||||
homepage
|
||||
license
|
||||
description
|
||||
longDescription
|
||||
platforms
|
||||
teams
|
||||
mainProgram
|
||||
;
|
||||
}
|
||||
// optionalAttrs (!atLeast11) {
|
||||
|
||||
@@ -14,7 +14,7 @@ in
|
||||
runCommand "zig-cc-${zig.version}"
|
||||
{
|
||||
pname = "zig-cc";
|
||||
inherit (zig) version meta;
|
||||
inherit (zig) version;
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
@@ -24,6 +24,10 @@ runCommand "zig-cc-${zig.version}"
|
||||
};
|
||||
|
||||
inherit zig;
|
||||
|
||||
meta = zig.meta // {
|
||||
mainProgram = "${targetPrefix}clang";
|
||||
};
|
||||
}
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -233,6 +236,24 @@ let
|
||||
KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \
|
||||
PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. MAKE_FLAGS="$makeFlags" \
|
||||
perl -w $generateConfig
|
||||
''
|
||||
+ lib.optionalString stdenv.cc.isClang ''
|
||||
if ! grep -Fq CONFIG_CC_IS_CLANG=y $buildRoot/.config; then
|
||||
echo "Kernel config didn't recognize the clang compiler?"
|
||||
exit 1
|
||||
fi
|
||||
''
|
||||
+ lib.optionalString stdenv.cc.bintools.isLLVM ''
|
||||
if ! grep -Fq CONFIG_LD_IS_LLD=y $buildRoot/.config; then
|
||||
echo "Kernel config didn't recognize the LLVM linker?"
|
||||
exit 1
|
||||
fi
|
||||
''
|
||||
+ lib.optionalString withRust ''
|
||||
if ! grep -Fq CONFIG_RUST_IS_AVAILABLE=y $buildRoot/.config; then
|
||||
echo "Kernel config didn't find Rust toolchain?"
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
|
||||
installPhase = "mv $buildRoot/.config $out";
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -102,6 +102,7 @@ bash.runCommand "${pname}-${version}"
|
||||
license = licenses.gpl3Plus;
|
||||
teams = [ teams.minimal-bootstrap ];
|
||||
platforms = platforms.unix;
|
||||
mainProgram = "gcc";
|
||||
};
|
||||
}
|
||||
''
|
||||
|
||||
@@ -84,6 +84,7 @@ bash.runCommand "${pname}-${version}"
|
||||
license = licenses.gpl3Plus;
|
||||
teams = [ teams.minimal-bootstrap ];
|
||||
platforms = platforms.unix;
|
||||
mainProgram = "gcc";
|
||||
};
|
||||
}
|
||||
''
|
||||
|
||||
@@ -101,6 +101,7 @@ bash.runCommand "${pname}-${version}"
|
||||
license = licenses.gpl3Plus;
|
||||
teams = [ teams.minimal-bootstrap ];
|
||||
platforms = platforms.unix;
|
||||
mainProgram = "gcc";
|
||||
};
|
||||
}
|
||||
''
|
||||
|
||||
@@ -100,6 +100,7 @@ bash.runCommand "${pname}-${version}"
|
||||
license = licenses.gpl3Plus;
|
||||
teams = [ teams.minimal-bootstrap ];
|
||||
platforms = platforms.unix;
|
||||
mainProgram = "gcc";
|
||||
};
|
||||
}
|
||||
''
|
||||
|
||||
Reference in New Issue
Block a user