Skip to content

Commit 544707d

Browse files
committed
llvmPackages_*.llvm: fix llvm-config-native with static libs
Since both static and shared libs are installed to the same `lib` output, we override the ActiveLibDir unconditionally. Fixes `llvm-config-native --link-static --libs`
1 parent 6c39b6e commit 544707d

21 files changed

Lines changed: 43 additions & 153 deletions

File tree

pkgs/development/compilers/llvm/10/llvm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ in stdenv.mkDerivation (rec {
8181
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
8282
''
8383
# Patch llvm-config to return correct library path based on --link-{shared,static}.
84-
+ optionalString (enableSharedLibraries) ''
84+
+ ''
8585
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
8686
patch -p1 < ./outputs.patch
8787
'' + ''

pkgs/development/compilers/llvm/10/llvm/outputs.patch

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
22
index 94d426b..37f7794 100644
33
--- a/tools/llvm-config/llvm-config.cpp
44
+++ b/tools/llvm-config/llvm-config.cpp
5-
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
5+
@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
66
ActiveIncludeOption = "-I" + ActiveIncludeDir;
77
}
88

9-
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
9+
+ /// Nix-specific multiple-output handling: override ActiveLibDir
1010
+ if (!IsInDevelopmentTree) {
11-
+ bool WantShared = true;
12-
+ for (int i = 1; i < argc; ++i) {
13-
+ StringRef Arg = argv[i];
14-
+ if (Arg == "--link-shared")
15-
+ WantShared = true;
16-
+ else if (Arg == "--link-static")
17-
+ WantShared = false; // the last one wins
18-
+ }
19-
+
20-
+ if (WantShared)
21-
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
11+
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2212
+ }
2313
+
2414
/// We only use `shared library` mode in cases where the static library form

pkgs/development/compilers/llvm/11/llvm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ in stdenv.mkDerivation (rec {
7373
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
7474
''
7575
# Patch llvm-config to return correct library path based on --link-{shared,static}.
76-
+ optionalString (enableSharedLibraries) ''
76+
+ ''
7777
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
7878
patch -p1 < ./outputs.patch
7979
'' + ''

pkgs/development/compilers/llvm/11/llvm/outputs.patch

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
22
index 94d426b..37f7794 100644
33
--- a/tools/llvm-config/llvm-config.cpp
44
+++ b/tools/llvm-config/llvm-config.cpp
5-
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
5+
@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
66
ActiveIncludeOption = "-I" + ActiveIncludeDir;
77
}
88

9-
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
9+
+ /// Nix-specific multiple-output handling: override ActiveLibDir
1010
+ if (!IsInDevelopmentTree) {
11-
+ bool WantShared = true;
12-
+ for (int i = 1; i < argc; ++i) {
13-
+ StringRef Arg = argv[i];
14-
+ if (Arg == "--link-shared")
15-
+ WantShared = true;
16-
+ else if (Arg == "--link-static")
17-
+ WantShared = false; // the last one wins
18-
+ }
19-
+
20-
+ if (WantShared)
21-
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
11+
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2212
+ }
2313
+
2414
/// We only use `shared library` mode in cases where the static library form

pkgs/development/compilers/llvm/12/llvm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ in stdenv.mkDerivation (rec {
7474
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
7575
''
7676
# Patch llvm-config to return correct library path based on --link-{shared,static}.
77-
+ optionalString (enableSharedLibraries) ''
77+
+ ''
7878
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
7979
patch -p1 < ./outputs.patch
8080
'' + ''

pkgs/development/compilers/llvm/12/llvm/outputs.patch

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
22
index 94d426b..37f7794 100644
33
--- a/tools/llvm-config/llvm-config.cpp
44
+++ b/tools/llvm-config/llvm-config.cpp
5-
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
5+
@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
66
ActiveIncludeOption = "-I" + ActiveIncludeDir;
77
}
88

9-
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
9+
+ /// Nix-specific multiple-output handling: override ActiveLibDir
1010
+ if (!IsInDevelopmentTree) {
11-
+ bool WantShared = true;
12-
+ for (int i = 1; i < argc; ++i) {
13-
+ StringRef Arg = argv[i];
14-
+ if (Arg == "--link-shared")
15-
+ WantShared = true;
16-
+ else if (Arg == "--link-static")
17-
+ WantShared = false; // the last one wins
18-
+ }
19-
+
20-
+ if (WantShared)
21-
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
11+
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2212
+ }
2313
+
2414
/// We only use `shared library` mode in cases where the static library form

pkgs/development/compilers/llvm/13/llvm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ in stdenv.mkDerivation (rec {
6868
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' ""
6969
''
7070
# Patch llvm-config to return correct library path based on --link-{shared,static}.
71-
+ optionalString (enableSharedLibraries) ''
71+
+ ''
7272
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
7373
patch -p1 < ./outputs.patch
7474
'' + ''

pkgs/development/compilers/llvm/13/llvm/outputs.patch

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
22
index 94d426b..37f7794 100644
33
--- a/tools/llvm-config/llvm-config.cpp
44
+++ b/tools/llvm-config/llvm-config.cpp
5-
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
5+
@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
66
ActiveIncludeOption = "-I" + ActiveIncludeDir;
77
}
88

9-
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
9+
+ /// Nix-specific multiple-output handling: override ActiveLibDir
1010
+ if (!IsInDevelopmentTree) {
11-
+ bool WantShared = true;
12-
+ for (int i = 1; i < argc; ++i) {
13-
+ StringRef Arg = argv[i];
14-
+ if (Arg == "--link-shared")
15-
+ WantShared = true;
16-
+ else if (Arg == "--link-static")
17-
+ WantShared = false; // the last one wins
18-
+ }
19-
+
20-
+ if (WantShared)
21-
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
11+
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2212
+ }
2313
+
2414
/// We only use `shared library` mode in cases where the static library form

pkgs/development/compilers/llvm/5/llvm/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ stdenv.mkDerivation ({
7474
--replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' ""
7575
''
7676
# Patch llvm-config to return correct library path based on --link-{shared,static}.
77-
+ optionalString (enableSharedLibraries) ''
77+
+ ''
7878
substitute '${./outputs.patch}' ./outputs.patch --subst-var lib
7979
patch -p1 < ./outputs.patch
8080
'' + ''

pkgs/development/compilers/llvm/5/llvm/outputs.patch

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.c
22
index 94d426b..37f7794 100644
33
--- a/tools/llvm-config/llvm-config.cpp
44
+++ b/tools/llvm-config/llvm-config.cpp
5-
@@ -333,6 +333,21 @@ int main(int argc, char **argv) {
5+
@@ -333,6 +333,11 @@ int main(int argc, char **argv) {
66
ActiveIncludeOption = "-I" + ActiveIncludeDir;
77
}
88

9-
+ /// Nix-specific multiple-output handling: override ActiveLibDir if --link-shared
9+
+ /// Nix-specific multiple-output handling: override ActiveLibDir
1010
+ if (!IsInDevelopmentTree) {
11-
+ bool WantShared = true;
12-
+ for (int i = 1; i < argc; ++i) {
13-
+ StringRef Arg = argv[i];
14-
+ if (Arg == "--link-shared")
15-
+ WantShared = true;
16-
+ else if (Arg == "--link-static")
17-
+ WantShared = false; // the last one wins
18-
+ }
19-
+
20-
+ if (WantShared)
21-
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
11+
+ ActiveLibDir = std::string("@lib@") + "/lib" + LLVM_LIBDIR_SUFFIX;
2212
+ }
2313
+
2414
/// We only use `shared library` mode in cases where the static library form

0 commit comments

Comments
 (0)