From 152b59855d2a7de9cbd0ad8051a85fa0e44de619 Mon Sep 17 00:00:00 2001 From: Congee Date: Tue, 15 Feb 2022 16:26:12 -0500 Subject: racket: support aarch64-darwin According to https://reviews.llvm.org/D96164, aarch64-darwin executables require at least an ad hoc signature. The build tool from the racket repo tries to sign $out/bin/racket but errors out, because that binary already has a signature. It is not clear yet at which stage the signature was introduced. This patch removes the existing signature always before calling add-ad-hoc-signature to circumvent that error. --- pkgs/development/interpreters/racket/default.nix | 35 ++++++++++++++++++++-- .../racket/force-remove-codesign-then-add.patch | 11 +++++++ pkgs/development/interpreters/racket/minimal.nix | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 pkgs/development/interpreters/racket/force-remove-codesign-then-add.patch diff --git a/pkgs/development/interpreters/racket/default.nix b/pkgs/development/interpreters/racket/default.nix index 89c81e2b4a2..bd96562d9e5 100644 --- a/pkgs/development/interpreters/racket/default.nix +++ b/pkgs/development/interpreters/racket/default.nix @@ -78,6 +78,13 @@ stdenv.mkDerivation rec { # fail to detect its variant at runtime. # See: https://github.com/NixOS/nixpkgs/issues/114993#issuecomment-812951247 ./force-cs-variant.patch + + # The entry point binary $out/bin/racket is codesigned at least once. The + # following error is triggered as a result. + # (error 'add-ad-hoc-signature "file already has a signature") + # We always remove the existing signature then call add-ad-hoc-signature to + # circumvent this error. + ./force-remove-codesign-then-add.patch ]; preConfigure = '' @@ -90,10 +97,34 @@ stdenv.mkDerivation rec { --replace /bin/rm ${coreutils}/bin/rm \ --replace /bin/true ${coreutils}/bin/true done + + # The configure script forces using `libtool -o` as AR on Darwin. But, the + # `-o` option is only available from Apple libtool. GNU ar works here. + substituteInPlace src/ChezScheme/zlib/configure \ + --replace 'ARFLAGS="-o"' 'AR=ar; ARFLAGS="rc"' + mkdir src/build cd src/build - gappsWrapperArgs+=("--prefix" "LD_LIBRARY_PATH" ":" ${LD_LIBRARY_PATH}) + '' + lib.optionalString stdenv.isLinux '' + gappsWrapperArgs+=("--prefix" "LD_LIBRARY_PATH" ":" ${libPath}) + '' + lib.optionalString stdenv.isDarwin '' + gappsWrapperArgs+=("--prefix" "DYLD_LIBRARY_PATH" ":" ${libPath}) + '' + ; + + preBuild = lib.optionalString stdenv.isDarwin '' + # Cannot set DYLD_LIBRARY_PATH as an attr of this drv, becasue dynamic + # linker environment variables like this are purged. + # See: https://apple.stackexchange.com/a/212954/167199 + + # Make builders feed it to dlopen(...). Do not expose all of $libPath to + # DYLD_LIBRARY_PATH as the order of looking up symbols like + # `__cg_jpeg_resync_to_restart` will be messed up. Our libJPEG.dyllib + # expects it from our libTIFF.dylib, but instead it could not be found from + # the system `libTIFF.dylib`. DYLD_FALLBACK_LIBRARY_PATH has its own problem + # , too. + export DYLD_FALLBACK_LIBRARY_PATH="${libPath}" ''; shared = if stdenv.isDarwin then "dylib" else "shared"; @@ -119,6 +150,6 @@ stdenv.mkDerivation rec { homepage = "https://racket-lang.org/"; license = with licenses; [ asl20 /* or */ mit ]; maintainers = with maintainers; [ kkallio henrytill vrthra ]; - platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" ]; + platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; }; } diff --git a/pkgs/development/interpreters/racket/force-remove-codesign-then-add.patch b/pkgs/development/interpreters/racket/force-remove-codesign-then-add.patch new file mode 100644 index 00000000000..c34457ceb95 --- /dev/null +++ b/pkgs/development/interpreters/racket/force-remove-codesign-then-add.patch @@ -0,0 +1,11 @@ +--- old/src/mac/codesign.rkt 2022-01-08 18:25:53.000000000 -0500 ++++ new/src/mac/codesign.rkt 2022-02-15 15:49:51.000000000 -0500 +@@ -17,6 +17,5 @@ + #:args (file) + file)) + +-(if remove? +- (remove-signature file) +- (add-ad-hoc-signature file)) ++(remove-signature file) ++(add-ad-hoc-signature file) diff --git a/pkgs/development/interpreters/racket/minimal.nix b/pkgs/development/interpreters/racket/minimal.nix index ac15cd24e50..e56945ed651 100644 --- a/pkgs/development/interpreters/racket/minimal.nix +++ b/pkgs/development/interpreters/racket/minimal.nix @@ -14,7 +14,7 @@ racket.overrideAttrs (oldAttrs: rec { as well as libraries that live in collections. In particular, raco and the pkg library are still bundled. ''; - platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; + platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; broken = false; # Minimal build does not require working FFI }; }) -- cgit 1.4.1