Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let
platforms = import ./platforms.nix { inherit lib; };
examples = import ./examples.nix { inherit lib; };
architectures = import ./architectures.nix { inherit lib; };
toolchain = import ./toolchain.nix { inherit lib; };

/**
Elaborated systems contain functions, which means that they don't satisfy
Expand Down Expand Up @@ -83,6 +84,15 @@ let
# TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL.
rust = args.rust or args.rustc or { };

toolchainSet = {
cc = toolchain.chooseComponent "cc" final;
bintools = toolchain.chooseComponent "bintools" final;
cxxlib = toolchain.chooseComponent "cxxlib" final;
cxxrtlib = toolchain.chooseComponent "cxxrtlib" final;
unwindlib = toolchain.chooseComponent "unwindlib" final;
rtlib = toolchain.chooseComponent "rtlib" final;
};

final = {
# Prefer to parse `config` as it is strictly more informative.
parsed = parse.mkSystemFromString (args.config or allArgs.system);
Expand Down Expand Up @@ -116,6 +126,8 @@ let
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
Expand Down Expand Up @@ -413,6 +425,7 @@ let
// mapAttrs (n: v: v final.parsed) inspect.predicates
// mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates
// args
// toolchainSet
// {
rust = rust // {
# Once args.rustc.platform.target-family is deprecated and
Expand Down Expand Up @@ -569,6 +582,7 @@ let
assert foldl (pass: { assertion, message }: if assertion final then pass else throw message) true (
final.parsed.abi.assertions or [ ]
);
assert toolchainSet == lib.mapAttrs (key: _: final.${key}) toolchainSet;
final;

in
Expand All @@ -585,6 +599,7 @@ in
inspect
parse
platforms
toolchain
systemToAttrs
;
}
48 changes: 48 additions & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ rec {
libc = "bionic";
useAndroidPrebuilt = false;
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
Comment on lines 95 to 101
Copy link
Member

Choose a reason for hiding this comment

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

I don’t think we should set these while they’re redundant to useLLVM (since they couldn’t be any other possible value, and adjusting them won’t work, and it means that e.g. lib.systems.examples.aarch64-freebsd // { useLLVM = false; } becomes broken for no good reason).

Copy link
Member Author

Choose a reason for hiding this comment

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

It's necessary for eval to 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.

Since we have lib.systems.toolchain, we can use that to easily help clean out stdenv.hostPlatform of the toolchain attributes. Now that logic is handled outside of this file for setting the new toolchain attributes.

};

pogoplug4 = {
Expand Down Expand Up @@ -370,6 +376,12 @@ rec {
libc = "ucrt";
rust.rustcTarget = "aarch64-pc-windows-gnullvm";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

# Target the MSVC ABI
Expand All @@ -388,11 +400,23 @@ rec {
aarch64-freebsd = {
config = "aarch64-unknown-freebsd";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

x86_64-freebsd = {
config = "x86_64-unknown-freebsd";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

x86_64-netbsd = {
Expand All @@ -403,11 +427,23 @@ rec {
x86_64-netbsd-llvm = {
config = "x86_64-unknown-netbsd";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

x86_64-openbsd = {
config = "x86_64-unknown-openbsd";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

#
Expand All @@ -417,12 +453,24 @@ rec {
wasi32 = {
config = "wasm32-unknown-wasi";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

wasm32-unknown-none = {
config = "wasm32-unknown-none";
rust.rustcTarget = "wasm32-unknown-unknown";
useLLVM = true;
cc = "clang";
bintools = "llvm";
cxxlib = "libcxx";
cxxrtlib = "libcxxabi";
unwindlib = "libunwind";
rtlib = "compiler-rt";
};

# Ghcjs
Expand Down
87 changes: 87 additions & 0 deletions lib/systems/toolchain.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{ lib }:
let
inherit (lib)
isAttrs
;

cc = {
llvm = "clang";
arocc = "arocc";
zig = "zig";
gnu = "gcc";
default = null;
};

bintools = {
llvm = "llvm";
gnu = "gnu";
default = null;
};

cxxlib = {
llvm = "libcxx";
gnu = "libstdcxx";
default = null;
};

cxxrtlib = {
llvm = "libcxxabi";
gnu = {
linux = "libsupcxx";
default = "libcxxrt";
};
default = null;
};

unwindlib = {
llvm = {
darwin = "libunwind-system";
default = "libunwind";
};
gnu = "libgcc";
default = null;
};

rtlib = {
llvm = "compiler-rt";
gnu = "libgcc";
default = null;
};

components = {
inherit
cc
bintools
cxxlib
cxxrtlib
unwindlib
rtlib
;
};

getToolchain =
platform:
if platform.useLLVM || platform.useArocc || platform.useZig || platform.isDarwin then
"llvm"
else
# TODO: don't imply GNU when nothing else is specified.
# Return null once we allow toolchain attributes to be changed.
"gnu";

chooseComponent =
componentName: platform:
let
toolchain = getToolchain platform;

componentSet =
components."${componentName}"."${toolchain}" or components."${componentName}".default;
in
if isAttrs componentSet then
componentSet."${platform.parsed.kernel.name}" or componentSet.default
else
componentSet;
in
components
// {
inherit chooseComponent;
}
9 changes: 6 additions & 3 deletions pkgs/top-level/variants.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ let
abi = lib.systems.parse.abis.llvm;
}
);

toolchainAttrs = lib.attrNames (builtins.removeAttrs lib.systems.toolchain [ "chooseComponent" ]);
hostPlatform = builtins.removeAttrs stdenv.hostPlatform toolchainAttrs;
in
self: super: {
pkgsLLVM = nixpkgsFun {
Expand All @@ -33,7 +36,7 @@ self: super: {
# 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 = hostPlatform // {
useLLVM = true;
linker = "lld";
};
Expand All @@ -49,7 +52,7 @@ self: super: {
# 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 = hostPlatform // {
useArocc = true;
linker = "lld";
};
Expand All @@ -65,7 +68,7 @@ self: super: {
# 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 = hostPlatform // {
useZig = true;
linker = "lld";
};
Expand Down
Loading