2022-02-27 18:42:36 +01:00
|
|
|
|
{ lowPrio, newScope, pkgs, lib, stdenv, cmake
|
2023-11-21 01:05:15 +01:00
|
|
|
|
, preLibcCrossHeaders
|
2023-02-28 14:20:11 +01:00
|
|
|
|
, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith
|
2022-02-27 18:42:36 +01:00
|
|
|
|
, buildLlvmTools # tools, but from the previous stage, for cross
|
|
|
|
|
, targetLlvmLibraries # libraries, but from the next stage, for cross
|
2022-10-25 08:40:01 +02:00
|
|
|
|
, targetLlvm
|
2022-02-27 18:42:36 +01:00
|
|
|
|
# This is the default binutils, but with *this* version of LLD rather
|
2023-05-08 19:00:07 +02:00
|
|
|
|
# than the default LLVM version's, if LLD is the choice. We use these for
|
2022-02-27 18:42:36 +01:00
|
|
|
|
# the `useLLVM` bootstrapping below.
|
|
|
|
|
, bootBintoolsNoLibc ?
|
|
|
|
|
if stdenv.targetPlatform.linker == "lld"
|
|
|
|
|
then null
|
|
|
|
|
else pkgs.bintoolsNoLibc
|
|
|
|
|
, bootBintools ?
|
|
|
|
|
if stdenv.targetPlatform.linker == "lld"
|
|
|
|
|
then null
|
|
|
|
|
else pkgs.bintools
|
|
|
|
|
, darwin
|
2023-11-21 00:44:34 +01:00
|
|
|
|
# LLVM release information; specify one of these but not both:
|
|
|
|
|
, gitRelease ? null
|
|
|
|
|
# i.e.:
|
|
|
|
|
# {
|
|
|
|
|
# version = /* i.e. "15.0.0" */;
|
|
|
|
|
# rev = /* commit SHA */;
|
|
|
|
|
# rev-version = /* human readable version; i.e. "unstable-2022-26-07" */;
|
|
|
|
|
# sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */;
|
|
|
|
|
# }
|
|
|
|
|
, officialRelease ? { version = "14.0.6"; sha256 = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE="; }
|
|
|
|
|
# i.e.:
|
|
|
|
|
# {
|
|
|
|
|
# version = /* i.e. "15.0.0" */;
|
|
|
|
|
# candidate = /* optional; if specified, should be: "rcN" */
|
|
|
|
|
# sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */;
|
|
|
|
|
# }
|
|
|
|
|
# By default, we'll try to fetch a release from `github:llvm/llvm-project`
|
|
|
|
|
# corresponding to the `gitRelease` or `officialRelease` specified.
|
|
|
|
|
#
|
|
|
|
|
# You can provide your own LLVM source by specifying this arg but then it's up
|
|
|
|
|
# to you to make sure that the LLVM repo given matches the release configuration
|
|
|
|
|
# specified.
|
|
|
|
|
, monorepoSrc ? null
|
2022-02-27 18:42:36 +01:00
|
|
|
|
}:
|
|
|
|
|
|
2024-04-04 16:05:18 +02:00
|
|
|
|
assert
|
2023-11-21 00:44:34 +01:00
|
|
|
|
lib.assertMsg
|
2024-04-04 16:05:18 +02:00
|
|
|
|
(lib.xor
|
2023-11-21 00:44:34 +01:00
|
|
|
|
(gitRelease != null)
|
|
|
|
|
(officialRelease != null))
|
|
|
|
|
("must specify `gitRelease` or `officialRelease`" +
|
|
|
|
|
(lib.optionalString (gitRelease != null) " — not both"));
|
2022-02-27 18:42:36 +01:00
|
|
|
|
let
|
2023-11-21 00:44:34 +01:00
|
|
|
|
monorepoSrc' = monorepoSrc;
|
|
|
|
|
in let
|
|
|
|
|
# Import releaseInfo separately to avoid infinite recursion
|
|
|
|
|
inherit (import ../common/common-let.nix { inherit lib gitRelease officialRelease; }) releaseInfo;
|
|
|
|
|
inherit (releaseInfo) release_version version;
|
|
|
|
|
inherit (import ../common/common-let.nix { inherit lib fetchFromGitHub release_version gitRelease officialRelease monorepoSrc'; }) llvm_meta monorepoSrc;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
|
|
|
|
|
tools = lib.makeExtensible (tools: let
|
2023-02-28 14:20:11 +01:00
|
|
|
|
callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 release_version version monorepoSrc buildLlvmTools; });
|
2022-02-27 18:42:36 +01:00
|
|
|
|
mkExtraBuildCommands0 = cc: ''
|
|
|
|
|
rsrc="$out/resource-root"
|
|
|
|
|
mkdir "$rsrc"
|
|
|
|
|
ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc"
|
|
|
|
|
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
|
|
|
|
|
'';
|
|
|
|
|
mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + ''
|
|
|
|
|
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
|
|
|
|
|
ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
bintoolsNoLibc' =
|
|
|
|
|
if bootBintoolsNoLibc == null
|
|
|
|
|
then tools.bintoolsNoLibc
|
|
|
|
|
else bootBintoolsNoLibc;
|
|
|
|
|
bintools' =
|
|
|
|
|
if bootBintools == null
|
|
|
|
|
then tools.bintools
|
|
|
|
|
else bootBintools;
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
|
|
libllvm = callPackage ./llvm {
|
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# `llvm` historically had the binaries. When choosing an output explicitly,
|
|
|
|
|
# we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get*
|
2023-02-27 03:53:33 +01:00
|
|
|
|
llvm = tools.libllvm;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
|
|
|
|
|
libclang = callPackage ./clang {
|
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-27 03:53:33 +01:00
|
|
|
|
clang-unwrapped = tools.libclang;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
|
|
|
|
|
llvm-manpages = lowPrio (tools.libllvm.override {
|
|
|
|
|
enableManpages = true;
|
|
|
|
|
python3 = pkgs.python3; # don't use python-boot
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
clang-manpages = lowPrio (tools.libclang.override {
|
|
|
|
|
enableManpages = true;
|
|
|
|
|
python3 = pkgs.python3; # don't use python-boot
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
# TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins'
|
|
|
|
|
# lldb-manpages = lowPrio (tools.lldb.override {
|
|
|
|
|
# enableManpages = true;
|
|
|
|
|
# python3 = pkgs.python3; # don't use python-boot
|
|
|
|
|
# });
|
|
|
|
|
|
|
|
|
|
# pick clang appropriate for package set we are targeting
|
|
|
|
|
clang =
|
2023-04-26 15:27:20 +02:00
|
|
|
|
/**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc
|
|
|
|
|
else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM
|
2022-02-27 18:42:36 +01:00
|
|
|
|
else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang
|
|
|
|
|
else tools.libcxxClang;
|
|
|
|
|
|
|
|
|
|
libstdcxxClang = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
# libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
|
|
|
|
|
libcxx = null;
|
|
|
|
|
extraPackages = [
|
|
|
|
|
targetLlvmLibraries.compiler-rt
|
|
|
|
|
];
|
|
|
|
|
extraBuildCommands = mkExtraBuildCommands cc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
libcxxClang = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = targetLlvmLibraries.libcxx;
|
|
|
|
|
extraPackages = [
|
|
|
|
|
targetLlvmLibraries.compiler-rt
|
|
|
|
|
];
|
|
|
|
|
extraBuildCommands = mkExtraBuildCommands cc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lld = callPackage ./lld {
|
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-06 20:03:17 +02:00
|
|
|
|
lldb = callPackage ../common/lldb.nix {
|
|
|
|
|
patches =
|
|
|
|
|
let
|
2023-09-06 00:05:32 +02:00
|
|
|
|
resourceDirPatch = callPackage
|
|
|
|
|
({ substituteAll, libclang }: substituteAll
|
|
|
|
|
{
|
|
|
|
|
src = ./lldb/resource-dir.patch;
|
|
|
|
|
clangLibDir = "${libclang.lib}/lib";
|
|
|
|
|
})
|
|
|
|
|
{ };
|
2023-05-06 20:03:17 +02:00
|
|
|
|
in
|
|
|
|
|
[
|
|
|
|
|
./lldb/procfs.patch
|
|
|
|
|
resourceDirPatch
|
2023-08-28 08:28:40 +02:00
|
|
|
|
../common/lldb/gnu-install-dirs.patch
|
2023-05-06 20:03:17 +02:00
|
|
|
|
]
|
|
|
|
|
# This is a stopgap solution if/until the macOS SDK used for x86_64 is
|
|
|
|
|
# updated.
|
|
|
|
|
#
|
|
|
|
|
# The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h`
|
|
|
|
|
# header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use
|
|
|
|
|
# of this preprocessor symbol in `lldb` with its expansion.
|
|
|
|
|
#
|
|
|
|
|
# See here for some context:
|
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
stdenv.targetPlatform.isDarwin
|
|
|
|
|
&& !stdenv.targetPlatform.isAarch64
|
|
|
|
|
&& (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
|
|
|
|
|
) ./lldb/cpu_subtype_arm64e_replacement.patch;
|
2023-09-06 05:53:50 +02:00
|
|
|
|
inherit llvm_meta;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Below, is the LLVM bootstrapping logic. It handles building a
|
|
|
|
|
# fully LLVM toolchain from scratch. No GCC toolchain should be
|
|
|
|
|
# pulled in. As a consequence, it is very quick to build different
|
|
|
|
|
# targets provided by LLVM and we can also build for what GCC
|
|
|
|
|
# doesn’t support like LLVM. Probably we should move to some other
|
|
|
|
|
# file.
|
|
|
|
|
|
2023-09-06 02:01:34 +02:00
|
|
|
|
bintools-unwrapped = callPackage ../common/bintools.nix { };
|
2022-02-27 18:42:36 +01:00
|
|
|
|
|
|
|
|
|
bintoolsNoLibc = wrapBintoolsWith {
|
|
|
|
|
bintools = tools.bintools-unwrapped;
|
|
|
|
|
libc = preLibcCrossHeaders;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bintools = wrapBintoolsWith {
|
|
|
|
|
bintools = tools.bintools-unwrapped;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clangUseLLVM = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = targetLlvmLibraries.libcxx;
|
|
|
|
|
bintools = bintools';
|
|
|
|
|
extraPackages = [
|
|
|
|
|
targetLlvmLibraries.compiler-rt
|
|
|
|
|
] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [
|
|
|
|
|
targetLlvmLibraries.libunwind
|
|
|
|
|
];
|
2022-05-01 04:17:08 +02:00
|
|
|
|
extraBuildCommands = mkExtraBuildCommands cc;
|
|
|
|
|
nixSupport.cc-cflags =
|
|
|
|
|
[ "-rtlib=compiler-rt"
|
|
|
|
|
"-Wno-unused-command-line-argument"
|
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt}/lib"
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
|
|
|
|
|
++ lib.optional
|
2023-01-22 23:31:34 +01:00
|
|
|
|
(!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false)
|
2022-05-01 04:17:08 +02:00
|
|
|
|
"-lunwind"
|
|
|
|
|
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
|
2023-10-15 04:35:33 +02:00
|
|
|
|
nixSupport.cc-ldflags = lib.optionals (!stdenv.targetPlatform.isWasm) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clangNoLibcxx = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintools';
|
|
|
|
|
extraPackages = [
|
|
|
|
|
targetLlvmLibraries.compiler-rt
|
|
|
|
|
];
|
2022-05-01 04:17:08 +02:00
|
|
|
|
extraBuildCommands = mkExtraBuildCommands cc;
|
|
|
|
|
nixSupport.cc-cflags = [
|
|
|
|
|
"-rtlib=compiler-rt"
|
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt}/lib"
|
|
|
|
|
"-nostdlib++"
|
|
|
|
|
];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clangNoLibc = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintoolsNoLibc';
|
|
|
|
|
extraPackages = [
|
|
|
|
|
targetLlvmLibraries.compiler-rt
|
|
|
|
|
];
|
2022-05-01 04:17:08 +02:00
|
|
|
|
extraBuildCommands = mkExtraBuildCommands cc;
|
|
|
|
|
nixSupport.cc-cflags = [
|
|
|
|
|
"-rtlib=compiler-rt"
|
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt}/lib"
|
|
|
|
|
];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clangNoCompilerRt = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintoolsNoLibc';
|
|
|
|
|
extraPackages = [ ];
|
2022-05-01 04:17:08 +02:00
|
|
|
|
extraBuildCommands = mkExtraBuildCommands0 cc;
|
|
|
|
|
nixSupport.cc-cflags = [ "-nostartfiles" ];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clangNoCompilerRtWithLibc = wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintools';
|
|
|
|
|
extraPackages = [ ];
|
|
|
|
|
extraBuildCommands = mkExtraBuildCommands0 cc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
libraries = lib.makeExtensible (libraries: let
|
2023-02-28 14:20:11 +01:00
|
|
|
|
callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 release_version version monorepoSrc; });
|
2022-02-27 18:42:36 +01:00
|
|
|
|
in {
|
|
|
|
|
|
|
|
|
|
compiler-rt-libc = callPackage ./compiler-rt {
|
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
stdenv = if stdenv.hostPlatform.useLLVM or false
|
|
|
|
|
then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc
|
|
|
|
|
else stdenv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
compiler-rt-no-libc = callPackage ./compiler-rt {
|
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
stdenv = if stdenv.hostPlatform.useLLVM or false
|
|
|
|
|
then overrideCC stdenv buildLlvmTools.clangNoCompilerRt
|
|
|
|
|
else stdenv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# N.B. condition is safe because without useLLVM both are the same.
|
|
|
|
|
compiler-rt = if stdenv.hostPlatform.isAndroid
|
|
|
|
|
then libraries.compiler-rt-libc
|
|
|
|
|
else libraries.compiler-rt-no-libc;
|
|
|
|
|
|
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clang;
|
|
|
|
|
|
|
|
|
|
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
|
|
|
|
|
|
|
|
|
|
libcxx = callPackage ./libcxx {
|
|
|
|
|
inherit llvm_meta;
|
llvmPackages_{12,13,14,15,16,17,git}.{libcxx,libcxxabi}: merge libcxxabi into libcxx (#292043)
- merge libcxxabi into libcxx for LLVM 12, 13, 14, 15, 16, 17, and git.
- remove the link time workaround `-lc++ -lc++abi` from 58 packages as it is no longer required.
- fixes https://github.com/NixOS/nixpkgs/issues/166205
- provides alternative fixes for. https://github.com/NixOS/nixpkgs/issues/269548 https://github.com/NixOS/nix/issues/9640
- pkgsCross.x86_64-freebsd builds work again
This change can be represented in 3 stages
1. merge libcxxabi into libcxx -- files: pkgs/development/compilers/llvm/[12, git]/{libcxx, libcxxabi}
2. update stdenv to account for merge -- files: stdenv.{adapters, cc.wrapper, darwin}
3. remove all references to libcxxabi outside of llvm (about 58 packages modified)
### merging libcxxabi into libcxx
- take the union of the libcxxabi and libcxx cmake flags
- eliminate the libcxx-headers-only package - it was only needed to break libcxx <-> libcxxabi circular dependency
- libcxx.cxxabi is removed. external cxxabi (freebsd) will symlink headers / libs into libcxx.
- darwin will re-export the libcxxabi symbols into libcxx so linking `-lc++` is sufficient.
- linux/freebsd `libc++.so` is a linker script `LINK(libc++.so.1, -lc++abi)` making `-lc++` sufficient.
- libcxx/default.nix [12, 17] are identical except for patches and `LIBCXX_ADDITIONAL_LIBRARIES` (only used in 16+)
- git/libcxx/defaul.nix does not link with -nostdlib when useLLVM is true so flag is removed. this is not much different than before as libcxxabi used -nostdlib where libcxx did not, so libc was linked in anyway.
### stdenv changes
- darwin bootstrap, remove references to libcxxabi and cxxabi
- cc-wrapper: remove c++ link workaround when libcxx.cxxabi doesn't exist (still exists for LLVM pre 12)
- adapter: update overrideLibcxx to account for a pkgs.stdenv that only has libcxx
### 58 package updates
- remove `NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}` as no longer needed
- swift, nodejs_v8 remove libcxxabi references in the clang override
https://github.com/NixOS/nixpkgs/pull/292043
2024-03-11 11:53:37 +01:00
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-28 19:25:39 +01:00
|
|
|
|
libunwind = callPackage ../common/libunwind {
|
|
|
|
|
patches = [
|
|
|
|
|
./libunwind/gnu-install-dirs.patch
|
|
|
|
|
];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
inherit llvm_meta;
|
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-28 19:28:13 +01:00
|
|
|
|
openmp = callPackage ../common/openmp {
|
|
|
|
|
patches = [
|
|
|
|
|
./openmp/gnu-install-dirs.patch
|
|
|
|
|
./openmp/run-lit-directly.patch
|
|
|
|
|
];
|
2022-10-25 08:40:01 +02:00
|
|
|
|
inherit llvm_meta targetLlvm;
|
2022-02-27 18:42:36 +01:00
|
|
|
|
};
|
|
|
|
|
});
|
2023-06-06 06:56:13 +02:00
|
|
|
|
noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
|
2022-02-27 18:42:36 +01:00
|
|
|
|
|
2023-06-06 06:56:13 +02:00
|
|
|
|
in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools)
|