Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.systems: introduce toolchain, cc, and bintools attributes #365057

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f8b6a50
lib.systems: introduce cc, bintools, cxxlib, unwinderlib, and rtlib a…
RossComputerGuy Jan 24, 2025
dd70d76
cc-wrapper: use new toolchain attributes
RossComputerGuy Jan 24, 2025
8ed961e
alsa-lib: use new toolchain attributes
RossComputerGuy Jan 24, 2025
2fe7a2d
cling: use new toolchain attributes
RossComputerGuy Jan 24, 2025
f595cd1
cyrus_sasl: use new toolchain attributes
RossComputerGuy Jan 24, 2025
4303e7c
elfutils: use new toolchain attributes
RossComputerGuy Jan 24, 2025
0024757
kexec-tools: use new toolchain attributes
RossComputerGuy Jan 24, 2025
944dea5
libseccomp: use new toolchain attributes
RossComputerGuy Jan 24, 2025
be6da8f
sourceHighlight: use new toolchain attributes
RossComputerGuy Jan 24, 2025
8c1131e
clang: use new toolchain attributes
RossComputerGuy Jan 24, 2025
ee4f416
compiler-rt: use new toolchain attributes
RossComputerGuy Jan 24, 2025
64976d4
llvmPackages: use new toolchain attributes
RossComputerGuy Jan 24, 2025
4577079
libcxx: use new toolchain attributes
RossComputerGuy Jan 24, 2025
79d1424
rust: use new toolchain attributes
RossComputerGuy Jan 24, 2025
13497dc
krb5: use new toolchain attributes
RossComputerGuy Jan 24, 2025
50422fa
libunwind: use new toolchain attributes
RossComputerGuy Jan 24, 2025
e8848c9
libva: use new toolchain attributes
RossComputerGuy Jan 24, 2025
ec7e5fd
openssl: use new toolchain attributes
RossComputerGuy Jan 24, 2025
acb6e15
quictls: use new toolchain attributes
RossComputerGuy Jan 24, 2025
604cf6b
graphite2: use new toolchain attributes
RossComputerGuy Jan 24, 2025
402a6f0
pythonPackages.jedi: use new toolchain attributes
RossComputerGuy Jan 24, 2025
5a742d3
pythonPackages.mako: use new toolchain attributes
RossComputerGuy Jan 24, 2025
82bf960
systemd: use new toolchain attributes
RossComputerGuy Jan 24, 2025
33a1aea
windows.crossThreadsStdenv: use new toolchain attributes
RossComputerGuy Jan 24, 2025
5180289
xorg.{libX11,libXt}: use new toolchain attributes
RossComputerGuy Jan 24, 2025
442cabd
pkgs/stdenv/cross/default.nix: use new toolchain attributes
RossComputerGuy Jan 24, 2025
fbd0032
stdenvNoLibs: use new toolchain attributes
RossComputerGuy Jan 24, 2025
1f177a7
stdenvNoLibc: use new toolchain attributes
RossComputerGuy Jan 24, 2025
a436f63
gccWithoutTargetLibc: use new toolchain attributes
RossComputerGuy Jan 24, 2025
0f89421
threadsCross: use new toolchain attributes
RossComputerGuy Jan 24, 2025
d74fade
libcxxrt: use new toolchain attributes
RossComputerGuy Jan 24, 2025
12543fe
busybox: use new toolchain attributes
RossComputerGuy Jan 24, 2025
dc8f207
pkgs/top-level/stage.nix: use new toolchain attributes
RossComputerGuy Jan 24, 2025
2315a77
xwayland: use new toolchain attributes
RossComputerGuy Feb 19, 2025
75e5d73
nixVersions.nix_2_26: use new toolchain attributes
RossComputerGuy Feb 19, 2025
019a73b
rutabaga_gfx: use new toolchain attributes
RossComputerGuy Feb 19, 2025
5200443
pythonPackages.cffi: use new toolchain attributes
RossComputerGuy Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,60 @@ let
# `parsed` is inferred from args, both because there are two options with one
# clearly preferred, and to prevent cycles. A simpler fixed point where the RHS
# always just used `final.*` would fail on both counts.
elaborate = systemOrArgs: let
elaborate = systemOrArgs:
assert lib.assertMsg (!(lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useZig)) "The useZig attribute has been deprecated in favor of the toolchain attributes.";
let
allArgs = systemToAttrs systemOrArgs;

# Those two will always be derived from "config", if given, so they should NOT
# be overridden further down with "// args".
args = builtins.removeAttrs allArgs [ "parsed" "system" ];
args = lib.pipe (builtins.removeAttrs allArgs [ "parsed" "system" ]) [
(lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useLLVM) "The useLLVM attribute has been deprecated in favor of the toolchain attributes.")
(lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useArocc) "The useArocc attribute has been deprecated in favor of the toolchain attributes.")
(lib.warnIf (lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useZig) "The useZig attribute has been deprecated in favor of the toolchain attributes.")
];

# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
rust = args.rust or args.rustc or {};

toolchain = {
cc = if final.useLLVM || final.isDarwin then "clang"
else if final.useArocc then "arocc"
else if final.useZig then "zig"
else "gcc";

bintools = if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then
"llvm"
else "gnu";

cxxlib =
/**/ if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then "libcxx"
else "libstdcxx";

unwinderlib =
/**/ if final.useLLVM || final.useArocc || final.useZig then "libunwind"
else if final.isDarwin then "libunwind-system"
else "libgcc_s";

rtlib =
/**/ if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then "compiler-rt"
else "libgcc";

# Choose what linker we wish to use by default. Someday we might also
# choose the C compiler, runtime library, C++ standard library, etc. in
# this way, nice and orthogonally, and deprecate `useLLVM`. But due to
# the monolithic GCC build we cannot actually make those choices
# independently, so we are just doing `linker` and keeping `useLLVM` for
# now.
linker =
/**/ if final.useLLVM then "lld"
else if final.isDarwin 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.
else "bfd";
};

final = {
# Prefer to parse `config` as it is strictly more informative.
parsed = parse.mkSystemFromString (args.config or allArgs.system);
Expand All @@ -92,6 +136,8 @@ let
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;
useArocc = false;
useZig = false;

libc =
/**/ if final.isDarwin then "libSystem"
Expand All @@ -112,19 +158,7 @@ let
else if final.isNone then "newlib"
# TODO(@Ericson2314) think more about other operating systems
else "native/impure";
# Choose what linker we wish to use by default. Someday we might also
# choose the C compiler, runtime library, C++ standard library, etc. in
# this way, nice and orthogonally, and deprecate `useLLVM`. But due to
# the monolithic GCC build we cannot actually make those choices
# 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"
# "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.
else "bfd";

# The standard lib directory name that non-nixpkgs binaries distributed
# for this platform normally assume.
libDir = if final.isLinux then
Expand Down Expand Up @@ -318,7 +352,7 @@ let

}) // mapAttrs (n: v: v final.parsed) inspect.predicates
// mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates
// args // {
// toolchain // args // {
rust = rust // {
# Once args.rustc.platform.target-family is deprecated and
# removed, there will no longer be any need to modify any
Expand Down Expand Up @@ -430,6 +464,7 @@ let
else throw message)
true
(final.parsed.abi.assertions or []);
assert (lib.listToAttrs (lib.map (key: lib.nameValuePair key final.${key}) (lib.attrNames toolchain))) == toolchain;
final;

in
Expand Down
5 changes: 2 additions & 3 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ let

useGccForLibs = useCcForLibs
&& libcxx == null
&& !targetPlatform.isDarwin
&& !(targetPlatform.useLLVM or false)
&& targetPlatform.rtlib == "libgcc"
&& !(targetPlatform.useAndroidPrebuilt or false)
&& !(targetPlatform.isiOS or false)
&& gccForLibs != null;
Expand Down Expand Up @@ -520,7 +519,7 @@ stdenvNoCC.mkDerivation {
+ optionalString (isClang
&& targetPlatform.isLinux
&& !(targetPlatform.useAndroidPrebuilt or false)
&& !(targetPlatform.useLLVM or false)
&& targetPlatform.rtlib == "libgcc"
&& gccForLibs != null) (''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags

Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/al/alsa-lib/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stdenv.mkDerivation (finalAttrs: {
# order to support apps with 32bit sound running on x86_64 architecture.
./alsa-plugin-conf-multilib.patch
]
++ lib.optional (stdenv.hostPlatform.useLLVM or false)
++ lib.optional (stdenv.hostPlatform.linker == "lld")
# Fixes version script under LLVM, should be fixed in the next update.
# Check if "pkgsLLVM.alsa-lib" builds on next version bump and remove this
# if it succeeds.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/cl/cling/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Build with libc++ (LLVM) rather than stdlibc++ (GCC).
# This is experimental and not all features work.
useLLVMLibcxx ? clangStdenv.hostPlatform.isDarwin,
useLLVMLibcxx ? clangStdenv.hostPlatform.cxxlib == "libcxx",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing, since clangStdenv is precisely the one that doesn’t use libc++ by default. But I guess you could override it? (Does it work?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this works, I'm kinda thinking of dropping the useLLVMLibcxx attribute and making an override of the stdenv be required but it is handy to be able to switch it easily.

}:

let
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.hostPlatform.cc == "clang" && stdenv.hostPlatform.libc == "glibc") [
"--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 @@ -63,7 +63,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.cxxlib == "libcxx") ./cxx-header-collision.patch;

postPatch =
''
Expand Down Expand Up @@ -94,7 +94,7 @@ stdenv.mkDerivation rec {
bzip2
]
++ lib.optional enableDebuginfod pkg-config
++ lib.optional (stdenv.targetPlatform.useLLVM or false) autoreconfHook;
++ lib.optional (stdenv.targetPlatform.cxxlib == "libcxx") autoreconfHook;
buildInputs =
[
zlib
Expand Down Expand Up @@ -128,7 +128,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.cxxlib == "libcxx") "--disable-demangler"
++ lib.optionals stdenv.cc.isClang [
"CFLAGS=-Wno-unused-private-field"
"CXXFLAGS=-Wno-unused-private-field"
Expand Down
18 changes: 11 additions & 7 deletions pkgs/by-name/ke/kexec-tools/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ stdenv.mkDerivation rec {
sha256 = "sha256-Z7GsUDqt5FpU2wvHkiiogwo11dT4PO6TLP8+eoGkqew=";
};

patches = [
# Use ELFv2 ABI on ppc64be
(fetchpatch {
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;
patches =
[
# Use ELFv2 ABI on ppc64be
(fetchpatch {
url = "https://raw.githubusercontent.com/void-linux/void-packages/6c1192cbf166698932030c2e3de71db1885a572d/srcpkgs/kexec-tools/patches/ppc64-elfv2.patch";
sha256 = "19wzfwb0azm932v0vhywv4221818qmlmvdfwpvvpfyw4hjsc2s1l";
})
]
++ lib.optional (
stdenv.hostPlatform.unwinderlib == "libunwind"
) ./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
2 changes: 1 addition & 1 deletion pkgs/by-name/ru/rutabaga_gfx/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ stdenv.mkDerivation (finalAttrs: {
./link-cxx.patch
];

env = lib.optionalAttrs stdenv.hostPlatform.useLLVM {
env = lib.optionalAttrs (stdenv.hostPlatform.cxxlib == "libcxx" && !stdenv.hostPlatform.isDarwin) {
USE_CLANG = true;
};

Expand Down
18 changes: 9 additions & 9 deletions pkgs/by-name/so/sourceHighlight/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ];
buildInputs =
[ boost ]
++ lib.optional (stdenv.targetPlatform.useLLVM or false) (
llvmPackages.compiler-rt.override {
doFakeLibgcc = true;
}
);
++ lib.optional (
stdenv.hostPlatform.rtlib == "compiler-rt" && !stdenv.hostPlatform.isDarwin
) llvmPackages.compiler-rt;

configureFlags = [
"--with-boost=${boost.out}"
Expand All @@ -92,7 +90,9 @@ stdenv.mkDerivation rec {
maintainers = with maintainers; [ SuperSandro2000 ];
};
}
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
# Force linking to "libgcc" so tests pass
NIX_CFLAGS_COMPILE = "-lgcc";
}
//
lib.optionalAttrs (stdenv.targetPlatform.rtlib == "compiler-rt" && !stdenv.hostPlatform.isDarwin)
{
# Force linking to "libgcc" so tests pass
NIX_CFLAGS_COMPILE = "-lgcc";
}
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/common/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ let
ninjaFlags = [ "docs-clang-man" ];
}))
// (lib.optionalAttrs (lib.versionAtLeast release_version "15") {
env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM) {
env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && stdenv.hostPlatform.cc != "clang") {
# The following warning is triggered with (at least) gcc >=
# 12, but appears to occur only for cross compiles.
NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized";
Expand Down
13 changes: 6 additions & 7 deletions pkgs/development/compilers/llvm/common/compiler-rt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

let

useLLVM = stdenv.hostPlatform.useLLVM or false;
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 Expand Up @@ -92,22 +91,22 @@ stdenv.mkDerivation {
"-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}"
] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [
"-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include"
] ++ lib.optionals (useLLVM && haveLibc && stdenv.cc.libcxx == libcxx) [
] ++ lib.optionals (stdenv.hostPlatform.cxxlib == "libcxx" && haveLibc && stdenv.cc.libcxx == libcxx && !stdenv.hostPlatform.isDarwin) [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually right for these to skip Darwin? cc @reckenrode

This will presumably want to look at cxxrtlib given the libcxxabi references below.

"-DSANITIZER_CXX_ABI=libcxxabi"
"-DSANITIZER_CXX_ABI_LIBNAME=libcxxabi"
"-DCOMPILER_RT_USE_BUILTINS_LIBRARY=ON"
] ++ lib.optionals ((!haveLibc || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")) [
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
] ++ lib.optionals (useLLVM && haveLibc) [
] ++ lib.optionals (stdenv.hostPlatform.rtlib == "compiler-rt" && haveLibc && !stdenv.hostPlatform.isDarwin) [
"-DCOMPILER_RT_BUILD_SANITIZERS=ON"
] ++ lib.optionals (noSanitizers) [
"-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
] ++ lib.optionals ((useLLVM && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [
] ++ lib.optionals ((stdenv.hostPlatform.rtlib == "compiler-rt" && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [
"-DCOMPILER_RT_BUILD_XRAY=OFF"
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
"-DCOMPILER_RT_BUILD_MEMPROF=OFF"
"-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary
] ++ lib.optionals (useLLVM && haveLibc) [
] ++ lib.optionals (stdenv.hostPlatform.rtlib == "compiler-rt" && haveLibc && !stdenv.hostPlatform.isDarwin) [
"-DCOMPILER_RT_BUILD_PROFILE=ON"
] ++ lib.optionals (!haveLibc || bareMetal) [
"-DCOMPILER_RT_BUILD_PROFILE=OFF"
Expand All @@ -119,7 +118,7 @@ stdenv.mkDerivation {
"-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}"
] ++ lib.optionals (!haveLibc) [
"-DCMAKE_C_FLAGS=-nodefaultlibs"
] ++ lib.optionals (useLLVM) [
] ++ lib.optionals (stdenv.hostPlatform.rtlib == "compiler-rt" && !stdenv.hostPlatform.isDarwin) [
"-DCOMPILER_RT_BUILD_BUILTINS=ON"
#https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
"-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
Expand Down Expand Up @@ -191,7 +190,7 @@ stdenv.mkDerivation {
# Hack around weird upsream RPATH bug
postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) ''
ln -s "$out/lib"/*/* "$out/lib"
'' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) ''
'' + lib.optionalString (stdenv.hostPlatform.rtlib == "compiler-rt" && stdenv.hostPlatform.isLinux) ''
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
# Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
Expand Down
Loading