summary refs log tree commit diff
path: root/pkgs/build-support/libredirect
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2022-01-08 07:32:21 +0800
committerGitHub <noreply@github.com>2022-01-07 18:32:21 -0500
commit38377ab02680908d1c83fd5f5691e0594e08df30 (patch)
tree397655ae7f73638dc09f3f3de3776e3e5467007a /pkgs/build-support/libredirect
parentecd989e7ee7ac6e38863cdebff6129e663810142 (diff)
downloadnixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar.gz
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar.bz2
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar.lz
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar.xz
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.tar.zst
nixpkgs-38377ab02680908d1c83fd5f5691e0594e08df30.zip
libredirect: build fat library for x86_64, arm64, arm64e on darwin (#153441)
macOS's dyld can be rather picky as to what dylib it accepts. This
even changes across macOS versions. Therefore we now build a fat
dylib with all three architectures (x86_64, arm64, arm64e). This
should then be compatible with pretty much any macOS's dyld.
Diffstat (limited to 'pkgs/build-support/libredirect')
-rw-r--r--pkgs/build-support/libredirect/default.nix34
1 files changed, 26 insertions, 8 deletions
diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix
index f87c6d23dd7..68ffeb04d31 100644
--- a/pkgs/build-support/libredirect/default.nix
+++ b/pkgs/build-support/libredirect/default.nix
@@ -1,5 +1,4 @@
-{ stdenv, lib, coreutils }:
-
+{ lib, stdenv, bintools-unwrapped, llvmPackages_13, coreutils }:
 stdenv.mkDerivation rec {
   pname = "libredirect";
   version = "0";
@@ -9,17 +8,36 @@ stdenv.mkDerivation rec {
     cp ${./test.c} test.c
   '';
 
-  libName = "libredirect" + stdenv.targetPlatform.extensions.sharedLibrary;
-
   outputs = ["out" "hook"];
 
+  libName = "libredirect" + stdenv.targetPlatform.extensions.sharedLibrary;
+
   buildPhase = ''
     runHook preBuild
 
-    $CC -Wall -std=c99 -O3 -fPIC -ldl -shared \
-      ${lib.optionalString stdenv.isDarwin "-Wl,-install_name,$out/lib/$libName"} \
-      -o "$libName" \
-      libredirect.c
+    ${if stdenv.isDarwin && stdenv.isAarch64 then ''
+    # We need the unwrapped binutils and clang:
+    # We also want to build a fat library with x86_64, arm64, arm64e in there.
+    # Because we use the unwrapped tools, we need to provide -isystem for headers
+    # and the library search directory for libdl.
+    # We can't build this on x86_64, because the libSystem we point to doesn't
+    # like arm64(e).
+    PATH=${bintools-unwrapped}/bin:${llvmPackages_13.clang-unwrapped}/bin:$PATH \
+      clang -arch x86_64 -arch arm64 -arch arm64e \
+      -isystem ${llvmPackages_13.clang.libc}/include \
+      -isystem ${llvmPackages_13.libclang.lib}/lib/clang/*/include \
+      -L${llvmPackages_13.clang.libc}/lib \
+      -Wl,-install_name,$out/lib/$libName \
+      -Wall -std=c99 -O3 -fPIC libredirect.c \
+      -ldl -shared -o "$libName"
+    '' else if stdenv.isDarwin then ''
+    $CC -Wall -std=c99 -O3 -fPIC libredirect.c \
+      -Wl,-install_name,$out/lib/$libName \
+      -ldl -shared -o "$libName"
+    '' else ''
+    $CC -Wall -std=c99 -O3 -fPIC libredirect.c \
+      -ldl -shared -o "$libName"
+    ''}
 
     if [ -n "$doInstallCheck" ]; then
       $CC -Wall -std=c99 -O3 test.c -o test