Skip to content

Commit

Permalink
llvmPackages_13: build from filtered monorepoSrc
Browse files Browse the repository at this point in the history
This change implements a leftover task from NixOS#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.
  • Loading branch information
sternenseemann authored and yuanwang-wf committed Oct 17, 2024
1 parent 69e52f9 commit 9da0a11
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 33 deletions.
25 changes: 16 additions & 9 deletions pkgs/development/compilers/llvm/common/bolt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
stdenv,
llvm_meta,
monorepoSrc,
release_version,
runCommand,
cmake,
libxml2,
Expand All @@ -20,16 +21,22 @@ stdenv.mkDerivation (finalAttrs: {
inherit version patches;

# Blank llvm dir just so relative path works
src = runCommand "bolt-src-${finalAttrs.version}" { } ''
mkdir $out
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/third-party "$out"
src = runCommand "bolt-src-${finalAttrs.version}" { } (
''
mkdir $out
''
+ lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
''
+ ''
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/third-party "$out"
# tablegen stuff, probably not the best way but it works...
cp -r ${monorepoSrc}/llvm/ "$out"
chmod -R +w $out/llvm
'';
# tablegen stuff, probably not the best way but it works...
cp -r ${monorepoSrc}/llvm/ "$out"
chmod -R +w $out/llvm
''
);

sourceRoot = "${finalAttrs.src.name}/bolt";

Expand Down
6 changes: 4 additions & 2 deletions pkgs/development/compilers/llvm/common/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ let
pname = "clang";

src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} ''
runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out"
cp -r ${monorepoSrc}/clang-tools-extra "$out"
'' else src;
'') else src;

self = stdenv.mkDerivation (finalAttrs: rec {
inherit pname version patches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ let
pname = baseName + lib.optionalString (haveLibc) "-libc";

src' = if monorepoSrc != null then
runCommand "${baseName}-src-${version}" {} ''
runCommand "${baseName}-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${baseName} "$out"
'' else src;
'') else src;

preConfigure = lib.optionalString (!haveLibc) ''
cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding")
Expand Down
8 changes: 1 addition & 7 deletions pkgs/development/compilers/llvm/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,7 @@ let
tools = lib.makeExtensible (
tools:
let
callPackage = newScope (
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.
);
callPackage = newScope (tools // args // metadata);
clangVersion =
if (lib.versionOlder metadata.release_version "16") then
metadata.release_version
Expand Down
16 changes: 11 additions & 5 deletions pkgs/development/compilers/llvm/common/libclc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ stdenv.mkDerivation rec {
pname = "libclc";
inherit version;

src = runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out"
'';
src = runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
''
+ ''
cp -r ${monorepoSrc}/${pname} "$out"
''
);

sourceRoot = "${src.name}/${pname}";

Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/compilers/llvm/common/libunwind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ let
src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out"
mkdir -p "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
Expand Down
10 changes: 6 additions & 4 deletions pkgs/development/compilers/llvm/common/lld/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ let
pname = "lld";
src' =
if monorepoSrc != null then
runCommand "lld-src-${version}" {} ''
runCommand "lld-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out"
mkdir -p "$out/libunwind"
cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
mkdir -p "$out/llvm"
'' else src;
'') else src;

postPatch = lib.optionalString (lib.versions.major release_version == "12") ''
substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '('
mkdir -p 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 \
'(''${LLVM_MAIN_SRC_DIR}/' '(../'
'';
Expand Down Expand Up @@ -75,4 +77,4 @@ stdenv.mkDerivation (rec {
of several different linkers.
'';
};
} // (if (postPatch == "" && lib.versions.major release_version != "13") then {} else { inherit postPatch; }))
} // (lib.optionalAttrs (postPatch != "") { inherit postPatch; }))
2 changes: 2 additions & 0 deletions pkgs/development/compilers/llvm/common/lldb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ let
if monorepoSrc != null then
runCommand "lldb-src-${version}" { } (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/lldb "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
mkdir -p "$out/llvm"
Expand Down
4 changes: 4 additions & 0 deletions pkgs/development/compilers/llvm/common/llvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ let

pname = "llvm";

# TODO: simplify versionAtLeast condition for cmake and third-party via rebuild
src' = if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/third-party "$out"
'' + lib.optionalString enablePolly ''
chmod u+w "$out/${pname}/tools"
Expand Down
7 changes: 5 additions & 2 deletions pkgs/development/compilers/llvm/common/mlir/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib
, stdenv
, llvm_meta
, release_version
, buildLlvmTools
, monorepoSrc
, runCommand
Expand All @@ -18,14 +19,16 @@ stdenv.mkDerivation rec {
inherit version doCheck;

# Blank llvm dir just so relative path works
src = runCommand "${pname}-src-${version}" { } ''
src = runCommand "${pname}-src-${version}" { } (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out/third-party"
mkdir -p "$out/llvm"
'';
'');

sourceRoot = "${src.name}/mlir";

Expand Down
6 changes: 4 additions & 2 deletions pkgs/development/compilers/llvm/common/openmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ let
pname = "openmp";
src' =
if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} ''
runCommand "${pname}-src-${version}" {} (''
mkdir -p "$out"
'' + lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out"
'' + ''
cp -r ${monorepoSrc}/${pname} "$out"
'' else src;
'') else src;
in
stdenv.mkDerivation (rec {
inherit pname version patches;
Expand Down

0 comments on commit 9da0a11

Please sign in to comment.