-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the LRE flake overlay (#1516)
This change migrates the last patch to an overlay and removes the patch structure. This resolves all IFDs, cleans up the main flake and makes our custom toolchains portable across flakes. The `customClang` and `customStdenv` packages are now available as `lre.clang` and `lre.stdenv`. While the new packages are differently named, they produce the exact same setup as previously. This can be verified by the fact that `generate-toolchains` is a noop between the previous commit and this one. Since a renaming of the `customClang` executable itself would cause differences in the lre-cc toolchain we defer this to a future commit. Fixes #1262 Closes #1512
- Loading branch information
1 parent
301e51b
commit ae71bc8
Showing
7 changed files
with
141 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
final: _prev: { | ||
lre = { | ||
stdenv = final.callPackage ./stdenv.nix { | ||
llvmPackages = final.llvmPackages_19; | ||
targetPackages = final; | ||
}; | ||
|
||
clang = final.callPackage ./clang.nix { | ||
inherit (final.lre) stdenv; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
lib, | ||
llvmPackages, | ||
overrideCC, | ||
stdenv, | ||
targetPackages, | ||
useMoldLinker, | ||
wrapCCWith, | ||
}: let | ||
# Adapted from clangUseLLVM. | ||
# See: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/llvm/common/default.nix | ||
clangVersion = "19"; | ||
targetLlvmLibraries = targetPackages.llvmPackages_19.libraries; | ||
|
||
mkExtraBuildCommands0 = cc: '' | ||
rsrc="$out/resource-root" | ||
mkdir "$rsrc" | ||
ln -s "${lib.getLib cc}/lib/clang/${clangVersion}/include" "$rsrc" | ||
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags | ||
''; | ||
mkExtraBuildCommands = cc: | ||
mkExtraBuildCommands0 cc | ||
+ '' | ||
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" | ||
ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" | ||
''; | ||
|
||
toolchain' = wrapCCWith ( | ||
rec { | ||
cc = llvmPackages.clang-unwrapped; | ||
inherit (targetLlvmLibraries) libcxx; | ||
inherit (llvmPackages) bintools; | ||
extraPackages = [ | ||
targetLlvmLibraries.compiler-rt | ||
targetLlvmLibraries.libunwind | ||
]; | ||
extraBuildCommands = mkExtraBuildCommands cc; | ||
} | ||
// { | ||
nixSupport.cc-cflags = | ||
[ | ||
"-rtlib=compiler-rt" | ||
"-Wno-unused-command-line-argument" | ||
"-B${targetLlvmLibraries.compiler-rt}/lib" | ||
"-stdlib=libc++" | ||
] | ||
++ lib.optional stdenv.targetPlatform.isLinux "-fuse-ld=mold" | ||
++ lib.optional ( | ||
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD | ||
) "--unwindlib=libunwind" | ||
++ lib.optional ( | ||
!stdenv.targetPlatform.isWasm | ||
&& !stdenv.targetPlatform.isFreeBSD | ||
&& stdenv.targetPlatform.useLLVM or false | ||
) ["-lunwind" "-lc++"] | ||
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; | ||
nixSupport.cc-ldflags = | ||
lib.optionals ( | ||
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD | ||
) [ | ||
"-L${targetLlvmLibraries.libunwind}/lib" | ||
"-rpath" | ||
"${targetLlvmLibraries.libunwind}/lib" | ||
"-L${targetLlvmLibraries.libcxx}/lib" | ||
"-rpath" | ||
"${targetLlvmLibraries.libcxx}/lib" | ||
]; | ||
} | ||
); | ||
|
||
stdenv' = | ||
overrideCC | ||
llvmPackages.libcxxStdenv | ||
toolchain'; | ||
|
||
toolchain = | ||
if stdenv.targetPlatform.isDarwin | ||
then stdenv' # Mold doesn't support darwin. | ||
else useMoldLinker stdenv'; | ||
in | ||
# This toolchain uses Clang as compiler, Mold as linker, libc++ as C++ | ||
# standard library and compiler-rt as compiler runtime. Resulting rust | ||
# binaries depend dynamically linked on the nixpkgs distribution of glibc. | ||
# C++ binaries additionally depend dynamically on libc++, libunwind and | ||
# libcompiler-rt. Due to a bug we also depend on libgcc_s. | ||
# | ||
# TODO(aaronmondal): At the moment this toolchain is only used for the Cargo | ||
# build. The Bazel build uses a different mostly hermetic LLVM toolchain. We | ||
# should merge the two by generating the Bazel cc_toolchain from this stdenv. | ||
# This likely requires a rewrite of | ||
# https://github.com/bazelbuild/bazel-toolchains as the current implementation | ||
# has poor compatibility with custom container images and doesn't support | ||
# generating toolchain configs from image archives. | ||
# | ||
# TODO(aaronmondal): Due to various issues in the nixpkgs LLVM toolchains | ||
# we're not getting a pure Clang/LLVM toolchain here. My guess is that the | ||
# runtimes were not built with the degenerate LLVM toolchain but with the | ||
# regular GCC stdenv from nixpkgs. | ||
# | ||
# For instance, outputs depend on libgcc_s since libcxx seems to have been was | ||
# built with a GCC toolchain. We're also not using builtin atomics, or at | ||
# least we're redundantly linking libatomic. | ||
# | ||
# Fix this as it fixes a large number of issues, including better | ||
# cross-platform compatibility, reduced closure size, and | ||
# static-linking-friendly licensing. This requires building the llvm project | ||
# with the correct multistage bootstrapping process. | ||
toolchain |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.