Skip to content

Commit

Permalink
lib.systems: introduce libcxx, unwinderlib, and rtlib
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Dec 27, 2024
1 parent a225595 commit 09a9885
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 33 deletions.
18 changes: 17 additions & 1 deletion lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ let
"clang"
else "gcc";

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

libcxx =
/**/ if final.toolchain == "llvm" then "libcxx"
else if final.toolchain == "gnu" then "libstdcxx"
else null;

libc =
/**/ if final.isDarwin then "libSystem"
else if final.isMinGW then "msvcrt"
Expand All @@ -129,6 +134,17 @@ let
else if final.isNone then "newlib"
# TODO(@Ericson2314) think more about other operating systems
else "native/impure";

unwinderlib =
/**/ if final.toolchain == "llvm" then "libunwinder"
else if final.toolchain == "gnu" then "libgcc_s"
else null;

rtlib =
/**/ if final.toolchain == "llvm" then "compiler-rt"
else if final.toolchain == "gnu" then "libgcc"
else null;

# 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
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 @@ -120,8 +120,8 @@ let

useGccForLibs = useCcForLibs
&& libcxx == null
&& targetPlatform.rtlib == "libgcc"
&& !targetPlatform.isDarwin
&& !(targetPlatform.toolchain == "llvm")
&& !(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.toolchain == "llvm")
&& 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/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.toolchain == "llvm") [
++ lib.optionals (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) [
"--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.toolchain == "llvm") ./cxx-header-collision.patch;
++ lib.optional (stdenv.hostPlatform.libcxx == "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.toolchain == "llvm") autoreconfHook;
++ lib.optional (stdenv.hostPlatform.libcxx == "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.toolchain == "llvm") "--disable-demangler"
++ lib.optional (stdenv.hostPlatform.unwinderlib == "libunwind") "--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.toolchain == "llvm") ./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
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.toolchain == "llvm") (
++ lib.optional (stdenv.hostPlatform.rtlib == "compiler-rt") (
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.toolchain == "llvm") {
// lib.optionalAttrs (stdenv.targetPlatform.rtlib == "libunwind") {
# Force linking to "libgcc" so tests pass
NIX_CFLAGS_COMPILE = "-lgcc";
}
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.toolchain == "llvm") (fetchpatch {
patches = lib.optional (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) (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.toolchain == "llvm") {
// lib.optionalAttrs (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) {
NIX_CFLAGS_COMPILE = "-DHAVE_SECURE_GETENV";
};

Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/libraries/openssl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ let
++ lib.optional static "etc";
setOutputFlags = false;
separateDebugInfo =
!stdenv.hostPlatform.isDarwin && !(stdenv.hostPlatform.toolchain == "llvm") && stdenv.cc.isGNU;
# Using "cc.isClang" causes infinite recursion.
!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.toolchain == "llvm") &&
!stdenv.cc.isClang &&
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.toolchain == "llvm") (
++ lib.optional (stdenv.hostPlatform.rtlib == "compiler-rt") (
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 @@ -53,7 +53,7 @@ buildPythonPackage rec {
# AssertionError: assert 'foo' in ['setup']
"test_init_extension_module"
]
++ lib.optionals (stdenv.targetPlatform.toolchain == "llvm") [
++ lib.optionals (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) [
# 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.toolchain == "llvm") "test_future_import";
++ lib.optional (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) "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.toolchain == "llvm") (llvmPackages.compiler-rt.override {
++ lib.optional (withBootloader && stdenv.hostPlatform.rtlib == "compiler-rt") (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.toolchain == "llvm" then
if stdenv.cc.isClang 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.toolchain == "llvm") "ac_cv_path_RAWCPP=cpp";
++ lib.optional (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) "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.toolchain == "llvm") "ac_cv_path_RAWCPP=cpp";
++ lib.optional (stdenv.cc.isClang && !stdenv.hostPlatform.isDarwin) "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
6 changes: 3 additions & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ with pkgs;
# thing to to create an earlier thing (leading to infinite recursion) and
# we also would still respect the stage arguments choices for these
# things.
(if stdenvNoCC.hostPlatform.isDarwin || stdenvNoCC.hostPlatform.toolchain == "llvm"
(if stdenvNoCC.hostPlatform.cc == "clang"
then overrideCC stdenvNoCC buildPackages.llvmPackages.clangNoCompilerRt
else gccCrossLibcStdenv)
else mkStdenvNoLibs stdenv;

stdenvNoLibc =
if stdenvNoCC.hostPlatform != stdenvNoCC.buildPlatform
then
(if stdenvNoCC.hostPlatform.isDarwin || stdenvNoCC.hostPlatform.toolchain == "llvm"
(if stdenvNoCC.hostPlatform.cc == "clang"
then overrideCC stdenvNoCC buildPackages.llvmPackages.clangNoLibc
else gccCrossLibcStdenv)
else mkStdenvNoLibs stdenv;
Expand Down Expand Up @@ -12163,7 +12163,7 @@ with pkgs;

busybox = callPackage ../os-specific/linux/busybox {
# Fixes libunwind from being dynamically linked to a static binary.
stdenv = if stdenv.targetPlatform.toolchain == "llvm" then
stdenv = if stdenv.cc.isClang && stdenv.hostPlatform.unwinderlib == "libunwind" then
overrideCC stdenv buildPackages.llvmPackages.clangNoLibcxx
else stdenv;
};
Expand Down
9 changes: 6 additions & 3 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ let
inherit (self.pkgsBuildHost.xorg) lndir;
};

cleanToolchain = platform: builtins.removeAttrs platform
[ "toolchain" "cc" "bintools" "linker" "libc" "libcxx" "unwinderlib" "rtlib" ];

stdenvBootstappingAndPlatforms = self: super: let
withFallback = thisPkgs:
(if adjacentPackages == null then self else thisPkgs)
Expand Down Expand Up @@ -201,7 +204,7 @@ let
# Bootstrap a cross stdenv using the LLVM toolchain.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
crossSystem = (cleanToolchain stdenv.hostPlatform) // {
toolchain = "llvm";
};
};
Expand All @@ -215,7 +218,7 @@ let
# Bootstrap a cross stdenv using the Aro C compiler.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
crossSystem = (cleanToolchain stdenv.hostPlatform) // {
toolchain = "llvm";
cc = "arocc";
linker = "lld";
Expand All @@ -231,7 +234,7 @@ let
# Bootstrap a cross stdenv using the Zig toolchain.
# This is currently not possible when compiling natively,
# so we don't need to check hostPlatform != buildPlatform.
crossSystem = stdenv.hostPlatform // {
crossSystem = (cleanToolchain stdenv.hostPlatform) // {
toolchain = "llvm";
cc = "zig";
linker = "lld";
Expand Down

0 comments on commit 09a9885

Please sign in to comment.