Skip to content

Commit

Permalink
lib.systems: introduce toolchain, cc, and bintools attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Dec 14, 2024
1 parent d237fee commit cbea667
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 53 deletions.
18 changes: 15 additions & 3 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@ let
&& final.parsed.kernel == platform.parsed.kernel;
isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";
# Derived meta-data
useLLVM = final.isFreeBSD || final.isOpenBSD;

toolchain =
/**/ if final.isDarwin then "apple"
else if final.isFreeBSD || final.isOpenBSD then "llvm"
else "gnu";

cc = if final.toolchain == "apple" || final.toolchain == "llvm" then
"clang"
else "gcc";

bintools = if final.toolchain == "apple" || final.toolchain == "bintools" then
"llvm"
else "gnu";

libc =
/**/ if final.isDarwin then "libSystem"
Expand All @@ -118,8 +130,8 @@ let
# independently, so we are just doing `linker` and keeping `useLLVM` for
# now.
linker =
/**/ if final.useLLVM or false then "lld"
else if final.isDarwin then "cctools"
/**/ if final.toolchain == "llvm" then "lld"
else if final.toolchain == "apple" then "cctools"
# "bfd" and "gold" both come from GNU binutils. The existence of Gold
# is why we use the more obscure "bfd" and not "binutils" for this
# choice.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let
useGccForLibs = useCcForLibs
&& libcxx == null
&& !targetPlatform.isDarwin
&& !(targetPlatform.useLLVM or false)
&& !(targetPlatform.cc == "clang")
&& !(targetPlatform.useAndroidPrebuilt or false)
&& !(targetPlatform.isiOS or false)
&& gccForLibs != null;
Expand Down Expand Up @@ -514,7 +514,7 @@ stdenvNoCC.mkDerivation {
+ optionalString (isClang
&& targetPlatform.isLinux
&& !(targetPlatform.useAndroidPrebuilt or false)
&& !(targetPlatform.useLLVM or false)
&& !(targetPlatform.cc == "clang")
&& gccForLibs != null) (''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/cy/cyrus_sasl/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ stdenv.mkDerivation rec {
"--enable-shared"
]
++ lib.optional enableLdap "--with-ldap=${openldap.dev}"
++ lib.optionals (stdenv.targetPlatform.useLLVM or false) [
++ lib.optionals (stdenv.targetPlatform.cc == "clang") [
"--disable-sample"
"CFLAGS=-DTIME_WITH_SYS_TIME"
];
Expand Down
6 changes: 3 additions & 3 deletions pkgs/by-name/el/elfutils/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
++ lib.optionals stdenv.hostPlatform.isMusl [ ./musl-error_h.patch ]
# Prevent headers and binaries from colliding which results in an error.
# https://sourceware.org/pipermail/elfutils-devel/2024q3/007281.html
++ lib.optional (stdenv.targetPlatform.useLLVM or false) ./cxx-header-collision.patch;
++ lib.optional (stdenv.targetPlatform.cc == "clang") ./cxx-header-collision.patch;

postPatch =
''
Expand Down Expand Up @@ -93,7 +93,7 @@ stdenv.mkDerivation rec {
bzip2
]
++ lib.optional enableDebuginfod pkg-config
++ lib.optional (stdenv.targetPlatform.useLLVM or false) autoreconfHook;
++ lib.optional (stdenv.targetPlatform.cc == "clang") autoreconfHook;
buildInputs =
[
zlib
Expand Down Expand Up @@ -126,7 +126,7 @@ stdenv.mkDerivation rec {
# Versioned symbols are nice to have, but we can do without.
(lib.enableFeature (!stdenv.hostPlatform.isMicroBlaze) "symbol-versioning")
]
++ lib.optional (stdenv.targetPlatform.useLLVM or false) "--disable-demangler"
++ lib.optional (stdenv.targetPlatform.cc == "clang") "--disable-demangler"
++ lib.optionals stdenv.cc.isClang [
"CFLAGS=-Wno-unused-private-field"
"CXXFLAGS=-Wno-unused-private-field"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/ke/kexec-tools/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stdenv.mkDerivation rec {
url = "https://raw.githubusercontent.com/void-linux/void-packages/6c1192cbf166698932030c2e3de71db1885a572d/srcpkgs/kexec-tools/patches/ppc64-elfv2.patch";
sha256 = "19wzfwb0azm932v0vhywv4221818qmlmvdfwpvvpfyw4hjsc2s1l";
})
] ++ lib.optional (stdenv.hostPlatform.useLLVM or false) ./fix-purgatory-llvm-libunwind.patch;
] ++ lib.optional (stdenv.hostPlatform.cc == "clang") ./fix-purgatory-llvm-libunwind.patch;

hardeningDisable = [
"format"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/li/libseccomp/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
util-linuxMinimal
which
];
doCheck = !(stdenv.targetPlatform.useLLVM or false);
doCheck = !(stdenv.targetPlatform.cc == "clang");

# Hack to ensure that patchelf --shrink-rpath get rids of a $TMPDIR reference.
preFixup = "rm -rfv src";
Expand Down
4 changes: 2 additions & 2 deletions pkgs/by-name/so/sourceHighlight/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ];
buildInputs =
[ boost ]
++ lib.optional (stdenv.targetPlatform.useLLVM or false) (
++ lib.optional (stdenv.targetPlatform.cc == "clang") (
llvmPackages.compiler-rt.override {
doFakeLibgcc = true;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ stdenv.mkDerivation rec {
maintainers = with maintainers; [ SuperSandro2000 ];
};
}
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
// lib.optionalAttrs (stdenv.targetPlatform.cc == "clang") {
# Force linking to "libgcc" so tests pass
NIX_CFLAGS_COMPILE = "-lgcc";
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

let

useLLVM = stdenv.hostPlatform.useLLVM or false;
useLLVM = stdenv.hostPlatform.cc == "clang";
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
haveLibc = stdenv.cc.libc != null;
# TODO: Make this account for GCC having libstdcxx, which will help
Expand Down
16 changes: 8 additions & 8 deletions pkgs/development/compilers/llvm/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ let
clang =
if stdenv.targetPlatform.libc == null then
tools.clangNoLibc
else if stdenv.targetPlatform.useLLVM or false then
else if stdenv.targetPlatform.toolchain == "llvm" then
tools.clangUseLLVM
else if (pkgs.targetPackages.stdenv or args.stdenv).cc.isGNU then
tools.libstdcxxClang
Expand Down Expand Up @@ -780,7 +780,7 @@ let
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
echo "-L${targetLlvmLibraries.libunwind}/lib" >> $out/nix-support/cc-ldflags
''
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.cc == "clang") ''
echo "-lunwind" >> $out/nix-support/cc-ldflags
''
+ lib.optionalString stdenv.targetPlatform.isWasm ''
Expand All @@ -802,7 +802,7 @@ let
++ lib.optional (
!stdenv.targetPlatform.isWasm
&& !stdenv.targetPlatform.isFreeBSD
&& stdenv.targetPlatform.useLLVM or false
&& stdenv.targetPlatform.cc == "clang"
) "-lunwind"
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
nixSupport.cc-ldflags = lib.optionals (
Expand Down Expand Up @@ -835,7 +835,7 @@ let
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
echo "-L${targetLlvmLibraries.libunwind}/lib" >> $out/nix-support/cc-ldflags
''
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.cc == "clang") ''
echo "-lunwind" >> $out/nix-support/cc-ldflags
''
+ lib.optionalString stdenv.targetPlatform.isWasm ''
Expand All @@ -857,7 +857,7 @@ let
++ lib.optional (
!stdenv.targetPlatform.isWasm
&& !stdenv.targetPlatform.isFreeBSD
&& stdenv.targetPlatform.useLLVM or false
&& stdenv.targetPlatform.cc == "clang"
) "-lunwind"
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
nixSupport.cc-ldflags = lib.optionals (
Expand Down Expand Up @@ -1073,7 +1073,7 @@ let
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if args.stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else if args.stdenv.hostPlatform.useLLVM or false then
else if args.stdenv.hostPlatform.cc == "clang" then
overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else
args.stdenv;
Expand All @@ -1082,7 +1082,7 @@ let
patches = compiler-rtPatches;
inherit stdenv;
}
// lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
// lib.optionalAttrs (stdenv.hostPlatform.cc == "clang") {
libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--disable-symvers" ];
});
Expand All @@ -1091,7 +1091,7 @@ let

compiler-rt-no-libc = callPackage ./compiler-rt {
patches = compiler-rtPatches;
doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
doFakeLibgcc = stdenv.hostPlatform.cc == "clang";
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if stdenv.hostPlatform.isDarwin then
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/common/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let
runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi";

# Note: useLLVM is likely false for Darwin but true under pkgsLLVM
useLLVM = stdenv.hostPlatform.useLLVM or false;
useLLVM = stdenv.hostPlatform.cc == "clang";

src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} (''
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/rust/1_82.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let
{
enableSharedLibraries = true;
}
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
// lib.optionalAttrs (stdenv.targetPlatform.cc == "clang") {
# Force LLVM to compile using clang + LLVM libs when targeting pkgsLLVM
stdenv = pkgSet.stdenv.override {
allowedRequisites = null;
Expand All @@ -60,7 +60,7 @@ import ./default.nix

# Expose llvmPackages used for rustc from rustc via passthru for LTO in Firefox
llvmPackages =
if (stdenv.targetPlatform.useLLVM or false) then
if (stdenv.targetPlatform.cc == "clang") then
callPackage (
{
pkgs,
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let
concatStringsSep
;
inherit (darwin.apple_sdk.frameworks) Security;
useLLVM = stdenv.targetPlatform.useLLVM or false;
useLLVM = stdenv.targetPlatform.cc == "clang";
in
stdenv.mkDerivation (finalAttrs: {
pname = "${targetPackages.stdenv.cc.targetPrefix}rustc";
Expand Down Expand Up @@ -207,7 +207,7 @@ stdenv.mkDerivation (finalAttrs: {
# doesn't work) to build a linker.
"--disable-llvm-bitcode-linker"
]
++ optionals (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) [
++ optionals (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.cc == "clang")) [
"--enable-profiler" # build libprofiler_builtins
]
++ optionals stdenv.buildPlatform.isMusl [
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/kerberos/krb5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ stdenv.mkDerivation rec {
++ lib.optionals (
stdenv.hostPlatform.isLinux
&& stdenv.hostPlatform.libc != "bionic"
&& !(stdenv.hostPlatform.useLLVM or false)
&& !(stdenv.hostPlatform.cc == "clang")
) [ keyutils ]
++ lib.optionals withLdap [ openldap ]
++ lib.optionals withLibedit [ libedit ]
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/libunwind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-rCFBHs6rCSnp5FEwbUR5veNNTqSQpFblAv8ebSPX0qE=";
};

patches = lib.optional (stdenv.targetPlatform.useLLVM or false) (fetchpatch {
patches = lib.optional (stdenv.targetPlatform.cc == "clang") (fetchpatch {
url = "https://github.com/libunwind/libunwind/pull/770/commits/a69d0f14c9e6c46e82ba6e02fcdedb2eb63b7f7f.patch";
hash = "sha256-9oBZimCXonNN++jJs3emp9w+q1aj3eNzvSKPgh92itA=";
});
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/libva/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ stdenv.mkDerivation (finalAttrs: {
{
NIX_LDFLAGS = "--undefined-version";
}
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
// lib.optionalAttrs (stdenv.targetPlatform.cc == "clang") {
NIX_CFLAGS_COMPILE = "-DHAVE_SECURE_GETENV";
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/openssl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ let
++ lib.optional static "etc";
setOutputFlags = false;
separateDebugInfo =
!stdenv.hostPlatform.isDarwin && !(stdenv.hostPlatform.useLLVM or false) && stdenv.cc.isGNU;
!stdenv.hostPlatform.isDarwin && !(stdenv.hostPlatform.cc == "clang") && stdenv.cc.isGNU;

nativeBuildInputs =
lib.optional (!stdenv.hostPlatform.isWindows) makeBinaryWrapper
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/quictls/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ stdenv.mkDerivation rec {

separateDebugInfo =
!stdenv.hostPlatform.isDarwin &&
!(stdenv.hostPlatform.useLLVM or false) &&
!(stdenv.hostPlatform.cc == "clang") &&
stdenv.cc.isGNU;

# TODO(@Ericson2314): Improve with mass rebuild
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/silgraphite/graphite2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ stdenv.mkDerivation (finalAttrs: {
];
buildInputs =
[ freetype ]
++ lib.optional (stdenv.targetPlatform.useLLVM or false) (
++ lib.optional (stdenv.targetPlatform.cc == "clang") (
llvmPackages.compiler-rt.override {
doFakeLibgcc = true;
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/jedi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ buildPythonPackage rec {
# AssertionError: assert 'foo' in ['setup']
"test_init_extension_module"
]
++ lib.optionals (stdenv.targetPlatform.useLLVM or false) [
++ lib.optionals (stdenv.targetPlatform.cc == "clang") [
# InvalidPythonEnvironment: The python binary is potentially unsafe.
"test_create_environment_executable"
# AssertionError: assert ['', '.1000000000000001'] == ['', '.1']
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/mako/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ buildPythonPackage rec {
"test_bytestring_passthru"
]
# https://github.com/sqlalchemy/mako/issues/408
++ lib.optional (stdenv.targetPlatform.useLLVM or false) "test_future_import";
++ lib.optional (stdenv.targetPlatform.cc == "clang") "test_future_import";

meta = with lib; {
description = "Super-fast templating language";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/systemd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ stdenv.mkDerivation (finalAttrs: {
++ lib.optionals withPasswordQuality [ libpwquality ]
++ lib.optionals withQrencode [ qrencode ]
++ lib.optionals withLibarchive [ libarchive ]
++ lib.optional (withBootloader && stdenv.targetPlatform.useLLVM or false) (llvmPackages.compiler-rt.override {
++ lib.optional (withBootloader && stdenv.targetPlatform.cc == "clang") (llvmPackages.compiler-rt.override {
doFakeLibgcc = true;
})
;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/windows/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lib.makeScope newScope (

# FIXME untested with llvmPackages_16 was using llvmPackages_8
crossThreadsStdenv = overrideCC stdenvNoLibc (
if stdenv.hostPlatform.useLLVM or false then
if stdenv.hostPlatform.cc == "clang" then
buildPackages.llvmPackages.clangNoLibcxx
else
buildPackages.gccWithoutTargetLibc.override (old: {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/servers/x11/xorg/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ self: super:
];
configureFlags = attrs.configureFlags or []
++ malloc0ReturnsNullCrossFlag
++ lib.optional (stdenv.targetPlatform.useLLVM or false) "ac_cv_path_RAWCPP=cpp";
++ lib.optional (stdenv.targetPlatform.cc == "clang") "ac_cv_path_RAWCPP=cpp";
depsBuildBuild = [
buildPackages.stdenv.cc
] ++ lib.optionals stdenv.hostPlatform.isStatic [
Expand Down Expand Up @@ -269,7 +269,7 @@ self: super:
'';
configureFlags = attrs.configureFlags or []
++ malloc0ReturnsNullCrossFlag
++ lib.optional (stdenv.targetPlatform.useLLVM or false) "ac_cv_path_RAWCPP=cpp";
++ lib.optional (stdenv.targetPlatform.cc == "clang") "ac_cv_path_RAWCPP=cpp";
propagatedBuildInputs = attrs.propagatedBuildInputs or [] ++ [ xorg.libSM ];
depsBuildBuild = [ buildPackages.stdenv.cc ];
CPP = if stdenv.hostPlatform.isDarwin then "clang -E -" else "${stdenv.cc.targetPrefix}cc -E -";
Expand Down
10 changes: 6 additions & 4 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ lib.init bootStages
throw "no C compiler provided for this platform"
else if crossSystem.isDarwin then
buildPackages.llvmPackages.libcxxClang
else if crossSystem.useLLVM or false then
else if crossSystem.cc == "clang" then
buildPackages.llvmPackages.clang
else if crossSystem.useZig or false then
else if crossSystem.cc == "zig" then
buildPackages.zig.cc
else if crossSystem.useArocc or false then
else if crossSystem.cc == "arocc" then
buildPackages.arocc
else if crossSystem.cc == "gcc" then
buildPackages.gcc
else
buildPackages.gcc;
throw "no C compiler provided for this platform";

};
in
Expand Down
Loading

0 comments on commit cbea667

Please sign in to comment.