Skip to content

Commit eeed51a

Browse files
lib.systems: introduce cc, bintools, cxxlib, unwinderlib, and rtlib attributes
1 parent 564ebca commit eeed51a

File tree

30 files changed

+211
-115
lines changed

30 files changed

+211
-115
lines changed

lib/systems/default.nix

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ let
6666
# `parsed` is inferred from args, both because there are two options with one
6767
# clearly preferred, and to prevent cycles. A simpler fixed point where the RHS
6868
# always just used `final.*` would fail on both counts.
69-
elaborate = systemOrArgs: let
69+
elaborate = systemOrArgs:
70+
assert lib.assertMsg (!(lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useLLVM)) "The useLLVM attribute has been deprecated in favor of the toolchain attributes.";
71+
assert lib.assertMsg (!(lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useArocc)) "The useArocc attribute has been deprecated in favor of the toolchain attributes.";
72+
assert lib.assertMsg (!(lib.oldestSupportedReleaseIsAtLeast 2511 && systemOrArgs ? useZig)) "The useZig attribute has been deprecated in favor of the toolchain attributes.";
73+
let
7074
allArgs = systemToAttrs systemOrArgs;
7175

7276
# Those two will always be derived from "config", if given, so they should NOT
@@ -92,6 +96,21 @@ let
9296
isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details";
9397
# Derived meta-data
9498
useLLVM = final.isFreeBSD || final.isOpenBSD;
99+
useArocc = false;
100+
useZig = false;
101+
102+
cc = if final.useLLVM || final.isDarwin then "clang"
103+
else if final.useArocc then "arocc"
104+
else if final.useZig then "zig"
105+
else "gcc";
106+
107+
bintools = if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then
108+
"llvm"
109+
else "gnu";
110+
111+
cxxlib =
112+
/**/ if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then "libcxx"
113+
else "libstdcxx";
95114

96115
libc =
97116
/**/ if final.isDarwin then "libSystem"
@@ -112,15 +131,25 @@ let
112131
else if final.isNone then "newlib"
113132
# TODO(@Ericson2314) think more about other operating systems
114133
else "native/impure";
134+
135+
unwinderlib =
136+
/**/ if final.useLLVM || final.useArocc || final.useZig then "libunwind"
137+
else if final.isDarwin then "libunwind-system"
138+
else "libgcc_s";
139+
140+
rtlib =
141+
/**/ if final.useLLVM || final.useArocc || final.useZig || final.isDarwin then "compiler-rt"
142+
else "libgcc";
143+
115144
# Choose what linker we wish to use by default. Someday we might also
116145
# choose the C compiler, runtime library, C++ standard library, etc. in
117146
# this way, nice and orthogonally, and deprecate `useLLVM`. But due to
118147
# the monolithic GCC build we cannot actually make those choices
119148
# independently, so we are just doing `linker` and keeping `useLLVM` for
120149
# now.
121150
linker =
122-
/**/ if final.useLLVM or false then "lld"
123-
else if final.isDarwin then "cctools"
151+
/**/ if final.useLLVM then "lld"
152+
else if final.isDarwin then "cctools"
124153
# "bfd" and "gold" both come from GNU binutils. The existence of Gold
125154
# is why we use the more obscure "bfd" and not "binutils" for this
126155
# choice.

lib/systems/examples.nix

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ rec {
7979
androidNdkVersion = "26";
8080
libc = "bionic";
8181
useAndroidPrebuilt = false;
82-
useLLVM = true;
82+
toolchain = "llvm";
8383
};
8484

8585
pogoplug4 = {
@@ -330,19 +330,19 @@ rec {
330330
config = "aarch64-w64-mingw32";
331331
libc = "ucrt";
332332
rust.rustcTarget = "aarch64-pc-windows-gnullvm";
333-
useLLVM = true;
333+
toolchain = "llvm";
334334
};
335335

336336
# BSDs
337337

338338
aarch64-freebsd = {
339339
config = "aarch64-unknown-freebsd";
340-
useLLVM = true;
340+
toolchain = "llvm";
341341
};
342342

343343
x86_64-freebsd = {
344344
config = "x86_64-unknown-freebsd";
345-
useLLVM = true;
345+
toolchain = "llvm";
346346
};
347347

348348
x86_64-netbsd = {
@@ -352,12 +352,12 @@ rec {
352352
# this is broken and never worked fully
353353
x86_64-netbsd-llvm = {
354354
config = "x86_64-unknown-netbsd";
355-
useLLVM = true;
355+
toolchain = "llvm";
356356
};
357357

358358
x86_64-openbsd = {
359359
config = "x86_64-unknown-openbsd";
360-
useLLVM = true;
360+
toolchain = "llvm";
361361
};
362362

363363
#
@@ -366,13 +366,13 @@ rec {
366366

367367
wasi32 = {
368368
config = "wasm32-unknown-wasi";
369-
useLLVM = true;
369+
toolchain = "llvm";
370370
};
371371

372372
wasm32-unknown-none = {
373373
config = "wasm32-unknown-none";
374374
rust.rustcTarget = "wasm32-unknown-unknown";
375-
useLLVM = true;
375+
toolchain = "llvm";
376376
};
377377

378378
# Ghcjs

pkgs/build-support/cc-wrapper/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ let
120120

121121
useGccForLibs = useCcForLibs
122122
&& libcxx == null
123+
&& targetPlatform.rtlib == "libgcc"
123124
&& !targetPlatform.isDarwin
124-
&& !(targetPlatform.useLLVM or false)
125125
&& !(targetPlatform.useAndroidPrebuilt or false)
126126
&& !(targetPlatform.isiOS or false)
127127
&& gccForLibs != null;
@@ -514,7 +514,7 @@ stdenvNoCC.mkDerivation {
514514
+ optionalString (isClang
515515
&& targetPlatform.isLinux
516516
&& !(targetPlatform.useAndroidPrebuilt or false)
517-
&& !(targetPlatform.useLLVM or false)
517+
&& targetPlatform.rtlib == "libgcc"
518518
&& gccForLibs != null) (''
519519
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
520520

pkgs/by-name/al/alsa-lib/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ stdenv.mkDerivation (finalAttrs: {
2525
# order to support apps with 32bit sound running on x86_64 architecture.
2626
./alsa-plugin-conf-multilib.patch
2727
]
28-
++ lib.optional (stdenv.hostPlatform.useLLVM or false)
28+
++ lib.optional (stdenv.hostPlatform.linker == "lld")
2929
# Fixes version script under LLVM, should be fixed in the next update.
3030
# Check if "pkgsLLVM.alsa-lib" builds on next version bump and remove this
3131
# if it succeeds.

pkgs/by-name/cl/cling/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Build with libc++ (LLVM) rather than stdlibc++ (GCC).
2929
# This is experimental and not all features work.
30-
useLLVMLibcxx ? clangStdenv.hostPlatform.isDarwin,
30+
useLLVMLibcxx ? clangStdenv.hostPlatform.cxxlib == "libcxx",
3131
}:
3232

3333
let

pkgs/by-name/cy/cyrus_sasl/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ stdenv.mkDerivation rec {
7474
"--enable-shared"
7575
]
7676
++ lib.optional enableLdap "--with-ldap=${openldap.dev}"
77-
++ lib.optionals (stdenv.targetPlatform.useLLVM or false) [
77+
++ lib.optionals (stdenv.hostPlatform.cc == "clang" && !stdenv.hostPlatform.isDarwin) [
7878
"--disable-sample"
7979
"CFLAGS=-DTIME_WITH_SYS_TIME"
8080
];

pkgs/by-name/el/elfutils/package.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ stdenv.mkDerivation rec {
6363
++ lib.optionals stdenv.hostPlatform.isMusl [ ./musl-error_h.patch ]
6464
# Prevent headers and binaries from colliding which results in an error.
6565
# https://sourceware.org/pipermail/elfutils-devel/2024q3/007281.html
66-
++ lib.optional (stdenv.targetPlatform.useLLVM or false) ./cxx-header-collision.patch;
66+
++ lib.optional (stdenv.hostPlatform.cxxlib == "libcxx") ./cxx-header-collision.patch;
6767

6868
postPatch =
6969
''
@@ -94,7 +94,7 @@ stdenv.mkDerivation rec {
9494
bzip2
9595
]
9696
++ lib.optional enableDebuginfod pkg-config
97-
++ lib.optional (stdenv.targetPlatform.useLLVM or false) autoreconfHook;
97+
++ lib.optional (stdenv.hostPlatform.cxxlib == "libcxx") autoreconfHook;
9898
buildInputs =
9999
[
100100
zlib
@@ -128,7 +128,7 @@ stdenv.mkDerivation rec {
128128
# Versioned symbols are nice to have, but we can do without.
129129
(lib.enableFeature (!stdenv.hostPlatform.isMicroBlaze) "symbol-versioning")
130130
]
131-
++ lib.optional (stdenv.targetPlatform.useLLVM or false) "--disable-demangler"
131+
++ lib.optional (stdenv.hostPlatform.unwinderlib == "libunwind") "--disable-demangler"
132132
++ lib.optionals stdenv.cc.isClang [
133133
"CFLAGS=-Wno-unused-private-field"
134134
"CXXFLAGS=-Wno-unused-private-field"

pkgs/by-name/ke/kexec-tools/package.nix

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ stdenv.mkDerivation rec {
1919
sha256 = "sha256-Z7GsUDqt5FpU2wvHkiiogwo11dT4PO6TLP8+eoGkqew=";
2020
};
2121

22-
patches = [
23-
# Use ELFv2 ABI on ppc64be
24-
(fetchpatch {
25-
url = "https://raw.githubusercontent.com/void-linux/void-packages/6c1192cbf166698932030c2e3de71db1885a572d/srcpkgs/kexec-tools/patches/ppc64-elfv2.patch";
26-
sha256 = "19wzfwb0azm932v0vhywv4221818qmlmvdfwpvvpfyw4hjsc2s1l";
27-
})
28-
] ++ lib.optional (stdenv.hostPlatform.useLLVM or false) ./fix-purgatory-llvm-libunwind.patch;
22+
patches =
23+
[
24+
# Use ELFv2 ABI on ppc64be
25+
(fetchpatch {
26+
url = "https://raw.githubusercontent.com/void-linux/void-packages/6c1192cbf166698932030c2e3de71db1885a572d/srcpkgs/kexec-tools/patches/ppc64-elfv2.patch";
27+
sha256 = "19wzfwb0azm932v0vhywv4221818qmlmvdfwpvvpfyw4hjsc2s1l";
28+
})
29+
]
30+
++ lib.optional (
31+
stdenv.hostPlatform.unwinderlib == "libunwind"
32+
) ./fix-purgatory-llvm-libunwind.patch;
2933

3034
hardeningDisable = [
3135
"format"

pkgs/by-name/li/libseccomp/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ stdenv.mkDerivation rec {
3737
util-linuxMinimal
3838
which
3939
];
40-
doCheck = !(stdenv.targetPlatform.useLLVM or false);
40+
doCheck = stdenv.hostPlatform.cc != "clang";
4141

4242
# Hack to ensure that patchelf --shrink-rpath get rids of a $TMPDIR reference.
4343
preFixup = "rm -rfv src";

pkgs/by-name/so/sourceHighlight/package.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ stdenv.mkDerivation rec {
6262
nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ];
6363
buildInputs =
6464
[ boost ]
65-
++ lib.optional (stdenv.targetPlatform.useLLVM or false) (
65+
++ lib.optional (stdenv.hostPlatform.rtlib == "compiler-rt") (
6666
llvmPackages.compiler-rt.override {
6767
doFakeLibgcc = true;
6868
}
@@ -92,7 +92,7 @@ stdenv.mkDerivation rec {
9292
maintainers = with maintainers; [ SuperSandro2000 ];
9393
};
9494
}
95-
// lib.optionalAttrs (stdenv.targetPlatform.useLLVM or false) {
95+
// lib.optionalAttrs (stdenv.targetPlatform.rtlib == "libunwind") {
9696
# Force linking to "libgcc" so tests pass
9797
NIX_CFLAGS_COMPILE = "-lgcc";
9898
}

0 commit comments

Comments
 (0)