flake: unbreak llvm-config for cross-compilation of static libs

This commit is contained in:
Sebastien Bourdeauducq 2021-12-02 18:46:04 +08:00
parent 31fba04cee
commit 8a46032f4c
2 changed files with 45 additions and 1 deletions

View File

@ -10,7 +10,7 @@
nixpkgs-patched = pkgs-orig.applyPatches { nixpkgs-patched = pkgs-orig.applyPatches {
name = "nixpkgs"; name = "nixpkgs";
src = nixpkgs; src = nixpkgs;
patches = [ ./llvm-future-riscv-abi.diff ./llvm-restrict-targets.diff ./llvm-mingw-crosscompile.diff ]; patches = [ ./llvm-future-riscv-abi.diff ./llvm-restrict-targets.diff ./llvm-mingw-crosscompile.diff ./llvm-unbreak-static-cross.diff ];
}; };
pkgs = import nixpkgs-patched { system = "x86_64-linux"; }; pkgs = import nixpkgs-patched { system = "x86_64-linux"; };
pkgs-mingw = import nixpkgs-patched { system = "x86_64-linux"; crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; }; }; pkgs-mingw = import nixpkgs-patched { system = "x86_64-linux"; crossSystem = { config = "x86_64-w64-mingw32"; libc = "msvcrt"; }; };

View File

@ -0,0 +1,44 @@
diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix
index 30a1a7a16df..bb5676b9d48 100644
--- a/pkgs/development/compilers/llvm/12/llvm/default.nix
+++ b/pkgs/development/compilers/llvm/12/llvm/default.nix
@@ -74,7 +74,7 @@ in stdenv.mkDerivation (rec {
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
''
# Patch llvm-config to return correct library path based on --link-{shared,static}.
- + optionalString (enableSharedLibraries) ''
+ + ''
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
patch -p1 < ./outputs.patch
'' + ''
diff --git a/pkgs/development/compilers/llvm/12/llvm/outputs.patch b/pkgs/development/compilers/llvm/12/llvm/outputs.patch
index 40096fa3497..878460e05b8 100644
--- a/pkgs/development/compilers/llvm/12/llvm/outputs.patch
+++ b/pkgs/development/compilers/llvm/12/llvm/outputs.patch
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
index 94d426b..37f7794 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
-@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
+@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
ActiveIncludeOption = "-I" + ActiveIncludeDir;
}
-+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
++ /// Nix-specific multiple-output handling: override ActiveLibDir
+ if (!IsInDevelopmentTree) {
-+ bool WantShared = true;
-+ for (int i = 1; i < argc; ++i) {
-+ StringRef Arg = argv[i];
-+ if (Arg == "--link-shared")
-+ WantShared = true;
-+ else if (Arg == "--link-static")
-+ WantShared = false; // the last one wins
-+ }
-+
-+ if (WantShared)
-+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
++ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
+ }
+
/// We only use `shared library` mode in cases where the static library form