Skip to content

Commit

Permalink
llvmPackages_git.libc: init
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Dec 25, 2024
1 parent c8a2502 commit 41bcc2c
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 135 deletions.
283 changes: 148 additions & 135 deletions pkgs/development/compilers/llvm/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1065,160 +1065,173 @@ let
relative = "compiler-rt";
});
in
{
compiler-rt-libc = callPackage ./compiler-rt (
let
# temp rename to avoid infinite recursion
(
{
compiler-rt-libc = callPackage ./compiler-rt (
let
# temp rename to avoid infinite recursion
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if args.stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else if args.stdenv.hostPlatform.useLLVM or false then
overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else
args.stdenv;
in
{
patches = compiler-rtPatches;
inherit stdenv;
}
// lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--disable-symvers" ];
});
}
);

compiler-rt-no-libc = callPackage ./compiler-rt {
patches = compiler-rtPatches;
doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if args.stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
else if args.stdenv.hostPlatform.useLLVM or false then
overrideCC args.stdenv buildLlvmTools.clangWithLibcAndBasicRtAndLibcxx
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt
else
args.stdenv;
in
{
patches = compiler-rtPatches;
inherit stdenv;
}
// lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
libxcrypt = (libxcrypt.override { inherit stdenv; }).overrideAttrs (old: {
configureFlags = old.configureFlags ++ [ "--disable-symvers" ];
});
}
);
overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
};

compiler-rt-no-libc = callPackage ./compiler-rt {
patches = compiler-rtPatches;
doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
stdenv =
# Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangNoLibcNoRt
compiler-rt =
if
stdenv.hostPlatform.libc == null
# Building the with-libc compiler-rt and WASM doesn't yet work,
# because wasilibc doesn't provide some expected things. See
# compiler-rt's file for further details.
|| stdenv.hostPlatform.isWasm
# Failing `#include <term.h>` in
# `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp`
# sanitizers, not sure where to get it.
|| stdenv.hostPlatform.isFreeBSD
then
libraries.compiler-rt-no-libc
else
overrideCC stdenv buildLlvmTools.clangNoLibcNoRt;
};

compiler-rt =
if
stdenv.hostPlatform.libc == null
# Building the with-libc compiler-rt and WASM doesn't yet work,
# because wasilibc doesn't provide some expected things. See
# compiler-rt's file for further details.
|| stdenv.hostPlatform.isWasm
# Failing `#include <term.h>` in
# `lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp`
# sanitizers, not sure where to get it.
|| stdenv.hostPlatform.isFreeBSD
then
libraries.compiler-rt-no-libc
else
libraries.compiler-rt-libc;
libraries.compiler-rt-libc;

stdenv = overrideCC stdenv buildLlvmTools.clang;
stdenv = overrideCC stdenv buildLlvmTools.clang;

libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;

libcxx = callPackage ./libcxx (
{
patches =
lib.optionals (lib.versionOlder metadata.release_version "16") (
lib.optional (lib.versions.major metadata.release_version == "15")
# See:
# - https://reviews.llvm.org/D133566
# - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432
# !!! Drop in LLVM 16+
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch";
hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY=";
}
)
++ [
(substitute {
src = ./libcxxabi/wasm.patch;
libcxx = callPackage ./libcxx (
{
patches =
lib.optionals (lib.versionOlder metadata.release_version "16") (
lib.optional (lib.versions.major metadata.release_version == "15")
# See:
# - https://reviews.llvm.org/D133566
# - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432
# !!! Drop in LLVM 16+
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch";
hash = "sha256-B07vHmSjy5BhhkGSj3e1E0XmMv5/9+mvC/k70Z29VwY=";
}
)
++ [
(substitute {
src = ./libcxxabi/wasm.patch;
substitutions = [
"--replace-fail"
"/cmake/"
"/llvm/cmake/"
];
})
]
++ lib.optional stdenv.hostPlatform.isMusl (substitute {
src = ./libcxx/libcxx-0001-musl-hacks.patch;
substitutions = [
"--replace-fail"
"/cmake/"
"/llvm/cmake/"
"/include/"
"/libcxx/include/"
];
})
]
++ lib.optional stdenv.hostPlatform.isMusl (substitute {
src = ./libcxx/libcxx-0001-musl-hacks.patch;
substitutions = [
"--replace-fail"
"/include/"
"/libcxx/include/"
];
})
)
++
lib.optional
(
lib.versions.major metadata.release_version == "17"
&& stdenv.hostPlatform.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
)
# https://github.com/llvm/llvm-project/issues/64226
(
fetchpatch {
name = "0042-mbstate_t-not-defined.patch";
url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch";
hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI=";
}
)
++
lib.optional
(
lib.versionAtLeast metadata.release_version "18"
&& stdenv.hostPlatform.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
)
# https://github.com/llvm/llvm-project/issues/64226
(metadata.getVersionFile "libcxx/0001-darwin-10.12-mbstate_t-fix.patch");
stdenv =
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt
else
overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
}
// lib.optionalAttrs (lib.versionOlder metadata.release_version "14") {
# TODO: remove this, causes LLVM 13 packages rebuild.
inherit (metadata) monorepoSrc; # Preserve bug during #307211 refactor.
}
);

libunwind = callPackage ./libunwind {
patches = lib.optional (lib.versionOlder metadata.release_version "17") (
metadata.getVersionFile "libunwind/gnu-install-dirs.patch"
);
stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};

openmp = callPackage ./openmp {
patches =
lib.optional (
lib.versionAtLeast metadata.release_version "15" && lib.versionOlder metadata.release_version "19"
) (metadata.getVersionFile "openmp/fix-find-tool.patch")
++ lib.optional (
lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18"
) (metadata.getVersionFile "openmp/gnu-install-dirs.patch")
++ lib.optional (lib.versionAtLeast metadata.release_version "14") (
metadata.getVersionFile "openmp/run-lit-directly.patch"
)
++
lib.optional
(
lib.versions.major metadata.release_version == "17"
&& stdenv.hostPlatform.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
)
# https://github.com/llvm/llvm-project/issues/64226
lib.optional (lib.versionOlder metadata.release_version "14")
# Fix cross.
(
fetchpatch {
name = "0042-mbstate_t-not-defined.patch";
url = "https://github.com/macports/macports-ports/raw/acd8acb171f1658596ed1cf25da48d5b932e2d19/lang/llvm-17/files/0042-mbstate_t-not-defined.patch";
hash = "sha256-jo+DYA6zuSv9OH3A0bYwY5TlkWprup4OKQ7rfK1WHBI=";
url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
}
)
++
lib.optional
(
lib.versionAtLeast metadata.release_version "18"
&& stdenv.hostPlatform.isDarwin
&& lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13"
)
# https://github.com/llvm/llvm-project/issues/64226
(metadata.getVersionFile "libcxx/0001-darwin-10.12-mbstate_t-fix.patch");
stdenv =
if stdenv.hostPlatform.isDarwin then
overrideCC darwin.bootstrapStdenv buildLlvmTools.clangWithLibcAndBasicRt
else
overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
}
// lib.optionalAttrs (lib.versionOlder metadata.release_version "14") {
# TODO: remove this, causes LLVM 13 packages rebuild.
inherit (metadata) monorepoSrc; # Preserve bug during #307211 refactor.
}
);
);
};
}
// lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
libc-overlay = callPackage ./libc {
isFullBuild = false;
};

libunwind = callPackage ./libunwind {
patches = lib.optional (lib.versionOlder metadata.release_version "17") (
metadata.getVersionFile "libunwind/gnu-install-dirs.patch"
);
stdenv = overrideCC stdenv buildLlvmTools.clangWithLibcAndBasicRt;
};
libc-full = callPackage ./libc {
isFullBuild = true;
};

openmp = callPackage ./openmp {
patches =
lib.optional (
lib.versionAtLeast metadata.release_version "15" && lib.versionOlder metadata.release_version "19"
) (metadata.getVersionFile "openmp/fix-find-tool.patch")
++ lib.optional (
lib.versionAtLeast metadata.release_version "14" && lib.versionOlder metadata.release_version "18"
) (metadata.getVersionFile "openmp/gnu-install-dirs.patch")
++ lib.optional (lib.versionAtLeast metadata.release_version "14") (
metadata.getVersionFile "openmp/run-lit-directly.patch"
)
++
lib.optional (lib.versionOlder metadata.release_version "14")
# Fix cross.
(
fetchpatch {
url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
}
);
};
}
libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
}
)
);

noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
Expand Down
Loading

0 comments on commit 41bcc2c

Please sign in to comment.