forked from mirrors/nixpkgs
Merge pull request #52031 from Mic92/cross-llvm
LLVM: fix cross compilation (llvm_6 & llvm_7)
This commit is contained in:
commit
4ccba8b26d
|
@ -9,18 +9,27 @@
|
||||||
, version
|
, version
|
||||||
, release_version
|
, release_version
|
||||||
, zlib
|
, zlib
|
||||||
|
, buildPackages
|
||||||
|
, fetchpatch
|
||||||
, debugVersion ? false
|
, debugVersion ? false
|
||||||
, enableManpages ? false
|
, enableManpages ? false
|
||||||
|
, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
|
||||||
, enableSharedLibraries ? true
|
, enableSharedLibraries ? true
|
||||||
, enableWasm ? true
|
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (stdenv.lib) optional optionals optionalString;
|
||||||
|
|
||||||
src = fetch "llvm" "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn";
|
src = fetch "llvm" "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn";
|
||||||
|
|
||||||
# Used when creating a version-suffixed symlink of libLLVM.dylib
|
# Used when creating a version-suffixed symlink of libLLVM.dylib
|
||||||
shortVersion = with stdenv.lib;
|
shortVersion = with stdenv.lib;
|
||||||
concatStringsSep "." (take 2 (splitString "." release_version));
|
concatStringsSep "." (take 2 (splitString "." release_version));
|
||||||
|
|
||||||
|
inherit
|
||||||
|
(import ../common.nix { inherit (stdenv) lib; })
|
||||||
|
llvmBackendList;
|
||||||
|
|
||||||
in stdenv.mkDerivation (rec {
|
in stdenv.mkDerivation (rec {
|
||||||
name = "llvm-${version}";
|
name = "llvm-${version}";
|
||||||
|
|
||||||
|
@ -31,22 +40,30 @@ in stdenv.mkDerivation (rec {
|
||||||
'';
|
'';
|
||||||
|
|
||||||
outputs = [ "out" "python" ]
|
outputs = [ "out" "python" ]
|
||||||
++ stdenv.lib.optional enableSharedLibraries "lib";
|
++ optional enableSharedLibraries "lib";
|
||||||
|
|
||||||
nativeBuildInputs = [ cmake python ]
|
nativeBuildInputs = [ cmake python ]
|
||||||
++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
|
++ optional enableManpages python.pkgs.sphinx;
|
||||||
|
|
||||||
buildInputs = [ libxml2 libffi ];
|
buildInputs = [ libxml2 libffi ];
|
||||||
|
|
||||||
propagatedBuildInputs = [ ncurses zlib ];
|
propagatedBuildInputs = [ ncurses zlib ];
|
||||||
|
|
||||||
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
|
patches = [
|
||||||
|
# fixes tests, included in llvm_7
|
||||||
|
(fetchpatch {
|
||||||
|
url = "https://github.com/llvm-mirror/llvm/commit/737553be0c9c25c497b45a241689994f177d5a5d.patch";
|
||||||
|
sha256 = "0hnaxnkx7zy5yg98f1ggv8a9l0r6g19n6ygqsv26masrnlcbccli";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
postPatch = 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 INSTALL_NAME_DIR "$lib/lib")" \
|
--replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
|
||||||
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
|
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
|
||||||
''
|
''
|
||||||
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
||||||
+ stdenv.lib.optionalString (enableSharedLibraries) ''
|
+ optionalString (enableSharedLibraries) ''
|
||||||
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
||||||
patch -p1 < ./llvm-outputs.patch
|
patch -p1 < ./llvm-outputs.patch
|
||||||
'' + ''
|
'' + ''
|
||||||
|
@ -54,7 +71,7 @@ in stdenv.mkDerivation (rec {
|
||||||
substituteInPlace unittests/Support/CMakeLists.txt \
|
substituteInPlace unittests/Support/CMakeLists.txt \
|
||||||
--replace "Path.cpp" ""
|
--replace "Path.cpp" ""
|
||||||
rm unittests/Support/Path.cpp
|
rm unittests/Support/Path.cpp
|
||||||
'' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
|
'' + optionalString stdenv.hostPlatform.isMusl ''
|
||||||
patch -p1 -i ${../TLI-musl.patch}
|
patch -p1 -i ${../TLI-musl.patch}
|
||||||
substituteInPlace unittests/Support/CMakeLists.txt \
|
substituteInPlace unittests/Support/CMakeLists.txt \
|
||||||
--replace "add_subdirectory(DynamicLibrary)" ""
|
--replace "add_subdirectory(DynamicLibrary)" ""
|
||||||
|
@ -73,31 +90,28 @@ in stdenv.mkDerivation (rec {
|
||||||
"-DLLVM_BUILD_TESTS=ON"
|
"-DLLVM_BUILD_TESTS=ON"
|
||||||
"-DLLVM_ENABLE_FFI=ON"
|
"-DLLVM_ENABLE_FFI=ON"
|
||||||
"-DLLVM_ENABLE_RTTI=ON"
|
"-DLLVM_ENABLE_RTTI=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.targetPlatform.config}"
|
||||||
"-DTARGET_TRIPLE=${stdenv.hostPlatform.config}"
|
"-DLLVM_TARGETS_TO_BUILD=${llvmBackendList enableTargets}"
|
||||||
|
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
|
||||||
"-DLLVM_ENABLE_DUMP=ON"
|
"-DLLVM_ENABLE_DUMP=ON"
|
||||||
]
|
] ++ optionals enableSharedLibraries [
|
||||||
++ stdenv.lib.optional enableSharedLibraries
|
|
||||||
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
||||||
++ stdenv.lib.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 (!isDarwin) [
|
||||||
++ stdenv.lib.optional (!isDarwin)
|
|
||||||
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
|
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
|
||||||
++ stdenv.lib.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.lib.optional enableWasm
|
"-DCMAKE_CROSSCOMPILING=True"
|
||||||
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
|
"-DLLVM_TABLEGEN=${buildPackages.llvm_6}/bin/llvm-tblgen"
|
||||||
;
|
];
|
||||||
|
|
||||||
postBuild = ''
|
postBuild = ''
|
||||||
rm -fR $out
|
rm -fR $out
|
||||||
|
@ -117,13 +131,13 @@ in stdenv.mkDerivation (rec {
|
||||||
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
|
||||||
''
|
''
|
||||||
+ stdenv.lib.optionalString enableSharedLibraries ''
|
+ optionalString enableSharedLibraries ''
|
||||||
moveToOutput "lib/libLLVM-*" "$lib"
|
moveToOutput "lib/libLLVM-*" "$lib"
|
||||||
moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
|
moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
|
||||||
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
||||||
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
||||||
''
|
''
|
||||||
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
+ optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
||||||
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
||||||
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
|
--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-${shortVersion}.dylib
|
||||||
|
|
|
@ -10,15 +10,17 @@
|
||||||
, version
|
, version
|
||||||
, release_version
|
, release_version
|
||||||
, zlib
|
, zlib
|
||||||
|
, buildPackages
|
||||||
, debugVersion ? false
|
, debugVersion ? false
|
||||||
, enableManpages ? false
|
, enableManpages ? false
|
||||||
, enableSharedLibraries ? true
|
, enableSharedLibraries ? true
|
||||||
, targets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
|
, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
|
||||||
, enableWasm ? true # TODO fold this into `targets` somehow
|
|
||||||
, enablePFM ? !stdenv.isDarwin
|
, enablePFM ? !stdenv.isDarwin
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
inherit (stdenv.lib) optional optionals optionalString;
|
||||||
|
|
||||||
src = fetch "llvm" "08p27wv1pr9ql2zc3f3qkkymci46q7myvh8r5ijippnbwr2gihcb";
|
src = fetch "llvm" "08p27wv1pr9ql2zc3f3qkkymci46q7myvh8r5ijippnbwr2gihcb";
|
||||||
|
|
||||||
# Used when creating a version-suffixed symlink of libLLVM.dylib
|
# Used when creating a version-suffixed symlink of libLLVM.dylib
|
||||||
|
@ -38,23 +40,23 @@ in stdenv.mkDerivation (rec {
|
||||||
'';
|
'';
|
||||||
|
|
||||||
outputs = [ "out" "python" ]
|
outputs = [ "out" "python" ]
|
||||||
++ stdenv.lib.optional enableSharedLibraries "lib";
|
++ optional enableSharedLibraries "lib";
|
||||||
|
|
||||||
nativeBuildInputs = [ cmake python ]
|
nativeBuildInputs = [ cmake python ]
|
||||||
++ stdenv.lib.optional enableManpages python.pkgs.sphinx;
|
++ optional enableManpages python.pkgs.sphinx;
|
||||||
|
|
||||||
buildInputs = [ libxml2 libffi ]
|
buildInputs = [ libxml2 libffi ]
|
||||||
++ stdenv.lib.optional enablePFM libpfm; # exegesis
|
++ optional enablePFM libpfm; # exegesis
|
||||||
|
|
||||||
propagatedBuildInputs = [ ncurses zlib ];
|
propagatedBuildInputs = [ ncurses zlib ];
|
||||||
|
|
||||||
postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
|
postPatch = 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 INSTALL_NAME_DIR "$lib/lib")" \
|
--replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir INSTALL_NAME_DIR "$lib/lib")" \
|
||||||
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
|
--replace 'set(_install_rpath "@loader_path/../lib" ''${extra_libdir})' ""
|
||||||
''
|
''
|
||||||
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
# Patch llvm-config to return correct library path based on --link-{shared,static}.
|
||||||
+ stdenv.lib.optionalString (enableSharedLibraries) ''
|
+ optionalString (enableSharedLibraries) ''
|
||||||
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
substitute '${./llvm-outputs.patch}' ./llvm-outputs.patch --subst-var lib
|
||||||
patch -p1 < ./llvm-outputs.patch
|
patch -p1 < ./llvm-outputs.patch
|
||||||
'' + ''
|
'' + ''
|
||||||
|
@ -62,7 +64,7 @@ in stdenv.mkDerivation (rec {
|
||||||
substituteInPlace unittests/Support/CMakeLists.txt \
|
substituteInPlace unittests/Support/CMakeLists.txt \
|
||||||
--replace "Path.cpp" ""
|
--replace "Path.cpp" ""
|
||||||
rm unittests/Support/Path.cpp
|
rm unittests/Support/Path.cpp
|
||||||
'' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
|
'' + optionalString stdenv.hostPlatform.isMusl ''
|
||||||
patch -p1 -i ${../TLI-musl.patch}
|
patch -p1 -i ${../TLI-musl.patch}
|
||||||
substituteInPlace unittests/Support/CMakeLists.txt \
|
substituteInPlace unittests/Support/CMakeLists.txt \
|
||||||
--replace "add_subdirectory(DynamicLibrary)" ""
|
--replace "add_subdirectory(DynamicLibrary)" ""
|
||||||
|
@ -85,28 +87,26 @@ in stdenv.mkDerivation (rec {
|
||||||
"-DLLVM_ENABLE_RTTI=ON"
|
"-DLLVM_ENABLE_RTTI=ON"
|
||||||
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
|
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
|
||||||
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}"
|
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.targetPlatform.config}"
|
||||||
"-DLLVM_TARGETS_TO_BUILD=${llvmBackendList targets}"
|
"-DLLVM_TARGETS_TO_BUILD=${llvmBackendList enableTargets}"
|
||||||
|
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
|
||||||
"-DLLVM_ENABLE_DUMP=ON"
|
"-DLLVM_ENABLE_DUMP=ON"
|
||||||
]
|
] ++ optionals enableSharedLibraries [
|
||||||
++ stdenv.lib.optional enableSharedLibraries
|
|
||||||
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
"-DLLVM_LINK_LLVM_DYLIB=ON"
|
||||||
++ stdenv.lib.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 (!isDarwin) [
|
||||||
++ stdenv.lib.optional (!isDarwin)
|
|
||||||
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
|
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
|
||||||
++ stdenv.lib.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.lib.optional enableWasm
|
"-DCMAKE_CROSSCOMPILING=True"
|
||||||
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly"
|
"-DLLVM_TABLEGEN=${buildPackages.llvm_7}/bin/llvm-tblgen"
|
||||||
;
|
];
|
||||||
|
|
||||||
postBuild = ''
|
postBuild = ''
|
||||||
rm -fR $out
|
rm -fR $out
|
||||||
|
@ -126,13 +126,13 @@ in stdenv.mkDerivation (rec {
|
||||||
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
|
||||||
''
|
''
|
||||||
+ stdenv.lib.optionalString enableSharedLibraries ''
|
+ optionalString enableSharedLibraries ''
|
||||||
moveToOutput "lib/libLLVM-*" "$lib"
|
moveToOutput "lib/libLLVM-*" "$lib"
|
||||||
moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
|
moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
|
||||||
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
||||||
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
|
||||||
''
|
''
|
||||||
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
+ optionalString (stdenv.isDarwin && enableSharedLibraries) ''
|
||||||
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
|
||||||
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
|
--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-${shortVersion}.dylib
|
||||||
|
|
Loading…
Reference in a new issue