Skip to content

Commit

Permalink
llvmPackages_12: build from monorepo source
Browse files Browse the repository at this point in the history
As mentioned in NixOS#305146, keeping LLVM 12 is a source of pain because it
is the only version to be built from individual release tarball instead
of the LLVM monorepo. This commit makes LLVM 12 start from the monorepo
as well, simplifying all common LLVM expressions in the process.

With NixOS#347887, some quirks in the expressions for LLVM <14 were ironed
out, so building LLVM through from the monorepo is quite simple now.

- Most expressions only required minor changes, mostly removing the
  special casing for `sourceRoot`.

- The patch lists from llvm/12/default.nix were ported to
  common/default.nix. This only required a few extra conditionals which
  could be reduced via a rebuild also involving other LLVM versions.
  Outstanding tasks of little urgency have been noted in TODO comments.
  I have verified that the patch lists stay the same for all packages
  except LLVM where merely the order changes. An extra set of eyes
  is appreciated, of course.

- clang: The expression was reworked to use the same symlink location
  for clang-tools-extra for all versions including LLVM 12. This
  required adjusting the ad hoc patching of the clangd cmake files
  slightly.

- libunwind: We no longer need to make the libcxx sources available
  manually. We can rely on the monorepo source instead.

- lld: We no longer need to make the libunwind sources available manually.

- llvm: We no longer need to make the polly sources available manually
  • Loading branch information
sternenseemann committed Oct 14, 2024
1 parent d87b32b commit 0ee936c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 522 deletions.
445 changes: 0 additions & 445 deletions pkgs/development/compilers/llvm/12/default.nix

This file was deleted.

29 changes: 10 additions & 19 deletions pkgs/development/compilers/llvm/common/clang/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
, buildLlvmTools
, fixDarwinDylibNames
, enableManpages ? false
, clang-tools-extra_src ? null
, devExtraCmakeFlags ? []
}:

Expand All @@ -38,8 +37,7 @@ let

src = src';

sourceRoot = if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
sourceRoot = "${src.name}/${pname}";

nativeBuildInputs = [ cmake ]
++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
Expand Down Expand Up @@ -81,13 +79,17 @@ let
# Make sure clang passes the correct location of libLTO to ld64
substituteInPlace lib/Driver/ToolChains/Darwin.cpp \
--replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";'
'' + (if lib.versionOlder release_version "13" then ''
(cd tools && ln -s ../../clang-tools-extra extra)
'' + lib.optionalString (lib.versionOlder release_version "13") ''
sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
-e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
lib/Driver/ToolChains/*.cpp
'' else ''
(cd tools && ln -s ../../clang-tools-extra extra)
'') + lib.optionalString stdenv.hostPlatform.isMusl ''
substituteInPlace tools/extra/clangd/quality/CompletionModel.cmake \
--replace ' ''${CMAKE_SOURCE_DIR}/../clang-tools-extra' ' ''${CMAKE_SOURCE_DIR}/tools/extra'
''
+ lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
'';

Expand Down Expand Up @@ -213,18 +215,7 @@ let
'';
} else {
ninjaFlags = [ "docs-clang-man" ];
})) // (lib.optionalAttrs (clang-tools-extra_src != null) { inherit clang-tools-extra_src; })
// (lib.optionalAttrs (lib.versionOlder release_version "13") {
unpackPhase = ''
unpackFile $src
mv clang-* clang
sourceRoot=$PWD/clang
unpackFile ${clang-tools-extra_src}
mv clang-tools-extra-* $sourceRoot/tools/extra
substituteInPlace $sourceRoot/tools/extra/clangd/quality/CompletionModel.cmake \
--replace ' ''${CMAKE_SOURCE_DIR}/../clang-tools-extra' ' ''${CMAKE_SOURCE_DIR}/tools/extra'
'';
})
}))
// (lib.optionalAttrs (lib.versionAtLeast release_version "15") {
env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM) {
# The following warning is triggered with (at least) gcc >=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ stdenv.mkDerivation ({
inherit pname version patches;

src = src';
sourceRoot = if lib.versionOlder release_version "13" then null
else "${src'.name}/${baseName}";
sourceRoot = "${src'.name}/${baseName}";

nativeBuildInputs = [ cmake ]
++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
Expand Down
50 changes: 39 additions & 11 deletions pkgs/development/compilers/llvm/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ let
libllvm = callPackage ./llvm {
patches =
lib.optional (lib.versionOlder metadata.release_version "14") ./llvm/llvm-config-link-static.patch
++ lib.optionals (lib.versions.major metadata.release_version == "12") [
(metadata.getVersionFile "llvm/fix-llvm-issue-49955.patch")

# On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test.
(fetchpatch {
name = "uops-CMOV16rm-noreg.diff";
url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff";
sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi";
stripLen = 1;
})
]
++ [ (metadata.getVersionFile "llvm/gnu-install-dirs.patch") ]
++ lib.optionals (lib.versionAtLeast metadata.release_version "15") [
# Running the tests involves invoking binaries (like `opt`) that depend on
Expand Down Expand Up @@ -443,7 +454,7 @@ let
hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA=";
}
)
++ lib.optionals (lib.versions.major metadata.release_version == "13") [
++ lib.optionals (lib.versionOlder metadata.release_version "14") [
# Backport gcc-13 fixes with missing includes.
(fetchpatch {
name = "signals-gcc-13.patch";
Expand Down Expand Up @@ -529,8 +540,11 @@ let
# mis-compilation in firefox.
# See: https://bugzilla.mozilla.org/show_bug.cgi?id=1741454
(metadata.getVersionFile "clang/revert-malloc-alignment-assumption.patch")
++ [
++ lib.optionals (lib.versionAtLeast metadata.release_version "13") [
# TODO: This also applies for clang == 12, do we need it?
./clang/add-nostdlibinc-flag.patch
]
++ [
(substituteAll {
src =
if (lib.versionOlder metadata.release_version "16") then
Expand Down Expand Up @@ -959,24 +973,33 @@ let
);

compiler-rtPatches =
lib.optional (lib.versionOlder metadata.release_version "15") (
metadata.getVersionFile "compiler-rt/codesign.patch"
) # Revert compiler-rt commit that makes codesign mandatory
lib.optionals (lib.versions.major metadata.release_version == "12") [
# Revert compiler-rt commit that makes codesign mandatory
./compiler-rt/7-12-codesign.patch
]
++ lib.optional (
lib.versionAtLeast metadata.release_version "13" && lib.versionOlder metadata.release_version "15"
) (metadata.getVersionFile "compiler-rt/codesign.patch") # Revert compiler-rt commit that makes codesign mandatory
++ [
(metadata.getVersionFile "compiler-rt/X86-support-extension.patch") # Add support for i486 i586 i686 by reusing i386 config
]
++ lib.optional (
lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18"
lib.versions.major metadata.release_version == "12"
|| (
lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18"
)
) (metadata.getVersionFile "compiler-rt/gnu-install-dirs.patch")
++ [
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
(metadata.getVersionFile "compiler-rt/normalize-var.patch")
]
++
lib.optional (lib.versionOlder metadata.release_version "18")
lib.optional
(lib.versionAtLeast metadata.release_version "13" && lib.versionOlder metadata.release_version "18")
# Prevent a compilation error on darwin
(metadata.getVersionFile "compiler-rt/darwin-targetconditionals.patch")
# TODO: make unconditional and remove in <15 section below. Causes rebuilds.
++ lib.optionals (lib.versionAtLeast metadata.release_version "15") [
# See: https://github.com/NixOS/nixpkgs/pull/186575
./compiler-rt/darwin-plistbuddy-workaround.patch
Expand All @@ -992,13 +1015,18 @@ let
./compiler-rt/armv6-mcr-dmb.patch
./compiler-rt/armv6-sync-ops-no-thumb.patch
]
++ lib.optionals (lib.versionOlder metadata.release_version "18") [
# Fix build on armv6l
./compiler-rt/armv6-scudo-no-yield.patch
]
++
lib.optionals
(lib.versionAtLeast metadata.release_version "13" && lib.versionOlder metadata.release_version "18")
[
# Fix build on armv6l
./compiler-rt/armv6-scudo-no-yield.patch
]
++ [
# Fix build on armv6l
./compiler-rt/armv6-no-ldrexd-strexd.patch
]
++ lib.optionals (lib.versionAtLeast metadata.release_version "13") [
(metadata.getVersionFile "compiler-rt/armv6-scudo-libatomic.patch")
]
++ lib.optional (lib.versionAtLeast metadata.release_version "19") (fetchpatch {
Expand Down
12 changes: 3 additions & 9 deletions pkgs/development/compilers/llvm/common/libunwind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ let

hasPatches = builtins.length patches > 0;

postUnpack = lib.optionalString (lib.versions.major release_version == "12") ''
ln -s ${libcxx.src}/libcxx .
ln -s ${libcxx.src}/llvm .
'';

prePatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) ''
cd ../${pname}
chmod -R u+w .
Expand All @@ -60,8 +55,8 @@ stdenv.mkDerivation (rec {
src = src';

sourceRoot =
if lib.versionOlder release_version "13" then null
else if lib.versionAtLeast release_version "15" then "${src.name}/runtimes"
if lib.versionAtLeast release_version "15"
then "${src.name}/runtimes"
else "${src.name}/${pname}";

outputs = [ "out" "dev" ];
Expand All @@ -85,7 +80,6 @@ stdenv.mkDerivation (rec {
dependency of other runtimes.
'';
};
} // (if postUnpack != "" then { inherit postUnpack; } else {})
// (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {})
} // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {})
// (if prePatch != "" then { inherit prePatch; } else {})
// (if postPatch != "" then { inherit postPatch; } else {}))
12 changes: 2 additions & 10 deletions pkgs/development/compilers/llvm/common/lld/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
, buildLlvmTools
, monorepoSrc ? null
, src ? null
, libunwind ? null
, runCommand
, cmake
, ninja
Expand All @@ -30,12 +29,7 @@ let
mkdir -p "$out/llvm"
'') 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") ''
postPatch = lib.optionalString (lib.versionOlder release_version "14") ''
substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '(../'
'';
Expand All @@ -45,9 +39,7 @@ stdenv.mkDerivation (rec {

src = src';

sourceRoot =
if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
sourceRoot = "${src.name}/${pname}";

nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja;
buildInputs = [ libllvm libxml2 ];
Expand Down
17 changes: 2 additions & 15 deletions pkgs/development/compilers/llvm/common/llvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
, pkgsBuildBuild
, pollyPatches ? []
, patches ? []
, polly_src ? null
, src ? null
, monorepoSrc ? null
, runCommand
Expand Down Expand Up @@ -107,8 +106,7 @@ stdenv.mkDerivation (finalAttrs: {
src = src';
patches = patches';

sourceRoot = if lib.versionOlder release_version "13" then null
else "${finalAttrs.src.name}/${pname}";
sourceRoot = "${finalAttrs.src.name}/${pname}";

outputs = [ "out" "lib" "dev" "python" ];

Expand Down Expand Up @@ -493,18 +491,7 @@ stdenv.mkDerivation (finalAttrs: {

postPatch = null;
postInstall = null;
})) // lib.optionalAttrs (lib.versionOlder release_version "13") {
inherit polly_src;

unpackPhase = ''
unpackFile $src
mv llvm-${release_version}* llvm
sourceRoot=$PWD/llvm
'' + optionalString enablePolly ''
unpackFile $polly_src
mv polly-* $sourceRoot/tools/polly
'';
} // lib.optionalAttrs (lib.versionAtLeast release_version "13") {
})) // lib.optionalAttrs (lib.versionAtLeast release_version "13") {
nativeCheckInputs = [ which ] ++ lib.optional (stdenv.hostPlatform.isDarwin && lib.versionAtLeast release_version "15") sysctl;
} // lib.optionalAttrs (lib.versionOlder release_version "15") {
# hacky fix: created binaries need to be run before installation
Expand Down
4 changes: 1 addition & 3 deletions pkgs/development/compilers/llvm/common/openmp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ stdenv.mkDerivation (rec {

src = src';

sourceRoot =
if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
sourceRoot = "${src.name}/${pname}";

outputs = [ "out" ]
++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/compilers/llvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}@packageSetArgs:
let
versions = {
"12.0.1".officialRelease.sha256 = "08s5w2db9imb2yaqsvxs6pg21csi1cf6wa35rf8x6q07mam7j8qv";
"13.0.1".officialRelease.sha256 = "06dv6h5dmvzdxbif2s8njki6h32796v368dyb5945x8gjj72xh7k";
"14.0.6".officialRelease.sha256 = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE=";
"15.0.7".officialRelease.sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s=";
Expand Down
11 changes: 3 additions & 8 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15262,16 +15262,10 @@ with pkgs;
stdenv.targetPlatform));
in pkgs.${"llvmPackages_${minSupported}"};

llvmPackages_12 = recurseIntoAttrs (callPackage ../development/compilers/llvm/12 {
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_12.tools;
targetLlvmLibraries = targetPackages.llvmPackages_12.libraries or llvmPackages_12.libraries;
targetLlvm = targetPackages.llvmPackages_12.llvm or llvmPackages_12.llvm;
});

inherit (rec {
llvmPackagesSet = recurseIntoAttrs (callPackages ../development/compilers/llvm { });

llvmPackages_12 = llvmPackagesSet."12";
llvmPackages_13 = llvmPackagesSet."13";
llvmPackages_14 = llvmPackagesSet."14";
llvmPackages_15 = llvmPackagesSet."15";
Expand All @@ -15290,7 +15284,8 @@ with pkgs;
lldb_19 = llvmPackages_19.lldb;
llvm_19 = llvmPackages_19.llvm;
bolt_19 = llvmPackages_19.bolt;
}) llvmPackages_13
}) llvmPackages_12
llvmPackages_13
llvmPackages_14
llvmPackages_15
llvmPackages_16
Expand Down

0 comments on commit 0ee936c

Please sign in to comment.