llvmPackages_13: build from filtered monorepoSrc

This change implements a leftover task from #307211, namely passing
monorepoSrc to the different llvmPackages_13 package expressions. Before
this change, all packages llvmPackages_13 would be built from a
subdirectory of the full LLVM monorepo tree. After this change only the
relevant directories are made available at build time. This

- reduces the size of the source that needs to be made available to the
  builder.
- prevents LLVM from sidestepping our instructions and including extra
  sources from other directories it shouldn't.

Since LLVM 12 and 13 don't have the `cmake` directory at the top level,
the runCommand expressions filtering the source need to be adjusted, but
this causes no rebuild for any other LLVM version (ofborg should confirm
this).

The only problem encountered was in lld:

- We need to make the patch to the inclusion of libunwind headers
  unconditional now. lld needs this on non-darwin as well. In the
  full monorepo, LLVM_MAIN_SRC_DIR would be set correctly, so the
  patch wasn't necessary.
- The substitute mechanism for LLVM 12 and 13 can't be unified yet since
  LLVM 12 still uses a non monorepo build, so we come up with a
  different LLVM_MAIN_SRC_DIR.

Change was tested by building the following expression on x86_64-linux.

    with import ./. {};
    builtins.removeAttrs llvmPackages_13 [ "lldb" "lldbPlugins" ]'

lld was also tested on aarch64-darwin.
This commit is contained in:
sternenseemann 2024-10-11 11:41:49 +02:00
parent f7dbf14e43
commit 1d6675e530
11 changed files with 59 additions and 33 deletions

View File

@ -3,6 +3,7 @@
stdenv, stdenv,
llvm_meta, llvm_meta,
monorepoSrc, monorepoSrc,
release_version,
runCommand, runCommand,
cmake, cmake,
libxml2, libxml2,
@ -20,16 +21,22 @@ stdenv.mkDerivation (finalAttrs: {
inherit version patches; inherit version patches;
# Blank llvm dir just so relative path works # Blank llvm dir just so relative path works
src = runCommand "bolt-src-${finalAttrs.version}" { } '' src = runCommand "bolt-src-${finalAttrs.version}" { } (
''
mkdir $out mkdir $out
''
+ lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
''
+ ''
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out" cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/third-party "$out" cp -r ${monorepoSrc}/third-party "$out"
# tablegen stuff, probably not the best way but it works... # tablegen stuff, probably not the best way but it works...
cp -r ${monorepoSrc}/llvm/ "$out" cp -r ${monorepoSrc}/llvm/ "$out"
chmod -R +w $out/llvm chmod -R +w $out/llvm
''; ''
);
sourceRoot = "${finalAttrs.src.name}/bolt"; sourceRoot = "${finalAttrs.src.name}/bolt";

View File

@ -24,12 +24,14 @@ let
pname = "clang"; pname = "clang";
src' = if monorepoSrc != null then src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} '' runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
cp -r ${monorepoSrc}/clang-tools-extra "$out" cp -r ${monorepoSrc}/clang-tools-extra "$out"
'' else src; '') else src;
self = stdenv.mkDerivation (finalAttrs: rec { self = stdenv.mkDerivation (finalAttrs: rec {
inherit pname version patches; inherit pname version patches;

View File

@ -47,11 +47,13 @@ let
pname = baseName + lib.optionalString (haveLibc) "-libc"; pname = baseName + lib.optionalString (haveLibc) "-libc";
src' = if monorepoSrc != null then src' = if monorepoSrc != null then
runCommand "${baseName}-src-${version}" {} '' runCommand "${baseName}-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${baseName} "$out" cp -r ${monorepoSrc}/${baseName} "$out"
'' else src; '') else src;
preConfigure = lib.optionalString (!haveLibc) '' preConfigure = lib.optionalString (!haveLibc) ''
cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding")

View File

@ -346,13 +346,7 @@ let
tools = lib.makeExtensible ( tools = lib.makeExtensible (
tools: tools:
let let
callPackage = newScope ( callPackage = newScope (tools // args // metadata);
tools
// args
// metadata
# Previously monorepoSrc was erroneously not being passed through.
// lib.optionalAttrs (lib.versionOlder metadata.release_version "14") { monorepoSrc = null; } # Preserve a bug during #307211, TODO: remove; causes llvm 13 rebuild.
);
clangVersion = clangVersion =
if (lib.versionOlder metadata.release_version "16") then if (lib.versionOlder metadata.release_version "16") then
metadata.release_version metadata.release_version

View File

@ -22,11 +22,17 @@ stdenv.mkDerivation rec {
pname = "libclc"; pname = "libclc";
inherit version; inherit version;
src = runCommand "${pname}-src-${version}" { } '' src = runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out" mkdir -p "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
''
+ ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
''; ''
);
sourceRoot = "${src.name}/${pname}"; sourceRoot = "${src.name}/${pname}";

View File

@ -19,7 +19,9 @@ let
src' = if monorepoSrc != null then src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} ('' runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
mkdir -p "$out/libcxx" mkdir -p "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"

View File

@ -19,21 +19,23 @@ let
pname = "lld"; pname = "lld";
src' = src' =
if monorepoSrc != null then if monorepoSrc != null then
runCommand "lld-src-${version}" {} '' runCommand "lld-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
mkdir -p "$out/libunwind" mkdir -p "$out/libunwind"
cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
mkdir -p "$out/llvm" mkdir -p "$out/llvm"
'' else src; '') else src;
postPatch = lib.optionalString (lib.versions.major release_version == "12") '' postPatch = lib.optionalString (lib.versions.major release_version == "12") ''
substituteInPlace MachO/CMakeLists.txt --replace \ substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '(' '(''${LLVM_MAIN_SRC_DIR}/' '('
mkdir -p libunwind/include mkdir -p libunwind/include
tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/" tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/"
'' + lib.optionalString (lib.versions.major release_version == "13" && stdenv.hostPlatform.isDarwin) '' '' + lib.optionalString (lib.versions.major release_version == "13") ''
substituteInPlace MachO/CMakeLists.txt --replace \ substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '(../' '(''${LLVM_MAIN_SRC_DIR}/' '(../'
''; '';
@ -75,4 +77,4 @@ stdenv.mkDerivation (rec {
of several different linkers. of several different linkers.
''; '';
}; };
} // (if (postPatch == "" && lib.versions.major release_version != "13") then {} else { inherit postPatch; })) } // (lib.optionalAttrs (postPatch != "") { inherit postPatch; }))

View File

@ -32,7 +32,9 @@ let
if monorepoSrc != null then if monorepoSrc != null then
runCommand "lldb-src-${version}" { } ('' runCommand "lldb-src-${version}" { } (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/lldb "$out" cp -r ${monorepoSrc}/lldb "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) '' '' + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
mkdir -p "$out/llvm" mkdir -p "$out/llvm"

View File

@ -77,11 +77,15 @@ let
pname = "llvm"; pname = "llvm";
# TODO: simplify versionAtLeast condition for cmake and third-party via rebuild
src' = if monorepoSrc != null then src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} ('' runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/third-party "$out" cp -r ${monorepoSrc}/third-party "$out"
'' + lib.optionalString enablePolly '' '' + lib.optionalString enablePolly ''
chmod u+w "$out/${pname}/tools" chmod u+w "$out/${pname}/tools"

View File

@ -1,6 +1,7 @@
{ lib { lib
, stdenv , stdenv
, llvm_meta , llvm_meta
, release_version
, buildLlvmTools , buildLlvmTools
, monorepoSrc , monorepoSrc
, runCommand , runCommand
@ -18,14 +19,16 @@ stdenv.mkDerivation rec {
inherit version doCheck; inherit version doCheck;
# Blank llvm dir just so relative path works # Blank llvm dir just so relative path works
src = runCommand "${pname}-src-${version}" { } '' src = runCommand "${pname}-src-${version}" { } (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/mlir "$out" cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out/third-party" cp -r ${monorepoSrc}/third-party "$out/third-party"
mkdir -p "$out/llvm" mkdir -p "$out/llvm"
''; '');
sourceRoot = "${src.name}/mlir"; sourceRoot = "${src.name}/mlir";

View File

@ -21,11 +21,13 @@ let
pname = "openmp"; pname = "openmp";
src' = src' =
if monorepoSrc != null then if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} '' runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out" mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
'' else src; '') else src;
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (rec {
inherit pname version patches; inherit pname version patches;