llvmPackages_20.libc-full: fix building (#385706)

This commit is contained in:
Tristan Ross
2025-03-26 20:32:27 -07:00
committed by GitHub
3 changed files with 44 additions and 18 deletions

View File

@@ -200,7 +200,7 @@ let
# don't support dynamic linking, but don't get the `staticMarker`.
# `pkgsStatic` sets `isStatic=true`, so `pkgsStatic.hostPlatform` always
# has the `staticMarker`.
isStatic = final.isWasi || final.isRedox;
isStatic = final.isWasi || final.isRedox || final.isLLVMLibc;
# Just a guess, based on `system`
inherit

View File

@@ -14,6 +14,7 @@
overrideCC,
wrapCCWith,
wrapBintoolsWith,
buildPackages,
buildLlvmTools, # tools, but from the previous stage, for cross
targetLlvmLibraries, # libraries, but from the next stage, for cross
targetLlvm,
@@ -423,18 +424,14 @@ let
libcxx = null;
bintools = bintoolsNoLibc';
extraPackages = [ ];
extraBuildCommands =
lib.optionalString (lib.versions.major metadata.release_version == "13") ''
echo "-nostartfiles" >> $out/nix-support/cc-cflags
''
+ mkExtraBuildCommands0 cc;
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
extraBuildCommands = mkExtraBuildCommands0 cc;
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
nixSupport.cc-cflags =
[ "-nostartfiles" ]
++ lib.optional (
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
) "-fno-exceptions";
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
nixSupport.cc-cflags = lib.optional (
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
) "-fno-exceptions";
}
);
@@ -576,6 +573,13 @@ let
# Use clang due to "gnu::naked" not working on aarch64.
# Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
cmake =
if stdenv.targetPlatform.libc == "llvm" then buildPackages.cmakeMinimal else buildPackages.cmake;
python3 =
if stdenv.targetPlatform.libc == "llvm" then
buildPackages.python3Minimal
else
buildPackages.python3;
};
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;

View File

@@ -23,6 +23,7 @@ let
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/runtimes "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/compiler-rt "$out"
cp -r ${monorepoSrc}/${pname} "$out"
'');
in
@@ -46,6 +47,7 @@ stdenv.mkDerivation (finalAttrs: {
outputs = [ "out" ] ++ (lib.optional isFullBuild "dev");
postUnpack = lib.optionalString isFullBuild ''
chmod +w $sourceRoot/../$pname/utils/hdrgen
patchShebangs $sourceRoot/../$pname/utils/hdrgen/main.py
chmod +x $sourceRoot/../$pname/utils/hdrgen/main.py
'';
@@ -59,16 +61,36 @@ stdenv.mkDerivation (finalAttrs: {
cd ../runtimes
'';
postInstall = lib.optionalString (!isFullBuild) ''
substituteAll ${./libc-shim.tpl} $out/lib/libc.so
'';
postInstall =
lib.optionalString (!isFullBuild) ''
substituteAll ${./libc-shim.tpl} $out/lib/libc.so
''
# LLVM libc doesn't recognize static vs dynamic yet.
# Treat LLVM libc as a static libc, requires this symlink until upstream fixes it.
+ lib.optionalString (isFullBuild && stdenv.hostPlatform.isLinux) ''
ln $out/lib/crt1.o $out/lib/Scrt1.o
'';
libc = if (!isFullBuild) then stdenv.cc.libc else null;
cmakeFlags = [
(lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc")
];
cmakeFlags =
[
(lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc;compiler-rt")
# Tests requires the host to have a libc.
(lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null))
(lib.cmakeBool "LLVM_LIBC_INCLUDE_SCUDO" true)
(lib.cmakeBool "COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC" true)
(lib.cmakeBool "COMPILER_RT_BUILD_GWP_ASAN" false)
(lib.cmakeBool "COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED" false)
]
++ lib.optional (isFullBuild && stdenv.cc.libc == null) [
# CMake runs a check to see if the compiler works.
# This includes including headers which requires a libc.
# Skip these checks because a libc cannot be used when one doesn't exist.
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
];
# For the update script:
passthru = {