2024-07-06 21:43:37 -07:00
|
|
|
|
{
|
|
|
|
|
lowPrio,
|
|
|
|
|
newScope,
|
|
|
|
|
pkgs,
|
2025-05-26 01:40:09 -04:00
|
|
|
|
targetPackages,
|
2024-07-06 21:43:37 -07:00
|
|
|
|
lib,
|
|
|
|
|
stdenv,
|
2023-11-27 08:02:52 +02:00
|
|
|
|
libxcrypt,
|
2024-07-06 21:43:37 -07:00
|
|
|
|
substitute,
|
2024-11-23 13:45:07 +01:00
|
|
|
|
replaceVars,
|
2024-07-06 21:43:37 -07:00
|
|
|
|
fetchFromGitHub,
|
|
|
|
|
fetchpatch,
|
2024-09-12 11:20:59 +01:00
|
|
|
|
fetchpatch2,
|
2024-07-06 21:43:37 -07:00
|
|
|
|
overrideCC,
|
|
|
|
|
wrapCCWith,
|
|
|
|
|
wrapBintoolsWith,
|
2025-03-19 17:52:07 -07:00
|
|
|
|
buildPackages,
|
2024-07-06 21:43:37 -07:00
|
|
|
|
buildLlvmTools, # tools, but from the previous stage, for cross
|
|
|
|
|
targetLlvmLibraries, # libraries, but from the next stage, for cross
|
|
|
|
|
targetLlvm,
|
|
|
|
|
# This is the default binutils, but with *this* version of LLD rather
|
|
|
|
|
# than the default LLVM version's, if LLD is the choice. We use these for
|
|
|
|
|
# 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,
|
|
|
|
|
gitRelease ? null,
|
|
|
|
|
officialRelease ? null,
|
|
|
|
|
monorepoSrc ? null,
|
|
|
|
|
version ? null,
|
2025-03-16 20:36:53 -07:00
|
|
|
|
patchesFn ? lib.id,
|
2024-09-14 15:37:31 +01:00
|
|
|
|
# Allows passthrough to packages via newScope. This makes it possible to
|
|
|
|
|
# do `(llvmPackages.override { <someLlvmDependency> = bar; }).clang` and get
|
|
|
|
|
# an llvmPackages whose packages are overridden in an internally consistent way.
|
2024-07-06 21:43:37 -07:00
|
|
|
|
...
|
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
|
|
assert lib.assertMsg (lib.xor (gitRelease != null) (officialRelease != null)) (
|
|
|
|
|
"must specify `gitRelease` or `officialRelease`"
|
|
|
|
|
+ (lib.optionalString (gitRelease != null) " — not both")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
monorepoSrc' = monorepoSrc;
|
|
|
|
|
|
|
|
|
|
metadata = rec {
|
|
|
|
|
# Import releaseInfo separately to avoid infinite recursion
|
|
|
|
|
inherit
|
|
|
|
|
(import ./common-let.nix {
|
|
|
|
|
inherit (args)
|
|
|
|
|
lib
|
|
|
|
|
gitRelease
|
|
|
|
|
officialRelease
|
|
|
|
|
version
|
|
|
|
|
;
|
|
|
|
|
})
|
|
|
|
|
releaseInfo
|
|
|
|
|
;
|
|
|
|
|
inherit (releaseInfo) release_version version;
|
|
|
|
|
inherit
|
|
|
|
|
(import ./common-let.nix {
|
|
|
|
|
inherit
|
|
|
|
|
lib
|
|
|
|
|
fetchFromGitHub
|
|
|
|
|
release_version
|
|
|
|
|
gitRelease
|
|
|
|
|
officialRelease
|
|
|
|
|
monorepoSrc'
|
|
|
|
|
version
|
|
|
|
|
;
|
|
|
|
|
})
|
|
|
|
|
llvm_meta
|
|
|
|
|
monorepoSrc
|
|
|
|
|
;
|
|
|
|
|
src = monorepoSrc;
|
|
|
|
|
versionDir =
|
|
|
|
|
(builtins.toString ../.)
|
|
|
|
|
+ "/${if (gitRelease != null) then "git" else lib.versions.major release_version}";
|
|
|
|
|
getVersionFile =
|
|
|
|
|
p:
|
|
|
|
|
builtins.path {
|
|
|
|
|
name = builtins.baseNameOf p;
|
2024-08-09 12:34:48 -07:00
|
|
|
|
path =
|
2024-08-12 20:50:07 -07:00
|
|
|
|
let
|
2025-03-16 20:36:53 -07:00
|
|
|
|
patches = args.patchesFn (import ./patches.nix);
|
2024-08-12 20:50:07 -07:00
|
|
|
|
|
|
|
|
|
constraints = patches."${p}" or null;
|
|
|
|
|
matchConstraint =
|
|
|
|
|
{
|
|
|
|
|
before ? null,
|
|
|
|
|
after ? null,
|
|
|
|
|
path,
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
check = fn: value: if value == null then true else fn release_version value;
|
|
|
|
|
matchBefore = check lib.versionOlder before;
|
|
|
|
|
matchAfter = check lib.versionAtLeast after;
|
|
|
|
|
in
|
|
|
|
|
matchBefore && matchAfter;
|
|
|
|
|
|
|
|
|
|
patchDir =
|
|
|
|
|
toString
|
|
|
|
|
(
|
|
|
|
|
if constraints == null then
|
|
|
|
|
{ path = metadata.versionDir; }
|
|
|
|
|
else
|
|
|
|
|
(lib.findFirst matchConstraint { path = metadata.versionDir; } constraints)
|
|
|
|
|
).path;
|
|
|
|
|
in
|
|
|
|
|
"${patchDir}/${p}";
|
2024-07-06 21:43:37 -07:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tools = lib.makeExtensible (
|
|
|
|
|
tools:
|
|
|
|
|
let
|
2024-10-11 11:41:49 +02:00
|
|
|
|
callPackage = newScope (tools // args // metadata);
|
2024-07-06 21:43:37 -07:00
|
|
|
|
clangVersion =
|
|
|
|
|
if (lib.versionOlder metadata.release_version "16") then
|
|
|
|
|
metadata.release_version
|
|
|
|
|
else
|
|
|
|
|
lib.versions.major metadata.release_version;
|
|
|
|
|
mkExtraBuildCommands0 = cc: ''
|
|
|
|
|
rsrc="$out/resource-root"
|
|
|
|
|
mkdir "$rsrc"
|
2024-11-07 09:43:39 +00:00
|
|
|
|
ln -s "${lib.getLib cc}/lib/clang/${clangVersion}/include" "$rsrc"
|
2024-07-06 21:43:37 -07:00
|
|
|
|
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
|
|
|
|
|
'';
|
2023-11-27 08:02:52 +02:00
|
|
|
|
mkExtraBuildCommandsBasicRt =
|
|
|
|
|
cc:
|
|
|
|
|
mkExtraBuildCommands0 cc
|
|
|
|
|
+ ''
|
|
|
|
|
ln -s "${targetLlvmLibraries.compiler-rt-no-libc.out}/lib" "$rsrc/lib"
|
|
|
|
|
'';
|
2024-07-06 21:43:37 -07:00
|
|
|
|
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 {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# `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*
|
|
|
|
|
llvm = tools.libllvm;
|
|
|
|
|
|
2024-12-18 22:23:34 +00:00
|
|
|
|
tblgen = callPackage ./tblgen.nix {
|
2025-02-05 19:05:38 -08:00
|
|
|
|
patches =
|
|
|
|
|
builtins.filter
|
|
|
|
|
# Crude method to drop polly patches if present, they're not needed for tblgen.
|
|
|
|
|
(p: (!lib.hasInfix "-polly" p))
|
|
|
|
|
tools.libllvm.patches;
|
2025-02-11 14:16:39 +01:00
|
|
|
|
clangPatches =
|
|
|
|
|
[
|
|
|
|
|
# Would take tools.libclang.patches, but this introduces a cycle due
|
|
|
|
|
# to replacements depending on the llvm outpath (e.g. the LLVMgold patch).
|
|
|
|
|
# So take the only patch known to be necessary.
|
|
|
|
|
(metadata.getVersionFile "clang/gnu-install-dirs.patch")
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional (stdenv.isAarch64 && lib.versions.major metadata.release_version == "17")
|
|
|
|
|
# Fixes llvm17 tblgen builds on aarch64.
|
|
|
|
|
# https://github.com/llvm/llvm-project/issues/106521#issuecomment-2337175680
|
|
|
|
|
(metadata.getVersionFile "clang/aarch64-tblgen.patch");
|
2024-12-18 22:23:34 +00:00
|
|
|
|
};
|
2024-12-06 11:26:22 +00:00
|
|
|
|
|
2024-07-06 21:43:37 -07:00
|
|
|
|
libclang = callPackage ./clang {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clang-unwrapped = tools.libclang;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Wrapper for standalone command line utilities
|
|
|
|
|
clang-tools = callPackage ./clang-tools { };
|
|
|
|
|
|
|
|
|
|
# pick clang appropriate for package set we are targeting
|
|
|
|
|
clang =
|
|
|
|
|
if stdenv.targetPlatform.libc == null then
|
|
|
|
|
tools.clangNoLibc
|
|
|
|
|
else if stdenv.targetPlatform.useLLVM or false then
|
|
|
|
|
tools.clangUseLLVM
|
|
|
|
|
else if (pkgs.targetPackages.stdenv or args.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 {
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-18 18:00:15 -08:00
|
|
|
|
lldbPlugins = lib.makeExtensible (
|
|
|
|
|
lldbPlugins:
|
|
|
|
|
let
|
2025-02-05 19:05:38 -08:00
|
|
|
|
callPackage = newScope (lldbPlugins // tools // args // metadata);
|
2024-12-18 18:00:15 -08:00
|
|
|
|
in
|
|
|
|
|
lib.recurseIntoAttrs { llef = callPackage ./lldb-plugins/llef.nix { }; }
|
|
|
|
|
);
|
|
|
|
|
|
2025-03-30 21:05:14 -07:00
|
|
|
|
lldb = callPackage ./lldb (
|
2024-07-06 21:43:37 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versions.major metadata.release_version == "16") {
|
|
|
|
|
src = callPackage (
|
|
|
|
|
{ runCommand }:
|
|
|
|
|
runCommand "lldb-src-${metadata.version}" { } ''
|
|
|
|
|
mkdir -p "$out"
|
|
|
|
|
cp -r ${monorepoSrc}/cmake "$out"
|
|
|
|
|
cp -r ${monorepoSrc}/lldb "$out"
|
|
|
|
|
''
|
|
|
|
|
) { };
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
bintools-unwrapped = callPackage ./bintools.nix { };
|
|
|
|
|
|
|
|
|
|
bintoolsNoLibc = wrapBintoolsWith {
|
|
|
|
|
bintools = tools.bintools-unwrapped;
|
2025-05-26 01:40:09 -04:00
|
|
|
|
libc = targetPackages.preLibcHeaders;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 && !stdenv.targetPlatform.isFreeBSD) [
|
|
|
|
|
targetLlvmLibraries.libunwind
|
|
|
|
|
];
|
|
|
|
|
extraBuildCommands =
|
|
|
|
|
lib.optionalString (lib.versions.major metadata.release_version == "13") (
|
|
|
|
|
''
|
|
|
|
|
echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
|
|
|
|
|
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
|
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString (!stdenv.targetPlatform.isWasm) ''
|
|
|
|
|
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
|
|
|
|
|
echo "-L${targetLlvmLibraries.libunwind}/lib" >> $out/nix-support/cc-ldflags
|
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
|
|
|
|
|
echo "-lunwind" >> $out/nix-support/cc-ldflags
|
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString stdenv.targetPlatform.isWasm ''
|
|
|
|
|
echo "-fno-exceptions" >> $out/nix-support/cc-cflags
|
|
|
|
|
''
|
|
|
|
|
)
|
|
|
|
|
+ mkExtraBuildCommands cc;
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
|
|
|
|
|
nixSupport.cc-cflags =
|
|
|
|
|
[
|
|
|
|
|
"-rtlib=compiler-rt"
|
|
|
|
|
"-Wno-unused-command-line-argument"
|
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt}/lib"
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
|
|
|
|
|
) "--unwindlib=libunwind"
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
!stdenv.targetPlatform.isWasm
|
|
|
|
|
&& !stdenv.targetPlatform.isFreeBSD
|
|
|
|
|
&& stdenv.targetPlatform.useLLVM or false
|
|
|
|
|
) "-lunwind"
|
|
|
|
|
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
|
Revert "llvmPackages.clangUseLLVM: add --undefined-version by default"
This reverts commit 019d0919383f5b28f0339020bb85fb291000bf54.
My comments from the PR (which I only saw after it was merged):
> I'm not convinced this is a good idea — compiler authors turn things
> into errors for a reason, and as a distribution we have our part to
> play in getting problematic things fixed. It's fine to disable the
> errors for packages where it's not reasonably possible to get them
> fixed, but doing it globally means even packages that would be
> simple to fix properly don't get fixed.
> To expand a bit, the problem with this sort of thing is that it's
> very difficult later to tell when it can be removed. By setting this
> globally instead of setting it for individual packages that need it,
> we're effectively stuck with it forever, because it's impossible to
> tell if removing it is going to break any packages. If we mark
> packages individually, it's very easy to tell in future when those
> markings can be removed.
>
> This isn't a theoretical concern: something similar was done for
> pkgsMusl — some compatibility headers were added globally, instead
> of fixing individual affected packages, and now, even though we've
> discovered that the presence of those headers actually causes
> problems for other packages, it's impossible to know what the
> fallout would be of removing it. Let's not repeat this mistake.
So let's revert now, before it's too late.
2024-09-02 17:35:20 +02:00
|
|
|
|
nixSupport.cc-ldflags = lib.optionals (
|
|
|
|
|
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
|
|
|
|
|
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-27 08:02:52 +02:00
|
|
|
|
clangWithLibcAndBasicRtAndLibcxx = wrapCCWith (
|
|
|
|
|
rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = targetLlvmLibraries.libcxx;
|
|
|
|
|
bintools = bintools';
|
|
|
|
|
extraPackages =
|
|
|
|
|
[ targetLlvmLibraries.compiler-rt-no-libc ]
|
2024-09-23 22:06:54 -04:00
|
|
|
|
++ lib.optionals
|
|
|
|
|
(
|
|
|
|
|
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
|
|
|
|
|
)
|
|
|
|
|
[
|
|
|
|
|
targetLlvmLibraries.libunwind
|
|
|
|
|
];
|
2023-11-27 08:02:52 +02:00
|
|
|
|
extraBuildCommands =
|
|
|
|
|
lib.optionalString (lib.versions.major metadata.release_version == "13") (
|
|
|
|
|
''
|
|
|
|
|
echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
|
|
|
|
|
echo "-B${targetLlvmLibraries.compiler-rt-no-libc}/lib" >> $out/nix-support/cc-cflags
|
|
|
|
|
''
|
2024-09-23 22:06:54 -04:00
|
|
|
|
+ lib.optionalString (!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isDarwin) ''
|
2023-11-27 08:02:52 +02:00
|
|
|
|
echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
|
|
|
|
|
echo "-L${targetLlvmLibraries.libunwind}/lib" >> $out/nix-support/cc-ldflags
|
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
|
|
|
|
|
echo "-lunwind" >> $out/nix-support/cc-ldflags
|
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString stdenv.targetPlatform.isWasm ''
|
|
|
|
|
echo "-fno-exceptions" >> $out/nix-support/cc-cflags
|
|
|
|
|
''
|
|
|
|
|
)
|
|
|
|
|
+ mkExtraBuildCommandsBasicRt cc;
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
|
|
|
|
|
nixSupport.cc-cflags =
|
|
|
|
|
[
|
|
|
|
|
"-rtlib=compiler-rt"
|
|
|
|
|
"-Wno-unused-command-line-argument"
|
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional (
|
2024-09-23 22:06:54 -04:00
|
|
|
|
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
|
2023-11-27 08:02:52 +02:00
|
|
|
|
) "--unwindlib=libunwind"
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
!stdenv.targetPlatform.isWasm
|
|
|
|
|
&& !stdenv.targetPlatform.isFreeBSD
|
|
|
|
|
&& stdenv.targetPlatform.useLLVM or false
|
|
|
|
|
) "-lunwind"
|
|
|
|
|
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
|
|
|
|
|
nixSupport.cc-ldflags = lib.optionals (
|
2024-09-23 22:06:54 -04:00
|
|
|
|
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
|
2023-11-27 08:02:52 +02:00
|
|
|
|
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
clangWithLibcAndBasicRt = wrapCCWith (
|
2024-07-06 21:43:37 -07:00
|
|
|
|
rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintools';
|
2023-11-27 08:02:52 +02:00
|
|
|
|
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
|
2024-07-06 21:43:37 -07:00
|
|
|
|
extraBuildCommands =
|
|
|
|
|
lib.optionalString (lib.versions.major metadata.release_version == "13") ''
|
|
|
|
|
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
2023-11-27 08:02:52 +02:00
|
|
|
|
echo "-B${targetLlvmLibraries.compiler-rt-no-libc}/lib" >> $out/nix-support/cc-cflags
|
2024-07-06 21:43:37 -07:00
|
|
|
|
echo "-nostdlib++" >> $out/nix-support/cc-cflags
|
|
|
|
|
''
|
2023-11-27 08:02:52 +02:00
|
|
|
|
+ mkExtraBuildCommandsBasicRt cc;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
|
|
|
|
|
nixSupport.cc-cflags =
|
|
|
|
|
[
|
|
|
|
|
"-rtlib=compiler-rt"
|
2023-11-27 08:02:52 +02:00
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
|
2024-07-06 21:43:37 -07:00
|
|
|
|
"-nostdlib++"
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
|
|
|
|
|
) "-fno-exceptions";
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-27 08:02:52 +02:00
|
|
|
|
clangNoLibcWithBasicRt = wrapCCWith (
|
2024-07-06 21:43:37 -07:00
|
|
|
|
rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintoolsNoLibc';
|
2023-11-27 08:02:52 +02:00
|
|
|
|
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
|
2024-07-06 21:43:37 -07:00
|
|
|
|
extraBuildCommands =
|
|
|
|
|
lib.optionalString (lib.versions.major metadata.release_version == "13") ''
|
|
|
|
|
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
2023-11-27 08:02:52 +02:00
|
|
|
|
echo "-B${targetLlvmLibraries.compiler-rt-no-libc}/lib" >> $out/nix-support/cc-cflags
|
2024-07-06 21:43:37 -07:00
|
|
|
|
''
|
2023-11-27 08:02:52 +02:00
|
|
|
|
+ mkExtraBuildCommandsBasicRt cc;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
|
|
|
|
|
nixSupport.cc-cflags =
|
|
|
|
|
[
|
|
|
|
|
"-rtlib=compiler-rt"
|
2023-11-27 08:02:52 +02:00
|
|
|
|
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
|
2024-07-06 21:43:37 -07:00
|
|
|
|
]
|
|
|
|
|
++ lib.optional (
|
|
|
|
|
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
|
|
|
|
|
) "-fno-exceptions";
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-27 08:02:52 +02:00
|
|
|
|
clangNoLibcNoRt = wrapCCWith (
|
2024-07-06 21:43:37 -07:00
|
|
|
|
rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintoolsNoLibc';
|
|
|
|
|
extraPackages = [ ];
|
2025-03-20 08:06:42 -07:00
|
|
|
|
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
|
|
|
|
|
extraBuildCommands = mkExtraBuildCommands0 cc;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "14") {
|
2025-03-20 08:06:42 -07:00
|
|
|
|
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
|
|
|
|
|
nixSupport.cc-cflags = lib.optional (
|
|
|
|
|
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
|
|
|
|
|
) "-fno-exceptions";
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-27 08:02:52 +02:00
|
|
|
|
# This is an "oddly ordered" bootstrap just for Darwin. Probably
|
|
|
|
|
# don't want it otherwise.
|
2024-07-06 21:43:37 -07:00
|
|
|
|
clangNoCompilerRtWithLibc =
|
|
|
|
|
wrapCCWith rec {
|
|
|
|
|
cc = tools.clang-unwrapped;
|
|
|
|
|
libcxx = null;
|
|
|
|
|
bintools = bintools';
|
|
|
|
|
extraPackages = [ ];
|
|
|
|
|
extraBuildCommands = mkExtraBuildCommands0 cc;
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (
|
|
|
|
|
lib.versionAtLeast metadata.release_version "15" && stdenv.targetPlatform.isWasm
|
|
|
|
|
) { nixSupport.cc-cflags = [ "-fno-exceptions" ]; };
|
2023-11-27 08:02:52 +02:00
|
|
|
|
|
|
|
|
|
# Aliases
|
|
|
|
|
clangNoCompilerRt = tools.clangNoLibcNoRt;
|
|
|
|
|
clangNoLibc = tools.clangNoLibcWithBasicRt;
|
|
|
|
|
clangNoLibcxx = tools.clangWithLibcAndBasicRt;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "15") {
|
|
|
|
|
# TODO: pre-15: 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
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "16") {
|
|
|
|
|
mlir = callPackage ./mlir { };
|
2025-03-30 21:38:45 -07:00
|
|
|
|
libclc = callPackage ./libclc { };
|
2024-07-06 21:43:37 -07:00
|
|
|
|
}
|
2024-03-02 22:08:04 +08:00
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "19") {
|
|
|
|
|
bolt = callPackage ./bolt {
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-07-06 21:43:37 -07:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
libraries = lib.makeExtensible (
|
|
|
|
|
libraries:
|
|
|
|
|
let
|
|
|
|
|
callPackage = newScope (
|
|
|
|
|
libraries
|
|
|
|
|
// buildLlvmTools
|
|
|
|
|
// 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.
|
|
|
|
|
);
|
|
|
|
|
in
|
2024-12-08 19:56:12 -08:00
|
|
|
|
(
|
|
|
|
|
{
|
|
|
|
|
compiler-rt-libc = callPackage ./compiler-rt (
|
|
|
|
|
let
|
|
|
|
|
# temp rename to avoid infinite recursion
|
|
|
|
|
stdenv =
|
|
|
|
|
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
|
|
|
|
|
if args.stdenv.hostPlatform.isDarwin then
|
|
|
|
|
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
|
|
|
|
|
else if args.stdenv.hostPlatform.useLLVM or false then
|
|
|
|
|
overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
|
|
|
|
|
else
|
|
|
|
|
args.stdenv;
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
inherit stdenv;
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
|
|
|
|
|
libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: {
|
|
|
|
|
configureFlags = old.configureFlags ++ [ "--disable-symvers" ];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
compiler-rt-no-libc = callPackage ./compiler-rt {
|
|
|
|
|
doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
|
2023-11-27 08:02:52 +02:00
|
|
|
|
stdenv =
|
2024-09-23 22:06:54 -04:00
|
|
|
|
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
|
2024-12-08 19:56:12 -08:00
|
|
|
|
if stdenv.hostPlatform.isDarwin then
|
|
|
|
|
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt
|
2023-11-27 08:02:52 +02:00
|
|
|
|
else
|
2024-12-08 19:56:12 -08:00
|
|
|
|
overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
|
|
|
|
|
};
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
compiler-rt =
|
|
|
|
|
if
|
|
|
|
|
stdenv.hostPlatform.libc == null
|
|
|
|
|
# Building the with-libc compiler-rt and WASM doesn't yet work,
|
|
|
|
|
# because wasilibc doesn't provide some expected things. See
|
|
|
|
|
# compiler-rt's file for further details.
|
|
|
|
|
|| stdenv.hostPlatform.isWasm
|
|
|
|
|
# Failing `#include <term.h>` in
|
|
|
|
|
# `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp`
|
|
|
|
|
# sanitizers, not sure where to get it.
|
|
|
|
|
|| stdenv.hostPlatform.isFreeBSD
|
|
|
|
|
then
|
|
|
|
|
libraries.compiler-rt-no-libc
|
2024-07-06 21:43:37 -07:00
|
|
|
|
else
|
2024-12-08 19:56:12 -08:00
|
|
|
|
libraries.compiler-rt-libc;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clang;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
libcxx = callPackage ./libcxx (
|
|
|
|
|
{
|
|
|
|
|
stdenv =
|
|
|
|
|
if stdenv.hostPlatform.isDarwin then
|
|
|
|
|
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt
|
|
|
|
|
else
|
|
|
|
|
overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionOlder metadata.release_version "14") {
|
|
|
|
|
# TODO: remove this, causes LLVM 13 packages rebuild.
|
|
|
|
|
inherit (metadata) monorepoSrc; # Preserve bug during #307211 refactor.
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
libunwind = callPackage ./libunwind {
|
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
|
|
|
|
|
};
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
openmp = callPackage ./openmp {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
|
|
|
|
|
libc-overlay = callPackage ./libc {
|
|
|
|
|
isFullBuild = false;
|
2025-02-10 20:30:09 -08:00
|
|
|
|
# Use clang due to "gnu::naked" not working on aarch64.
|
|
|
|
|
# Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882
|
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clang;
|
2024-12-08 19:56:12 -08:00
|
|
|
|
};
|
2024-07-06 21:43:37 -07:00
|
|
|
|
|
2024-12-08 19:56:12 -08:00
|
|
|
|
libc-full = callPackage ./libc {
|
|
|
|
|
isFullBuild = true;
|
2025-02-10 20:30:09 -08:00
|
|
|
|
# Use clang due to "gnu::naked" not working on aarch64.
|
|
|
|
|
# Issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77882
|
|
|
|
|
stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
|
2025-03-19 17:52:07 -07:00
|
|
|
|
cmake =
|
|
|
|
|
if stdenv.targetPlatform.libc == "llvm" then buildPackages.cmakeMinimal else buildPackages.cmake;
|
|
|
|
|
python3 =
|
|
|
|
|
if stdenv.targetPlatform.libc == "llvm" then
|
|
|
|
|
buildPackages.python3Minimal
|
|
|
|
|
else
|
|
|
|
|
buildPackages.python3;
|
2024-12-08 19:56:12 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
|
|
|
|
|
}
|
|
|
|
|
)
|
2024-07-06 21:43:37 -07:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
|
|
|
|
|
in
|
|
|
|
|
{
|
2024-12-18 18:00:15 -08:00
|
|
|
|
inherit tools libraries;
|
2024-07-06 21:43:37 -07:00
|
|
|
|
inherit (metadata) release_version;
|
|
|
|
|
}
|
|
|
|
|
// (noExtend libraries)
|
|
|
|
|
// (noExtend tools)
|