push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
{
lib,
runCommand,
stdenv,
llvm,
lld,
version,
release_version,
}:
let
targetPrefix = lib.optionalString (
stdenv.hostPlatform != stdenv.targetPlatform
) "${stdenv.targetPlatform.config}-";
in
runCommand "llvm-binutils-${version}"
{
preferLocalBuild = true;
passthru = {
isLLVM = true;
inherit targetPrefix;
inherit llvm lld;
};
}
''
mkdir -p $out/bin
for prog in ${lld}/bin/*; do
ln -s $prog $out/bin/${targetPrefix}$(basename $prog)
done
for prog in ${llvm}/bin/*; do
ln -sf $prog $out/bin/${targetPrefix}$(basename $prog)
done
llvmBin="${llvm}/bin"
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool
ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib
ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt
ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp
ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy
ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip
ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump
ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf
ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size
ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings
ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line
if [ -e "$llvmBin/llvm-debuginfod" ]; then
ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod
ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find
fi
ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld
# Only >=13 show GNU windres compatible in help
ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres
''

View File

@@ -0,0 +1,92 @@
{
lib,
stdenv,
llvm_meta,
monorepoSrc,
release_version,
runCommand,
cmake,
libxml2,
libllvm,
ninja,
libclang,
version,
python3,
buildLlvmTools,
patches ? [ ],
devExtraCmakeFlags ? [ ],
fetchpatch,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "bolt";
inherit version;
# Blank llvm dir just so relative path works
src = runCommand "bolt-src-${finalAttrs.version}" { inherit (monorepoSrc) passthru; } ''
mkdir $out
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/third-party "$out"
# BOLT re-runs tablegen against LLVM sources, so needs them available.
cp -r ${monorepoSrc}/llvm/ "$out"
chmod -R +w $out/llvm
'';
sourceRoot = "${finalAttrs.src.name}/bolt";
patches = lib.optionals (lib.versions.major release_version == "19") [
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/abc2eae68290c453e1899a94eccc4ed5ea3b69c1.patch";
hash = "sha256-oxCxOjhi5BhNBEraWalEwa1rS3Mx9CuQgRVZ2hrbd7M=";
})
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/5909979869edca359bcbca74042c2939d900680e.patch";
hash = "sha256-l4rQHYbblEADBXaZIdqTG0sZzH4fEQvYiqhLYNZDMa8=";
})
];
nativeBuildInputs = [
cmake
ninja
python3
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
]
++ devExtraCmakeFlags;
postUnpack = ''
chmod -R u+w -- $sourceRoot/..
'';
prePatch = ''
cd ..
'';
postPatch = ''
cd bolt
'';
postInstall = ''
mkdir -p $dev/lib
mv $out/lib/libLLVMBOLT*.a $dev/lib
'';
outputs = [
"out"
"dev"
];
meta = llvm_meta // {
homepage = "https://github.com/llvm/llvm-project/tree/main/bolt";
description = "LLVM post-link optimizer";
};
})

View File

@@ -0,0 +1,59 @@
{
lib,
stdenv,
clang-unwrapped,
clang,
libcxxClang,
llvm_meta,
# enableLibcxx will use the c++ headers from clang instead of gcc.
# This shouldn't have any effect on platforms that use clang as the default compiler already.
enableLibcxx ? false,
}:
stdenv.mkDerivation {
unwrapped = clang-unwrapped;
pname = "clang-tools";
version = lib.getVersion clang-unwrapped;
dontUnpack = true;
clang = if enableLibcxx then libcxxClang else clang;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
for tool in $unwrapped/bin/clang-*; do
tool=$(basename "$tool")
# Compilers have their own derivation, no need to include them here:
if [[ $tool == "clang-cl" || $tool == "clang-cpp" ]]; then
continue
fi
# Clang's derivation produces a lot of binaries, but the tools we are
# interested in follow the `clang-something` naming convention - except
# for clang-$version (e.g. clang-13), which is the compiler again:
if [[ ! $tool =~ ^clang\-[a-zA-Z_\-]+$ ]]; then
continue
fi
ln -s $out/bin/clangd $out/bin/$tool
done
if [[ -z "$(ls -A $out/bin)" ]]; then
echo "Found no binaries - maybe their location or naming convention changed?"
exit 1
fi
substituteAll ${./wrapper} $out/bin/clangd
chmod +x $out/bin/clangd
runHook postInstall
'';
meta = llvm_meta // {
description = "Standalone command line tools for C++ development";
maintainers = with lib.maintainers; [ patryk27 ];
};
}

View File

@@ -0,0 +1,27 @@
#!/bin/sh
buildcpath() {
local path after
while (( $# )); do
case $1 in
-isystem)
shift
path=$path${path:+':'}$1
;;
-idirafter)
shift
after=$after${after:+':'}$1
;;
esac
shift
done
echo $path${after:+':'}$after
}
export CPATH=${CPATH}${CPATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \
$(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include
export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}${CPLUS_INCLUDE_PATH:+':'}$(buildcpath ${NIX_CFLAGS_COMPILE} \
$(<@clang@/nix-support/libcxx-cxxflags) \
$(<@clang@/nix-support/libc-cflags)):@clang@/resource-root/include
exec -a "$0" @unwrapped@/bin/$(basename $0) "$@"

View File

@@ -0,0 +1,14 @@
diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp
index 34640b3c450d..93c4a4f4ec5c 100644
--- a/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/lib/Driver/ToolChains/CommonArgs.cpp
@@ -589,8 +589,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
#endif
SmallString<1024> Plugin;
- llvm::sys::path::native(Twine(D.Dir) +
- "/../" CLANG_INSTALL_LIBDIR_BASENAME +
+ llvm::sys::path::native(Twine("@libllvmLibdir@") +
PluginName + Suffix,
Plugin);
CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));

View File

@@ -0,0 +1,75 @@
From 7ef5ed98cc6666f64db2f155ded2077ce038e1e4 Mon Sep 17 00:00:00 2001
From: Reno Dakota <paparodeo@proton.me>
Date: Sat, 16 Nov 2024 05:57:40 +0000
Subject: [PATCH] [Clang][Driver] report unsupported option error regardless of
argument order
This change updates clang to report unsupported option errors regardless
of the command line argument order.
When clang with a source file and without `-c` it will both compile and
link. When an unsupported option is also part of the command line clang
should generated an error. However, if the source file name comes before
an object file, eg: `-lc`, the error is ignored.
```
$ clang --target=x86_64 -lc hello.c -mhtm
clang: error: unsupported option '-mhtm' for target 'x86_64'
$ echo $?
1
```
but if `-lc` comes after `hello.c` the error is dropped
```
$ clang --target=x86_64 hello.c -mhtm -lc
$ echo $?
0
```
after this change clang will report the error regardless of the command
line argument order.
---
clang/lib/Driver/Driver.cpp | 13 ++++++-------
clang/test/Driver/unsupported-option.c | 10 ++++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 93e85f7dffe35a..8e784a7b130ac3 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -4064,17 +4064,18 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
YcArg = YuArg = nullptr;
}
- unsigned LastPLSize = 0;
+ bool LinkOnly = phases::Link == FinalPhase && Inputs.size() > 0;
for (auto &I : Inputs) {
types::ID InputType = I.first;
const Arg *InputArg = I.second;
auto PL = types::getCompilationPhases(InputType);
- LastPLSize = PL.size();
+
+ phases::ID InitialPhase = PL[0];
+ LinkOnly = LinkOnly && phases::Link == InitialPhase && PL.size() == 1;
// If the first step comes after the final phase we are doing as part of
// this compilation, warn the user about it.
- phases::ID InitialPhase = PL[0];
if (InitialPhase > FinalPhase) {
if (InputArg->isClaimed())
continue;
@@ -4129,10 +4130,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
}
}
- // If we are linking, claim any options which are obviously only used for
- // compilation.
- // FIXME: Understand why the last Phase List length is used here.
- if (FinalPhase == phases::Link && LastPLSize == 1) {
+ // claim any options which are obviously only used for compilation.
+ if (LinkOnly) {
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
}

View File

@@ -0,0 +1,261 @@
{
lib,
stdenv,
llvm_meta,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
release_version,
version,
python3,
buildLlvmTools,
fixDarwinDylibNames,
enableManpages ? false,
enableClangToolsExtra ? true,
devExtraCmakeFlags ? [ ],
replaceVars,
getVersionFile,
fetchpatch,
# for tests
libclang,
}:
stdenv.mkDerivation (
finalAttrs:
{
pname = "clang";
inherit version;
src =
if monorepoSrc != null then
runCommand "clang-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/clang "$out"
${lib.optionalString enableClangToolsExtra "cp -r ${monorepoSrc}/clang-tools-extra \"$out\""}
''
else
src;
sourceRoot = "${finalAttrs.src.name}/clang";
patches = [
(getVersionFile "clang/purity.patch")
# Remove extraneous ".a" suffix from baremetal clang_rt.builtins when compiling for baremetal.
# https://reviews.llvm.org/D51899
(getVersionFile "clang/gnu-install-dirs.patch")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# https://github.com/llvm/llvm-project/pull/116476
# prevent clang ignoring warnings / errors for unsuppored
# options when building & linking a source file with trailing
# libraries. eg: `clang -munsupported hello.c -lc`
./clang-unsupported-option.patch
]
# Pass the correct path to libllvm
++ [
(replaceVars ./clang-at-least-16-LLVMgold-path.patch {
libllvmLibdir = "${libllvm.lib}/lib";
})
]
# Fixes a bunch of lambda-related crashes
# https://github.com/llvm/llvm-project/pull/93206
++ lib.optional (lib.versions.major release_version == "18") (fetchpatch {
name = "tweak-tryCaptureVariable-for-unevaluated-lambdas.patch";
url = "https://github.com/llvm/llvm-project/commit/3d361b225fe89ce1d8c93639f27d689082bd8dad.patch";
# TreeTransform.h is not affected in LLVM 18.
excludes = [
"docs/ReleaseNotes.rst"
"lib/Sema/TreeTransform.h"
];
stripLen = 1;
hash = "sha256-1NKej08R9SPlbDY/5b0OKUsHjX07i9brR84yXiPwi7E=";
});
nativeBuildInputs = [
cmake
python3
ninja
]
++ lib.optionals enableManpages [
python3.pkgs.myst-parser
python3.pkgs.sphinx
]
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [
libxml2
libllvm
];
cmakeFlags = [
(lib.cmakeFeature "CLANG_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/clang")
(lib.cmakeBool "CLANGD_BUILD_XPC" false)
(lib.cmakeBool "LLVM_ENABLE_RTTI" true)
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
(lib.cmakeFeature "CLANG_TABLEGEN" "${buildLlvmTools.tblgen}/bin/clang-tblgen")
]
++ lib.optionals (lib.versionAtLeast release_version "21") [
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "${placeholder "lib"}/lib/clang/${lib.versions.major release_version}")
]
# TODO: Clean up on `staging`.
++ [
(lib.cmakeBool "LLVM_INCLUDE_TESTS" false)
]
++ lib.optionals enableManpages [
(lib.cmakeBool "CLANG_INCLUDE_DOCS" true)
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
# TODO: Clean up on `staging`.
++ [
# Added in LLVM15:
# `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb
# `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7
(lib.cmakeFeature "CLANG_TIDY_CONFUSABLE_CHARS_GEN" "${buildLlvmTools.tblgen}/bin/clang-tidy-confusable-chars-gen")
]
++ lib.optionals (lib.versionOlder release_version "20") [
# clang-pseudo removed in LLVM20: https://github.com/llvm/llvm-project/commit/ed8f78827895050442f544edef2933a60d4a7935
(lib.cmakeFeature "CLANG_PSEUDO_GEN" "${buildLlvmTools.tblgen}/bin/clang-pseudo-gen")
]
++ lib.optional (lib.versionAtLeast release_version "20") (
lib.cmakeFeature "LLVM_DIR" "${libllvm.dev}/lib/cmake/llvm"
)
++ devExtraCmakeFlags;
postPatch = ''
# 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}";'
(cd tools && ln -s ../../clang-tools-extra extra)
''
+ lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
'';
outputs = [
"out"
"lib"
"dev"
"python"
];
separateDebugInfo = stdenv.buildPlatform.is64bit; # OOMs on 32 bit
postInstall = ''
ln -sv $out/bin/clang $out/bin/cpp
''
+ (lib.optionalString
((lib.versionAtLeast release_version "19") && !(lib.versionAtLeast release_version "21"))
''
mv $out/lib/clang $lib/lib/clang
''
)
+ ''
# Move libclang to 'lib' output
moveToOutput "lib/libclang.*" "$lib"
moveToOutput "lib/libclang-cpp.*" "$lib"
mkdir -p $python/bin $python/share/clang/
''
+ ''
mv $out/bin/{git-clang-format,scan-view} $python/bin
if [ -e $out/bin/set-xcode-analyzer ]; then
mv $out/bin/set-xcode-analyzer $python/bin
fi
mv $out/share/clang/*.py $python/share/clang
rm $out/bin/c-index-test
patchShebangs $python/bin
mkdir -p $dev/bin
''
# TODO(@LunNova): Clean up this rebuild avoidance in staging
+ lib.optionalString enableClangToolsExtra (
if lib.versionOlder release_version "20" then
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin
''
else
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen} $dev/bin
''
)
+ lib.optionalString (!enableClangToolsExtra) ''
cp bin/clang-tblgen $dev/bin
'';
env =
lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.useLLVM)
{
# The following warning is triggered with (at least) gcc >=
# 12, but appears to occur only for cross compiles.
NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized";
};
passthru = {
inherit libllvm;
isClang = true;
hardeningUnsupportedFlagsByTargetPlatform =
targetPlatform:
[ "fortify3" ]
++ lib.optional (!targetPlatform.isLinux || !targetPlatform.isx86_64) "shadowstack"
++ lib.optional (!targetPlatform.isAarch64 || !targetPlatform.isLinux) "pacret"
++ lib.optional (
!(targetPlatform.isLinux || targetPlatform.isFreeBSD)
|| !(
targetPlatform.isx86
|| targetPlatform.isPower64
|| targetPlatform.isS390x
|| targetPlatform.isAarch64
)
) "stackclashprotection"
++ lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or [ ]);
tests.withoutOptionalFeatures = libclang.override {
enableClangToolsExtra = false;
};
};
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://clang.llvm.org/";
description = "C language family frontend for LLVM";
longDescription = ''
The Clang project provides a language front-end and tooling
infrastructure for languages in the C language family (C, C++, Objective
C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project.
It aims to deliver amazingly fast compiles, extremely useful error and
warning messages and to provide a platform for building great source
level tools. The Clang Static Analyzer and clang-tidy are tools that
automatically find bugs in your code, and are great examples of the sort
of tools that can be built using the Clang frontend as a library to
parse C/C++ code.
'';
mainProgram = "clang";
};
}
// lib.optionalAttrs enableManpages {
pname = "clang-manpages";
ninjaFlags = [ "docs-clang-man" ];
installPhase = ''
mkdir -p $out/share/man/man1
# Manually install clang manpage
cp docs/man/*.1 $out/share/man/man1/
'';
outputs = [ "out" ];
doCheck = false;
meta = llvm_meta // {
description = "man page for Clang ${version}";
};
}
)

View File

@@ -0,0 +1,71 @@
{
lib,
fetchFromGitHub ? null,
release_version ? null,
gitRelease ? null,
officialRelease ? null,
monorepoSrc' ? null,
version ? null,
}@args:
rec {
llvm_meta = {
license =
with lib.licenses;
[ ncsa ]
++
# Contributions after June 1st, 2024 are only licensed under asl20 and
# llvm-exception: https://github.com/llvm/llvm-project/pull/92394
lib.optionals (lib.versionAtLeast release_version "19") [
asl20
llvm-exception
];
teams = [ lib.teams.llvm ];
# See llvm/cmake/config-ix.cmake.
platforms =
lib.platforms.aarch64
++ lib.platforms.arm
++ lib.platforms.mips
++ lib.platforms.power
++ lib.platforms.s390x
++ lib.platforms.wasi
++ lib.platforms.x86
++ lib.platforms.riscv
++ lib.platforms.m68k
++ lib.platforms.loongarch64;
identifiers.cpeParts.vendor = "llvm";
};
releaseInfo =
if gitRelease != null then
rec {
original = gitRelease;
release_version = args.version or original.version;
version = gitRelease.rev-version;
}
else
rec {
original = officialRelease;
release_version = args.version or original.version;
version =
if original ? candidate then "${release_version}-${original.candidate}" else release_version;
};
monorepoSrc =
if monorepoSrc' != null then
monorepoSrc'
else
let
sha256 = releaseInfo.original.sha256;
rev = if gitRelease != null then gitRelease.rev else "llvmorg-${releaseInfo.version}";
in
fetchFromGitHub rec {
owner = "llvm";
repo = "llvm-project";
inherit rev sha256;
passthru = { inherit owner repo rev; };
};
}

View File

@@ -0,0 +1,162 @@
From 4fe3f21bf8b20c766877d2251d61118d0ff36688 Mon Sep 17 00:00:00 2001
From: Ben Wolsieffer <benwolsieffer@gmail.com>
Date: Wed, 7 Dec 2022 14:56:51 -0500
Subject: [PATCH] [compiler-rt][builtins] Do not use ldrexd or strexd on ARMv6
The ldrexd and strexd instructions are not available on base ARMv6, and were
only added in ARMv6K (see [1]). This patch solves this problem once and for all
using the __ARM_FEATURE_LDREX macro (see [2]) defined in the ARM C Language
Extensions (ACLE). Although this macro is technically deprecated in the ACLE,
it allows compiler-rt to reliably detect whether ldrexd and strexd are supported
without complicated conditionals to detect different ARM architecture variants.
[1] https://developer.arm.com/documentation/dht0008/a/ch01s02s01
[2] https://arm-software.github.io/acle/main/acle.html#ldrexstrex
Differential Revision: https://reviews.llvm.org/D139585
---
compiler-rt/lib/builtins/arm/sync_fetch_and_add_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_and_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_max_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_min_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_nand_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_or_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_sub_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_umax_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_umin_8.S | 2 +-
compiler-rt/lib/builtins/arm/sync_fetch_and_xor_8.S | 2 +-
10 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lib/builtins/arm/sync_fetch_and_add_8.S b/lib/builtins/arm/sync_fetch_and_add_8.S
index 18bdd875b8b7..bee6f7ba0f34 100644
--- a/lib/builtins/arm/sync_fetch_and_add_8.S
+++ b/lib/builtins/arm/sync_fetch_and_add_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define add_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
adds rD_LO, rN_LO, rM_LO ; \
adc rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_and_8.S b/lib/builtins/arm/sync_fetch_and_and_8.S
index 3716eff809d5..b4e77a54edf6 100644
--- a/lib/builtins/arm/sync_fetch_and_and_8.S
+++ b/lib/builtins/arm/sync_fetch_and_and_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define and_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
and rD_LO, rN_LO, rM_LO ; \
and rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_max_8.S b/lib/builtins/arm/sync_fetch_and_max_8.S
index 06115ab55246..1813274cc649 100644
--- a/lib/builtins/arm/sync_fetch_and_max_8.S
+++ b/lib/builtins/arm/sync_fetch_and_max_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define max_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, gt)
SYNC_OP_8(max_8)
diff --git a/lib/builtins/arm/sync_fetch_and_min_8.S b/lib/builtins/arm/sync_fetch_and_min_8.S
index 4f3e299d95cc..fa8f3477757b 100644
--- a/lib/builtins/arm/sync_fetch_and_min_8.S
+++ b/lib/builtins/arm/sync_fetch_and_min_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define min_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lt)
SYNC_OP_8(min_8)
diff --git a/lib/builtins/arm/sync_fetch_and_nand_8.S b/lib/builtins/arm/sync_fetch_and_nand_8.S
index 425c94474af7..fb27219ee200 100644
--- a/lib/builtins/arm/sync_fetch_and_nand_8.S
+++ b/lib/builtins/arm/sync_fetch_and_nand_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define nand_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
bic rD_LO, rN_LO, rM_LO ; \
bic rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_or_8.S b/lib/builtins/arm/sync_fetch_and_or_8.S
index 4f18dcf84df9..3b077c8737b1 100644
--- a/lib/builtins/arm/sync_fetch_and_or_8.S
+++ b/lib/builtins/arm/sync_fetch_and_or_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define or_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
orr rD_LO, rN_LO, rM_LO ; \
orr rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_sub_8.S b/lib/builtins/arm/sync_fetch_and_sub_8.S
index 25a4a1076555..c171607eabd8 100644
--- a/lib/builtins/arm/sync_fetch_and_sub_8.S
+++ b/lib/builtins/arm/sync_fetch_and_sub_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define sub_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
subs rD_LO, rN_LO, rM_LO ; \
sbc rD_HI, rN_HI, rM_HI
diff --git a/lib/builtins/arm/sync_fetch_and_umax_8.S b/lib/builtins/arm/sync_fetch_and_umax_8.S
index aa5213ff1def..d1224f758049 100644
--- a/lib/builtins/arm/sync_fetch_and_umax_8.S
+++ b/lib/builtins/arm/sync_fetch_and_umax_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define umax_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, hi)
SYNC_OP_8(umax_8)
diff --git a/lib/builtins/arm/sync_fetch_and_umin_8.S b/lib/builtins/arm/sync_fetch_and_umin_8.S
index 8b40541ab47d..595444e6d053 100644
--- a/lib/builtins/arm/sync_fetch_and_umin_8.S
+++ b/lib/builtins/arm/sync_fetch_and_umin_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define umin_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lo)
SYNC_OP_8(umin_8)
diff --git a/lib/builtins/arm/sync_fetch_and_xor_8.S b/lib/builtins/arm/sync_fetch_and_xor_8.S
index 7436eb1d4cae..9fc3d85cef75 100644
--- a/lib/builtins/arm/sync_fetch_and_xor_8.S
+++ b/lib/builtins/arm/sync_fetch_and_xor_8.S
@@ -13,7 +13,7 @@
#include "sync-ops.h"
-#if __ARM_ARCH_PROFILE != 'M'
+#if __ARM_FEATURE_LDREX & 8
#define xor_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \
eor rD_LO, rN_LO, rM_LO ; \
eor rD_HI, rN_HI, rM_HI
--
2.38.1

View File

@@ -0,0 +1,25 @@
CMake tries to read a list field from SDKSettings.plist, but the output of
xcbuild PlistBuddy is incompatible with Apple's. (Plus we don't want it in our
dependencies.)
Simply assume ARM64 is supported by the SDK. We already limit the actual archs
we build for by setting DARWIN_osx_BUILTIN_ARCHS explicitely.
--- a/cmake/builtin-config-ix.cmake
+++ b/cmake/builtin-config-ix.cmake
@@ -97,14 +97,7 @@ if(APPLE)
set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
- set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
- # Add support for arm64 macOS if available in SDK.
- foreach(arch ${ARM64})
- sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
- if (MACOS_ARM_SUPPORT)
- list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
- endif()
- endforeach(arch)
+ set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} ${ARM64})
if(COMPILER_RT_ENABLE_IOS)
list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)

View File

@@ -0,0 +1,292 @@
{
lib,
stdenv,
llvm_meta,
release_version,
version,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
python3,
libllvm,
jq,
libcxx,
linuxHeaders,
freebsd,
libxcrypt,
# Some platforms have switched to using compiler-rt, but still want a
# libgcc.a for ABI compat purposes. The use case would be old code that
# expects to link `-lgcc` but doesn't care exactly what its contents
# are, so long as it provides some builtins.
doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD,
# In recent releases, the compiler-rt build seems to produce
# many `libclang_rt*` libraries, but not a single unified
# `libcompiler_rt` library, at least under certain configurations. Some
# platforms still expect this, however, so we symlink one into place.
forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
}:
let
useLLVM = stdenv.hostPlatform.useLLVM or false;
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
haveLibc = stdenv.cc.libc != null;
# TODO: Make this account for GCC having libstdcxx, which will help
# use clean up the `cmakeFlags` rats nest below.
haveLibcxx = stdenv.cc.libcxx != null;
isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic;
inherit (stdenv.hostPlatform) isMusl isAarch64 isWindows;
noSanitizers = !haveLibc || bareMetal || isMusl || isDarwinStatic || isWindows;
in
stdenv.mkDerivation (finalAttrs: {
pname = "compiler-rt${lib.optionalString haveLibc "-libc"}";
inherit version;
src =
if monorepoSrc != null then
runCommand "compiler-rt-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/third-party "$out"
''
+ ''
cp -r ${monorepoSrc}/compiler-rt "$out"
''
)
else
src;
sourceRoot = "${finalAttrs.src.name}/compiler-rt";
patches = [
(getVersionFile "compiler-rt/X86-support-extension.patch") # Add support for i486 i586 i686 by reusing i386 config
# ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
# extra `/`.
(getVersionFile "compiler-rt/normalize-var.patch")
# Fix build on armv6l
./armv6-no-ldrexd-strexd.patch
# See: https://github.com/NixOS/nixpkgs/pull/186575
./darwin-plistbuddy-workaround.patch
]
++ [
(getVersionFile "compiler-rt/armv6-scudo-libatomic.patch")
]
++ lib.optional (lib.versions.major release_version == "19") (fetchpatch {
url = "https://github.com/llvm/llvm-project/pull/99837/commits/14ae0a660a38e1feb151928a14f35ff0f4487351.patch";
hash = "sha256-JykABCaNNhYhZQxCvKiBn54DZ5ZguksgCHnpdwWF2no=";
relative = "compiler-rt";
});
nativeBuildInputs = [
cmake
python3
libllvm.dev
ninja
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ jq ];
buildInputs =
lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders
++ lib.optional (stdenv.hostPlatform.isFreeBSD) freebsd.include;
env = {
NIX_CFLAGS_COMPILE = toString (
[
"-DSCUDO_DEFAULT_OPTIONS=delete_size_mismatch=false:dealloc_type_mismatch=false"
]
++ lib.optionals (!haveLibc) [
# The compiler got stricter about this, and there is a usellvm patch below
# which patches out the assert include causing an implicit definition of
# assert. It would be nicer to understand why compiler-rt thinks it should
# be able to #include <assert.h> in the first place; perhaps it's in the
# wrong, or perhaps there is a way to provide an assert.h.
"-Wno-error=implicit-function-declaration"
]
);
# Work around clangs trying to invoke unprefixed-ld on Darwin when `-target` is passed.
NIX_CFLAGS_LINK = lib.optionalString (stdenv.hostPlatform.isDarwin) "--ld-path=${stdenv.cc.bintools}/bin/${stdenv.cc.targetPrefix}ld";
};
cmakeFlags = [
(lib.cmakeBool "COMPILER_RT_DEFAULT_TARGET_ONLY" true)
(lib.cmakeFeature "CMAKE_C_COMPILER_TARGET" stdenv.hostPlatform.config)
(lib.cmakeFeature "CMAKE_ASM_COMPILER_TARGET" stdenv.hostPlatform.config)
]
++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [
(lib.cmakeFeature "SANITIZER_COMMON_CFLAGS" "-I${libxcrypt}/include")
]
++ lib.optionals (useLLVM && haveLibc && stdenv.cc.libcxx == libcxx) [
(lib.cmakeFeature "SANITIZER_CXX_ABI" "libcxxabi")
(lib.cmakeFeature "SANITIZER_CXX_ABI_LIBNAME" "libcxxabi")
(lib.cmakeBool "COMPILER_RT_USE_BUILTINS_LIBRARY" true)
]
++ lib.optionals (useLLVM && haveLibc) [
(lib.cmakeBool "COMPILER_RT_BUILD_SANITIZERS" true)
(lib.cmakeBool "COMPILER_RT_BUILD_PROFILE" true)
]
++ lib.optionals noSanitizers [
(lib.cmakeBool "COMPILER_RT_BUILD_SANITIZERS" false)
]
++ lib.optionals ((useLLVM && !haveLibcxx) || !haveLibc || bareMetal || isMusl || isDarwinStatic) [
(lib.cmakeBool "COMPILER_RT_BUILD_XRAY" false)
(lib.cmakeBool "COMPILER_RT_BUILD_LIBFUZZER" false)
(lib.cmakeBool "COMPILER_RT_BUILD_MEMPROF" false)
(lib.cmakeBool "COMPILER_RT_BUILD_ORC" false) # may be possible to build with musl if necessary
]
++ lib.optionals (!haveLibc || bareMetal) [
(lib.cmakeBool "COMPILER_RT_BUILD_PROFILE" false)
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "COMPILER_RT_BAREMETAL_BUILD" true)
(lib.cmakeFeature "CMAKE_SIZEOF_VOID_P" (toString (stdenv.hostPlatform.parsed.cpu.bits / 8)))
]
++ lib.optionals (!haveLibc || bareMetal || isDarwinStatic) [
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
]
++ lib.optionals (!haveLibc) [
(lib.cmakeFeature "CMAKE_C_FLAGS" "-nodefaultlibs")
]
++ lib.optionals useLLVM [
(lib.cmakeBool "COMPILER_RT_BUILD_BUILTINS" true)
#https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
(lib.cmakeFeature "CMAKE_TRY_COMPILE_TARGET_TYPE" "STATIC_LIBRARY")
]
++ lib.optionals bareMetal [
(lib.cmakeFeature "COMPILER_RT_OS_DIR" "baremetal")
]
++ lib.optionals (stdenv.hostPlatform.isDarwin) (
[
(lib.cmakeFeature "CMAKE_LIPO" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo")
]
++ lib.optionals (!haveLibcxx) [
# Darwin fails to detect that the compiler supports the `-g` flag when there is no libc++ during the
# compiler-rt bootstrap, which prevents compiler-rt from building. The `-g` flag is required by the
# Darwin support, so force it to be enabled during the first stage of the compiler-rt bootstrap.
(lib.cmakeBool "COMPILER_RT_HAS_G_FLAG" true)
]
++ [
(lib.cmakeFeature "DARWIN_osx_ARCHS" stdenv.hostPlatform.darwinArch)
(lib.cmakeFeature "DARWIN_osx_BUILTIN_ARCHS" stdenv.hostPlatform.darwinArch)
(lib.cmakeFeature "SANITIZER_MIN_OSX_VERSION" stdenv.hostPlatform.darwinMinVersion)
# `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin:
# https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153
(lib.cmakeBool "COMPILER_RT_ENABLE_IOS" false)
]
)
++ lib.optionals (noSanitizers && lib.versionAtLeast release_version "19") [
(lib.cmakeBool "COMPILER_RT_BUILD_CTX_PROFILE" false)
]
++
lib.optional (stdenv.hostPlatform.isAarch64 && !haveLibc)
# Fixes https://github.com/NixOS/nixpkgs/issues/393603
(lib.cmakeBool "COMPILER_RT_DISABLE_AARCH64_FMV" true)
++ devExtraCmakeFlags;
outputs = [
"out"
"dev"
];
postPatch =
lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
substituteInPlace cmake/builtin-config-ix.cmake \
--replace-fail 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
''
+ lib.optionalString (!haveLibc) (
(lib.optionalString (lib.versions.major release_version == "18") ''
substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \
--replace-fail "<stdlib.h>" "<stddef.h>"
'')
+ ''
substituteInPlace lib/builtins/int_util.c \
--replace-fail "#include <stdlib.h>" ""
''
+ (lib.optionalString (!stdenv.hostPlatform.isFreeBSD)
# On FreeBSD, assert/static_assert are macros and allowing them to be implicitly declared causes link errors.
# see description above for why we're nuking assert.h normally but that doesn't work here.
# instead, we add the freebsd.include dependency explicitly
''
substituteInPlace lib/builtins/clear_cache.c \
--replace-fail "#include <assert.h>" ""
substituteInPlace lib/builtins/cpu_model/x86.c \
--replace-fail "#include <assert.h>" ""
''
)
)
+
lib.optionalString (lib.versionAtLeast release_version "19")
# codesign in sigtool doesn't support the various options used by the build
# and is present in the bootstrap-tools. Removing find_program prevents the
# build from trying to use it and failing.
''
substituteInPlace cmake/Modules/AddCompilerRT.cmake \
--replace-fail 'find_program(CODESIGN codesign)' ""
'';
preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin ''
cmakeFlagsArray+=(
"-DDARWIN_macosx_CACHED_SYSROOT=$SDKROOT"
"-DDARWIN_macosx_OVERRIDE_SDK_VERSION=$(jq -r .Version "$SDKROOT/SDKSettings.json")"
)
'';
# Hack around weird upstream RPATH bug
postInstall =
lib.optionalString (stdenv.hostPlatform.isDarwin) ''
ln -s "$out/lib"/*/* "$out/lib"
''
+ lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) ''
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
# Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
# The presence of crtbegin_shared has been added and removed; it's possible
# people have added/removed it to get it working on their platforms.
# Try each in turn for now.
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o
ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
''
+ lib.optionalString doFakeLibgcc ''
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a
''
+ lib.optionalString forceLinkCompilerRt ''
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a
'';
meta = llvm_meta // {
homepage = "https://compiler-rt.llvm.org/";
description = "Compiler runtime libraries";
longDescription = ''
The compiler-rt project provides highly tuned implementations of the
low-level code generator support routines like "__fixunsdfdi" and other
calls generated when a target doesn't have a short sequence of native
instructions to implement a core IR operation. It also provides
implementations of run-time libraries for dynamic testing tools such as
AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer.
'';
# "All of the code in the compiler-rt project is dual licensed under the MIT
# license and the UIUC License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
broken =
# compiler-rt requires a Clang stdenv on 32-bit RISC-V:
# https://reviews.llvm.org/D43106#1019077
(stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang)
# emutls wants `<pthread.h>` which isn't available (without experimental WASM threads proposal).
# `enable_execute_stack.c` Also doesn't sound like something WASM would support.
|| (stdenv.hostPlatform.isWasm && haveLibc);
};
})

View File

@@ -0,0 +1,517 @@
{
lowPrio,
newScope,
pkgs,
targetPackages,
lib,
stdenv,
libxcrypt,
substitute,
replaceVars,
fetchFromGitHub,
fetchpatch,
fetchpatch2,
overrideCC,
wrapCCWith,
wrapBintoolsWith,
buildPackages,
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,
patchesFn ? lib.id,
# 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.
...
}@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 =
(toString ../.) + "/${if (gitRelease != null) then "git" else lib.versions.major release_version}";
getVersionFile =
p:
builtins.path {
name = baseNameOf p;
path =
let
patches = args.patchesFn (import ./patches.nix);
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}";
};
};
tools = lib.makeExtensible (
tools:
let
callPackage = newScope (tools // args // metadata);
clangVersion = lib.versions.major metadata.release_version;
mkExtraBuildCommands0 =
cc:
''
rsrc="$out/resource-root"
mkdir "$rsrc"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
''
# clang standard c headers are incompatible with FreeBSD so we have to put them in -idirafter instead of -resource-dir
# see https://github.com/freebsd/freebsd-src/commit/f382bac49b1378da3c2dd66bf721beaa16b5d471
+ (
if stdenv.targetPlatform.isFreeBSD then
''
echo "-idirafter ${lib.getLib cc}/lib/clang/${clangVersion}/include" >> $out/nix-support/cc-cflags
''
else
''
ln -s "${lib.getLib cc}/lib/clang/${clangVersion}/include" "$rsrc"
''
);
mkExtraBuildCommandsBasicRt =
cc:
mkExtraBuildCommands0 cc
+ ''
ln -s "${targetLlvmLibraries.compiler-rt-no-libc.out}/lib" "$rsrc/lib"
'';
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;
tblgen = callPackage ./tblgen.nix {
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;
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")
];
};
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.isDarwin then
tools.systemLibcxxClang
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;
};
# Darwin uses the system libc++ by default. It is set up as its own clang definition so that `libcxxClang`
# continues to use the libc++ from LLVM.
systemLibcxxClang = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = darwin.libcxx;
extraPackages = [ targetLlvmLibraries.compiler-rt ];
extraBuildCommands = mkExtraBuildCommands cc;
};
lld = callPackage ./lld {
};
lldbPlugins = lib.makeExtensible (
lldbPlugins:
let
callPackage = newScope (lldbPlugins // tools // args // metadata);
in
lib.recurseIntoAttrs { llef = callPackage ./lldb-plugins/llef.nix { }; }
);
lldb = callPackage ./lldb { };
lldb-manpages = lowPrio (
tools.lldb.override {
enableManpages = true;
python3 = pkgs.python3; # don't use python-boot
}
);
# 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
# doesnt support like LLVM. Probably we should move to some other
# file.
bintools-unwrapped = callPackage ./bintools.nix { };
bintoolsNoLibc = wrapBintoolsWith {
bintools = tools.bintools-unwrapped;
libc = targetPackages.preLibcHeaders;
};
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 = mkExtraBuildCommands cc;
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";
nixSupport.cc-ldflags = lib.optionals (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
};
clangWithLibcAndBasicRtAndLibcxx = wrapCCWith rec {
cc = tools.clang-unwrapped;
# This is used to build compiler-rt. Make sure to use the system libc++ on Darwin.
libcxx = if stdenv.hostPlatform.isDarwin then darwin.libcxx else targetLlvmLibraries.libcxx;
bintools = bintools';
extraPackages = [
targetLlvmLibraries.compiler-rt-no-libc
]
++
lib.optionals
(
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
)
[
targetLlvmLibraries.libunwind
];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-Wno-unused-command-line-argument"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
]
++ lib.optional (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
) "--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 (
!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && !stdenv.targetPlatform.isDarwin
) [ "-L${targetLlvmLibraries.libunwind}/lib" ];
};
clangWithLibcAndBasicRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintools';
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
"-nostdlib++"
]
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
clangNoLibcWithBasicRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc';
extraPackages = [ targetLlvmLibraries.compiler-rt-no-libc ];
extraBuildCommands = mkExtraBuildCommandsBasicRt cc;
nixSupport.cc-cflags = [
"-rtlib=compiler-rt"
"-B${targetLlvmLibraries.compiler-rt-no-libc}/lib"
]
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
clangNoLibcNoRt = wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintoolsNoLibc';
extraPackages = [ ];
# "-nostartfiles" used to be needed for pkgsLLVM, causes problems so don't include it.
extraBuildCommands = mkExtraBuildCommands0 cc;
nixSupport.cc-cflags = lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
};
# This is an "oddly ordered" bootstrap just for Darwin. Probably
# don't want it otherwise.
clangNoCompilerRtWithLibc =
wrapCCWith rec {
cc = tools.clang-unwrapped;
libcxx = null;
bintools = bintools';
extraPackages = [ ];
extraBuildCommands = mkExtraBuildCommands0 cc;
}
# FIXME: This should be inside the `wrapCCWith` call.
// lib.optionalAttrs stdenv.targetPlatform.isWasm {
nixSupport.cc-cflags = [ "-fno-exceptions" ];
};
# Aliases
clangNoCompilerRt = tools.clangNoLibcNoRt;
clangNoLibc = tools.clangNoLibcWithBasicRt;
clangNoLibcxx = tools.clangWithLibcAndBasicRt;
mlir = callPackage ./mlir { };
libclc = callPackage ./libclc { };
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "19") {
bolt = callPackage ./bolt {
};
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
flang = callPackage ./flang {
mlir = tools.mlir;
};
}
);
libraries = lib.makeExtensible (
libraries:
let
callPackage = newScope (libraries // buildLlvmTools // args // metadata);
in
(
{
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;
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt
else
overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
};
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
else
libraries.compiler-rt-libc;
stdenv = overrideCC stdenv buildLlvmTools.clang;
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
libcxx = callPackage ./libcxx {
stdenv =
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt
else
overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};
libunwind = callPackage ./libunwind {
stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};
openmp = callPackage ./openmp {
};
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
libc-overlay = callPackage ./libc {
isFullBuild = false;
# 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;
};
libc-full = callPackage ./libc {
isFullBuild = true;
# 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;
cmake =
if stdenv.targetPlatform.libc == "llvm" then buildPackages.cmakeMinimal else buildPackages.cmake;
python3 =
if stdenv.targetPlatform.libc == "llvm" then
buildPackages.python3Minimal
else
buildPackages.python3;
};
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
}
)
);
noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
in
{
inherit tools libraries;
inherit (metadata) release_version;
}
// (noExtend libraries)
// (noExtend tools)

View File

@@ -0,0 +1,95 @@
{
lib,
llvm_meta,
monorepoSrc,
release_version,
runCommand,
cmake,
libxml2,
libllvm,
ninja,
libffi,
libclang,
stdenv,
clang,
mlir,
version,
python3,
buildLlvmTools,
devExtraCmakeFlags ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
pname = "flang";
inherit version;
src = runCommand "flang-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/${finalAttrs.pname} "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/clang "$out"
cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out"
chmod -R +w $out/llvm
'';
patches = [
./dummy_target_19+.patch
];
patchFlags = [ "-p2" ];
sourceRoot = "${finalAttrs.src.name}/flang";
buildInputs = [
libffi
libxml2
libllvm
libclang
mlir
];
nativeBuildInputs = [
cmake
clang
ninja
python3
libllvm.dev
mlir.dev
];
preConfigure = ''
ls -l ${libllvm.dev}/lib/cmake/llvm/LLVMConfig.cmake
ls -l ${libclang.dev}/lib/cmake/clang/ClangConfig.cmake
ls -l ${mlir.dev}/lib/cmake/mlir/MLIRConfig.cmake
'';
cmakeFlags = [
(lib.cmakeBool "CMAKE_VERBOSE_MAKEFILE" true)
(lib.cmakeFeature "LLVM_DIR" "${libllvm.dev}/lib/cmake/llvm")
(lib.cmakeFeature "LLVM_TOOLS_BINARY_DIR" "${buildLlvmTools.tblgen}/bin/")
(lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${buildLlvmTools.tblgen}/bin/llvm-lit")
(lib.cmakeFeature "CLANG_DIR" "${libclang.dev}/lib/cmake/clang")
(lib.cmakeFeature "MLIR_DIR" "${mlir.dev}/lib/cmake/mlir")
(lib.cmakeFeature "MLIR_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/mlir-tblgen")
(lib.cmakeFeature "MLIR_TABLEGEN_TARGET" "MLIR-TBLGen")
(lib.cmakeBool "LLVM_BUILD_EXAMPLES" false)
(lib.cmakeBool "LLVM_ENABLE_PLUGINS" false)
(lib.cmakeBool "FLANG_STANDALONE_BUILD" true)
(lib.cmakeBool "LLVM_INCLUDE_EXAMPLES" false)
(lib.cmakeBool "FLANG_INCLUDE_TESTS" false)
]
++ devExtraCmakeFlags;
postUnpack = ''
chmod -R u+w -- $sourceRoot/..
'';
outputs = [ "out" ];
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://flang.llvm.org/";
description = "LLVM-based Fortran frontend";
license = lib.licenses.ncsa;
mainProgram = "flang";
maintainers = with lib.maintainers; [ acture ];
};
})

View File

@@ -0,0 +1,27 @@
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 070c39eb6e9a..168c97524943 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -1,6 +1,22 @@
cmake_minimum_required(VERSION 3.20.0)
set(LLVM_SUBPROJECT_TITLE "Flang")
+# Patch: define dummy mlir-tblgen target for TableGen.cmake
+if(DEFINED MLIR_TABLEGEN_EXE AND NOT TARGET mlir-tblgen)
+ add_executable(mlir-tblgen IMPORTED GLOBAL)
+ set_target_properties(mlir-tblgen PROPERTIES
+ IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}"
+ )
+endif()
+
+if(DEFINED MLIR_TABLEGEN_EXE AND NOT TARGET MLIR-TBLGen)
+ add_executable(MLIR-TBLGen IMPORTED GLOBAL)
+ set_target_properties(MLIR-TBLGen PROPERTIES
+ IMPORTED_LOCATION "${MLIR_TABLEGEN_EXE}"
+ )
+endif()
+
+
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
endif()

View File

@@ -0,0 +1,105 @@
{
lib,
stdenv,
llvm_meta,
src ? null,
monorepoSrc ? null,
version,
release_version,
runCommand,
python3,
python3Packages,
patches ? [ ],
cmake,
ninja,
isFullBuild ? true,
linuxHeaders,
}:
let
pname = "libc";
src' = runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/runtimes "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/compiler-rt "$out"
cp -r ${monorepoSrc}/${pname} "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/third-party "$out"
''
);
in
stdenv.mkDerivation (finalAttrs: {
inherit pname version patches;
src = src';
sourceRoot = "${finalAttrs.src.name}/runtimes";
nativeBuildInputs = [
cmake
python3
ninja
]
++ (lib.optional isFullBuild python3Packages.pyyaml);
buildInputs = lib.optional isFullBuild linuxHeaders;
outputs = [ "out" ] ++ (lib.optional isFullBuild "dev");
postUnpack = lib.optionalString isFullBuild ''
chmod +w $sourceRoot/../$pname/utils/hdrgen
patchShebangs $sourceRoot/../$pname/utils/hdrgen/main.py
chmod +x $sourceRoot/../$pname/utils/hdrgen/main.py
'';
prePatch = ''
cd ../${finalAttrs.pname}
chmod -R u+w ../
'';
postPatch = ''
cd ../runtimes
'';
postInstall =
lib.optionalString (!isFullBuild) ''
substituteAll ${./libc-shim.tpl} $out/lib/libc.so
''
# LLVM libc doesn't recognize static vs dynamic yet.
# Treat LLVM libc as a static libc, requires this symlink until upstream fixes it.
+ lib.optionalString (isFullBuild && stdenv.hostPlatform.isLinux) ''
ln $out/lib/crt1.o $out/lib/Scrt1.o
'';
libc = if (!isFullBuild) then stdenv.cc.libc else null;
cmakeFlags = [
(lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc;compiler-rt")
# Tests requires the host to have a libc.
(lib.cmakeBool "LLVM_INCLUDE_TESTS" (stdenv.cc.libc != null))
]
++ lib.optionals (isFullBuild && stdenv.cc.libc == null) [
# CMake runs a check to see if the compiler works.
# This includes including headers which requires a libc.
# Skip these checks because a libc cannot be used when one doesn't exist.
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
];
# For the update script:
passthru = {
monorepoSrc = monorepoSrc;
inherit isFullBuild;
};
meta = llvm_meta // {
broken = stdenv.hostPlatform.isDarwin;
homepage = "https://libc.llvm.org/";
description = "Standard C library for LLVM";
};
})

View File

@@ -0,0 +1 @@
GROUP (@libc@ @out@/lib/libllvmlibc.a)

View File

@@ -0,0 +1,111 @@
{
lib,
stdenv,
version,
runCommand,
monorepoSrc,
llvm,
buildPackages,
buildLlvmTools,
ninja,
cmake,
python3,
release_version,
getVersionFile,
}:
let
spirv-llvm-translator = buildPackages.spirv-llvm-translator.override {
inherit (buildLlvmTools) llvm;
};
# The build requires an unwrapped clang but wrapped clang++ thus we need to
# split the unwrapped clang out to prevent the build from finding the
# unwrapped clang++
clang-only = runCommand "clang-only" { } ''
mkdir -p "$out"/bin
ln -s "${lib.getExe' buildLlvmTools.clang.cc "clang"}" "$out"/bin
'';
in
stdenv.mkDerivation (finalAttrs: {
pname = "libclc";
inherit version;
src = runCommand "libclc-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libclc "$out"
'';
sourceRoot = "${finalAttrs.src.name}/libclc";
outputs = [
"out"
"dev"
];
patches = [
(getVersionFile "libclc/gnu-install-dirs.patch")
]
# LLVM 19 changes how host tools are looked up.
# Need to remove NO_DEFAULT_PATH and the PATHS arguments for find_program
# so CMake can actually find the tools in nativeBuildInputs.
# https://github.com/llvm/llvm-project/pull/105969
++ lib.optional (lib.versionAtLeast release_version "19") (
getVersionFile "libclc/use-default-paths.patch"
);
# cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
postPatch =
lib.optionalString (lib.versionOlder release_version "19") ''
substituteInPlace CMakeLists.txt \
--replace-fail 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace-fail 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
''
+ lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) (
if (lib.versionOlder release_version "19") then
''
substituteInPlace CMakeLists.txt \
--replace-fail 'COMMAND prepare_builtins' \
'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
''
else
''
substituteInPlace CMakeLists.txt \
--replace-fail 'set( prepare_builtins_exe prepare_builtins )' \
'set( prepare_builtins_exe ${buildLlvmTools.libclc.dev}/bin/prepare_builtins )'
''
);
nativeBuildInputs = [
cmake
ninja
python3
]
++ lib.optionals (lib.versionAtLeast release_version "19") [
clang-only
buildLlvmTools.llvm
spirv-llvm-translator
];
buildInputs = [ llvm ];
strictDeps = true;
postInstall = ''
install -Dt $dev/bin prepare_builtins
'';
meta = with lib; {
homepage = "http://libclc.llvm.org/";
description = "Implementation of the library requirements of the OpenCL C programming language";
mainProgram = "prepare_builtins";
license = licenses.mit;
platforms = platforms.all;
};
})

View File

@@ -0,0 +1,221 @@
{
lib,
stdenv,
llvm_meta,
release_version,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
lndir,
ninja,
python3,
fixDarwinDylibNames,
version,
freebsd,
cxxabi ? if stdenv.hostPlatform.isFreeBSD then freebsd.libcxxrt else null,
libunwind,
enableShared ? stdenv.hostPlatform.hasSharedLibraries,
devExtraCmakeFlags ? [ ],
substitute,
fetchpatch,
}:
# external cxxabi is not supported on Darwin as the build will not link libcxx
# properly and not re-export the cxxabi symbols into libcxx
# https://github.com/NixOS/nixpkgs/issues/166205
# https://github.com/NixOS/nixpkgs/issues/269548
assert cxxabi == null || !stdenv.hostPlatform.isDarwin;
let
cxxabiName = "lib${if cxxabi == null then "cxxabi" else cxxabi.libName}";
runtimes = [ "libcxx" ] ++ lib.optional (cxxabi == null) "libcxxabi";
# Note: useLLVM is likely false for Darwin but true under pkgsLLVM
useLLVM = stdenv.hostPlatform.useLLVM or false;
cxxabiCMakeFlags = [
(lib.cmakeBool "LIBCXXABI_USE_LLVM_UNWINDER" false)
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [
(lib.cmakeFeature "LIBCXXABI_ADDITIONAL_LIBRARIES" "unwind")
(lib.cmakeBool "LIBCXXABI_USE_COMPILER_RT" true)
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "LIBCXXABI_ENABLE_THREADS" false)
(lib.cmakeBool "LIBCXXABI_ENABLE_EXCEPTIONS" false)
]
++ lib.optionals (!enableShared || stdenv.hostPlatform.isWindows) [
# Required on Windows due to https://github.com/llvm/llvm-project/issues/55245
(lib.cmakeBool "LIBCXXABI_ENABLE_SHARED" false)
];
cxxCMakeFlags = [
(lib.cmakeFeature "LIBCXX_CXX_ABI" cxxabiName)
(lib.cmakeBool "LIBCXX_ENABLE_SHARED" enableShared)
# https://github.com/llvm/llvm-project/issues/55245
(lib.cmakeBool "LIBCXX_ENABLE_STATIC_ABI_LIBRARY" stdenv.hostPlatform.isWindows)
]
++ lib.optionals (cxxabi == null) [
# Include libc++abi symbols within libc++.a for static linking libc++;
# dynamic linking includes them through libc++.so being a linker script
# which includes both shared objects.
(lib.cmakeBool "LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY" true)
]
++ lib.optionals (cxxabi != null) [
(lib.cmakeFeature "LIBCXX_CXX_ABI_INCLUDE_PATHS" "${lib.getDev cxxabi}/include")
]
++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [
(lib.cmakeFeature "LIBCXX_HAS_MUSL_LIBC" "1")
]
++
lib.optionals (!useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic)
[
(lib.cmakeFeature "LIBCXX_ADDITIONAL_LIBRARIES" "gcc_s")
]
++ lib.optionals stdenv.hostPlatform.isFreeBSD [
# Name and documentation claim this is for libc++abi, but its man effect is adding `-lunwind`
# to the libc++.so linker script. We want FreeBSD's so-called libgcc instead of libunwind.
(lib.cmakeBool "LIBCXXABI_USE_LLVM_UNWINDER" false)
]
++ lib.optionals useLLVM [
(lib.cmakeBool "LIBCXX_USE_COMPILER_RT" true)
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isFreeBSD) [
(lib.cmakeFeature "LIBCXX_ADDITIONAL_LIBRARIES" "unwind")
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "LIBCXX_ENABLE_THREADS" false)
(lib.cmakeBool "LIBCXX_ENABLE_FILESYSTEM" false)
(lib.cmakeBool "LIBCXX_ENABLE_EXCEPTIONS" false)
]
++ lib.optionals (cxxabi != null && cxxabi.libName == "cxxrt") [
(lib.cmakeBool "LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS" true)
];
cmakeFlags = [
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" (lib.concatStringsSep ";" runtimes))
]
++ lib.optionals stdenv.hostPlatform.isWasm [
(lib.cmakeBool "CMAKE_CXX_COMPILER_WORKS" true)
(lib.cmakeBool "CMAKE_C_COMPILER_WORKS" true)
(lib.cmakeBool "UNIX" true) # Required otherwise libc++ fails to detect the correct linker
]
++ cxxCMakeFlags
++ lib.optionals (cxxabi == null) cxxabiCMakeFlags
++ devExtraCmakeFlags;
in
stdenv.mkDerivation (finalAttrs: {
pname = "libcxx";
inherit version cmakeFlags;
src =
if monorepoSrc != null then
runCommand "libcxx-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libcxx "$out"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
cp -r ${monorepoSrc}/third-party "$out"
''
+ (lib.optionalString (lib.versionAtLeast release_version "20") ''
cp -r ${monorepoSrc}/libc "$out"
'')
+ ''
cp -r ${monorepoSrc}/runtimes "$out"
''
+ (lib.optionalString (cxxabi == null) ''
cp -r ${monorepoSrc}/libcxxabi "$out"
'')
)
else
src;
outputs = [
"out"
"dev"
];
preConfigure = lib.optionalString stdenv.hostPlatform.isMusl ''
patchShebangs utils/cat_files.py
'';
# TODO: Remove on `staging`.
patches = [ ];
nativeBuildInputs = [
cmake
ninja
python3
]
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames
++ lib.optional (cxxabi != null) lndir;
buildInputs = [
cxxabi
]
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm && !stdenv.hostPlatform.isFreeBSD) [
libunwind
];
# TODO: Possibly move back to `sourceRoot` on `staging`?
postPatch = ''
cd runtimes
'';
# libc++.so is a linker script which expands to multiple libraries,
# libc++.so.1 and libc++abi.so or the external cxxabi. ld-wrapper doesn't
# support linker scripts so the external cxxabi needs to be symlinked in
postInstall =
lib.optionalString (cxxabi != null) ''
lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1
lndir ${lib.getLib cxxabi}/lib $out/lib
libcxxabi=$out/lib/lib${cxxabi.libName}.a
''
# LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for
# external cxxabi libraries so merge libc++abi.a into libc++.a ourselves.
# GNU binutils emits objects in LIFO order in MRI scripts so after the merge
# the objects are in reversed order so a second MRI script is required so the
# objects in the archive are listed in proper order (libc++.a, libc++abi.a)
+ lib.optionalString (cxxabi != null) ''
libcxxabi=''${libcxxabi-$out/lib/libc++abi.a}
if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then
$AR -M <<MRI
create $out/lib/libc++.a
addlib $out/lib/libc++.a
addlib $libcxxabi
save
end
MRI
$AR -M <<MRI
create $out/lib/libc++.a
addlib $out/lib/libc++.a
save
end
MRI
fi
'';
passthru = {
isLLVM = true;
};
meta = llvm_meta // {
homepage = "https://libcxx.llvm.org/";
description = "C++ standard library";
longDescription = ''
libc++ is an implementation of the C++ standard library, targeting C++11,
C++14 and above.
'';
# "All of the code in libc++ is dual licensed under the MIT license and the
# UIUC License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
};
})

View File

@@ -0,0 +1,95 @@
{
lib,
stdenv,
release_version,
src ? null,
llvm_meta,
version,
monorepoSrc ? null,
runCommand,
cmake,
ninja,
python3,
libcxx,
enableShared ? !stdenv.hostPlatform.isStatic,
doFakeLibgcc ? stdenv.hostPlatform.useLLVM && !stdenv.hostPlatform.isStatic,
devExtraCmakeFlags ? [ ],
getVersionFile,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libunwind";
inherit version;
# TODO: Remove on `staging`.
patches = [ ];
src =
if monorepoSrc != null then
runCommand "libunwind-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/libunwind "$out"
mkdir -p "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
cp -r ${monorepoSrc}/runtimes "$out"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/runtimes";
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
cmake
ninja
python3
];
cmakeFlags = [
(lib.cmakeBool "LIBUNWIND_ENABLE_SHARED" enableShared)
(lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libunwind")
]
++ devExtraCmakeFlags;
# TODO: Remove on `staging`.
prePatch = "";
postPatch = "";
postInstall =
lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows)
''
# libcxxabi wants to link to libunwind_shared.so (?).
ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
''
+ lib.optionalString (enableShared && stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.dll.a $out/lib/libunwind_shared.dll.a
''
+ lib.optionalString (doFakeLibgcc && !stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so
ln -s $out/lib/libunwind.so $out/lib/libgcc_s.so.1
''
+ lib.optionalString (doFakeLibgcc && stdenv.hostPlatform.isWindows) ''
ln -s $out/lib/libunwind.dll.a $out/lib/libgcc_s.dll.a
'';
meta = llvm_meta // {
# Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
description = "LLVM's unwinder library";
longDescription = ''
The unwind library provides a family of _Unwind_* functions implementing
the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
I). It is a dependency of the C++ ABI library, and sometimes is a
dependency of other runtimes.
'';
};
})

View File

@@ -0,0 +1,90 @@
{
lib,
stdenv,
llvm_meta,
release_version,
buildLlvmTools,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
version,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "lld";
inherit version;
src =
if monorepoSrc != null then
runCommand "lld-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/lld "$out"
mkdir -p "$out/libunwind"
cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
mkdir -p "$out/llvm"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/lld";
patches = [
(getVersionFile "lld/gnu-install-dirs.patch")
]
++ lib.optional (lib.versions.major release_version == "18") (
# https://github.com/llvm/llvm-project/pull/97122
fetchpatch {
name = "more-openbsd-program-headers.patch";
url = "https://github.com/llvm/llvm-project/commit/d7fd8b19e560fbb613159625acd8046d0df75115.patch";
stripLen = 1;
hash = "sha256-7wTy7XDTx0+fhWQpW1KEuz7xJvpl42qMTUfd20KGOfA=";
}
);
nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeFeature "LLD_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/lld")
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
]
++ devExtraCmakeFlags;
# TODO: Remove on `staging`.
postPatch = "";
# Musl's default stack size is too small for lld to be able to link Firefox.
LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
outputs = [
"out"
"lib"
"dev"
];
meta = llvm_meta // {
homepage = "https://lld.llvm.org/";
description = "LLVM linker (unwrapped)";
longDescription = ''
LLD is a linker from the LLVM project that is a drop-in replacement for
system linkers and runs much faster than them. It also provides features
that are useful for toolchain developers.
The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
WebAssembly in descending order of completeness. Internally, LLD consists
of several different linkers.
'';
};
})

View File

@@ -0,0 +1,44 @@
{
lib,
stdenv,
fetchFromGitHub,
makeWrapper,
lldb,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "llef";
version = "2.0.0";
src = fetchFromGitHub {
owner = "foundryzero";
repo = "llef";
rev = "v${finalAttrs.version}";
hash = "sha256-pAFjLaZi4Sjlq3evKT2IG+0/imf4Fp5bM2gknLKpRvs=";
};
dontBuild = true;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/share/llef
cp -r llef.py arch commands common handlers $out/share/llef
makeWrapper ${lib.getExe lldb} $out/bin/llef \
--add-flags "-o 'settings set stop-disassembly-display never'" \
--add-flags "-o \"command script import $out/share/llef/llef.py\""
runHook postInstall
'';
meta = with lib; {
description = "LLEF is a plugin for LLDB to make it more useful for RE and VR";
homepage = "https://github.com/foundryzero/llef";
license = licenses.mit;
platforms = platforms.all;
maintainers = with maintainers; [ nrabulinski ];
mainProgram = "llef";
};
})

View File

@@ -0,0 +1,211 @@
{
lib,
stdenv,
llvm_meta,
release_version,
cmake,
zlib,
ncurses,
swig,
which,
libedit,
libxml2,
libllvm,
libclang,
python3,
version,
darwin,
lit,
makeWrapper,
lua5_3,
ninja,
runCommand,
src ? null,
monorepoSrc ? null,
enableManpages ? false,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
fetchpatch2,
replaceVars,
}:
let
vscodeExt = {
name = "lldb-dap";
version = "0.2.0";
};
in
stdenv.mkDerivation (
finalAttrs:
{
passthru.monorepoSrc = monorepoSrc;
pname = "lldb";
inherit version;
src =
if monorepoSrc != null then
runCommand "lldb-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/lldb "$out"
''
+ lib.optionalString (lib.versionAtLeast release_version "19" && enableManpages) ''
mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/llvm/docs "$out/llvm/docs"
''
)
else
src;
# There is no `lib` output because some of the files in `$out/lib` depend on files in `$out/bin`.
# For example, `$out/lib/python3.12/site-packages/lldb/lldb-argdumper` is a symlink to `$out/bin/lldb-argdumper`.
# Also, LLDB expects to find the path to `bin` relative to `lib` on Darwin.
outputs = [
"out"
"dev"
];
sourceRoot = "${finalAttrs.src.name}/lldb";
patches = [ ./gnu-install-dirs.patch ];
nativeBuildInputs = [
cmake
python3
which
swig
lit
makeWrapper
lua5_3
]
++ lib.optionals enableManpages [
python3.pkgs.sphinx
python3.pkgs.myst-parser
]
# TODO: Clean up on `staging`.
++ [
ninja
];
buildInputs = [
ncurses
zlib
libedit
libxml2
libllvm
# Starting with LLVM 16, the resource dir patch is no longer enough to get
# libclang into the rpath of the lldb executables. By putting it into
# buildInputs cc-wrapper will set up rpath correctly for us.
(lib.getLib libclang)
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
darwin.bootstrap_cmds
];
hardeningDisable = [ "format" ];
cmakeFlags = [
(lib.cmakeBool "LLDB_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_RTTI" false)
(lib.cmakeFeature "Clang_DIR" "${lib.getDev libclang}/lib/cmake")
(lib.cmakeFeature "LLVM_EXTERNAL_LIT" "${lit}/bin/lit")
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
(lib.cmakeBool "LLDB_USE_SYSTEM_DEBUGSERVER" true)
]
++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
(lib.cmakeFeature "LLDB_CODESIGN_IDENTITY" "") # codesigning makes nondeterministic
]
# TODO: Clean up on `staging`.
++ [
(lib.cmakeFeature "CLANG_RESOURCE_DIR" "../../../../${lib.getLib libclang}")
]
++ lib.optionals enableManpages [
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
# docs reference `automodapi` but it's not added to the extensions list when
# only building the manpages:
# https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54
#
# so, we just ignore the resulting errors
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
++ lib.optionals finalAttrs.finalPackage.doCheck [
(lib.cmakeFeature "LLDB_TEST_C_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc")
(lib.cmakeFeature "-DLLDB_TEST_CXX_COMPILER" "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++")
]
++ devExtraCmakeFlags;
doCheck = false;
doInstallCheck = false;
# TODO: cleanup with mass-rebuild
installCheckPhase = ''
if [ ! -e ''${!outputLib}/${python3.sitePackages}/lldb/_lldb*.so ] ; then
echo "ERROR: python files not installed where expected!";
return 1;
fi
if [ ! -e "''${!outputLib}/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
echo "ERROR: lua files not installed where expected!";
return 1;
fi
'';
postInstall = ''
wrapProgram $out/bin/lldb --prefix PYTHONPATH : ''${!outputLib}/${python3.sitePackages}/
# Editor support
# vscode:
install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json
mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
ln -s $out/bin/*${vscodeExt.name} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
'';
passthru.vscodeExtName = vscodeExt.name;
passthru.vscodeExtPublisher = "llvm";
passthru.vscodeExtUniqueId = "llvm-org.${vscodeExt.name}-${vscodeExt.version}";
meta = llvm_meta // {
homepage = "https://lldb.llvm.org/";
description = "Next-generation high-performance debugger";
longDescription = ''
LLDB is a next generation, high-performance debugger. It is built as a set
of reusable components which highly leverage existing libraries in the
larger LLVM Project, such as the Clang expression parser and LLVM
disassembler.
'';
mainProgram = "lldb";
};
}
// lib.optionalAttrs enableManpages {
pname = "lldb-manpages";
# TODO: Remove on `staging`.
buildPhase = "";
ninjaFlags = [ "docs-lldb-man" ];
propagatedBuildInputs = [ ];
# manually install lldb man page
installPhase = ''
mkdir -p $out/share/man/man1
install docs/man/lldb.1 -t $out/share/man/man1/
'';
postPatch = null;
postInstall = null;
outputs = [ "out" ];
doCheck = false;
meta = llvm_meta // {
description = "man pages for LLDB ${version}";
};
}
)

View File

@@ -0,0 +1,68 @@
diff --git a/bindings/lua/CMakeLists.txt b/bindings/lua/CMakeLists.txt
index 1a739a980..59f8fc3a0 100644
--- a/bindings/lua/CMakeLists.txt
+++ b/bindings/lua/CMakeLists.txt
@@ -56,7 +56,7 @@ function(finish_swig_lua swig_target lldb_lua_bindings_dir lldb_lua_target_dir)
if(LLDB_BUILD_FRAMEWORK)
set(LLDB_LUA_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python)
else()
- set(LLDB_LUA_INSTALL_PATH ${LLDB_LUA_RELATIVE_PATH})
+ set(LLDB_LUA_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_LUA_RELATIVE_PATH})
endif()
install(DIRECTORY ${lldb_lua_target_dir}/
DESTINATION ${LLDB_LUA_INSTALL_PATH}
diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt
index c631faf52ac3..1d92d069960b 100644
--- a/bindings/python/CMakeLists.txt
+++ b/bindings/python/CMakeLists.txt
@@ -160,7 +160,7 @@ function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_tar
if(LLDB_BUILD_FRAMEWORK)
set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources/Python)
else()
- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH})
+ set(LLDB_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH})
endif()
if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH})
diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake
index 3291a7c808e1..b27d27ce6a87 100644
--- a/cmake/modules/AddLLDB.cmake
+++ b/cmake/modules/AddLLDB.cmake
@@ -109,7 +109,7 @@ function(add_lldb_library name)
endif()
if(PARAM_SHARED)
- set(install_dest lib${LLVM_LIBDIR_SUFFIX})
+ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
if(PARAM_INSTALL_PREFIX)
set(install_dest ${PARAM_INSTALL_PREFIX})
endif()
diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt
index 7d48491ec89a..c04543585588 100644
--- a/tools/intel-features/CMakeLists.txt
+++ b/tools/intel-features/CMakeLists.txt
@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED
)
install(TARGETS lldbIntelFeatures
- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt
index 7d48491ec89a..c04543585588 100644
--- a/source/API/CMakeLists.txt 2024-05-30 18:59:13.449269853 -0700
+++ b/source/API/CMakeLists.txt 2024-05-30 19:00:33.721858164 -0700
@@ -115,14 +115,6 @@
${option_install_prefix}
)
-# lib/pythonX.Y/dist-packages/lldb/_lldb.so is a symlink to lib/liblldb.so,
-# which depends on lib/libLLVM*.so (BUILD_SHARED_LIBS) or lib/libLLVM-10git.so
-# (LLVM_LINK_LLVM_DYLIB). Add an additional rpath $ORIGIN/../../../../lib so
-# that _lldb.so can be loaded from Python.
-if(LLDB_ENABLE_PYTHON AND (BUILD_SHARED_LIBS OR LLVM_LINK_LLVM_DYLIB) AND UNIX AND NOT APPLE)
- set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "\$ORIGIN/../../../../lib${LLVM_LIBDIR_SUFFIX}")
-endif()
-
if(Python3_RPATH)
set_property(TARGET liblldb APPEND PROPERTY INSTALL_RPATH "${Python3_RPATH}")
set_property(TARGET liblldb APPEND PROPERTY BUILD_RPATH "${Python3_RPATH}")

View File

@@ -0,0 +1,35 @@
From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 18 Feb 2016 10:33:04 +0100
Subject: [PATCH 2/3] Fix build with musl libc
On musl libc the fopen64 and fopen are the same thing, but for
compatibility they have a `#define fopen64 fopen`. Same applies for
fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64.
---
include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h
index 7becdf0..7f14427 100644
--- a/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/include/llvm/Analysis/TargetLibraryInfo.h
@@ -18,6 +18,15 @@
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
+#undef fopen64
+#undef fseeko64
+#undef fstat64
+#undef fstatvfs64
+#undef ftello64
+#undef lstat64
+#undef stat64
+#undef tmpfile64
+
namespace llvm {
/// VecDesc - Describes a possible vectorization of a function.
/// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized
--
2.7.3

View File

@@ -0,0 +1,643 @@
{
lib,
stdenv,
llvm_meta,
pkgsBuildBuild,
src ? null,
monorepoSrc ? null,
runCommand,
cmake,
darwin,
ninja,
python3,
python3Packages,
libffi,
ld64,
libbfd,
libpfm,
libxml2,
ncurses,
version,
release_version,
zlib,
which,
sysctl,
buildLlvmTools,
updateAutotoolsGnuConfigScriptsHook,
enableManpages ? false,
enableSharedLibraries ? !stdenv.hostPlatform.isStatic,
enablePFM ?
stdenv.hostPlatform.isLinux # PFM only supports Linux
# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245
# broken for the armv7l builder
&& !stdenv.hostPlatform.isAarch,
enablePolly ? true,
enableTerminfo ? true,
devExtraCmakeFlags ? [ ],
getVersionFile,
fetchpatch,
# for tests
libllvm,
}:
let
inherit (lib) optional optionals optionalString;
# Is there a better way to do this? Darwin wants to disable tests in the first
# LLVM rebuild, but overriding doesnt work when building libc++, libc++abi,
# and libunwind. It also wants to disable LTO in the first rebuild.
isDarwinBootstrap = lib.getName stdenv == "bootstrap-stage-xclang-stdenv-darwin";
in
stdenv.mkDerivation (
finalAttrs:
let
# Ordinarily we would just the `doCheck` and `checkDeps` functionality
# `mkDerivation` gives us to manage our test dependencies (instead of breaking
# out `doCheck` as a package level attribute).
#
# Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in
# particular the children it uses to do feature detection.
#
# This means that python deps we add to `checkDeps` (which the python
# interpreter is made aware of via `$PYTHONPATH` populated by the python
# setup hook) are not picked up by `lit` which causes it to skip tests.
#
# Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work
# because this package is shadowed in `$PATH` by the regular `python3`
# package.
#
# So, we "manually" assemble one python derivation for the package to depend
# on, taking into account whether checks are enabled or not:
python =
if finalAttrs.finalPackage.doCheck && !isDarwinBootstrap then
# Note that we _explicitly_ ask for a python interpreter for our host
# platform here; the splicing that would ordinarily take care of this for
# us does not seem to work once we use `withPackages`.
let
checkDeps = ps: [ ps.psutil ];
in
pkgsBuildBuild.targetPackages.python3.withPackages checkDeps
else
python3;
in
{
pname = "llvm";
inherit version;
# TODO: Remove on `staging`.
shortVersion = lib.concatStringsSep "." (lib.take 1 (lib.splitString "." release_version));
src =
if monorepoSrc != null then
runCommand "llvm-src-${version}" { inherit (monorepoSrc) passthru; } (
''
mkdir -p "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/third-party "$out"
''
+ lib.optionalString enablePolly ''
chmod u+w "$out/llvm/tools"
cp -r ${monorepoSrc}/polly "$out/llvm/tools"
''
+ lib.optionalString (lib.versionAtLeast release_version "21") ''
cp -r ${monorepoSrc}/libc "$out"
''
)
else
src;
sourceRoot = "${finalAttrs.src.name}/llvm";
outputs = [
"out"
"lib"
"dev"
"python"
];
hardeningDisable = [
"trivialautovarinit"
"shadowstack"
];
patches =
# Support custom installation dirs
# Originally based off https://reviews.llvm.org/D99484
# Latest state: https://github.com/llvm/llvm-project/pull/125376
[ (getVersionFile "llvm/gnu-install-dirs.patch") ]
++ [
# Running the tests involves invoking binaries (like `opt`) that depend on
# the LLVM dylibs and reference them by absolute install path (i.e. their
# nix store path).
#
# Because we have not yet run the install phase (we're running these tests
# as part of `checkPhase` instead of `installCheckPhase`) these absolute
# paths do not exist yet; to work around this we point the loader (`ld` on
# unix, `dyld` on macOS) at the `lib` directory which will later become this
# package's `lib` output.
#
# Previously we would just set `LD_LIBRARY_PATH` to include the build `lib`
# dir but:
# - this doesn't generalize well to other platforms; `lit` doesn't forward
# `DYLD_LIBRARY_PATH` (macOS):
# + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26
# - even if `lit` forwarded this env var, we actually cannot set
# `DYLD_LIBRARY_PATH` in the child processes `lit` launches because
# `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for
# "protected processes" (i.e. the python interpreter that runs `lit`):
# https://stackoverflow.com/a/35570229
# - other LLVM subprojects deal with this issue by having their `lit`
# configuration set these env vars for us; it makes sense to do the same
# for LLVM:
# + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31
#
# !!! TODO: look into upstreaming this patch
(getVersionFile "llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch")
# `lit` has a mode where it executes run lines as a shell script which is
# constructs; this is problematic for macOS because it means that there's
# another process in between `lit` and the binaries being tested. As noted
# above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our
# tests fail with dyld errors.
#
# To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when
# present in the test configuration.
#
# It's not clear to me why this isn't an issue for LLVM developers running
# on macOS (nothing about this _seems_ nix specific)..
(getVersionFile "llvm/lit-shell-script-runner-set-dyld-library-path.patch")
]
++
lib.optional (lib.versionOlder release_version "19")
# Add missing include headers to build against gcc-15:
# https://github.com/llvm/llvm-project/pull/101761
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/7e44305041d96b064c197216b931ae3917a34ac1.patch";
hash = "sha256-1htuzsaPHbYgravGc1vrR8sqpQ/NSQ8PUZeAU8ucCFk=";
stripLen = 1;
}
)
++ lib.optionals (lib.versions.major release_version == "18") [
# Reorgs one test so the next patch applies
(fetchpatch {
name = "osabi-test-reorg.patch";
url = "https://github.com/llvm/llvm-project/commit/06cecdc60ec9ebfdd4d8cdb2586d201272bdf6bd.patch";
stripLen = 1;
hash = "sha256-s9GZTNgzLS511Pzh6Wb1hEV68lxhmLWXjlybHBDMhvM=";
})
# Sets the OSABI for OpenBSD, needed for an LLD patch for OpenBSD.
# https://github.com/llvm/llvm-project/pull/98553
(fetchpatch {
name = "mc-set-openbsd-osabi.patch";
url = "https://github.com/llvm/llvm-project/commit/b64c1de714c50bec7493530446ebf5e540d5f96a.patch";
stripLen = 1;
hash = "sha256-fqw5gTSEOGs3kAguR4tINFG7Xja1RAje+q67HJt2nGg=";
})
]
++ lib.optionals (lib.versionOlder release_version "19") [
# Fixes test-suite on glibc 2.40 (https://github.com/llvm/llvm-project/pull/100804)
(fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/1e8df9e85a1ff213e5868bd822877695f27504ad.patch";
hash = "sha256-mvBlG2RxpZPFnPI7jvCMz+Fc8JuM15Ye3th1FVZMizE=";
stripLen = 1;
})
]
++ lib.optionals enablePolly [
# Just like the `gnu-install-dirs` patch, but for `polly`.
(getVersionFile "llvm/gnu-install-dirs-polly.patch")
# Just like the `llvm-lit-cfg` patch, but for `polly`.
(getVersionFile "llvm/polly-lit-cfg-add-libs-to-dylib-path.patch")
]
++
lib.optional (lib.versions.major release_version == "20")
# Test failure on riscv64, fixed in llvm 21
# https://github.com/llvm/llvm-project/issues/150818
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/bd49bbaaafc98433a2cb4e95ce25b7a201baf5a5.patch";
hash = "sha256-3hkbYPUVRAtWpo5qBmc2jLZLivURMx8T0GQomvNZesc=";
stripLen = 1;
}
);
nativeBuildInputs = [
cmake
# while this is not an autotools build, it still includes a config.guess
# this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native
updateAutotoolsGnuConfigScriptsHook
python
ninja
]
++ optionals enableManpages [
# Note: we intentionally use `python3Packages` instead of `python3.pkgs`;
# splicing does *not* work with the latter. (TODO: fix)
python3Packages.sphinx
python3Packages.myst-parser
];
buildInputs = [
libxml2
libffi
]
++ optional enablePFM libpfm; # exegesis
propagatedBuildInputs = [
ncurses
zlib
];
nativeCheckInputs = [
which
]
++ lib.optional stdenv.hostPlatform.isDarwin sysctl;
postPatch =
optionalString stdenv.hostPlatform.isDarwin (
''
substituteInPlace cmake/modules/AddLLVM.cmake \
--replace-fail 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)"
''
+
# As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick
# this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7
''
rm test/MC/ELF/cfi-version.ll
''
+
# This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`)
# and thus fails under the sandbox:
''
substituteInPlace unittests/TargetParser/Host.cpp \
--replace-fail '/usr/bin/sw_vers' "${(toString darwin.DarwinTools) + "/bin/sw_vers"}"
''
+
# This test tries to call the intrinsics `@llvm.roundeven.f32` and
# `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf`
# and `roundeven` on macOS and FreeBSD.
#
# However these functions are glibc specific so the test fails:
# - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html
# - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html
#
# TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it
# pass there?
''
substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
--replace-fail "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
--replace-fail "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
''
+
# fails when run in sandbox
optionalString (!stdenv.hostPlatform.isx86) ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''
)
+
# dup of above patch with different conditions
optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86)
# fails when run in sandbox
(
''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace-fail "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''
+
# This test fails on darwin x86_64 because `sw_vers` reports a different
# macOS version than what LLVM finds by reading
# `/System/Library/CoreServices/SystemVersion.plist` (which is passed into
# the sandbox on macOS).
#
# The `sw_vers` provided by nixpkgs reports the macOS version associated
# with the `CoreFoundation` framework with which it was built. Because
# nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what
# `sw_vers` reports is not guaranteed to match the macOS version of the host
# that's building this derivation.
#
# Astute readers will note that we only _patch_ this test on aarch64-darwin
# (to use the nixpkgs provided `sw_vers`) instead of disabling it outright.
# So why does this test pass on aarch64?
#
# Well, it seems that `sw_vers` on aarch64 actually links against the _host_
# CoreFoundation framework instead of the nixpkgs provided one.
#
# Not entirely sure what the right fix is here. I'm assuming aarch64
# `sw_vers` doesn't intentionally link against the host `CoreFoundation`
# (still digging into how this ends up happening, will follow up) but that
# aside I think the more pertinent question is: should we be patching LLVM's
# macOS version detection logic to use `sw_vers` instead of reading host
# paths? This *is* a way in which details about builder machines can creep
# into the artifacts that are produced, affecting reproducibility, but it's
# not clear to me when/where/for what this even gets used in LLVM.
#
# TODO(@rrbutani): fix/follow-up
''
substituteInPlace unittests/TargetParser/Host.cpp \
--replace-fail "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
''
+
# This test fails with a `dysmutil` crash; have not yet dug into what's
# going on here (TODO(@rrbutani)).
lib.optionalString (lib.versionOlder release_version "19") ''
rm test/tools/dsymutil/ARM/obfuscated.test
''
)
+
# FileSystem permissions tests fail with various special bits
''
substituteInPlace unittests/Support/CMakeLists.txt \
--replace-fail "Path.cpp" ""
rm unittests/Support/Path.cpp
substituteInPlace unittests/IR/CMakeLists.txt \
--replace-fail "PassBuilderCallbacksTest.cpp" ""
rm unittests/IR/PassBuilderCallbacksTest.cpp
rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
''
+
# Fails in the presence of anti-virus software or other intrusion-detection software that
# modifies the atime when run. See #284056.
''
rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
''
+
# valgrind unhappy with musl or glibc, but fails w/musl only
optionalString stdenv.hostPlatform.isMusl ''
patch -p1 -i ${./TLI-musl.patch}
substituteInPlace unittests/Support/CMakeLists.txt \
--replace-fail "add_subdirectory(DynamicLibrary)" ""
rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
rm test/CodeGen/AArch64/wineh4.mir
''
+ optionalString stdenv.hostPlatform.isAarch32 ''
# skip failing X86 test cases on 32-bit ARM
rm test/DebugInfo/X86/convert-debugloc.ll
rm test/DebugInfo/X86/convert-inlined.ll
rm test/DebugInfo/X86/convert-linked.ll
rm test/tools/dsymutil/X86/op-convert.test
rm test/tools/gold/X86/split-dwarf.ll
rm test/tools/llvm-objcopy/MachO/universal-object.test
''
+
# Seems to require certain floating point hardware (NEON?)
optionalString (stdenv.hostPlatform.system == "armv6l-linux") ''
rm test/ExecutionEngine/frem.ll
''
+
# 1. TODO: Why does this test fail on FreeBSD?
# It seems to reference /usr/local/lib/libfile.a, which is clearly a problem.
# 2. This test fails for the same reason it fails on MacOS, but the fix is
# not trivial to apply.
optionalString stdenv.hostPlatform.isFreeBSD ''
rm test/tools/llvm-libtool-darwin/L-and-l.test
rm test/ExecutionEngine/Interpreter/intrinsics.ll
# Fails in sandbox
substituteInPlace unittests/Support/LockFileManagerTest.cpp --replace-fail "Basic" "DISABLED_Basic"
''
+
# https://github.com/llvm/llvm-project/issues/149616
optionalString stdenv.hostPlatform.isLoongArch64 ''
substituteInPlace unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp \
--replace-fail \
"TEST_F(X86SnippetRepetitorTest, Loop)" \
"TEST_F(X86SnippetRepetitorTest, DISABLED_Loop)"
''
+ ''
patchShebangs test/BugPoint/compile-custom.ll.py
'';
# Workaround for configure flags that need to have spaces
preConfigure = ''
cmakeFlagsArray+=(
-DLLVM_LIT_ARGS="--verbose -j''${NIX_BUILD_CORES}"
)
'';
# Defensive check: some paths (that we make symlinks to) depend on the release
# version, for example:
# - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185
#
# So we want to sure that the version in the source matches the release
# version we were given.
#
# We do this check here, in the LLVM build, because it happens early.
postConfigure =
let
v = lib.versions;
major = v.major release_version;
minor = v.minor release_version;
patch = v.patch release_version;
in
''
# $1: part, $2: expected
check_version() {
part="''${1^^}"
part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)"
if [[ "$part" != "$2" ]]; then
echo >&2 \
"mismatch in the $1 version! we have version ${release_version}" \
"and expected the $1 version to be '$2'; the source has '$part' instead"
exit 3
fi
}
check_version major ${major}
check_version minor ${minor}
check_version patch ${patch}
'';
# E.g. Mesa uses the build-id as a cache key (see #93946):
LDFLAGS = optionalString (
enableSharedLibraries && !stdenv.hostPlatform.isDarwin
) "-Wl,--build-id=sha1";
cmakeBuildType = "Release";
cmakeFlags =
let
# These flags influence llvm-config's BuildVariables.inc in addition to the
# general build. We need to make sure these are also passed via
# CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native
# will return different results from the cross llvm-config.
#
# Some flags don't need to be repassed because LLVM already does so (like
# CMAKE_BUILD_TYPE), others are irrelevant to the result.
flagsForLlvmConfig = [
(lib.cmakeFeature "LLVM_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/llvm")
(lib.cmakeBool "LLVM_ENABLE_RTTI" true)
(lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" enableSharedLibraries)
(lib.cmakeFeature "LLVM_TABLEGEN" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
];
in
flagsForLlvmConfig
++ [
(lib.cmakeBool "LLVM_INSTALL_UTILS" true) # Needed by rustc
(lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_FFI" true)
(lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeBool "LLVM_ENABLE_DUMP" true)
(lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo)
(lib.cmakeBool "LLVM_INCLUDE_TESTS" finalAttrs.finalPackage.doCheck)
]
++ optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper
(lib.cmakeBool "LLVM_ENABLE_PIC" false)
(lib.cmakeBool "CMAKE_SKIP_INSTALL_RPATH" true)
(lib.cmakeBool "LLVM_BUILD_STATIC" true)
# libxml2 needs to be disabled because the LLVM build system ignores its .la
# file and doesn't link zlib as well.
# https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812
(lib.cmakeBool "LLVM_ENABLE_LIBXML2" false)
]
++ optionals enableManpages [
(lib.cmakeBool "LLVM_BUILD_DOCS" true)
(lib.cmakeBool "LLVM_ENABLE_SPHINX" true)
(lib.cmakeBool "SPHINX_OUTPUT_MAN" true)
(lib.cmakeBool "SPHINX_OUTPUT_HTML" false)
(lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
]
++ optionals (libbfd != null) [
# LLVM depends on binutils only through libbfd/include/plugin-api.h, which
# is meant to be a stable interface. Depend on that file directly rather
# than through a build of BFD to break the dependency of clang on the target
# triple. The result of this is that a single clang build can be used for
# multiple targets.
(lib.cmakeFeature "LLVM_BINUTILS_INCDIR" "${libbfd.plugin-api-header}/include")
]
++ optionals stdenv.hostPlatform.isDarwin [
(lib.cmakeBool "LLVM_ENABLE_LIBCXX" true)
(lib.cmakeBool "CAN_TARGET_i386" false)
]
++
optionals
(
(stdenv.hostPlatform != stdenv.buildPlatform)
&& !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)
)
[
(lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
(
let
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
nativeBintools = nativeCC.bintools.bintools;
nativeToolchainFlags = [
(lib.cmakeFeature "CMAKE_C_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}cc")
(lib.cmakeFeature "CMAKE_CXX_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}c++")
(lib.cmakeFeature "CMAKE_AR" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ar")
(lib.cmakeFeature "CMAKE_STRIP" "${nativeBintools}/bin/${nativeBintools.targetPrefix}strip")
(lib.cmakeFeature "CMAKE_RANLIB" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib")
];
# We need to repass the custom GNUInstallDirs values, otherwise CMake
# will choose them for us, leading to wrong results in llvm-config-native
nativeInstallFlags = [
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" (placeholder "out"))
(lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "${placeholder "out"}/bin")
(lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "${placeholder "dev"}/include")
(lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "${placeholder "lib"}/lib")
(lib.cmakeFeature "CMAKE_INSTALL_LIBEXECDIR" "${placeholder "lib"}/libexec")
];
in
lib.cmakeOptionType "list" "CROSS_TOOLCHAIN_FLAGS_NATIVE" (
lib.concatStringsSep ";" (
lib.concatLists [
flagsForLlvmConfig
nativeToolchainFlags
nativeInstallFlags
]
)
)
)
]
++ devExtraCmakeFlags;
postInstall = ''
mkdir -p $python/share
mv $out/share/opt-viewer $python/share/opt-viewer
moveToOutput "bin/llvm-config*" "$dev"
substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${lib.toLower finalAttrs.finalPackage.cmakeBuildType}.cmake" \
--replace-fail "$out/bin/llvm-config" "$dev/bin/llvm-config"
substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
--replace-fail 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
''
+ optionalString (stdenv.hostPlatform.isDarwin && enableSharedLibraries) ''
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
''
+ optionalString (stdenv.buildPlatform != stdenv.hostPlatform) (
if stdenv.buildPlatform.canExecute stdenv.hostPlatform then
''
ln -s $dev/bin/llvm-config $dev/bin/llvm-config-native
''
else
''
cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native
''
);
doCheck =
!isDarwinBootstrap
&& !stdenv.hostPlatform.isAarch32
&& (
!stdenv.hostPlatform.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl)
&& !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian)
&& (stdenv.hostPlatform == stdenv.buildPlatform);
checkTarget = "check-all";
passthru = {
# For the update script:
inherit monorepoSrc;
tests.withoutOptionalFeatures = libllvm.override {
enablePFM = false;
enablePolly = false;
enableTerminfo = false;
};
};
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://llvm.org/";
description = "Collection of modular and reusable compiler and toolchain technologies";
longDescription = ''
The LLVM Project is a collection of modular and reusable compiler and
toolchain technologies. Despite its name, LLVM has little to do with
traditional virtual machines. The name "LLVM" itself is not an acronym; it
is the full name of the project.
LLVM began as a research project at the University of Illinois, with the
goal of providing a modern, SSA-based compilation strategy capable of
supporting both static and dynamic compilation of arbitrary programming
languages. Since then, LLVM has grown to be an umbrella project consisting
of a number of subprojects, many of which are being used in production by
a wide variety of commercial and open source projects as well as being
widely used in academic research. Code in the LLVM project is licensed
under the "Apache 2.0 License with LLVM exceptions".
'';
};
}
// lib.optionalAttrs enableManpages {
pname = "llvm-manpages";
propagatedBuildInputs = [ ];
ninjaFlags = [ "docs-llvm-man" ];
installTargets = [ "install-docs-llvm-man" ];
doCheck = false;
postPatch = null;
postInstall = null;
outputs = [ "out" ];
meta = llvm_meta // {
description = "man pages for LLVM ${version}";
};
}
)

View File

@@ -0,0 +1,95 @@
{
lib,
stdenv,
llvm_meta,
release_version,
buildLlvmTools,
monorepoSrc,
runCommand,
cmake,
ninja,
libxml2,
libllvm,
version,
devExtraCmakeFlags ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
pname = "mlir";
inherit version;
doCheck =
(
!stdenv.hostPlatform.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl);
# Blank llvm dir just so relative path works
src = runCommand "${finalAttrs.pname}-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/mlir "$out"
cp -r ${monorepoSrc}/third-party "$out/third-party"
mkdir -p "$out/llvm"
'';
sourceRoot = "${finalAttrs.src.name}/mlir";
patches = [
./gnu-install-dirs.patch
];
nativeBuildInputs = [
cmake
ninja
];
buildInputs = [
libllvm
libxml2
];
cmakeFlags = [
(lib.cmakeBool "LLVM_BUILD_TOOLS" true)
# Install headers as well
(lib.cmakeBool "LLVM_INSTALL_TOOLCHAIN_ONLY" false)
(lib.cmakeFeature "MLIR_TOOLS_INSTALL_DIR" "${placeholder "out"}/bin/")
(lib.cmakeBool "LLVM_ENABLE_IDE" false)
(lib.cmakeFeature "MLIR_INSTALL_PACKAGE_DIR" "${placeholder "dev"}/lib/cmake/mlir")
(lib.cmakeFeature "MLIR_INSTALL_CMAKE_DIR" "${placeholder "dev"}/lib/cmake/mlir")
(lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.finalPackage.doCheck)
(lib.cmakeBool "LLVM_ENABLE_FFI" true)
(lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
(lib.cmakeBool "LLVM_ENABLE_DUMP" true)
(lib.cmakeFeature "LLVM_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/llvm-tblgen")
(lib.cmakeFeature "MLIR_TABLEGEN_EXE" "${buildLlvmTools.tblgen}/bin/mlir-tblgen")
(lib.cmakeBool "LLVM_BUILD_LLVM_DYLIB" (!stdenv.hostPlatform.isStatic))
]
++ lib.optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper
(lib.cmakeBool "LLVM_ENABLE_PIC" false)
(lib.cmakeBool "LLVM_BUILD_STATIC" true)
(lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" false)
]
++ devExtraCmakeFlags;
outputs = [
"out"
"dev"
];
requiredSystemFeatures = [ "big-parallel" ];
meta = llvm_meta // {
homepage = "https://mlir.llvm.org/";
description = "Multi-Level IR Compiler Framework";
longDescription = ''
The MLIR project is a novel approach to building reusable and extensible
compiler infrastructure. MLIR aims to address software fragmentation,
improve compilation for heterogeneous hardware, significantly reduce
the cost of building domain specific compilers, and aid in connecting
existing compilers together.
'';
};
})

View File

@@ -0,0 +1,15 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c91e9cd93dc8..23b6032a46b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,8 +32,8 @@ if(MLIR_STANDALONE_BUILD)
endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
- "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
+ "${CMAKE_INSTALL_LIBDIR}/${LLVM_LIBDIR_SUFFIX}")
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_INSTALL_BINDIR}")
set(LLVM_LIT_ARGS "-sv" CACHE STRING "Default options for lit")
endif()

View File

@@ -0,0 +1,111 @@
{
lib,
stdenv,
llvm_meta,
release_version,
monorepoSrc ? null,
src ? null,
runCommand,
cmake,
ninja,
llvm,
targetLlvm,
lit,
clang-unwrapped,
perl,
pkg-config,
python3,
version,
devExtraCmakeFlags ? [ ],
ompdSupport ? true,
ompdGdbSupport ? ompdSupport,
getVersionFile,
fetchpatch,
}:
assert lib.assertMsg (ompdGdbSupport -> ompdSupport) "OMPD GDB support requires OMPD support!";
stdenv.mkDerivation (finalAttrs: {
pname = "openmp";
inherit version;
src =
if monorepoSrc != null then
runCommand "openmp-src-${version}" { inherit (monorepoSrc) passthru; } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/openmp "$out"
''
else
src;
sourceRoot = "${finalAttrs.src.name}/openmp";
outputs = [
"out"
"dev"
];
# TODO: Remove on `staging`.
patchFlags = null;
patches =
lib.optional (lib.versionOlder release_version "19") (getVersionFile "openmp/fix-find-tool.patch")
++ [
(getVersionFile "openmp/run-lit-directly.patch")
];
nativeBuildInputs = [
cmake
python3.pythonOnBuildForHost
perl
ninja
pkg-config
lit
];
buildInputs = [
(if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
]
++ lib.optionals (ompdSupport && ompdGdbSupport) [
python3
];
cmakeFlags = [
(lib.cmakeBool "LIBOMP_ENABLE_SHARED" (
!stdenv.hostPlatform.isStatic && stdenv.hostPlatform.hasSharedLibraries
))
(lib.cmakeBool "LIBOMP_OMPD_SUPPORT" ompdSupport)
(lib.cmakeBool "LIBOMP_OMPD_GDB_SUPPORT" ompdGdbSupport)
(lib.cmakeFeature "CLANG_TOOL" "${clang-unwrapped}/bin/clang")
(lib.cmakeFeature "OPT_TOOL" "${llvm}/bin/opt")
(lib.cmakeFeature "LINK_TOOL" "${llvm}/bin/llvm-link")
]
++ devExtraCmakeFlags;
doCheck = false;
checkTarget = "check-openmp";
preCheck = ''
patchShebangs ../tools/archer/tests/deflake.bash
'';
meta = llvm_meta // {
homepage = "https://openmp.llvm.org/";
description = "Support for the OpenMP language";
longDescription = ''
The OpenMP subproject of LLVM contains the components required to build an
executable OpenMP program that are outside the compiler itself.
Contains the code for the runtime library against which code compiled by
"clang -fopenmp" must be linked before it can run and the library that
supports offload to target devices.
'';
# "All of the code is dual licensed under the MIT license and the UIUC
# License (a BSD-like license)":
license = with lib.licenses; [
mit
ncsa
];
};
})

View File

@@ -0,0 +1,119 @@
{
"clang/gnu-install-dirs.patch" = [
{
after = "19";
path = ../19;
}
];
"clang/purity.patch" = [
{
path = ../18;
}
];
"lld/gnu-install-dirs.patch" = [
{
path = ../18;
}
];
"llvm/gnu-install-dirs.patch" = [
{
after = "22";
path = ../22;
}
{
after = "21";
before = "22";
path = ../21;
}
{
after = "20";
before = "21";
path = ../20;
}
{
before = "20";
path = ../18;
}
];
"llvm/gnu-install-dirs-polly.patch" = [
{
after = "20";
path = ../20;
}
{
before = "20";
path = ../18;
}
];
"llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch" = [
{
path = ../18;
}
];
"llvm/lit-shell-script-runner-set-dyld-library-path.patch" = [
{
path = ../18;
}
];
"llvm/polly-lit-cfg-add-libs-to-dylib-path.patch" = [
{
path = ../18;
}
];
"compiler-rt/X86-support-extension.patch" = [
{
path = ../18;
}
];
"compiler-rt/armv6-scudo-libatomic.patch" = [
{
after = "19";
path = ../19;
}
{
before = "19";
path = ../18;
}
];
"compiler-rt/normalize-var.patch" = [
{
path = ../18;
}
];
"openmp/fix-find-tool.patch" = [
{
before = "19";
path = ../18;
}
];
"openmp/run-lit-directly.patch" = [
{
path = ../18;
}
];
"libclc/use-default-paths.patch" = [
{
after = "20";
path = ../20;
}
{
after = "19";
before = "20";
path = ../19;
}
{
after = "20";
path = ../20;
}
];
"libclc/gnu-install-dirs.patch" = [
{
before = "21";
path = ../18;
}
{
after = "21";
path = ../21;
}
];
}

View File

@@ -0,0 +1,116 @@
{
cmake,
devExtraCmakeFlags ? [ ],
lib,
llvm_meta,
monorepoSrc ? null,
ninja,
patches ? [ ],
python3,
updateAutotoolsGnuConfigScriptsHook,
release_version,
runCommand,
src ? null,
stdenv,
version,
clangPatches,
}:
let
# This is a synthetic package which is not an official part of the llvm-project.
# See https://github.com/NixOS/nixpkgs/pull/362384 for discussion.
#
# LLVM has tools that run at build time. In native builds, these are
# built as a part of the usual build, but in cross builds they need to
# come from buildPackages.
#
# In many scenarios this is a small problem because LLVM from
# buildPackages is already available as a build; but if cross building a
# version of LLVM which is not available (e.g. a new git commit of LLVM)
# this results in two builds of LLVM and clang, one native and one for the
# cross.
#
# Full builds of LLVM are expensive; and unnecessary in this scenario. We
# don't need a native LLVM, only a native copy of the tools which run at
# build time. This is only tablegen and related tooling, which are cheap
# to build.
pname = "llvm-tblgen";
src' =
if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/third-party "$out"
cp -r ${monorepoSrc}/llvm "$out"
cp -r ${monorepoSrc}/clang "$out"
cp -r ${monorepoSrc}/clang-tools-extra "$out"
cp -r ${monorepoSrc}/mlir "$out"
''
else
src;
# List of tablegen targets.
targets = [
"clang-tblgen"
"llvm-tblgen"
"clang-tidy-confusable-chars-gen"
"mlir-tblgen"
]
++ lib.optionals (lib.versionOlder release_version "20") [
"clang-pseudo-gen" # Removed in LLVM 20 @ ed8f78827895050442f544edef2933a60d4a7935.
];
self = stdenv.mkDerivation (finalAttrs: {
inherit pname version patches;
src = src';
sourceRoot = "${finalAttrs.src.name}/llvm";
__structuredAttrs = true;
postPatch = ''
(
cd ../clang
chmod u+rwX -R .
for p in ${toString clangPatches}
do
patch -p1 < $p
done
)
'';
nativeBuildInputs = [
cmake
ninja
python3
# while this is not an autotools build, it still includes a config.guess
# this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native
updateAutotoolsGnuConfigScriptsHook
];
cmakeFlags = [
# Projects with tablegen-like tools.
"-DLLVM_ENABLE_PROJECTS=${
lib.concatStringsSep ";" [
"llvm"
"clang"
"clang-tools-extra"
"mlir"
]
}"
]
++ devExtraCmakeFlags;
ninjaFlags = targets;
inherit targets;
installPhase = ''
mkdir -p $out/bin
cp "''${targets[@]/#/bin/}" $out/bin
'';
});
in
self