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

llvmPackages_10: cross-compilation support #100574

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkgs/development/compilers/llvm/10/clang/default.nix
@@ -1,4 +1,5 @@
{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3, lld
{ stdenv, fetch, cmake, libxml2, llvm, version, clang-tools-extra_src, python3
, buildPackages
, fixDarwinDylibNames
, enableManpages ? false
}:
Expand All @@ -18,7 +19,7 @@ let
mv clang-tools-extra-* $sourceRoot/tools/extra
'';

nativeBuildInputs = [ cmake python3 lld ]
nativeBuildInputs = [ cmake python3 ]
++ stdenv.lib.optional enableManpages python3.pkgs.sphinx
++ stdenv.lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;

Expand All @@ -34,6 +35,10 @@ let
"-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DLLVM_CONFIG_PATH=${llvm}/bin/llvm-config-native"
"-DLLVM_TABLEGEN_EXE=${buildPackages.llvm_10}/bin/llvm-tblgen"
"-DCLANG_TABLEGEN=${buildPackages.llvmPackages_10.clang-unwrapped.tablegen}/bin/clang-tblgen"
];

patches = [
Expand All @@ -56,7 +61,7 @@ let
--replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE
'';

outputs = [ "out" "lib" "python" ];
outputs = [ "out" "lib" "python" "tablegen" ];

# Clang expects to find LLVMgold in its own prefix
postInstall = ''
Expand All @@ -80,6 +85,9 @@ let
fi
mv $out/share/clang/*.py $python/share/clang
rm $out/bin/c-index-test

mkdir -p $tablegen/bin
cp bin/clang-tblgen $tablegen/bin
'';

enableParallelBuilding = true;
Expand Down
1 change: 0 additions & 1 deletion pkgs/development/compilers/llvm/10/default.nix
Expand Up @@ -34,7 +34,6 @@ let
llvm = callPackage ./llvm.nix { };

clang-unwrapped = callPackage ./clang {
inherit (tools) lld;
inherit clang-tools-extra_src;
};

Expand Down
6 changes: 6 additions & 0 deletions pkgs/development/compilers/llvm/10/lld.nix
@@ -1,4 +1,5 @@
{ stdenv
, buildPackages
, fetch
, cmake
, libxml2
Expand All @@ -15,6 +16,11 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ cmake ];
buildInputs = [ llvm libxml2 ];

cmakeFlags = stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DLLVM_TABLEGEN_EXE=${buildPackages.llvm_10}/bin/llvm-tblgen"
"-DLLVM_CONFIG_PATH=${llvm}/bin/llvm-config-native"
];

outputs = [ "out" "dev" ];

enableParallelBuilding = true;
Expand Down
17 changes: 17 additions & 0 deletions pkgs/development/compilers/llvm/10/llvm.nix
Expand Up @@ -19,6 +19,7 @@
|| stdenv.isAarch32 # broken for the armv7l builder
)
, enablePolly ? true
, pkgsBuildBuild
}:

let
Expand Down Expand Up @@ -121,6 +122,19 @@ in stdenv.mkDerivation (rec {
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DCMAKE_CROSSCOMPILING=True"
"-DLLVM_TABLEGEN=${buildPackages.llvm_10}/bin/llvm-tblgen"
(
let
nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
nativeBintools = nativeCC.bintools.bintools;
Ericson2314 marked this conversation as resolved.
Show resolved Hide resolved
nativeToolchainFlags = [
"-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc"
"-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++"
"-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar"
"-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip"
"-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib"
];
in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=${lib.concatStringsSep ";" nativeToolchainFlags}"
)
];

postBuild = ''
Expand Down Expand Up @@ -148,6 +162,9 @@ in stdenv.mkDerivation (rec {
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
''
+ optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
cp NATIVE/bin/llvm-config $out/bin/llvm-config-native
'';

doCheck = stdenv.isLinux && (!stdenv.isx86_32);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/all-packages.nix
Expand Up @@ -9808,7 +9808,7 @@ in
llvmPackages_10 = callPackage ../development/compilers/llvm/10 {
inherit (stdenvAdapters) overrideCC;
buildLlvmTools = buildPackages.llvmPackages_10.tools;
targetLlvmLibraries = targetPackages.llvmPackages_10.libraries;
targetLlvmLibraries = targetPackages.llvmPackages_10.libraries or llvmPackages_10.libraries;
};

llvmPackages_11 = callPackage ../development/compilers/llvm/11 ({
Expand Down