Skip to content

Commit

Permalink
[needs touchup] cross: allow specifying llvmPackages version to use…
Browse files Browse the repository at this point in the history
… via `useLLVM`

needs:
  - tests!
  • Loading branch information
rrbutani committed Mar 19, 2023
1 parent 44fa242 commit 52f8707
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
20 changes: 19 additions & 1 deletion lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,25 @@ rec {

}) // mapAttrs (n: v: v final.parsed) inspect.predicates
// mapAttrs (n: v: v final.gcc.arch or "default") architectures.predicates
// args;
// args
// (lib.optionalAttrs ((
(builtins.trace args args.useLLVM or false)) != false) {
# `useLLVM` can be a boolean _or_ an int/string specifying what LLVM
# version to use for the system.
#
# We want to normalize `useLLVM` to a boolean and also expose
# `llvmPackageSetName`.
#
# Note that this means we will actually *override* the user's `useLLVM`
# value here (but not `llvmPackageSetName`, if it's specified by the
# user).
useLLVM = true;
${ if args ? llvmPackageSetName then null else "llvmPackageSetName" } =
/**/ if args.useLLVM == true then "llvmPackages"
else if builtins.isInt args.useLLVM then "llvmPackages_${builtins.toString args.useLLVM}"
else if builtins.isString args.useLLVM then args.useLLVM
else throw "`useLLVM` must be a boolean, an int, or a string";
});
in assert final.useAndroidPrebuilt -> final.isAndroid;
assert lib.foldl
(pass: { assertion, message }:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ in lib.init bootStages ++ [
else if crossSystem.isDarwin
then buildPackages.llvmPackages.libcxxClang
else if crossSystem.useLLVM or false
then buildPackages.llvmPackages.clangUseLLVM
then buildPackages.${crossSystem.llvmPackageSetName}.clangUseLLVM
else buildPackages.gcc;

extraNativeBuildInputs = old.extraNativeBuildInputs
Expand Down
6 changes: 6 additions & 0 deletions pkgs/test/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ let
in {
gcc = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = false;})) tests);
llvm = (lib.mapAttrs (_: mapMultiPlatformTest (system: system // {useLLVM = true;})) tests);

# TODO: move elsewhere
# test that `stdenv.hostPlatform.cc.cc.version` has a major version matching what we asked for...

# test that `llvmPackageSetName` is correct (test: boolean, number, string and then test that if we set true/int/string and specify our own string its preserved!)
# TODO: this is actually an `elaborate` test..
}
6 changes: 3 additions & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ 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.
overrideCC stdenv buildPackages.llvmPackages.clangNoCompilerRt
overrideCC stdenv buildPackages.${stdenv.hostPlatform.llvmPackageSetName or "llvmPackages"}.clangNoCompilerRt ####
else mkStdenvNoLibs stdenv;

gccStdenvNoLibs = mkStdenvNoLibs gccStdenv;
Expand Down Expand Up @@ -14650,7 +14650,7 @@ with pkgs;

crossLibcStdenv =
if stdenv.hostPlatform.useLLVM or false || stdenv.hostPlatform.isDarwin
then overrideCC stdenv buildPackages.llvmPackages.clangNoLibc
then overrideCC stdenv buildPackages.${stdenv.hostPlatform.llvmPackageSetName or "llvmPackages"}.clangNoLibc
else gccCrossLibcStdenv;

# The GCC used to build libc for the target platform. Normal gccs will be
Expand Down Expand Up @@ -21160,7 +21160,7 @@ with pkgs;

libcxxrt = callPackage ../development/libraries/libcxxrt {
stdenv = if stdenv.hostPlatform.useLLVM or false
then overrideCC stdenv buildPackages.llvmPackages.tools.clangNoLibcxx
then overrideCC stdenv buildPackages.${stdenv.hostPlatform.llvmPackageSetName}.tools.clangNoLibcxx
else stdenv;
};

Expand Down

0 comments on commit 52f8707

Please sign in to comment.