diff options
author | Moritz Angermann <moritz.angermann@gmail.com> | 2022-01-04 14:26:59 +0800 |
---|---|---|
committer | github-actions[bot] <github-actions[bot]@users.noreply.github.com> | 2022-01-07 23:36:57 +0000 |
commit | c552be03e8dbec698287d30fc8389e22c144687e (patch) | |
tree | 415c6a7efae4d6117233914a0a868ded6a31f9df | |
parent | b2793983547c62a3312a4e20e4402939afa66800 (diff) |
libredirect: build fat library for x86_64, arm64, arm64e on darwin
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. (cherry picked from commit a655bc02a78cbfdb6a87148503a0f2031efdd49a)
-rw-r--r-- | pkgs/build-support/libredirect/default.nix | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix index f87c6d23dd798..68ffeb04d31e4 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 |