llvm8: support c++ in cross case
this adds libc++ to the LLVM cross, giving us access to the full Nixpkgs set. This requires 4 stages of wrapped compilers: - Clang with no libraries - Clang with just compiler-rt - Clang with Libc, and compiler-rt - Clang with Libc++, Libc, and compiler-rt
This commit is contained in:
parent
d0506bed9f
commit
d453273fbf
@ -45,9 +45,9 @@ let
|
|||||||
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
|
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
|
||||||
coreutils_bin = if nativeTools then "" else getBin coreutils;
|
coreutils_bin = if nativeTools then "" else getBin coreutils;
|
||||||
|
|
||||||
default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) then
|
default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then
|
||||||
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"
|
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"
|
||||||
else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) then
|
else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then
|
||||||
"-isystem ${libcxx}/include/c++/v1"
|
"-isystem ${libcxx}/include/c++/v1"
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
|
@ -55,9 +55,9 @@ stdenv.mkDerivation rec {
|
|||||||
# Hack around weird upsream RPATH bug
|
# Hack around weird upsream RPATH bug
|
||||||
postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
|
postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
|
||||||
ln -s "$out/lib"/*/* "$out/lib"
|
ln -s "$out/lib"/*/* "$out/lib"
|
||||||
'' + stdenv.lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
|
'' + stdenv.lib.optionalString (stdenv.hostPlatform.useLLVM or false) ''
|
||||||
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/*/cclang_rt.crtend-*.o $out/lib/crtend.o
|
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.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
|
||||||
'';
|
'';
|
||||||
|
@ -23,7 +23,7 @@ let
|
|||||||
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
|
ln -s "${cc}/lib/clang/${release_version}/include" "$rsrc"
|
||||||
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
|
ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
|
||||||
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
|
echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
|
||||||
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc) ''
|
'' + stdenv.lib.optionalString (stdenv.targetPlatform.isLinux && tools.clang-unwrapped ? gcc && !(stdenv.targetPlatform.useLLVM or false)) ''
|
||||||
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
|
echo "--gcc-toolchain=${tools.clang-unwrapped.gcc}" >> $out/nix-support/cc-cflags
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
@ -78,48 +78,78 @@ let
|
|||||||
|
|
||||||
lldb = callPackage ./lldb.nix {};
|
lldb = callPackage ./lldb.nix {};
|
||||||
|
|
||||||
|
# Below, is the LLVM bootstrapping logic. It handles building a
|
||||||
|
# fully LLVM toolchain from scratch. No GCC toolchain should be
|
||||||
|
# pulled in. As a consequence, it is very quick to build different
|
||||||
|
# targets provided by LLVM and we can also build for what GCC
|
||||||
|
# doesn’t support like LLVM. Probably we should move to some other
|
||||||
|
# file.
|
||||||
|
|
||||||
bintools = callPackage ./bintools.nix {};
|
bintools = callPackage ./bintools.nix {};
|
||||||
|
|
||||||
lldClang = wrapCCWith rec {
|
lldClang = wrapCCWith rec {
|
||||||
cc = tools.clang-unwrapped;
|
cc = tools.clang-unwrapped;
|
||||||
|
libcxx = targetLlvmLibraries.libcxx;
|
||||||
bintools = wrapBintoolsWith {
|
bintools = wrapBintoolsWith {
|
||||||
inherit (tools) bintools;
|
inherit (tools) bintools;
|
||||||
};
|
};
|
||||||
extraPackages = [
|
extraPackages = [
|
||||||
# targetLlvmLibraries.libcxx
|
targetLlvmLibraries.libcxx
|
||||||
# targetLlvmLibraries.libcxxabi
|
targetLlvmLibraries.libcxxabi
|
||||||
targetLlvmLibraries.compiler-rt
|
targetLlvmLibraries.compiler-rt
|
||||||
];
|
];
|
||||||
extraBuildCommands = ''
|
extraBuildCommands = ''
|
||||||
echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
|
||||||
|
'' + mkExtraBuildCommands cc;
|
||||||
|
};
|
||||||
|
|
||||||
|
lldClangNoLibcxx = wrapCCWith rec {
|
||||||
|
cc = tools.clang-unwrapped;
|
||||||
|
libcxx = null;
|
||||||
|
bintools = wrapBintoolsWith {
|
||||||
|
inherit (tools) bintools;
|
||||||
|
};
|
||||||
|
extraPackages = [
|
||||||
|
targetLlvmLibraries.compiler-rt
|
||||||
|
];
|
||||||
|
extraBuildCommands = ''
|
||||||
|
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-nostdlib++" >> $out/nix-support/cc-cflags
|
||||||
'' + mkExtraBuildCommands cc;
|
'' + mkExtraBuildCommands cc;
|
||||||
};
|
};
|
||||||
|
|
||||||
lldClangNoLibc = wrapCCWith rec {
|
lldClangNoLibc = wrapCCWith rec {
|
||||||
cc = tools.clang-unwrapped;
|
cc = tools.clang-unwrapped;
|
||||||
|
libcxx = null;
|
||||||
bintools = wrapBintoolsWith {
|
bintools = wrapBintoolsWith {
|
||||||
inherit (tools) bintools;
|
inherit (tools) bintools;
|
||||||
libc = null;
|
libc = null;
|
||||||
};
|
};
|
||||||
extraPackages = [
|
extraPackages = [
|
||||||
# targetLlvmLibraries.libcxx
|
|
||||||
# targetLlvmLibraries.libcxxabi
|
|
||||||
targetLlvmLibraries.compiler-rt
|
targetLlvmLibraries.compiler-rt
|
||||||
];
|
];
|
||||||
extraBuildCommands = ''
|
extraBuildCommands = ''
|
||||||
echo "-target ${stdenv.targetPlatform.config} -rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
|
||||||
'' + mkExtraBuildCommands cc;
|
'' + mkExtraBuildCommands cc;
|
||||||
};
|
};
|
||||||
|
|
||||||
lldClangNoCompilerRt = wrapCCWith rec {
|
lldClangNoCompilerRt = wrapCCWith rec {
|
||||||
cc = tools.clang-unwrapped;
|
cc = tools.clang-unwrapped;
|
||||||
|
libcxx = null;
|
||||||
bintools = wrapBintoolsWith {
|
bintools = wrapBintoolsWith {
|
||||||
inherit (tools) bintools;
|
inherit (tools) bintools;
|
||||||
libc = null;
|
libc = null;
|
||||||
};
|
};
|
||||||
extraPackages = [ ];
|
extraPackages = [ ];
|
||||||
extraBuildCommands = ''
|
extraBuildCommands = ''
|
||||||
echo "-nostartfiles -target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
echo "-nostartfiles" >> $out/nix-support/cc-cflags
|
||||||
|
echo "-target ${stdenv.targetPlatform.config}" >> $out/nix-support/cc-cflags
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,21 +159,33 @@ let
|
|||||||
callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python isl release_version version fetch; });
|
callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python isl release_version version fetch; });
|
||||||
in {
|
in {
|
||||||
|
|
||||||
compiler-rt = callPackage ./compiler-rt.nix {
|
compiler-rt = callPackage ./compiler-rt.nix ({} //
|
||||||
stdenv = if stdenv.hostPlatform.useLLVM or false
|
(stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
|
||||||
then overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt
|
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoCompilerRt;
|
||||||
else stdenv;
|
}));
|
||||||
};
|
|
||||||
|
|
||||||
stdenv = overrideCC stdenv buildLlvmTools.clang;
|
stdenv = overrideCC stdenv buildLlvmTools.clang;
|
||||||
|
|
||||||
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
|
libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
|
||||||
|
|
||||||
libcxx = callPackage ./libc++ {};
|
libcxx = callPackage ./libc++ ({} //
|
||||||
|
(stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
|
||||||
|
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
|
||||||
|
}));
|
||||||
|
|
||||||
libcxxabi = callPackage ./libc++abi.nix {};
|
libcxxabi = callPackage ./libc++abi.nix ({} //
|
||||||
|
(stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
|
||||||
|
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
|
||||||
|
libunwind = libraries.libunwind;
|
||||||
|
}));
|
||||||
|
|
||||||
openmp = callPackage ./openmp.nix {};
|
openmp = callPackage ./openmp.nix {};
|
||||||
|
|
||||||
|
libunwind = callPackage ./libunwind.nix ({} //
|
||||||
|
(stdenv.lib.optionalAttrs (stdenv.hostPlatform.useLLVM or false) {
|
||||||
|
stdenv = overrideCC stdenv buildLlvmTools.lldClangNoLibcxx;
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
in { inherit tools libraries; } // libraries // tools
|
in { inherit tools libraries; } // libraries // tools
|
||||||
|
@ -30,7 +30,8 @@ stdenv.mkDerivation rec {
|
|||||||
"-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
|
"-DLIBCXX_LIBCXXABI_LIB_PATH=${libcxxabi}/lib"
|
||||||
"-DLIBCXX_LIBCPPABI_VERSION=2"
|
"-DLIBCXX_LIBCPPABI_VERSION=2"
|
||||||
"-DLIBCXX_CXX_ABI=libcxxabi"
|
"-DLIBCXX_CXX_ABI=libcxxabi"
|
||||||
] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1";
|
] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1"
|
||||||
|
++ stdenv.lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON";
|
||||||
|
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
|
@ -8,10 +8,15 @@ stdenv.mkDerivation {
|
|||||||
nativeBuildInputs = [ cmake ];
|
nativeBuildInputs = [ cmake ];
|
||||||
buildInputs = stdenv.lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) libunwind;
|
buildInputs = stdenv.lib.optional (!stdenv.isDarwin && !stdenv.isFreeBSD) libunwind;
|
||||||
|
|
||||||
|
cmakeFlags = stdenv.lib.optionals (stdenv.hostPlatform.useLLVM or false) [
|
||||||
|
"-DLLVM_ENABLE_LIBCXX=ON"
|
||||||
|
"-DLIBCXXABI_USE_LLVM_UNWINDER=ON"
|
||||||
|
];
|
||||||
|
|
||||||
postUnpack = ''
|
postUnpack = ''
|
||||||
unpackFile ${libcxx.src}
|
unpackFile ${libcxx.src}
|
||||||
unpackFile ${llvm.src}
|
unpackFile ${llvm.src}
|
||||||
export cmakeFlags="-DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)"
|
cmakeFlags+=" -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)"
|
||||||
'' + stdenv.lib.optionalString stdenv.isDarwin ''
|
'' + stdenv.lib.optionalString stdenv.isDarwin ''
|
||||||
export TRIPLE=x86_64-apple-darwin
|
export TRIPLE=x86_64-apple-darwin
|
||||||
'' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
|
'' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
|
||||||
|
22
pkgs/development/compilers/llvm/8/libunwind.nix
Normal file
22
pkgs/development/compilers/llvm/8/libunwind.nix
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{ stdenv, version, fetch, cmake, libcxx, fetchpatch }:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "libunwind-${version}";
|
||||||
|
|
||||||
|
src = fetch "libunwind" "0q7ndlldid9wchnny0a936llwxj7zgb9gxp46wjjxvwwkik3l97z";
|
||||||
|
|
||||||
|
nativeBuildInputs = [ cmake ];
|
||||||
|
|
||||||
|
patches = [
|
||||||
|
(fetchpatch {
|
||||||
|
url = "https://github.com/llvm-mirror/libunwind/commit/34a45c630d4c79af403661d267db42fbe7de1178.patch";
|
||||||
|
sha256 = "0n0pv6jvcky8pn3srhrf9x5kbnd0d2kia9xlx2g590f5q0bgwfhv";
|
||||||
|
})
|
||||||
|
(fetchpatch {
|
||||||
|
url = "https://github.com/llvm-mirror/libunwind/commit/e050272d2eb57eb4e56a37b429a61df2ebb8aa3e.patch";
|
||||||
|
sha256 = "1sxyx5xnax8k713jjcxgq3jq3cpnxygs2rcdf5vfja0f2k9jzldl";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
enableParallelBuilding = true;
|
||||||
|
}
|
@ -39,8 +39,9 @@ stdenv.mkDerivation rec {
|
|||||||
++ optional (!libOnly) yacc
|
++ optional (!libOnly) yacc
|
||||||
# Provides the mig command used by the build scripts
|
# Provides the mig command used by the build scripts
|
||||||
++ optional stdenv.isDarwin bootstrap_cmds;
|
++ optional stdenv.isDarwin bootstrap_cmds;
|
||||||
|
|
||||||
buildInputs = [ openssl ]
|
buildInputs = [ openssl ]
|
||||||
++ optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.libc != "bionic") [ keyutils ]
|
++ optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.libc != "bionic" && !(stdenv.hostPlatform.useLLVM or false)) [ keyutils ]
|
||||||
++ optionals (!libOnly) [ openldap libedit ];
|
++ optionals (!libOnly) [ openldap libedit ];
|
||||||
|
|
||||||
preConfigure = "cd ./src";
|
preConfigure = "cd ./src";
|
||||||
|
@ -55,7 +55,7 @@ in lib.init bootStages ++ [
|
|||||||
else if crossSystem.useAndroidPrebuilt or false
|
else if crossSystem.useAndroidPrebuilt or false
|
||||||
then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
|
then buildPackages."androidndkPkgs_${crossSystem.ndkVer}".clang
|
||||||
else if crossSystem.useLLVM or false
|
else if crossSystem.useLLVM or false
|
||||||
then buildPackages.llvmPackages_7.lldClang
|
then buildPackages.llvmPackages_8.lldClang
|
||||||
else buildPackages.gcc;
|
else buildPackages.gcc;
|
||||||
|
|
||||||
extraNativeBuildInputs = old.extraNativeBuildInputs
|
extraNativeBuildInputs = old.extraNativeBuildInputs
|
||||||
|
@ -6989,7 +6989,7 @@ in
|
|||||||
|
|
||||||
crossLibcStdenv = overrideCC stdenv
|
crossLibcStdenv = overrideCC stdenv
|
||||||
(if stdenv.targetPlatform.useLLVM or false
|
(if stdenv.targetPlatform.useLLVM or false
|
||||||
then buildPackages.llvmPackages_7.lldClangNoLibc
|
then buildPackages.llvmPackages_8.lldClangNoLibc
|
||||||
else buildPackages.gccCrossStageStatic);
|
else buildPackages.gccCrossStageStatic);
|
||||||
|
|
||||||
# The GCC used to build libc for the target platform. Normal gccs will be
|
# The GCC used to build libc for the target platform. Normal gccs will be
|
||||||
|
Loading…
Reference in New Issue
Block a user