Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv/darwin: assemble full clang toolchain #94427

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkgs/development/compilers/llvm/7/libc++abi.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ stdenv, cmake, fetch, libcxx, llvm, version
, standalone ? false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has very similar effects to stdenv.hostPlatform.useLLVM, in supporting bootstraping an llvm/clang based toolchain. Though useLLVM is only defined in versions 8, 9, 10 and 11. We should find a consistent approach to this. If possible I'd like to remove useLLVM from llvm/*/libc++abi.nix for something reusable that describes its effects.

# on musl the shared objects don't build
, enableShared ? ! stdenv.hostPlatform.isMusl }:

Expand All @@ -20,7 +21,9 @@ stdenv.mkDerivation {
patch -p1 -d $(ls -d libcxx-*) -i ${../libcxx-0001-musl-hacks.patch}
'';

cmakeFlags = stdenv.lib.optional (!enableShared) "-DLIBCXXABI_ENABLE_SHARED=OFF";
cmakeFlags =
stdenv.lib.optional standalone "-DLLVM_ENABLE_LIBCXX=ON" ++
stdenv.lib.optional (!enableShared) "-DLIBCXXABI_ENABLE_SHARED=OFF";

installPhase = if stdenv.isDarwin
then ''
Expand Down
150 changes: 117 additions & 33 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ assert crossSystem == localSystem;
let
inherit (localSystem) system platform;

bootstrapClangVersion = "7.1.0";

commonImpureHostDeps = [
"/bin/sh"
"/usr/lib/libSystem.B.dylib"
Expand Down Expand Up @@ -72,33 +74,48 @@ in rec {
inherit (last) stdenv;
};

coreutils = { name = "${name}-coreutils"; outPath = bootstrapTools; };
gnugrep = { name = "${name}-gnugrep"; outPath = bootstrapTools; };

bintools = import ../../build-support/bintools-wrapper {
inherit shell;
inherit (last) stdenvNoCC;

nativeTools = false;
nativeLibc = false;
inherit buildPackages coreutils gnugrep;
libc = last.pkgs.darwin.Libsystem;
bintools = { name = "${name}-binutils"; outPath = bootstrapTools; };
};

cc = if last == null then "/dev/null" else import ../../build-support/cc-wrapper {
inherit shell;
inherit (last) stdenvNoCC;

extraPackages = [];
mkExtraBuildCommands = cc: ''
rsrc="$out/resource-root"
mkdir "$rsrc"
ln -s "${cc}/lib/clang/${cc.version}/include" "$rsrc"
ln -s "${last.pkgs.llvmPackages_7.compiler-rt.out}/lib" "$rsrc/lib"
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
'';

mkCC = overrides: import ../../build-support/cc-wrapper (
let args = {
inherit shell;
inherit (last) stdenvNoCC;

nativeTools = false;
nativeLibc = false;
inherit buildPackages libcxx;
inherit (last.pkgs) coreutils gnugrep;
bintools = last.pkgs.darwin.binutils;
libc = last.pkgs.darwin.Libsystem;
isClang = true;
cc = last.pkgs.llvmPackages_7.clang-unwrapped;
}; in args // (overrides args));

cc = if last == null then "/dev/null" else mkCC ({ cc, ... }: {
extraPackages = [
last.pkgs.llvmPackages_7.libcxxabi
last.pkgs.llvmPackages_7.compiler-rt
];
extraBuildCommands = mkExtraBuildCommands cc;
});

nativeTools = false;
nativeLibc = false;
inherit buildPackages coreutils gnugrep bintools libcxx;
libc = last.pkgs.darwin.Libsystem;
isClang = true;
cc = { name = "${name}-clang"; outPath = bootstrapTools; };
};
ccNoLibcxx = if last == null then "/dev/null" else mkCC ({ cc, ... }: {
libcxx = null;
extraPackages = [
last.pkgs.llvmPackages_7.compiler-rt
];
extraBuildCommands = ''
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
echo "-B${last.pkgs.llvmPackages_7.compiler-rt}/lib" >> $out/nix-support/cc-cflags
echo "-nostdlib++" >> $out/nix-support/cc-cflags
'' + mkExtraBuildCommands cc;
});

thisStdenv = import ../generic {
name = "${name}-stdenv-darwin";
Expand Down Expand Up @@ -137,7 +154,10 @@ in rec {
extraAttrs = {
inherit macosVersionMin appleSdkVersion platform;
};
overrides = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; };
overrides = self: super: (overrides self super) // {
inherit ccNoLibcxx;
fetchurl = thisStdenv.fetchurlBoot;
};
};

in {
Expand All @@ -147,6 +167,9 @@ in rec {

stage0 = stageFun 0 null {
overrides = self: super: with stage0; {
coreutils = { name = "bootstrap-stage0-coreutils"; outPath = bootstrapTools; };
gnugrep = { name = "bootstrap-stage0-gnugrep"; outPath = bootstrapTools; };

darwin = super.darwin // {
Libsystem = stdenv.mkDerivation {
name = "bootstrap-stage0-Libsystem";
Expand All @@ -157,9 +180,26 @@ in rec {
'';
};
dyld = bootstrapTools;

binutils = lib.makeOverridable (import ../../build-support/bintools-wrapper) {
shell = "${bootstrapTools}/bin/bash";
inherit (self) stdenvNoCC;

nativeTools = false;
nativeLibc = false;
inherit (self) buildPackages coreutils gnugrep;
libc = self.pkgs.darwin.Libsystem;
bintools = { name = "bootstrap-stag0-binutils"; outPath = bootstrapTools; };
};
};

llvmPackages_7 = {
clang-unwrapped = {
name = "bootstrap-stage0-clang";
outPath = bootstrapTools;
version = bootstrapClangVersion;
};

libcxx = stdenv.mkDerivation {
name = "bootstrap-stage0-libcxx";
phases = [ "installPhase" "fixupPhase" ];
Expand All @@ -180,6 +220,15 @@ in rec {
ln -s ${bootstrapTools}/lib/libc++abi.dylib $out/lib/libc++abi.dylib
'';
};

compiler-rt = stdenv.mkDerivation {
name = "bootstrap-stage0-compiler-rt";
buildCommand = ''
mkdir -p $out/lib
ln -s ${bootstrapTools}/lib/libclang_rt* $out/lib
ln -s ${bootstrapTools}/lib/darwin $out/lib/darwin
'';
};
};
};

Expand All @@ -198,6 +247,21 @@ in rec {
python3 = super.python3Minimal;

ninja = super.ninja.override { buildDocs = false; };

llvmPackages_7 = super.llvmPackages_7 // (let
tools = super.llvmPackages_7.tools.extend (_: _: {
inherit (llvmPackages_7) clang-unwrapped;
});
libraries = super.llvmPackages_7.libraries.extend (_: _: {
inherit (llvmPackages_7) compiler-rt libcxx libcxxabi;
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // {
binutils = darwin.binutils.override {
libc = self.darwin.Libsystem;
};
};
};
in with prevStage; stageFun 1 prevStage {
extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
Expand All @@ -206,7 +270,9 @@ in rec {
libcxx = pkgs.libcxx;

allowedRequisites =
[ bootstrapTools ] ++ (with pkgs; [ libcxx libcxxabi ]) ++ [ pkgs.darwin.Libsystem ];
[ bootstrapTools ] ++
(with pkgs; [ libcxx libcxxabi llvmPackages_7.compiler-rt ]) ++
(with pkgs.darwin; [ Libsystem ]);

overrides = persistent;
};
Expand All @@ -220,9 +286,25 @@ in rec {
findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils
libssh2 nghttp2 libkrb5 ninja;

llvmPackages_7 = super.llvmPackages_7 // (let
tools = super.llvmPackages_7.tools.extend (_: _: {
inherit (llvmPackages_7) clang-unwrapped;
});
libraries = super.llvmPackages_7.libraries.extend (_: libSuper: {
inherit (llvmPackages_7) compiler-rt;
libcxx = libSuper.libcxx.override {
stdenv = overrideCC self.stdenv self.ccNoLibcxx;
};
libcxxabi = libSuper.libcxxabi.override {
stdenv = overrideCC self.stdenv self.ccNoLibcxx;
standalone = true;
};
});
in { inherit tools libraries; } // tools // libraries);

darwin = super.darwin // {
inherit (darwin)
dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF;
binutils dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF;
};
};
in with prevStage; stageFun 2 prevStage {
Expand All @@ -237,8 +319,9 @@ in rec {
allowedRequisites =
[ bootstrapTools ] ++
(with pkgs; [
xz.bin xz.out libcxx libcxxabi zlib libxml2.out curl.out openssl.out libssh2.out
nghttp2.lib libkrb5
xz.bin xz.out libcxx libcxxabi llvmPackages_7.compiler-rt
zlib libxml2.out curl.out openssl.out libssh2.out
nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv
]) ++
(with pkgs.darwin; [ dyld Libsystem CF ICU locale ]);

Expand Down Expand Up @@ -287,8 +370,9 @@ in rec {
allowedRequisites =
[ bootstrapTools ] ++
(with pkgs; [
xz.bin xz.out bash libcxx libcxxabi zlib libxml2.out curl.out openssl.out libssh2.out
nghttp2.lib libkrb5
xz.bin xz.out bash libcxx libcxxabi llvmPackages_7.compiler-rt
zlib libxml2.out curl.out openssl.out libssh2.out
nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv
]) ++
(with pkgs.darwin; [ dyld ICU Libsystem locale ]);

Expand Down