From eb8f8afac7a5ca3b824cc9032f900a6486f68536 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 19 Nov 2020 16:50:49 +0900 Subject: [PATCH] libtapi: cross compilation --- pkgs/os-specific/darwin/libtapi/default.nix | 40 +++++++++++++++---- .../darwin/libtapi/disable-rpath.patch | 14 +++++++ .../darwin/libtapi/native-clang-tblgen.patch | 21 ++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 pkgs/os-specific/darwin/libtapi/disable-rpath.patch create mode 100644 pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch diff --git a/pkgs/os-specific/darwin/libtapi/default.nix b/pkgs/os-specific/darwin/libtapi/default.nix index 8c83b4ae1e6..da071074097 100644 --- a/pkgs/os-specific/darwin/libtapi/default.nix +++ b/pkgs/os-specific/darwin/libtapi/default.nix @@ -1,6 +1,6 @@ -{ lib, stdenv, fetchFromGitHub, cmake, python3, ncurses }: +{ lib, stdenv, fetchFromGitHub, pkgsBuildBuild, cmake, python3, ncurses }: -stdenv.mkDerivation rec { +stdenv.mkDerivation { pname = "libtapi"; version = "1100.0.11"; # determined by looking at VERSION.txt @@ -13,13 +13,43 @@ stdenv.mkDerivation rec { sourceRoot = "source/src/llvm"; + # Backported from newer llvm, fixes configure error when cross compiling. + # Also means we don't have to manually fix the result with install_name_tool. + patches = [ + ./disable-rpath.patch + ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [ + # TODO: make unconditional and rebuild the world + # TODO: send upstream + ./native-clang-tblgen.patch + ]; + nativeBuildInputs = [ cmake python3 ]; # ncurses is required here to avoid a reference to bootstrap-tools, which is # not allowed for the stdenv. buildInputs = [ ncurses ]; - cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ]; + cmakeFlags = [ "-DLLVM_INCLUDE_TESTS=OFF" ] + ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + # This package could probably have a llvm_6 llvm-tblgen and clang-tblgen + # provided to reduce some building. This package seems intended to + # include all of its dependencies, including enough of LLVM to build the + # required tablegens. + ( + let + nativeCC = pkgsBuildBuild.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + 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}" + ) + ]; # fixes: fatal error: 'clang/Basic/Diagnostic.h' file not found # adapted from upstream @@ -35,10 +65,6 @@ stdenv.mkDerivation rec { installTargets = [ "install-libtapi" "install-tapi-headers" "install-tapi" ]; - postInstall = lib.optionalString stdenv.isDarwin '' - install_name_tool -id $out/lib/libtapi.dylib $out/lib/libtapi.dylib - ''; - meta = with lib; { description = "Replaces the Mach-O Dynamic Library Stub files in Apple's SDKs to reduce the size"; homepage = "https://github.com/tpoechtrager/apple-libtapi"; diff --git a/pkgs/os-specific/darwin/libtapi/disable-rpath.patch b/pkgs/os-specific/darwin/libtapi/disable-rpath.patch new file mode 100644 index 00000000000..87c0cf3330d --- /dev/null +++ b/pkgs/os-specific/darwin/libtapi/disable-rpath.patch @@ -0,0 +1,14 @@ +diff --git a/src/llvm/cmake/modules/AddLLVM.cmake b/src/llvm/cmake/modules/AddLLVM.cmake +index a53016eb0..b65e608a4 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -1683,8 +1683,7 @@ function(llvm_setup_rpath name) + endif() + + if (APPLE) +- set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_name_dir) + elseif(UNIX) + set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") diff --git a/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch b/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch new file mode 100644 index 00000000000..9b715766a12 --- /dev/null +++ b/pkgs/os-specific/darwin/libtapi/native-clang-tblgen.patch @@ -0,0 +1,21 @@ +diffprojects/libtapi/CMakeLists.txt b/src/llvm/projects/libtapi/CMakeLists.txt +index 8ee6d8138..8277be147 100644 +--- a/projects/libtapi/CMakeLists.txt ++++ b/projects/libtapi/CMakeLists.txt +@@ -193,7 +193,15 @@ if (NOT DEFINED CLANG_VERSION) + set(CLANG_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") + endif () + if (NOT DEFINED CLANG_TABLEGEN_EXE) +- set(CLANG_TABLEGEN_EXE "${LLVM_TOOLS_BINARY_DIR}/clang-tblgen") ++ if(LLVM_USE_HOST_TOOLS) ++ if (NOT CMAKE_CONFIGURATION_TYPES) ++ set(CLANG_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/clang-tblgen") ++ else() ++ set(CLANG_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/Release/bin/clang-tblgen") ++ endif() ++ else() ++ set(CLANG_TABLEGEN_EXE "${LLVM_TOOLS_BINARY_DIR}/clang-tblgen") ++ endif () + endif () + + # Include must go first.