Compare commits

...

6 Commits

Author SHA1 Message Date
John Ericson
5975ba6be1 clang: build with Ninja for all versions
Older versions using Make is a relic of old stdenv bootstrap.
2024-05-27 15:41:42 -04:00
John Ericson
95191cd7a5 llvmPackages: Clean up in a few ways 2024-05-27 15:41:42 -04:00
John Ericson
0fe5ab26b9 llvm: Alway disable hardening trivialautovarinit
Old code basically did just taht, this is simpler.
2024-05-27 14:34:19 -04:00
John Ericson
5b59dfc37a .git-blame-ignore-revs, .github: Mark formatting just done 2024-05-27 14:32:32 -04:00
John Ericson
65e2d797a2 llvmPackages: Format common files
This will help with further refactors
2024-05-27 14:30:55 -04:00
John Ericson
e8f0e65bf0 clang: Remove uneeded self
`finalAttrs` is good enough.
2024-05-27 13:47:01 -04:00
15 changed files with 1842 additions and 1462 deletions

View File

@@ -121,3 +121,6 @@ c759efa5e7f825913f9a69ef20f025f50f56dc4d
# python3Packages: format with nixfmt # python3Packages: format with nixfmt
59b1aef59071cae6e87859dc65de973d2cc595c0 59b1aef59071cae6e87859dc65de973d2cc595c0
# pkgs/development/compilers/llvm/common: Reformat with nixfmt-rfc-style
65e2d797a234feb71c787ad3ef0cafc52299bb37

View File

@@ -43,6 +43,7 @@ jobs:
nixos/modules/services/cluster/k3s nixos/modules/services/cluster/k3s
nixos/tests/k3s nixos/tests/k3s
pkgs/applications/networking/cluster/k3s pkgs/applications/networking/cluster/k3s
NIX_FMT_PATHS_LLVM_COMMON: pkgs/development/compilers/llvm/common
NIX_FMT_PATHS_VSCODE_EXTS: pkgs/applications/editors/vscode/extensions NIX_FMT_PATHS_VSCODE_EXTS: pkgs/applications/editors/vscode/extensions
NIX_FMT_PATHS_PHP_PACKAGES: pkgs/development/php-packages NIX_FMT_PATHS_PHP_PACKAGES: pkgs/development/php-packages
NIX_FMT_PATHS_BUILD_SUPPORT_PHP: pkgs/build-support/php NIX_FMT_PATHS_BUILD_SUPPORT_PHP: pkgs/build-support/php

View File

@@ -1,17 +1,28 @@
{ lib, runCommand, stdenv, llvm, lld, version, release_version }: {
lib,
runCommand,
stdenv,
llvm,
lld,
version,
release_version,
}:
let let
targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-"; targetPrefix = lib.optionalString (
stdenv.hostPlatform != stdenv.targetPlatform
) "${stdenv.targetPlatform.config}-";
in in
runCommand "llvm-binutils-${version}" runCommand "llvm-binutils-${version}"
{ {
preferLocalBuild = true; preferLocalBuild = true;
passthru = { passthru = {
isLLVM = true; isLLVM = true;
inherit targetPrefix; inherit targetPrefix;
}; };
} }
('' (
''
mkdir -p $out/bin mkdir -p $out/bin
for prog in ${lld}/bin/*; do for prog in ${lld}/bin/*; do
ln -s $prog $out/bin/${targetPrefix}$(basename $prog) ln -s $prog $out/bin/${targetPrefix}$(basename $prog)
@@ -44,6 +55,8 @@ runCommand "llvm-binutils-${version}"
ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld
# Only >=13 show GNU windres compatible in help # Only >=13 show GNU windres compatible in help
'' + lib.optionalString (lib.versionAtLeast release_version "13") '' ''
+ lib.optionalString (lib.versionAtLeast release_version "13") ''
ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres
'') ''
)

View File

@@ -1,148 +1,208 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, patches ? [] llvm_meta,
, src ? null patches ? [ ],
, monorepoSrc ? null src ? null,
, runCommand monorepoSrc ? null,
, substituteAll runCommand,
, cmake substituteAll,
, ninja cmake,
, libxml2 ninja,
, libllvm libxml2,
, release_version libllvm,
, version release_version,
, python3 version,
, buildLlvmTools python3,
, fixDarwinDylibNames buildLlvmTools,
, enableManpages ? false fixDarwinDylibNames,
, clang-tools-extra_src ? null enableManpages ? false,
clang-tools-extra_src ? null,
}: }:
let let
pname = "clang"; pname = "clang";
src' = if monorepoSrc != null then src' =
runCommand "${pname}-src-${version}" {} '' if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
cp -r ${monorepoSrc}/clang-tools-extra "$out" cp -r ${monorepoSrc}/clang-tools-extra "$out"
'' else src; ''
else
self = stdenv.mkDerivation (finalAttrs: rec { src;
in
stdenv.mkDerivation (
finalAttrs:
rec {
inherit pname version patches; inherit pname version patches;
src = src'; src = src';
sourceRoot = if lib.versionOlder release_version "13" then null sourceRoot = if lib.versionOlder release_version "13" then null else "${src.name}/${pname}";
else "${src.name}/${pname}";
nativeBuildInputs = [ cmake ] nativeBuildInputs =
++ (lib.optional (lib.versionAtLeast release_version "15") ninja) [
++ [ python3 ] cmake
ninja
python3
]
++ lib.optional (lib.versionAtLeast version "18" && enableManpages) python3.pkgs.myst-parser ++ lib.optional (lib.versionAtLeast version "18" && enableManpages) python3.pkgs.myst-parser
++ lib.optional enableManpages python3.pkgs.sphinx ++ lib.optional enableManpages python3.pkgs.sphinx
++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = [ libxml2 libllvm ]; buildInputs = [
libxml2
libllvm
];
cmakeFlags = (lib.optionals (lib.versionAtLeast release_version "15") [ cmakeFlags =
"-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" [
]) ++ [ "-DCMAKE_INSTALL_PACKAGEDIR=${placeholder "dev"}/lib/"
"-DCLANGD_BUILD_XPC=OFF" "-DCLANGD_BUILD_XPC=OFF"
"-DLLVM_ENABLE_RTTI=ON" "-DLLVM_ENABLE_RTTI=ON"
] ++ lib.optionals (lib.versionAtLeast release_version "17") [ (lib.cmakeBool "LLVM_INCLUDE_TESTS" finalAttrs.doCheck)
"-DLLVM_INCLUDE_TESTS=OFF" ]
] ++ lib.optionals enableManpages [ ++ lib.optionals enableManpages [
"-DCLANG_INCLUDE_DOCS=ON" "-DCLANG_INCLUDE_DOCS=ON"
"-DLLVM_ENABLE_SPHINX=ON" "-DLLVM_ENABLE_SPHINX=ON"
"-DSPHINX_OUTPUT_MAN=ON" "-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF" "-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF" "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) ([ ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) (
[
"-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
"-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen"
] ++ lib.optionals (lib.versionAtLeast release_version "15") [ ]
++ lib.optionals (lib.versionAtLeast release_version "15") [
# Added in LLVM15: # Added in LLVM15:
# `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb
# `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7
"-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen"
"-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen"
]); ]
);
postPatch = '' postPatch =
''
# Make sure clang passes the correct location of libLTO to ld64 # Make sure clang passes the correct location of libLTO to ld64
substituteInPlace lib/Driver/ToolChains/Darwin.cpp \ substituteInPlace lib/Driver/ToolChains/Darwin.cpp \
--replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";' --replace-fail 'StringRef P = llvm::sys::path::parent_path(D.Dir);' 'StringRef P = "${lib.getLib libllvm}";'
'' + (if lib.versionOlder release_version "13" then '' ''
+ (
if lib.versionOlder release_version "13" then
''
sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \
-e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \
lib/Driver/ToolChains/*.cpp lib/Driver/ToolChains/*.cpp
'' else '' ''
else
''
(cd tools && ln -s ../../clang-tools-extra extra) (cd tools && ln -s ../../clang-tools-extra extra)
'') + lib.optionalString stdenv.hostPlatform.isMusl '' ''
)
+ lib.optionalString stdenv.hostPlatform.isMusl ''
sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp
''; '';
outputs = [ "out" "lib" "dev" "python" ]; outputs = [
"out"
"lib"
"dev"
"python"
];
postInstall = '' postInstall =
''
ln -sv $out/bin/clang $out/bin/cpp ln -sv $out/bin/clang $out/bin/cpp
'' + (lib.optionalString (lib.versions.major release_version == "17") '' ''
+ (lib.optionalString (lib.versions.major release_version == "17") ''
mkdir -p $lib/lib/clang mkdir -p $lib/lib/clang
mv $lib/lib/17 $lib/lib/clang/17 mv $lib/lib/17 $lib/lib/clang/17
'') + '' '')
+ ''
# Move libclang to 'lib' output # Move libclang to 'lib' output
moveToOutput "lib/libclang.*" "$lib" moveToOutput "lib/libclang.*" "$lib"
moveToOutput "lib/libclang-cpp.*" "$lib" moveToOutput "lib/libclang-cpp.*" "$lib"
'' + (if lib.versionOlder release_version "15" then '' ''
+ (
if lib.versionOlder release_version "15" then
''
substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \
--replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \
--replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp."
'' else '' ''
else
''
substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \
--replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \
--replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp."
'') + '' ''
)
+ ''
'' + (if lib.versionOlder release_version "15" then '' ''
+ (
if lib.versionOlder release_version "15" then
''
mkdir -p $python/bin $python/share/{clang,scan-view} mkdir -p $python/bin $python/share/{clang,scan-view}
'' else '' ''
else
''
mkdir -p $python/bin $python/share/clang/ mkdir -p $python/bin $python/share/clang/
'') + '' ''
)
+ ''
mv $out/bin/{git-clang-format,scan-view} $python/bin mv $out/bin/{git-clang-format,scan-view} $python/bin
if [ -e $out/bin/set-xcode-analyzer ]; then if [ -e $out/bin/set-xcode-analyzer ]; then
mv $out/bin/set-xcode-analyzer $python/bin mv $out/bin/set-xcode-analyzer $python/bin
fi fi
mv $out/share/clang/*.py $python/share/clang mv $out/share/clang/*.py $python/share/clang
'' + (lib.optionalString (lib.versionOlder release_version "15") '' ''
+ (lib.optionalString (lib.versionOlder release_version "15") ''
mv $out/share/scan-view/*.py $python/share/scan-view mv $out/share/scan-view/*.py $python/share/scan-view
'') + '' '')
+ ''
rm $out/bin/c-index-test rm $out/bin/c-index-test
patchShebangs $python/bin patchShebangs $python/bin
mkdir -p $dev/bin mkdir -p $dev/bin
'' + (if lib.versionOlder release_version "15" then '' ''
+ (
if lib.versionOlder release_version "15" then
''
cp bin/clang-tblgen $dev/bin cp bin/clang-tblgen $dev/bin
'' else '' ''
else
''
cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin
''); ''
);
passthru = { doCheck = false;
passthru =
{
inherit libllvm; inherit libllvm;
isClang = true; isClang = true;
} // (lib.optionalAttrs (lib.versionAtLeast release_version "15") { }
// (lib.optionalAttrs (lib.versionAtLeast release_version "15") {
hardeningUnsupportedFlags = [ "fortify3" ];
hardeningUnsupportedFlagsByTargetPlatform =
targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or [ ]);
})
// (lib.optionalAttrs (lib.versionOlder release_version "15") {
hardeningUnsupportedFlags = [ hardeningUnsupportedFlags = [
"fortify3" "fortify3"
"zerocallusedregs"
]; ];
hardeningUnsupportedFlagsByTargetPlatform = targetPlatform:
lib.optional (!(targetPlatform.isx86_64 || targetPlatform.isAarch64)) "zerocallusedregs"
++ (finalAttrs.passthru.hardeningUnsupportedFlags or []);
}) // (lib.optionalAttrs (lib.versionOlder release_version "15") {
hardeningUnsupportedFlags = [ "fortify3" "zerocallusedregs" ];
}); });
meta = llvm_meta // { meta = llvm_meta // {
@@ -161,7 +221,8 @@ let
''; '';
mainProgram = "clang"; mainProgram = "clang";
}; };
} // lib.optionalAttrs enableManpages ({ }
// lib.optionalAttrs enableManpages {
pname = "clang-manpages"; pname = "clang-manpages";
installPhase = '' installPhase = ''
@@ -177,13 +238,10 @@ let
meta = llvm_meta // { meta = llvm_meta // {
description = "man page for Clang ${version}"; description = "man page for Clang ${version}";
}; };
} // (if lib.versionOlder release_version "15" then {
buildPhase = ''
make docs-clang-man
'';
} else {
ninjaFlags = [ "docs-clang-man" ]; ninjaFlags = [ "docs-clang-man" ];
})) // (lib.optionalAttrs (clang-tools-extra_src != null) { inherit clang-tools-extra_src; }) }
// (lib.optionalAttrs (clang-tools-extra_src != null) { inherit clang-tools-extra_src; })
// (lib.optionalAttrs (lib.versionOlder release_version "13") { // (lib.optionalAttrs (lib.versionOlder release_version "13") {
unpackPhase = '' unpackPhase = ''
unpackFile $src unpackFile $src
@@ -201,5 +259,5 @@ let
# 12, but appears to occur only for cross compiles. # 12, but appears to occur only for cross compiles.
NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized";
}; };
})); })
in self )

View File

@@ -1,9 +1,10 @@
{ lib {
, fetchFromGitHub ? null lib,
, release_version ? null fetchFromGitHub ? null,
, gitRelease ? null release_version ? null,
, officialRelease ? null gitRelease ? null,
, monorepoSrc' ? null officialRelease ? null,
monorepoSrc' ? null,
}: }:
rec { rec {
@@ -13,30 +14,30 @@ rec {
# See llvm/cmake/config-ix.cmake. # See llvm/cmake/config-ix.cmake.
platforms = platforms =
lib.platforms.aarch64 ++ lib.platforms.aarch64
lib.platforms.arm ++ ++ lib.platforms.arm
lib.platforms.mips ++ ++ lib.platforms.mips
lib.platforms.power ++ ++ lib.platforms.power
lib.platforms.s390x ++ ++ lib.platforms.s390x
lib.platforms.wasi ++ ++ lib.platforms.wasi
lib.platforms.x86 ++ ++ lib.platforms.x86
lib.optionals (lib.versionAtLeast release_version "7") lib.platforms.riscv ++ ++ lib.optionals (lib.versionAtLeast release_version "7") lib.platforms.riscv
lib.optionals (lib.versionAtLeast release_version "14") lib.platforms.m68k; ++ lib.optionals (lib.versionAtLeast release_version "14") lib.platforms.m68k;
}; };
releaseInfo = releaseInfo =
if gitRelease != null then rec { if gitRelease != null then
rec {
original = gitRelease; original = gitRelease;
release_version = original.version; release_version = original.version;
version = gitRelease.rev-version; version = gitRelease.rev-version;
} else rec { }
else
rec {
original = officialRelease; original = officialRelease;
release_version = original.version; release_version = original.version;
version = version =
if original ? candidate then if original ? candidate then "${release_version}-${original.candidate}" else release_version;
"${release_version}-${original.candidate}"
else
release_version;
}; };
monorepoSrc = monorepoSrc =
@@ -45,16 +46,11 @@ rec {
else else
let let
sha256 = releaseInfo.original.sha256; sha256 = releaseInfo.original.sha256;
rev = rev = if gitRelease != null then gitRelease.rev else "llvmorg-${releaseInfo.version}";
if gitRelease != null then
gitRelease.rev
else
"llvmorg-${releaseInfo.version}";
in in
fetchFromGitHub { fetchFromGitHub {
owner = "llvm"; owner = "llvm";
repo = "llvm-project"; repo = "llvm-project";
inherit rev sha256; inherit rev sha256;
}; };
} }

View File

@@ -1,20 +1,21 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, release_version llvm_meta,
, version release_version,
, patches ? [] version,
, src ? null patches ? [ ],
, monorepoSrc ? null src ? null,
, runCommand monorepoSrc ? null,
, cmake runCommand,
, ninja cmake,
, python3 ninja,
, xcbuild python3,
, libllvm xcbuild,
, linuxHeaders libllvm,
, libxcrypt linuxHeaders,
, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD libxcrypt,
doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD,
}: }:
let let
@@ -22,128 +23,168 @@ let
useLLVM = stdenv.hostPlatform.useLLVM or false; useLLVM = stdenv.hostPlatform.useLLVM or false;
bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none";
haveLibc = stdenv.cc.libc != null; haveLibc = stdenv.cc.libc != null;
isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic && lib.versionAtLeast release_version "16"; isDarwinStatic =
stdenv.hostPlatform.isDarwin
&& stdenv.hostPlatform.isStatic
&& lib.versionAtLeast release_version "16";
inherit (stdenv.hostPlatform) isMusl isAarch64; inherit (stdenv.hostPlatform) isMusl isAarch64;
baseName = "compiler-rt"; baseName = "compiler-rt";
pname = baseName + lib.optionalString (haveLibc) "-libc"; pname = baseName + lib.optionalString (haveLibc) "-libc";
src' = if monorepoSrc != null then src' =
runCommand "${baseName}-src-${version}" {} '' if monorepoSrc != null then
runCommand "${baseName}-src-${version}" { } ''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${baseName} "$out" cp -r ${monorepoSrc}/${baseName} "$out"
'' else src; ''
else
src;
preConfigure = lib.optionalString (useLLVM && !haveLibc) '' preConfigure = lib.optionalString (useLLVM && !haveLibc) ''
cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding")
''; '';
in in
stdenv.mkDerivation ({ stdenv.mkDerivation (
{
inherit pname version patches; inherit pname version patches;
src = src'; src = src';
sourceRoot = if lib.versionOlder release_version "13" then null sourceRoot = if lib.versionOlder release_version "13" then null else "${src'.name}/${baseName}";
else "${src'.name}/${baseName}";
nativeBuildInputs = [ cmake ] nativeBuildInputs =
[ cmake ]
++ (lib.optional (lib.versionAtLeast release_version "15") ninja) ++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
++ [ python3 libllvm.dev ] ++ [
python3
libllvm.dev
]
++ lib.optional stdenv.isDarwin xcbuild.xcrun; ++ lib.optional stdenv.isDarwin xcbuild.xcrun;
buildInputs = buildInputs = lib.optional (
lib.optional (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV) linuxHeaders; stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isRiscV
) linuxHeaders;
env.NIX_CFLAGS_COMPILE = toString ([ env.NIX_CFLAGS_COMPILE = toString (
"-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" [ "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" ]
] ++ lib.optionals (!haveLibc) [ ++ lib.optionals (!haveLibc) [
# The compiler got stricter about this, and there is a usellvm patch below # The compiler got stricter about this, and there is a usellvm patch below
# which patches out the assert include causing an implicit definition of # which patches out the assert include causing an implicit definition of
# assert. It would be nicer to understand why compiler-rt thinks it should # 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 # 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. # wrong, or perhaps there is a way to provide an assert.h.
"-Wno-error=implicit-function-declaration" "-Wno-error=implicit-function-declaration"
]); ]
);
cmakeFlags = [ cmakeFlags =
[
"-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON"
"-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}"
"-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}"
] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ ]
++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [
"-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include"
] ++ lib.optionals ((useLLVM || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")) [ ]
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" ++ lib.optionals (
] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ (useLLVM || bareMetal || isMusl || isAarch64) && (lib.versions.major release_version == "13")
) [ "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" ]
++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [
"-DCOMPILER_RT_BUILD_SANITIZERS=OFF" "-DCOMPILER_RT_BUILD_SANITIZERS=OFF"
"-DCOMPILER_RT_BUILD_XRAY=OFF" "-DCOMPILER_RT_BUILD_XRAY=OFF"
"-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF"
"-DCOMPILER_RT_BUILD_MEMPROF=OFF" "-DCOMPILER_RT_BUILD_MEMPROF=OFF"
"-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary
] ++ lib.optionals (useLLVM || bareMetal) [ ]
"-DCOMPILER_RT_BUILD_PROFILE=OFF" ++ lib.optionals (useLLVM || bareMetal) [ "-DCOMPILER_RT_BUILD_PROFILE=OFF" ]
] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic) [ ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic) [
"-DCMAKE_CXX_COMPILER_WORKS=ON" "-DCMAKE_CXX_COMPILER_WORKS=ON"
] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ ]
++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [
"-DCMAKE_C_COMPILER_WORKS=ON" "-DCMAKE_C_COMPILER_WORKS=ON"
"-DCOMPILER_RT_BAREMETAL_BUILD=ON" "-DCOMPILER_RT_BAREMETAL_BUILD=ON"
"-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}"
] ++ lib.optionals (useLLVM && !haveLibc) [ ]
"-DCMAKE_C_FLAGS=-nodefaultlibs" ++ lib.optionals (useLLVM && !haveLibc) [ "-DCMAKE_C_FLAGS=-nodefaultlibs" ]
] ++ lib.optionals (useLLVM) [ ++ lib.optionals (useLLVM) [
"-DCOMPILER_RT_BUILD_BUILTINS=ON" "-DCOMPILER_RT_BUILD_BUILTINS=ON"
#https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
"-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
] ++ lib.optionals (bareMetal) [ ]
"-DCOMPILER_RT_OS_DIR=baremetal" ++ lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" ]
] ++ lib.optionals (stdenv.hostPlatform.isDarwin) (lib.optionals (lib.versionAtLeast release_version "16") [ ++ lib.optionals (stdenv.hostPlatform.isDarwin) (
lib.optionals (lib.versionAtLeast release_version "16") [
"-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo"
] ++ [ ]
++ [
"-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON"
"-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}"
"-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}"
] ++ lib.optionals (lib.versionAtLeast release_version "15") [ ]
++ lib.optionals (lib.versionAtLeast release_version "15") [
# `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: # `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 # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153
"-DCOMPILER_RT_ENABLE_IOS=OFF" "-DCOMPILER_RT_ENABLE_IOS=OFF"
]) ++ lib.optionals (lib.versionAtLeast version "19" && stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [ ]
"-DSANITIZER_MIN_OSX_VERSION=10.10" )
]; ++ lib.optionals (
lib.versionAtLeast version "19"
&& stdenv.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
) [ "-DSANITIZER_MIN_OSX_VERSION=10.10" ];
outputs = [ "out" "dev" ]; outputs = [
"out"
"dev"
];
# TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks
# to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra
# can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd
# get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by
# a flag and turn the flag off during the stdenv build. # a flag and turn the flag off during the stdenv build.
postPatch = lib.optionalString (!stdenv.isDarwin) '' postPatch =
lib.optionalString (!stdenv.isDarwin) ''
substituteInPlace cmake/builtin-config-ix.cmake \ substituteInPlace cmake/builtin-config-ix.cmake \
--replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
'' + lib.optionalString stdenv.isDarwin '' ''
+ lib.optionalString stdenv.isDarwin ''
substituteInPlace cmake/config-ix.cmake \ substituteInPlace cmake/config-ix.cmake \
--replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
'' + lib.optionalString (useLLVM && !haveLibc) ((lib.optionalString (lib.versionAtLeast release_version "18") '' ''
+ lib.optionalString (useLLVM && !haveLibc) (
(lib.optionalString (lib.versionAtLeast release_version "18") ''
substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \ substituteInPlace lib/builtins/aarch64/sme-libc-routines.c \
--replace "<stdlib.h>" "<stddef.h>" --replace "<stdlib.h>" "<stddef.h>"
'') + '' '')
+ ''
substituteInPlace lib/builtins/int_util.c \ substituteInPlace lib/builtins/int_util.c \
--replace "#include <stdlib.h>" "" --replace "#include <stdlib.h>" ""
'' + (if stdenv.hostPlatform.isFreeBSD then ''
+ (
if stdenv.hostPlatform.isFreeBSD then
# As per above, but in FreeBSD assert is a macro and simply allowing it to be implicitly declared causes Issues!!!!! # As per above, but in FreeBSD assert is a macro and simply allowing it to be implicitly declared causes Issues!!!!!
'' ''
substituteInPlace lib/builtins/clear_cache.c lib/builtins/cpu_model.c \ substituteInPlace lib/builtins/clear_cache.c lib/builtins/cpu_model.c \
--replace "#include <assert.h>" "#define assert(e) ((e)?(void)0:__assert(__FUNCTION__,__FILE__,__LINE__,#e))" --replace "#include <assert.h>" "#define assert(e) ((e)?(void)0:__assert(__FUNCTION__,__FILE__,__LINE__,#e))"
'' else '' ''
else
''
substituteInPlace lib/builtins/clear_cache.c \ substituteInPlace lib/builtins/clear_cache.c \
--replace "#include <assert.h>" "" --replace "#include <assert.h>" ""
substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \ substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \
--replace "#include <assert.h>" "" --replace "#include <assert.h>" ""
'')); ''
)
);
# Hack around weird upsream RPATH bug # Hack around weird upsream RPATH bug
postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' postInstall =
lib.optionalString (stdenv.hostPlatform.isDarwin) ''
ln -s "$out/lib"/*/* "$out/lib" ln -s "$out/lib"/*/* "$out/lib"
'' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' ''
+ lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) ''
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.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: # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
@@ -154,7 +195,8 @@ stdenv.mkDerivation ({
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.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.crtbegin_shared-*.o $out/lib/crtbeginS.o
ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
'' + lib.optionalString doFakeLibgcc '' ''
+ lib.optionalString doFakeLibgcc ''
ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a
''; '';
@@ -171,9 +213,14 @@ stdenv.mkDerivation ({
''; '';
# "All of the code in the compiler-rt project is dual licensed under the MIT # "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 and the UIUC License (a BSD-like license)":
license = with lib.licenses; [ mit ncsa ]; license = with lib.licenses; [
mit
ncsa
];
# compiler-rt requires a Clang stdenv on 32-bit RISC-V: # compiler-rt requires a Clang stdenv on 32-bit RISC-V:
# https://reviews.llvm.org/D43106#1019077 # https://reviews.llvm.org/D43106#1019077
broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang; broken = stdenv.hostPlatform.isRiscV32 && !stdenv.cc.isClang;
}; };
} // (if lib.versionOlder release_version "16" then { inherit preConfigure; } else {})) }
// (if lib.versionOlder release_version "16" then { inherit preConfigure; } else { })
)

View File

@@ -1,10 +1,22 @@
{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3 }: {
lib,
stdenv,
version,
runCommand,
monorepoSrc,
llvm,
buildPackages,
buildLlvmTools,
ninja,
cmake,
python3,
}:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "libclc"; pname = "libclc";
inherit version; inherit version;
src = runCommand "${pname}-src-${version}" {} '' src = runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
@@ -12,14 +24,16 @@ stdenv.mkDerivation rec {
sourceRoot = "${src.name}/${pname}"; sourceRoot = "${src.name}/${pname}";
outputs = [ "out" "dev" ]; outputs = [
"out"
patches = [ "dev"
./libclc/libclc-gnu-install-dirs.patch
]; ];
patches = [ ./libclc/libclc-gnu-install-dirs.patch ];
# cmake expects all required binaries to be in the same place, so it will not be able to find clang without the 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 = '' postPatch =
''
substituteInPlace CMakeLists.txt \ substituteInPlace CMakeLists.txt \
--replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ --replace '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 )' \ 'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
@@ -30,13 +44,20 @@ stdenv.mkDerivation rec {
--replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ --replace '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 )' \ 'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
--replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ --replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
'find_program( LLVM_SPIRV llvm-spirv PATHS "${buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }}/bin" NO_DEFAULT_PATH )' 'find_program( LLVM_SPIRV llvm-spirv PATHS "${
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }
}/bin" NO_DEFAULT_PATH )'
''
+ lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
substituteInPlace CMakeLists.txt \ substituteInPlace CMakeLists.txt \
--replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins' --replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
''; '';
nativeBuildInputs = [ cmake ninja python3 ]; nativeBuildInputs = [
cmake
ninja
python3
];
buildInputs = [ llvm ]; buildInputs = [ llvm ];
strictDeps = true; strictDeps = true;

View File

@@ -1,22 +1,23 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, release_version llvm_meta,
, monorepoSrc ? null release_version,
, src ? null monorepoSrc ? null,
, patches ? [] src ? null,
, runCommand patches ? [ ],
, substitute runCommand,
, cmake substitute,
, lndir cmake,
, ninja lndir,
, python3 ninja,
, fixDarwinDylibNames python3,
, version fixDarwinDylibNames,
, cxxabi ? null version,
, libcxxrt cxxabi ? null,
, libunwind libcxxrt,
, enableShared ? !stdenv.hostPlatform.isStatic libunwind,
enableShared ? !stdenv.hostPlatform.isStatic,
}: }:
# note: our setup using libcxxabi instead of libcxxrt on FreeBSD diverges from # note: our setup using libcxxabi instead of libcxxrt on FreeBSD diverges from
@@ -37,103 +38,134 @@ let
# Note: useLLVM is likely false for Darwin but true under pkgsLLVM # Note: useLLVM is likely false for Darwin but true under pkgsLLVM
useLLVM = stdenv.hostPlatform.useLLVM or false; useLLVM = stdenv.hostPlatform.useLLVM or false;
src' = if monorepoSrc != null then src' =
runCommand "${pname}-src-${version}" {} ('' if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out/llvm" mkdir -p "$out/llvm"
'' + (lib.optionalString (lib.versionAtLeast release_version "14") '' ''
+ (lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
'') + '' '')
+ ''
cp -r ${monorepoSrc}/libcxx "$out" cp -r ${monorepoSrc}/libcxx "$out"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
cp -r ${monorepoSrc}/llvm/utils "$out/llvm" cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
'' + (lib.optionalString (lib.versionAtLeast release_version "14") '' ''
+ (lib.optionalString (lib.versionAtLeast release_version "14") ''
cp -r ${monorepoSrc}/third-party "$out" cp -r ${monorepoSrc}/third-party "$out"
'') + '' '')
+ ''
cp -r ${monorepoSrc}/runtimes "$out" cp -r ${monorepoSrc}/runtimes "$out"
'' + (lib.optionalString (cxxabi == null) '' ''
+ (lib.optionalString (cxxabi == null) ''
cp -r ${monorepoSrc}/libcxxabi "$out" cp -r ${monorepoSrc}/libcxxabi "$out"
'')) else src; '')
)
else
src;
cxxabiCMakeFlags = lib.optionals (lib.versionAtLeast release_version "18") [ cxxabiCMakeFlags =
"-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" lib.optionals (lib.versionAtLeast release_version "18") [ "-DLIBCXXABI_USE_LLVM_UNWINDER=OFF" ]
] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) (if lib.versionAtLeast release_version "18" then [ ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) (
if lib.versionAtLeast release_version "18" then
[
"-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind" "-DLIBCXXABI_ADDITIONAL_LIBRARIES=unwind"
"-DLIBCXXABI_USE_COMPILER_RT=ON" "-DLIBCXXABI_USE_COMPILER_RT=ON"
] else [ ]
else
[
"-DLIBCXXABI_USE_COMPILER_RT=ON" "-DLIBCXXABI_USE_COMPILER_RT=ON"
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON" "-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
]) ++ lib.optionals stdenv.hostPlatform.isWasm [ ]
)
++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXXABI_ENABLE_THREADS=OFF" "-DLIBCXXABI_ENABLE_THREADS=OFF"
"-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [ ]
"-DLIBCXXABI_ENABLE_SHARED=OFF" ++ lib.optionals (!enableShared) [ "-DLIBCXXABI_ENABLE_SHARED=OFF" ];
];
cxxCMakeFlags = [ cxxCMakeFlags =
"-DLIBCXX_CXX_ABI=${cxxabiName}" [ "-DLIBCXX_CXX_ABI=${cxxabiName}" ]
] ++ lib.optionals (cxxabi == null && lib.versionAtLeast release_version "16") [ ++ lib.optionals (cxxabi == null && lib.versionAtLeast release_version "16") [
# Note: llvm < 16 doesn't support this flag (or it's broken); handled in postInstall instead. # Note: llvm < 16 doesn't support this flag (or it's broken); handled in postInstall instead.
# Include libc++abi symbols within libc++.a for static linking libc++; # Include libc++abi symbols within libc++.a for static linking libc++;
# dynamic linking includes them through libc++.so being a linker script # dynamic linking includes them through libc++.so being a linker script
# which includes both shared objects. # which includes both shared objects.
"-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON" "-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON"
] ++ lib.optionals (cxxabi != null) [ ]
"-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" ++ lib.optionals (cxxabi != null) [ "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" ]
] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [
"-DLIBCXX_HAS_MUSL_LIBC=1" "-DLIBCXX_HAS_MUSL_LIBC=1"
] ++ lib.optionals (lib.versionAtLeast release_version "18" && !useLLVM && stdenv.hostPlatform.libc == "glibc" && !stdenv.hostPlatform.isStatic) [ ]
"-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" ++ lib.optionals (
] ++ lib.optionals useLLVM [ lib.versionAtLeast release_version "18"
"-DLIBCXX_USE_COMPILER_RT=ON" && !useLLVM
] ++ lib.optionals (useLLVM && lib.versionAtLeast release_version "16") [ && stdenv.hostPlatform.libc == "glibc"
&& !stdenv.hostPlatform.isStatic
) [ "-DLIBCXX_ADDITIONAL_LIBRARIES=gcc_s" ]
++ lib.optionals useLLVM [ "-DLIBCXX_USE_COMPILER_RT=ON" ]
++ lib.optionals (useLLVM && lib.versionAtLeast release_version "16") [
"-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind"
] ++ lib.optionals stdenv.hostPlatform.isWasm [ ]
++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXX_ENABLE_THREADS=OFF" "-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF" "-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF" "-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
] ++ lib.optionals (!enableShared) [ ]
"-DLIBCXX_ENABLE_SHARED=OFF" ++ lib.optionals (!enableShared) [ "-DLIBCXX_ENABLE_SHARED=OFF" ];
];
cmakeFlags = [ cmakeFlags =
"-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" [ "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" ]
] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [
# libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
# but that does not appear to be the case for example when building # but that does not appear to be the case for example when building
# pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
"-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
"-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
] ++ lib.optionals stdenv.hostPlatform.isWasm [ ]
++ lib.optionals stdenv.hostPlatform.isWasm [
"-DCMAKE_C_COMPILER_WORKS=ON" "-DCMAKE_C_COMPILER_WORKS=ON"
"-DCMAKE_CXX_COMPILER_WORKS=ON" "-DCMAKE_CXX_COMPILER_WORKS=ON"
"-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker
] ++ cxxCMakeFlags ]
++ cxxCMakeFlags
++ lib.optionals (cxxabi == null) cxxabiCMakeFlags; ++ lib.optionals (cxxabi == null) cxxabiCMakeFlags;
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
inherit pname version cmakeFlags patches; rec {
inherit
pname
version
cmakeFlags
patches
;
src = src'; src = src';
outputs = [ "out" "dev" ]; outputs = [
"out"
"dev"
];
preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' preConfigure = lib.optionalString stdenv.hostPlatform.isMusl ''
patchShebangs utils/cat_files.py patchShebangs utils/cat_files.py
''; '';
nativeBuildInputs = [ cmake ninja python3 ] nativeBuildInputs = [
++ lib.optional stdenv.isDarwin fixDarwinDylibNames cmake
++ lib.optional (cxxabi != null) lndir; ninja
python3
] ++ lib.optional stdenv.isDarwin fixDarwinDylibNames ++ lib.optional (cxxabi != null) lndir;
buildInputs = [ cxxabi ] buildInputs = [ cxxabi ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ];
++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ libunwind ];
# libc++.so is a linker script which expands to multiple libraries, # 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 # 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 # support linker scripts so the external cxxabi needs to be symlinked in
postInstall = lib.optionalString (cxxabi != null) '' postInstall =
lib.optionalString (cxxabi != null) ''
lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1 lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1
lndir ${lib.getLib cxxabi}/lib $out/lib lndir ${lib.getLib cxxabi}/lib $out/lib
libcxxabi=$out/lib/lib${cxxabi.libName}.a libcxxabi=$out/lib/lib${cxxabi.libName}.a
@@ -176,17 +208,30 @@ stdenv.mkDerivation (rec {
''; '';
# "All of the code in libc++ is dual licensed under the MIT license and the # "All of the code in libc++ is dual licensed under the MIT license and the
# UIUC License (a BSD-like license)": # UIUC License (a BSD-like license)":
license = with lib.licenses; [ mit ncsa ]; license = with lib.licenses; [
mit
ncsa
];
}; };
} // (if (lib.versionOlder release_version "16" || lib.versionAtLeast release_version "17") then { }
postPatch = (lib.optionalString (lib.versionAtLeast release_version "14" && lib.versionOlder release_version "15") '' // (
if (lib.versionOlder release_version "16" || lib.versionAtLeast release_version "17") then
{
postPatch =
(lib.optionalString
(lib.versionAtLeast release_version "14" && lib.versionOlder release_version "15")
''
# fix CMake error when static and LIBCXXABI_USE_LLVM_UNWINDER=ON. aren't # fix CMake error when static and LIBCXXABI_USE_LLVM_UNWINDER=ON. aren't
# building unwind so don't need to depend on it # building unwind so don't need to depend on it
substituteInPlace libcxx/src/CMakeLists.txt \ substituteInPlace libcxx/src/CMakeLists.txt \
--replace-fail "add_dependencies(cxx_static unwind)" "# add_dependencies(cxx_static unwind)" --replace-fail "add_dependencies(cxx_static unwind)" "# add_dependencies(cxx_static unwind)"
'') + '' ''
)
+ ''
cd runtimes cd runtimes
''; '';
} else { }
sourceRoot = "${src'.name}/runtimes"; else
})) { sourceRoot = "${src'.name}/runtimes"; }
)
)

View File

@@ -1,22 +1,25 @@
{ lib {
, stdenv lib,
, release_version stdenv,
, patches ? [] release_version,
, src ? null patches ? [ ],
, llvm_meta src ? null,
, version llvm_meta,
, monorepoSrc ? null version,
, runCommand monorepoSrc ? null,
, cmake runCommand,
, ninja cmake,
, python3 ninja,
, libcxx python3,
, enableShared ? !stdenv.hostPlatform.isStatic libcxx,
enableShared ? !stdenv.hostPlatform.isStatic,
}: }:
let let
pname = "libunwind"; pname = "libunwind";
src' = if monorepoSrc != null then src' =
runCommand "${pname}-src-${version}" {} ('' if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
@@ -25,10 +28,14 @@ let
cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
mkdir -p "$out/llvm" mkdir -p "$out/llvm"
cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
'' + lib.optionalString (lib.versionAtLeast release_version "15") '' ''
+ lib.optionalString (lib.versionAtLeast release_version "15") ''
cp -r ${monorepoSrc}/llvm/utils "$out/llvm" cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
cp -r ${monorepoSrc}/runtimes "$out" cp -r ${monorepoSrc}/runtimes "$out"
'') else src; ''
)
else
src;
hasPatches = builtins.length patches > 0; hasPatches = builtins.length patches > 0;
@@ -37,12 +44,18 @@ let
ln -s ${libcxx.src}/llvm . ln -s ${libcxx.src}/llvm .
''; '';
prePatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) '' prePatch =
lib.optionalString
(lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18"))
''
cd ../${pname} cd ../${pname}
chmod -R u+w . chmod -R u+w .
''; '';
postPatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) '' postPatch =
lib.optionalString
(lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18"))
''
cd ../runtimes cd ../runtimes
''; '';
@@ -51,23 +64,34 @@ let
ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
''; '';
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
rec {
inherit pname version patches; inherit pname version patches;
src = src'; src = src';
sourceRoot = sourceRoot =
if lib.versionOlder release_version "13" then null if lib.versionOlder release_version "13" then
else if lib.versionAtLeast release_version "15" then "${src.name}/runtimes" null
else "${src.name}/${pname}"; else if lib.versionAtLeast release_version "15" then
"${src.name}/runtimes"
else
"${src.name}/${pname}";
outputs = [ "out" "dev" ]; outputs = [
"out"
nativeBuildInputs = [ cmake ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ "dev"
ninja python3
]; ];
cmakeFlags = lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind" nativeBuildInputs =
[ cmake ]
++ lib.optionals (lib.versionAtLeast release_version "15") [
ninja
python3
];
cmakeFlags =
lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind"
++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
meta = llvm_meta // { meta = llvm_meta // {
@@ -81,7 +105,9 @@ stdenv.mkDerivation (rec {
dependency of other runtimes. dependency of other runtimes.
''; '';
}; };
} // (if postUnpack != "" then { inherit postUnpack; } else {}) }
// (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {}) // (if postUnpack != "" then { inherit postUnpack; } else { })
// (if prePatch != "" then { inherit prePatch; } else {}) // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else { })
// (if postPatch != "" then { inherit postPatch; } else {})) // (if prePatch != "" then { inherit prePatch; } else { })
// (if postPatch != "" then { inherit postPatch; } else { })
)

View File

@@ -1,66 +1,82 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, release_version llvm_meta,
, patches ? [] release_version,
, buildLlvmTools patches ? [ ],
, monorepoSrc ? null buildLlvmTools,
, src ? null monorepoSrc ? null,
, libunwind ? null src ? null,
, runCommand libunwind ? null,
, cmake runCommand,
, ninja cmake,
, libxml2 ninja,
, libllvm libxml2,
, version libllvm,
version,
}: }:
let let
pname = "lld"; pname = "lld";
src' = src' =
if monorepoSrc != null then if monorepoSrc != null then
runCommand "lld-src-${version}" {} '' runCommand "lld-src-${version}" { } ''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
mkdir -p "$out/libunwind" mkdir -p "$out/libunwind"
cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
mkdir -p "$out/llvm" mkdir -p "$out/llvm"
'' else src; ''
else
src;
postPatch = lib.optionalString (lib.versions.major release_version == "12") '' postPatch =
lib.optionalString (lib.versions.major release_version == "12") ''
substituteInPlace MachO/CMakeLists.txt --replace \ substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '(' '(''${LLVM_MAIN_SRC_DIR}/' '('
mkdir -p libunwind/include mkdir -p libunwind/include
tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/" tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/"
'' + lib.optionalString (lib.versions.major release_version == "13" && stdenv.isDarwin) '' ''
+ lib.optionalString (lib.versions.major release_version == "13" && stdenv.isDarwin) ''
substituteInPlace MachO/CMakeLists.txt --replace \ substituteInPlace MachO/CMakeLists.txt --replace \
'(''${LLVM_MAIN_SRC_DIR}/' '(../' '(''${LLVM_MAIN_SRC_DIR}/' '(../'
''; '';
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
rec {
inherit pname version patches; inherit pname version patches;
src = src'; src = src';
sourceRoot = sourceRoot = if lib.versionOlder release_version "13" then null else "${src.name}/${pname}";
if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja; nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja;
buildInputs = [ libllvm libxml2 ]; buildInputs = [
libllvm
libxml2
];
cmakeFlags = lib.optionals (lib.versionOlder release_version "14") [ cmakeFlags =
"-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" lib.optionals (lib.versionOlder release_version "14") [
] ++ lib.optionals (lib.versionAtLeast release_version "15") [ "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${
lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"
}"
]
++ lib.optionals (lib.versionAtLeast release_version "15") [
"-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ ]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
]; ];
# Musl's default stack size is too small for lld to be able to link Firefox. # 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"; LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
outputs = [ "out" "lib" "dev" ]; outputs = [
"out"
"lib"
"dev"
];
meta = llvm_meta // { meta = llvm_meta // {
homepage = "https://lld.llvm.org/"; homepage = "https://lld.llvm.org/";
@@ -74,4 +90,11 @@ stdenv.mkDerivation (rec {
of several different linkers. of several different linkers.
''; '';
}; };
} // (if (postPatch == "" && lib.versions.major release_version != "13") then {} else { inherit postPatch; })) }
// (
if (postPatch == "" && lib.versions.major release_version != "13") then
{ }
else
{ inherit postPatch; }
)
)

View File

@@ -1,8 +1,9 @@
{ lib {
, stdenv lib,
, fetchFromGitHub stdenv,
, makeWrapper fetchFromGitHub,
, lldb makeWrapper,
lldb,
}: }:
stdenv.mkDerivation { stdenv.mkDerivation {

View File

@@ -1,30 +1,31 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, release_version llvm_meta,
, cmake release_version,
, zlib cmake,
, ncurses zlib,
, swig3 ncurses,
, swig4 swig3,
, which swig4,
, libedit which,
, libxml2 libedit,
, libllvm libxml2,
, libclang libllvm,
, python3 libclang,
, version python3,
, darwin version,
, lit darwin,
, makeWrapper lit,
, lua5_3 makeWrapper,
, ninja lua5_3,
, runCommand ninja,
, src ? null runCommand,
, monorepoSrc ? null src ? null,
, patches ? [ ] monorepoSrc ? null,
, enableManpages ? false patches ? [ ],
, ... enableManpages ? false,
...
}: }:
let let
@@ -34,7 +35,9 @@ let
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/lldb "$out" cp -r ${monorepoSrc}/lldb "$out"
'' else src; ''
else
src;
vscodeExt = { vscodeExt = {
name = if lib.versionAtLeast release_version "18" then "lldb-dap" else "lldb-vscode"; name = if lib.versionAtLeast release_version "18" then "lldb-dap" else "lldb-vscode";
version = if lib.versionAtLeast release_version "18" then "0.2.0" else "0.1.0"; version = if lib.versionAtLeast release_version "18" then "0.2.0" else "0.1.0";
@@ -42,7 +45,8 @@ let
swig = if lib.versionAtLeast release_version "18" then swig4 else swig3; swig = if lib.versionAtLeast release_version "18" then swig4 else swig3;
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
rec {
passthru.monorepoSrc = monorepoSrc; passthru.monorepoSrc = monorepoSrc;
pname = "lldb"; pname = "lldb";
inherit version; inherit version;
@@ -50,11 +54,16 @@ stdenv.mkDerivation (rec {
src = src'; src = src';
inherit patches; inherit patches;
outputs = [ "out" "lib" "dev" ]; outputs = [
"out"
"lib"
"dev"
];
sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}"; sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}";
nativeBuildInputs = [ nativeBuildInputs =
[
cmake cmake
python3 python3
which which
@@ -62,28 +71,31 @@ stdenv.mkDerivation (rec {
lit lit
makeWrapper makeWrapper
lua5_3 lua5_3
] ++ lib.optionals enableManpages [ ]
python3.pkgs.sphinx ++ lib.optionals enableManpages [ python3.pkgs.sphinx ]
] ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [ ++ lib.optionals (lib.versionOlder release_version "18" && enableManpages) [
python3.pkgs.recommonmark python3.pkgs.recommonmark
] ++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [ ]
++ lib.optionals (lib.versionAtLeast release_version "18" && enableManpages) [
python3.pkgs.myst-parser python3.pkgs.myst-parser
] ++ lib.optionals (lib.versionAtLeast release_version "14") [ ]
ninja ++ lib.optionals (lib.versionAtLeast release_version "14") [ ninja ];
];
buildInputs = [ buildInputs =
[
ncurses ncurses
zlib zlib
libedit libedit
libxml2 libxml2
libllvm libllvm
] ++ lib.optionals (lib.versionAtLeast release_version "16") [ ]
++ lib.optionals (lib.versionAtLeast release_version "16") [
# Starting with LLVM 16, the resource dir patch is no longer enough to get # 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 # libclang into the rpath of the lldb executables. By putting it into
# buildInputs cc-wrapper will set up rpath correctly for us. # buildInputs cc-wrapper will set up rpath correctly for us.
(lib.getLib libclang) (lib.getLib libclang)
] ++ lib.optionals stdenv.isDarwin [ ]
++ lib.optionals stdenv.isDarwin [
darwin.libobjc darwin.libobjc
darwin.apple_sdk.libs.xpc darwin.apple_sdk.libs.xpc
darwin.apple_sdk.frameworks.Foundation darwin.apple_sdk.frameworks.Foundation
@@ -98,7 +110,8 @@ stdenv.mkDerivation (rec {
# #
# See here for context: # See here for context:
# https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132
++ lib.optional ++
lib.optional
( (
stdenv.targetPlatform.isDarwin stdenv.targetPlatform.isDarwin
&& !stdenv.targetPlatform.isAarch64 && !stdenv.targetPlatform.isAarch64
@@ -114,29 +127,36 @@ stdenv.mkDerivation (rec {
hardeningDisable = [ "format" ]; hardeningDisable = [ "format" ];
cmakeFlags = [ cmakeFlags =
[
"-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}"
"-DLLVM_ENABLE_RTTI=OFF" "-DLLVM_ENABLE_RTTI=OFF"
"-DClang_DIR=${lib.getDev libclang}/lib/cmake" "-DClang_DIR=${lib.getDev libclang}/lib/cmake"
"-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit"
] ++ lib.optionals stdenv.isDarwin [ ]
"-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" ++ lib.optionals stdenv.isDarwin [ "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" ]
] ++ lib.optionals (!stdenv.isDarwin) [ ++ lib.optionals (!stdenv.isDarwin) [
"-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic
] ++ lib.optionals (lib.versionAtLeast release_version "17") [ ]
++ lib.optionals (lib.versionAtLeast release_version "17") [
"-DCLANG_RESOURCE_DIR=../../../../${libclang.lib}" "-DCLANG_RESOURCE_DIR=../../../../${libclang.lib}"
] ++ lib.optionals enableManpages ([ ]
++ lib.optionals enableManpages (
[
"-DLLVM_ENABLE_SPHINX=ON" "-DLLVM_ENABLE_SPHINX=ON"
"-DSPHINX_OUTPUT_MAN=ON" "-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF" "-DSPHINX_OUTPUT_HTML=OFF"
] ++ lib.optionals (lib.versionAtLeast release_version "15") [ ]
++ lib.optionals (lib.versionAtLeast release_version "15") [
# docs reference `automodapi` but it's not added to the extensions list when # docs reference `automodapi` but it's not added to the extensions list when
# only building the manpages: # only building the manpages:
# https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54
# #
# so, we just ignore the resulting errors # so, we just ignore the resulting errors
"-DSPHINX_WARNINGS_AS_ERRORS=OFF" "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
]) ++ lib.optionals doCheck [ ]
)
++ lib.optionals doCheck [
"-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
"-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"
]; ];
@@ -145,7 +165,8 @@ stdenv.mkDerivation (rec {
doInstallCheck = lib.versionOlder release_version "15"; doInstallCheck = lib.versionOlder release_version "15";
# TODO: cleanup with mass-rebuild # TODO: cleanup with mass-rebuild
installCheckPhase = '' installCheckPhase =
''
if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then
echo "ERROR: python files not installed where expected!"; echo "ERROR: python files not installed where expected!";
return 1; return 1;
@@ -165,7 +186,9 @@ stdenv.mkDerivation (rec {
# vscode: # vscode:
install -D ../tools/${vscodeExt.name}/package.json $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/package.json 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 mkdir -p $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
ln -s $out/bin/*${if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode"} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin ln -s $out/bin/*${
if lib.versionAtLeast release_version "18" then vscodeExt.name else "-vscode"
} $out/share/vscode/extensions/llvm-org.${vscodeExt.name}-${vscodeExt.version}/bin
''; '';
passthru.vscodeExtName = vscodeExt.name; passthru.vscodeExtName = vscodeExt.name;
@@ -187,14 +210,14 @@ stdenv.mkDerivation (rec {
|| (((lib.versions.major release_version) == "13") && stdenv.isDarwin); || (((lib.versions.major release_version) == "13") && stdenv.isDarwin);
mainProgram = "lldb"; mainProgram = "lldb";
}; };
} // lib.optionalAttrs enableManpages { }
// lib.optionalAttrs enableManpages {
pname = "lldb-manpages"; pname = "lldb-manpages";
buildPhase = lib.optionalString (lib.versionOlder release_version "15") '' buildPhase = lib.optionalString (lib.versionOlder release_version "15") ''
make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"} make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"}
''; '';
ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ]; ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ];
propagatedBuildInputs = [ ]; propagatedBuildInputs = [ ];
@@ -215,4 +238,5 @@ stdenv.mkDerivation (rec {
meta = llvm_meta // { meta = llvm_meta // {
description = "man pages for LLDB ${version}"; description = "man pages for LLDB ${version}";
}; };
}) }
)

View File

@@ -1,53 +1,59 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, pkgsBuildBuild llvm_meta,
, pollyPatches ? [] pkgsBuildBuild,
, patches ? [] pollyPatches ? [ ],
, polly_src ? null patches ? [ ],
, src ? null polly_src ? null,
, monorepoSrc ? null src ? null,
, runCommand monorepoSrc ? null,
, cmake runCommand,
, darwin cmake,
, ninja darwin,
, python3 ninja,
, python3Packages python3,
, libffi python3Packages,
libffi,
# TODO: Can this memory corruption bug still occur? # TODO: Can this memory corruption bug still occur?
# <https://github.com/llvm/llvm-project/issues/61350> # <https://github.com/llvm/llvm-project/issues/61350>
, enableGoldPlugin ? libbfd.hasPluginAPI enableGoldPlugin ? libbfd.hasPluginAPI,
, libbfd libbfd,
, libpfm libpfm,
, libxml2 libxml2,
, ncurses ncurses,
, version version,
, release_version release_version,
, zlib zlib,
, which which,
, sysctl sysctl,
, buildLlvmTools buildLlvmTools,
, debugVersion ? false debugVersion ? false,
, doCheck ? !stdenv.isAarch32 && (if lib.versionOlder release_version "15" then stdenv.isLinux else true) doCheck ?
&& (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) !stdenv.isAarch32
&& (if lib.versionOlder release_version "15" then stdenv.isLinux else true)
&& (
!stdenv.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl)
&& !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian) && !(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian)
&& (stdenv.hostPlatform == stdenv.buildPlatform) && (stdenv.hostPlatform == stdenv.buildPlatform),
, enableManpages ? false enableManpages ? false,
, enableSharedLibraries ? !stdenv.hostPlatform.isStatic enableSharedLibraries ? !stdenv.hostPlatform.isStatic,
, enablePFM ? stdenv.isLinux /* PFM only supports Linux */ enablePFM ?
stdenv.isLinux # PFM only supports Linux
# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245
# broken for the armv7l builder # broken for the armv7l builder
&& !stdenv.hostPlatform.isAarch && !stdenv.hostPlatform.isAarch,
, enablePolly ? lib.versionAtLeast release_version "14" enablePolly ? lib.versionAtLeast release_version "14",
, enableTerminfo ? true enableTerminfo ? true,
}: }:
let let
inherit (lib) optional optionals optionalString; inherit (lib) optional optionals optionalString;
# Used when creating a version-suffixed symlink of libLLVM.dylib # Used when creating a version-suffixed symlink of libLLVM.dylib
shortVersion = with lib; shortVersion = with lib; concatStringsSep "." (take 1 (splitString "." release_version));
concatStringsSep "." (take 1 (splitString "." release_version));
# Ordinarily we would just the `doCheck` and `checkDeps` functionality # Ordinarily we would just the `doCheck` and `checkDeps` functionality
# `mkDerivation` gives us to manage our test dependencies (instead of breaking # `mkDerivation` gives us to manage our test dependencies (instead of breaking
@@ -66,113 +72,147 @@ let
# #
# So, we "manually" assemble one python derivation for the package to depend # So, we "manually" assemble one python derivation for the package to depend
# on, taking into account whether checks are enabled or not: # on, taking into account whether checks are enabled or not:
python = if doCheck then python =
if doCheck then
# Note that we _explicitly_ ask for a python interpreter for our host # Note that we _explicitly_ ask for a python interpreter for our host
# platform here; the splicing that would ordinarily take care of this for # platform here; the splicing that would ordinarily take care of this for
# us does not seem to work once we use `withPackages`. # us does not seem to work once we use `withPackages`.
let let
checkDeps = ps: with ps; [ psutil ]; checkDeps = ps: with ps; [ psutil ];
in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps in
else python3; pkgsBuildBuild.targetPackages.python3.withPackages checkDeps
else
python3;
pname = "llvm"; pname = "llvm";
src' = if monorepoSrc != null then src' =
runCommand "${pname}-src-${version}" {} ('' if monorepoSrc != null then
runCommand "${pname}-src-${version}" { } (
''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
cp -r ${monorepoSrc}/third-party "$out" cp -r ${monorepoSrc}/third-party "$out"
'' + lib.optionalString enablePolly '' ''
+ lib.optionalString enablePolly ''
chmod u+w "$out/${pname}/tools" chmod u+w "$out/${pname}/tools"
cp -r ${monorepoSrc}/polly "$out/${pname}/tools" cp -r ${monorepoSrc}/polly "$out/${pname}/tools"
'') else src; ''
)
else
src;
patches' = patches ++ lib.optionals enablePolly pollyPatches; patches' = patches ++ lib.optionals enablePolly pollyPatches;
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
finalAttrs:
{
inherit pname version; inherit pname version;
src = src'; src = src';
patches = patches'; patches = patches';
sourceRoot = if lib.versionOlder release_version "13" then null sourceRoot = if lib.versionOlder release_version "13" then null else "${src.name}/${pname}";
else "${src.name}/${pname}";
outputs = [ "out" "lib" "dev" "python" ]; outputs = [
"out"
"lib"
"dev"
"python"
];
nativeBuildInputs = [ cmake ] nativeBuildInputs =
[ cmake ]
++ (lib.optional (lib.versionAtLeast release_version "15") ninja) ++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
++ [ python ] ++ [ python ]
++ optionals enableManpages [ ++ optionals enableManpages [
# Note: we intentionally use `python3Packages` instead of `python3.pkgs`; # Note: we intentionally use `python3Packages` instead of `python3.pkgs`;
# splicing does *not* work with the latter. (TODO: fix) # splicing does *not* work with the latter. (TODO: fix)
python3Packages.sphinx python3Packages.sphinx
] ++ optionals (lib.versionOlder version "18" && enableManpages) [ ]
python3Packages.recommonmark ++ optionals (lib.versionOlder version "18" && enableManpages) [ python3Packages.recommonmark ]
] ++ optionals (lib.versionAtLeast version "18" && enableManpages) [ ++ optionals (lib.versionAtLeast version "18" && enableManpages) [ python3Packages.myst-parser ];
python3Packages.myst-parser
];
buildInputs = [ libxml2 libffi ] buildInputs = [
++ optional enablePFM libpfm; # exegesis libxml2
libffi
] ++ optional enablePFM libpfm; # exegesis
propagatedBuildInputs = (lib.optional (lib.versionAtLeast release_version "14" || stdenv.buildPlatform == stdenv.hostPlatform) ncurses) propagatedBuildInputs =
(lib.optional (
lib.versionAtLeast release_version "14" || stdenv.buildPlatform == stdenv.hostPlatform
) ncurses)
++ [ zlib ]; ++ [ zlib ];
postPatch = optionalString stdenv.isDarwin ('' nativeCheckInputs =
lib.optional (lib.versionAtLeast release_version "13") which
++ lib.optional (stdenv.isDarwin && lib.versionAtLeast release_version "15") sysctl;
postPatch =
''
patchShebangs test/BugPoint/compile-custom.ll.py
''
+
# FileSystem permissions tests fail with various special bits
''
substituteInPlace unittests/Support/CMakeLists.txt \
--replace "Path.cpp" ""
rm unittests/Support/Path.cpp
substituteInPlace unittests/IR/CMakeLists.txt \
--replace "PassBuilderCallbacksTest.cpp" ""
rm unittests/IR/PassBuilderCallbacksTest.cpp
''
+
# timing-based tests are trouble
''
rm utils/lit/tests/googletest-timeout.py
''
+
# FileSystem permissions tests fail with various special bits
''
substituteInPlace unittests/Support/CMakeLists.txt \
--replace "Path.cpp" ""
rm unittests/Support/Path.cpp
substituteInPlace unittests/IR/CMakeLists.txt \
--replace "PassBuilderCallbacksTest.cpp" ""
rm unittests/IR/PassBuilderCallbacksTest.cpp
''
+ optionalString stdenv.isDarwin (
''
substituteInPlace cmake/modules/AddLLVM.cmake \ substituteInPlace cmake/modules/AddLLVM.cmake \
--replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
'' + ''
+
# As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick # 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 # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7
(optionalString (lib.versionAtLeast release_version "15") ('' optionalString (lib.versionAtLeast release_version "15") (
''
rm test/MC/ELF/cfi-version.ll rm test/MC/ELF/cfi-version.ll
'' + ''
+
# This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`)
# and thus fails under the sandbox: # and thus fails under the sandbox:
(if lib.versionAtLeast release_version "16" then '' (
substituteInPlace unittests/TargetParser/Host.cpp \ let
--replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" file =
'' else '' if lib.versionAtLeast release_version "16" then
substituteInPlace unittests/Support/Host.cpp \ "unittests/TargetParser/Host.cpp"
--replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" else
'') + "unittests/Support/Host.cpp";
# This test tries to call the intrinsics `@llvm.roundeven.f32` and in
# `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` ''
# and `roundeven` on macOS and FreeBSD. substituteInPlace ${file} \
# --replace \
# However these functions are glibc specific so the test fails: '/usr/bin/sw_vers' \
# - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html "${builtins.toString darwin.DarwinTools + "/bin/sw_vers"}"
# - 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?
optionalString (lib.versionAtLeast release_version "16") ''
substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
--replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
--replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
'' +
# fails when run in sandbox
optionalString (!stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "18") ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''))) +
# dup of above patch with different conditions
optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "15") (optionalString (lib.versionOlder release_version "16") ''
substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
--replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
--replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
'' + + optionalString stdenv.hostPlatform.isAarch64 (
# fails when run in sandbox
((optionalString (lib.versionAtLeast release_version "18") ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
'') +
# This test fails on darwin x86_64 because `sw_vers` reports a different # This test fails on darwin x86_64 because `sw_vers` reports a different
# macOS version than what LLVM finds by reading # macOS version than what LLVM finds by reading
# `/System/Library/CoreServices/SystemVersion.plist` (which is passed into # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into
@@ -201,43 +241,65 @@ stdenv.mkDerivation (rec {
# not clear to me when/where/for what this even gets used in LLVM. # not clear to me when/where/for what this even gets used in LLVM.
# #
# TODO(@rrbutani): fix/follow-up # TODO(@rrbutani): fix/follow-up
(if lib.versionAtLeast release_version "16" then '' (
substituteInPlace unittests/TargetParser/Host.cpp \ let
file =
if lib.versionAtLeast release_version "16" then
"unittests/TargetParser/Host.cpp"
else
"unittests/Support/Host.cpp";
in
''
substituteInPlace ${file} \
--replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
'' else '' ''
substituteInPlace unittests/Support/Host.cpp \ )
--replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" +
'') +
# This test fails with a `dysmutil` crash; have not yet dug into what's # This test fails with a `dysmutil` crash; have not yet dug into what's
# going on here (TODO(@rrbutani)). # going on here (TODO(@rrbutani)).
'' ''
rm test/tools/dsymutil/ARM/obfuscated.test rm test/tools/dsymutil/ARM/obfuscated.test
'')) +
# FileSystem permissions tests fail with various special bits
'' ''
substituteInPlace unittests/Support/CMakeLists.txt \ )
--replace "Path.cpp" "" )
rm unittests/Support/Path.cpp +
substituteInPlace unittests/IR/CMakeLists.txt \ # This test tries to call the intrinsics `@llvm.roundeven.f32` and
--replace "PassBuilderCallbacksTest.cpp" "" # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf`
rm unittests/IR/PassBuilderCallbacksTest.cpp # and `roundeven` on macOS and FreeBSD.
'' + lib.optionalString (lib.versionAtLeast release_version "13") '' #
# 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?
optionalString (lib.versionAtLeast release_version "16") ''
substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \
--replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \
--replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" ""
''
+
# fails when run in sandbox
optionalString (!stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "18") ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''
)
+ lib.optionalString (lib.versionAtLeast release_version "13") ''
rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
'' + lib.optionalString (lib.versionOlder release_version "13") '' ''
+ lib.optionalString (lib.versionOlder release_version "13") ''
# TODO: Fix failing tests: # TODO: Fix failing tests:
rm test/DebugInfo/X86/vla-multi.ll rm test/DebugInfo/X86/vla-multi.ll
'' + ''
+
# Fails in the presence of anti-virus software or other intrusion-detection software that # Fails in the presence of anti-virus software or other intrusion-detection software that
# modifies the atime when run. See #284056. # modifies the atime when run. See #284056.
lib.optionalString (lib.versionAtLeast release_version "16") ('' lib.optionalString (lib.versionAtLeast release_version "16") (
''
rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
'' + lib.optionalString (lib.versionOlder release_version "17") '' ''
+
'') +
# timing-based tests are trouble
lib.optionalString (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "17") ''
rm utils/lit/tests/googletest-timeout.py
'' +
# valgrind unhappy with musl or glibc, but fails w/musl only # valgrind unhappy with musl or glibc, but fails w/musl only
optionalString stdenv.hostPlatform.isMusl '' optionalString stdenv.hostPlatform.isMusl ''
patch -p1 -i ${./TLI-musl.patch} patch -p1 -i ${./TLI-musl.patch}
@@ -245,7 +307,9 @@ stdenv.mkDerivation (rec {
--replace "add_subdirectory(DynamicLibrary)" "" --replace "add_subdirectory(DynamicLibrary)" ""
rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp
rm test/CodeGen/AArch64/wineh4.mir rm test/CodeGen/AArch64/wineh4.mir
'' + optionalString stdenv.hostPlatform.isAarch32 '' ''
)
+ optionalString stdenv.hostPlatform.isAarch32 ''
# skip failing X86 test cases on 32-bit ARM # skip failing X86 test cases on 32-bit ARM
rm test/DebugInfo/X86/convert-debugloc.ll rm test/DebugInfo/X86/convert-debugloc.ll
rm test/DebugInfo/X86/convert-inlined.ll rm test/DebugInfo/X86/convert-inlined.ll
@@ -253,11 +317,13 @@ stdenv.mkDerivation (rec {
rm test/tools/dsymutil/X86/op-convert.test rm test/tools/dsymutil/X86/op-convert.test
rm test/tools/gold/X86/split-dwarf.ll rm test/tools/gold/X86/split-dwarf.ll
rm test/tools/llvm-objcopy/MachO/universal-object.test rm test/tools/llvm-objcopy/MachO/universal-object.test
'' + ''
+
# Seems to require certain floating point hardware (NEON?) # Seems to require certain floating point hardware (NEON?)
optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' optionalString (stdenv.hostPlatform.system == "armv6l-linux") ''
rm test/ExecutionEngine/frem.ll rm test/ExecutionEngine/frem.ll
'' + ''
+
# 1. TODO: Why does this test fail on FreeBSD? # 1. TODO: Why does this test fail on FreeBSD?
# It seems to reference /usr/local/lib/libfile.a, which is clearly a problem. # 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 # 2. This test fails for the same reason it fails on MacOS, but the fix is
@@ -265,16 +331,16 @@ stdenv.mkDerivation (rec {
optionalString stdenv.isFreeBSD '' optionalString stdenv.isFreeBSD ''
rm test/tools/llvm-libtool-darwin/L-and-l.test rm test/tools/llvm-libtool-darwin/L-and-l.test
rm test/ExecutionEngine/Interpreter/intrinsics.ll rm test/ExecutionEngine/Interpreter/intrinsics.ll
'' + '' ''
patchShebangs test/BugPoint/compile-custom.ll.py +
'' +
# Tweak tests to ignore namespace part of type to support # Tweak tests to ignore namespace part of type to support
# gcc-12: https://gcc.gnu.org/PR103598. # gcc-12: https://gcc.gnu.org/PR103598.
# The change below mangles strings like: # The change below mangles strings like:
# CHECK-NEXT: Starting llvm::Function pass manager run. # CHECK-NEXT: Starting llvm::Function pass manager run.
# to: # to:
# CHECK-NEXT: Starting {{.*}}Function pass manager run. # CHECK-NEXT: Starting {{.*}}Function pass manager run.
(lib.optionalString (lib.versionOlder release_version "13") ('' lib.optionalString (lib.versionOlder release_version "13") (
''
for f in \ for f in \
test/Other/new-pass-manager.ll \ test/Other/new-pass-manager.ll \
test/Other/new-pm-O0-defaults.ll \ test/Other/new-pm-O0-defaults.ll \
@@ -295,19 +361,17 @@ stdenv.mkDerivation (rec {
--replace 'Starting llvm::' 'Starting {{.*}}' \ --replace 'Starting llvm::' 'Starting {{.*}}' \
--replace 'Finished llvm::' 'Finished {{.*}}' --replace 'Finished llvm::' 'Finished {{.*}}'
done done
'' + ''
+
# gcc-13 fix # gcc-13 fix
'' ''
sed -i '/#include <string>/i#include <cstdint>' \ sed -i '/#include <string>/i#include <cstdint>' \
include/llvm/DebugInfo/Symbolize/DIPrinter.h include/llvm/DebugInfo/Symbolize/DIPrinter.h
'')); ''
);
# Workaround for configure flags that need to have spaces # Workaround for configure flags that need to have spaces
preConfigure = if lib.versionAtLeast release_version "15" then '' preConfigure = ''
cmakeFlagsArray+=(
-DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar"
)
'' else ''
cmakeFlagsArray+=( cmakeFlagsArray+=(
-DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar'
) )
@@ -318,7 +382,9 @@ stdenv.mkDerivation (rec {
cmakeBuildType = if debugVersion then "Debug" else "Release"; cmakeBuildType = if debugVersion then "Debug" else "Release";
cmakeFlags = with stdenv; let cmakeFlags =
with stdenv;
let
# These flags influence llvm-config's BuildVariables.inc in addition to the # These flags influence llvm-config's BuildVariables.inc in addition to the
# general build. We need to make sure these are also passed via # general build. We need to make sure these are also passed via
# CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native
@@ -326,26 +392,25 @@ stdenv.mkDerivation (rec {
# #
# Some flags don't need to be repassed because LLVM already does so (like # Some flags don't need to be repassed because LLVM already does so (like
# CMAKE_BUILD_TYPE), others are irrelevant to the result. # CMAKE_BUILD_TYPE), others are irrelevant to the result.
flagsForLlvmConfig = (if lib.versionOlder release_version "15" then [ flagsForLlvmConfig = [
"-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/"
] else [
"-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm"
]) ++ [
"-DLLVM_ENABLE_RTTI=ON" "-DLLVM_ENABLE_RTTI=ON"
] ++ optionals enableSharedLibraries [ (lib.cmakeBool "LLVM_LINK_LLVM_DYLIB" enableSharedLibraries)
"-DLLVM_LINK_LLVM_DYLIB=ON" (lib.optional (lib.versionOlder release_version "15") "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/")
]; ];
in flagsForLlvmConfig ++ [ in
flagsForLlvmConfig
++ [
"-DCMAKE_INSTALL_PACKAGEDIR=${placeholder "dev"}/lib/"
"-DLLVM_INSTALL_UTILS=ON" # Needed by rustc "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc
"-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" (lib.cmakeBool "LLVM_INCLUDE_TESTS" finalAttrs.doCheck)
(lib.cmakeBool "LLVM_BUILD_TESTS" finalAttrs.doCheck)
"-DLLVM_ENABLE_FFI=ON" "-DLLVM_ENABLE_FFI=ON"
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_ENABLE_DUMP=ON" "-DLLVM_ENABLE_DUMP=ON"
(lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo) (lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo)
] ++ optionals (!doCheck) [ ]
"-DLLVM_INCLUDE_TESTS=OFF" ++ optionals stdenv.hostPlatform.isStatic [
] ++ optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper # Disables building of shared libs, -fPIC is still injected by cc-wrapper
"-DLLVM_ENABLE_PIC=OFF" "-DLLVM_ENABLE_PIC=OFF"
"-DCMAKE_SKIP_INSTALL_RPATH=ON" "-DCMAKE_SKIP_INSTALL_RPATH=ON"
@@ -354,18 +419,26 @@ stdenv.mkDerivation (rec {
# file and doesn't link zlib as well. # file and doesn't link zlib as well.
# https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812
"-DLLVM_ENABLE_LIBXML2=OFF" "-DLLVM_ENABLE_LIBXML2=OFF"
] ++ optionals enableManpages [ ]
++ optionals enableManpages [
"-DLLVM_BUILD_DOCS=ON" "-DLLVM_BUILD_DOCS=ON"
"-DLLVM_ENABLE_SPHINX=ON" "-DLLVM_ENABLE_SPHINX=ON"
"-DSPHINX_OUTPUT_MAN=ON" "-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF" "-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF" "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
] ++ optionals (enableGoldPlugin) [ ]
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" ++ optionals (enableGoldPlugin) [ "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" ]
] ++ optionals isDarwin [ ++ optionals isDarwin [
"-DLLVM_ENABLE_LIBCXX=ON" "-DLLVM_ENABLE_LIBCXX=ON"
"-DCAN_TARGET_i386=false" "-DCAN_TARGET_i386=false"
] ++ optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ ]
++
optionals
(
stdenv.hostPlatform != stdenv.buildPlatform
&& !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)
)
[
"-DCMAKE_CROSSCOMPILING=True" "-DCMAKE_CROSSCOMPILING=True"
"-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen"
( (
@@ -388,30 +461,44 @@ stdenv.mkDerivation (rec {
"-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib"
"-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec"
]; ];
in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" in
+ lib.concatStringsSep ";" (lib.concatLists [ "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list="
+ lib.concatStringsSep ";" (
lib.concatLists [
flagsForLlvmConfig flagsForLlvmConfig
nativeToolchainFlags nativeToolchainFlags
nativeInstallFlags nativeInstallFlags
]) ]
)
) )
]; ];
postInstall = '' postInstall =
''
mkdir -p $python/share mkdir -p $python/share
mv $out/share/opt-viewer $python/share/opt-viewer mv $out/share/opt-viewer $python/share/opt-viewer
moveToOutput "bin/llvm-config*" "$dev" moveToOutput "bin/llvm-config*" "$dev"
substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${
if debugVersion then "debug" else "release"
}.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \
--replace "$out/bin/llvm-config" "$dev/bin/llvm-config" --replace "$out/bin/llvm-config" "$dev/bin/llvm-config"
'' + (if lib.versionOlder release_version "15" then '' ''
+ (
if lib.versionOlder release_version "15" then
''
substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
--replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")'
'' else '' ''
else
''
substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \
--replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")'
'') ''
+ optionalString (stdenv.isDarwin && enableSharedLibraries && lib.versionOlder release_version "18") '' )
+
optionalString (stdenv.isDarwin && enableSharedLibraries && lib.versionOlder release_version "18")
''
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
'' ''
+ optionalString (stdenv.isDarwin && enableSharedLibraries) '' + optionalString (stdenv.isDarwin && enableSharedLibraries) ''
@@ -425,6 +512,8 @@ stdenv.mkDerivation (rec {
checkTarget = "check-all"; checkTarget = "check-all";
hardeningDisable = [ "trivialautovarinit" ];
# For the update script: # For the update script:
passthru.monorepoSrc = monorepoSrc; passthru.monorepoSrc = monorepoSrc;
@@ -447,10 +536,12 @@ stdenv.mkDerivation (rec {
under the "Apache 2.0 License with LLVM exceptions". under the "Apache 2.0 License with LLVM exceptions".
''; '';
}; };
} // lib.optionalAttrs enableManpages ({ }
// lib.optionalAttrs enableManpages (
{
pname = "llvm-manpages"; pname = "llvm-manpages";
propagatedBuildInputs = []; propagatedBuildInputs = [ ];
postPatch = null; postPatch = null;
postInstall = null; postInstall = null;
@@ -462,7 +553,10 @@ stdenv.mkDerivation (rec {
meta = llvm_meta // { meta = llvm_meta // {
description = "man pages for LLVM ${version}"; description = "man pages for LLVM ${version}";
}; };
} // (if lib.versionOlder release_version "15" then { }
// (
if lib.versionOlder release_version "15" then
{
buildPhase = '' buildPhase = ''
make docs-llvm-man make docs-llvm-man
''; '';
@@ -470,26 +564,32 @@ stdenv.mkDerivation (rec {
installPhase = '' installPhase = ''
make -C docs install make -C docs install
''; '';
} else { }
else
{
ninjaFlags = [ "docs-llvm-man" ]; ninjaFlags = [ "docs-llvm-man" ];
installTargets = [ "install-docs-llvm-man" ]; installTargets = [ "install-docs-llvm-man" ];
postPatch = null; postPatch = null;
postInstall = null; postInstall = null;
})) // lib.optionalAttrs (lib.versionOlder release_version "13") { }
)
)
// lib.optionalAttrs (lib.versionOlder release_version "13") {
inherit polly_src; inherit polly_src;
unpackPhase = '' unpackPhase =
''
unpackFile $src unpackFile $src
mv llvm-${release_version}* llvm mv llvm-${release_version}* llvm
sourceRoot=$PWD/llvm sourceRoot=$PWD/llvm
'' + optionalString enablePolly '' ''
+ optionalString enablePolly ''
unpackFile $polly_src unpackFile $polly_src
mv polly-* $sourceRoot/tools/polly mv polly-* $sourceRoot/tools/polly
''; '';
} // lib.optionalAttrs (lib.versionAtLeast release_version "13") { }
nativeCheckInputs = [ which ] ++ lib.optional (stdenv.isDarwin && lib.versionAtLeast release_version "15") sysctl; // lib.optionalAttrs (lib.versionOlder release_version "15") {
} // lib.optionalAttrs (lib.versionOlder release_version "15") {
# hacky fix: created binaries need to be run before installation # hacky fix: created binaries need to be run before installation
preBuild = '' preBuild = ''
mkdir -p $out/ mkdir -p $out/
@@ -503,7 +603,8 @@ stdenv.mkDerivation (rec {
preCheck = '' preCheck = ''
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib
''; '';
} // lib.optionalAttrs (lib.versionAtLeast release_version "15") { }
// lib.optionalAttrs (lib.versionAtLeast release_version "15") {
# Defensive check: some paths (that we make symlinks to) depend on the release # Defensive check: some paths (that we make symlinks to) depend on the release
# version, for example: # version, for example:
# - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185
@@ -512,12 +613,14 @@ stdenv.mkDerivation (rec {
# version we were given. # version we were given.
# #
# We do this check here, in the LLVM build, because it happens early. # We do this check here, in the LLVM build, because it happens early.
postConfigure = let postConfigure =
let
v = lib.versions; v = lib.versions;
major = v.major release_version; major = v.major release_version;
minor = v.minor release_version; minor = v.minor release_version;
patch = v.patch release_version; patch = v.patch release_version;
in '' in
''
# $1: part, $2: expected # $1: part, $2: expected
check_version() { check_version() {
part="''${1^^}" part="''${1^^}"
@@ -535,6 +638,5 @@ stdenv.mkDerivation (rec {
check_version minor ${minor} check_version minor ${minor}
check_version patch ${patch} check_version patch ${patch}
''; '';
} // lib.optionalAttrs (lib.versionOlder release_version "17" || lib.versionAtLeast release_version "18") { }
hardeningDisable = [ "trivialautovarinit" ]; )
})

View File

@@ -1,15 +1,20 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, buildLlvmTools llvm_meta,
, monorepoSrc buildLlvmTools,
, runCommand monorepoSrc,
, cmake runCommand,
, ninja cmake,
, libxml2 ninja,
, libllvm libxml2,
, version libllvm,
, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) version,
doCheck ?
(
!stdenv.isx86_32 # TODO: why
)
&& (!stdenv.hostPlatform.isMusl),
}: }:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@@ -28,9 +33,7 @@ stdenv.mkDerivation rec {
sourceRoot = "${src.name}/mlir"; sourceRoot = "${src.name}/mlir";
patches = [ patches = [ ./gnu-install-dirs.patch ];
./gnu-install-dirs.patch
];
nativeBuildInputs = [ nativeBuildInputs = [
cmake cmake
@@ -42,7 +45,8 @@ stdenv.mkDerivation rec {
libxml2 libxml2
]; ];
cmakeFlags = [ cmakeFlags =
[
"-DLLVM_BUILD_TOOLS=ON" "-DLLVM_BUILD_TOOLS=ON"
# Install headers as well # Install headers as well
"-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF" "-DLLVM_INSTALL_TOOLCHAIN_ONLY=OFF"
@@ -55,17 +59,28 @@ stdenv.mkDerivation rec {
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_ENABLE_DUMP=ON" "-DLLVM_ENABLE_DUMP=ON"
] ++ lib.optionals stdenv.hostPlatform.isStatic [ ]
++ lib.optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper # Disables building of shared libs, -fPIC is still injected by cc-wrapper
"-DLLVM_ENABLE_PIC=OFF" "-DLLVM_ENABLE_PIC=OFF"
"-DLLVM_BUILD_STATIC=ON" "-DLLVM_BUILD_STATIC=ON"
"-DLLVM_LINK_LLVM_DYLIB=OFF" "-DLLVM_LINK_LLVM_DYLIB=OFF"
] ++ lib.optionals ((stdenv.hostPlatform != stdenv.buildPlatform) && !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) [ ]
++
lib.optionals
(
(stdenv.hostPlatform != stdenv.buildPlatform)
&& !(stdenv.buildPlatform.canExecute stdenv.hostPlatform)
)
[
"-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
"-DMLIR_TABLEGEN_EXE=${buildLlvmTools.mlir}/bin/mlir-tblgen" "-DMLIR_TABLEGEN_EXE=${buildLlvmTools.mlir}/bin/mlir-tblgen"
]; ];
outputs = [ "out" "dev" ]; outputs = [
"out"
"dev"
];
meta = llvm_meta // { meta = llvm_meta // {
homepage = "https://mlir.llvm.org/"; homepage = "https://mlir.llvm.org/";

View File

@@ -1,63 +1,63 @@
{ lib {
, stdenv lib,
, llvm_meta stdenv,
, release_version llvm_meta,
, patches ? [] release_version,
, monorepoSrc ? null patches ? [ ],
, src ? null monorepoSrc ? null,
, runCommand src ? null,
, cmake runCommand,
, ninja cmake,
, llvm ninja,
, targetLlvm llvm,
, lit targetLlvm,
, clang-unwrapped lit,
, perl clang-unwrapped,
, pkg-config perl,
, xcbuild pkg-config,
, version xcbuild,
version,
}: }:
let let
pname = "openmp"; pname = "openmp";
src' = src' =
if monorepoSrc != null then if monorepoSrc != null then
runCommand "${pname}-src-${version}" {} '' runCommand "${pname}-src-${version}" { } ''
mkdir -p "$out" mkdir -p "$out"
cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/cmake "$out"
cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/${pname} "$out"
'' else src; ''
else
src;
in in
stdenv.mkDerivation (rec { stdenv.mkDerivation (
rec {
inherit pname version patches; inherit pname version patches;
src = src'; src = src';
sourceRoot = sourceRoot = if lib.versionOlder release_version "13" then null else "${src.name}/${pname}";
if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
outputs = [ "out" ] outputs = [ "out" ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
patchFlags = patchFlags = if lib.versionOlder release_version "14" then [ "-p2" ] else null;
if lib.versionOlder release_version "14" then [ "-p2" ]
else null;
nativeBuildInputs = [ nativeBuildInputs =
cmake [ cmake ]
] ++ lib.optionals (lib.versionAtLeast release_version "15") [ ++ lib.optionals (lib.versionAtLeast release_version "15") [ ninja ]
ninja ++ [ perl ]
] ++ [ perl ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ ++ lib.optionals (lib.versionAtLeast release_version "14") [
pkg-config lit pkg-config
lit
]; ];
buildInputs = [ buildInputs = [ (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) ];
(if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
];
cmakeFlags = lib.optionals (lib.versions.major release_version == "13") [ cmakeFlags =
lib.optionals (lib.versions.major release_version == "13") [
"-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails
] ++ lib.optionals (lib.versionAtLeast release_version "14") [ ]
++ lib.optionals (lib.versionAtLeast release_version "14") [
"-DCLANG_TOOL=${clang-unwrapped}/bin/clang" "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
"-DOPT_TOOL=${llvm}/bin/opt" "-DOPT_TOOL=${llvm}/bin/opt"
"-DLINK_TOOL=${llvm}/bin/llvm-link" "-DLINK_TOOL=${llvm}/bin/llvm-link"
@@ -75,12 +75,17 @@ stdenv.mkDerivation (rec {
''; '';
# "All of the code is dual licensed under the MIT license and the UIUC # "All of the code is dual licensed under the MIT license and the UIUC
# License (a BSD-like license)": # License (a BSD-like license)":
license = with lib.licenses; [ mit ncsa ]; license = with lib.licenses; [
mit
ncsa
];
}; };
} // (lib.optionalAttrs (lib.versionAtLeast release_version "14") { }
// (lib.optionalAttrs (lib.versionAtLeast release_version "14") {
doCheck = false; doCheck = false;
checkTarget = "check-openmp"; checkTarget = "check-openmp";
preCheck = '' preCheck = ''
patchShebangs ../tools/archer/tests/deflake.bash patchShebangs ../tools/archer/tests/deflake.bash
''; '';
})) })
)