Commit 1d6675e5 authored by sternenseemann's avatar sternenseemann
Browse files

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.
parent f7dbf14e
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
  stdenv,
  llvm_meta,
  monorepoSrc,
  release_version,
  runCommand,
  cmake,
  libxml2,
@@ -20,16 +21,22 @@ stdenv.mkDerivation (finalAttrs: {
  inherit version patches;

  # Blank llvm dir just so relative path works
  src = runCommand "bolt-src-${finalAttrs.version}" { } ''
  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
  '';
    ''
  );

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

+4 −2
Original line number Diff line number Diff line
@@ -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;
+4 −2
Original line number Diff line number Diff line
@@ -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")
+1 −7
Original line number Diff line number Diff line
@@ -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
+11 −5
Original line number Diff line number Diff line
@@ -22,11 +22,17 @@ stdenv.mkDerivation rec {
  pname = "libclc";
  inherit version;

  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}/${pname} "$out"
  '';
    ''
  );

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

Loading