From aee37e51f9080c1453c20e8a32f6d86fdc5443f0 Mon Sep 17 00:00:00 2001 From: Michal Rus Date: Fri, 2 Aug 2024 14:48:21 +0200 Subject: [PATCH] [LW-10808] Fix `*-darwin` builds --- nix/devshells.nix | 1 + nix/internal/any-darwin.nix | 6 ++++-- scripts/darwin-no-x-compile.sh | 21 +++++++++++++++++++++ scripts/rebuild-native-modules.sh | 19 +++---------------- 4 files changed, 29 insertions(+), 18 deletions(-) create mode 100755 scripts/darwin-no-x-compile.sh diff --git a/nix/devshells.nix b/nix/devshells.nix index fd95f026a1..51ea05a969 100644 --- a/nix/devshells.nix +++ b/nix/devshells.nix @@ -47,6 +47,7 @@ let darwin.apple_sdk.frameworks.AppKit darwin.cctools xcbuild + perl ] else [ internal.electronBin winePackages.minimal diff --git a/nix/internal/any-darwin.nix b/nix/internal/any-darwin.nix index a9867e707c..faf0a181f0 100644 --- a/nix/internal/any-darwin.nix +++ b/nix/internal/any-darwin.nix @@ -62,7 +62,7 @@ in rec { name = "daedalus-node_modules"; src = srcLockfiles; nativeBuildInputs = [ yarn nodejs ] - ++ (with pkgs; [ python3 pkgconfig jq darwin.cctools xcbuild ]); + ++ (with pkgs; [ python3 perl pkgconfig jq darwin.cctools xcbuild ]); buildInputs = (with pkgs.darwin; [ apple_sdk.frameworks.CoreServices apple_sdk.frameworks.AppKit @@ -80,6 +80,8 @@ in rec { patchShebangs . >/dev/null # a real lot of paths to patch, no need to litter logs + ${builtins.path { path = inputs.self + "/scripts/darwin-no-x-compile.sh"; }} + # And now, with correct shebangs, run the install scripts (we have to do that # semi-manually, because another `yarn install` will overwrite those shebangs…): find node_modules -type f -name 'package.json' | sort | xargs grep -F '"install":' | cut -d: -f1 | while IFS= read -r dependency ; do @@ -111,7 +113,7 @@ in rec { name = pname; src = srcWithoutNix; nativeBuildInputs = [ yarn nodejs daedalus-installer ] - ++ (with pkgs; [ python3 pkgconfig darwin.cctools xcbuild ]); + ++ (with pkgs; [ python3 perl pkgconfig darwin.cctools xcbuild ]); buildInputs = (with pkgs.darwin; [ apple_sdk.frameworks.CoreServices apple_sdk.frameworks.AppKit diff --git a/scripts/darwin-no-x-compile.sh b/scripts/darwin-no-x-compile.sh new file mode 100755 index 0000000000..760d326ab1 --- /dev/null +++ b/scripts/darwin-no-x-compile.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -o errexit +set -o pipefail + +# x86_64 cross-compilation won’t fly in this pure derivation: +if [[ $system == *darwin* ]]; then + if [[ $system == *aarch64* ]] ; then + changeFrom="x86_64" + changeTo="arm64" + else + changeFrom="arm64" + changeTo="x86_64" + fi + find node_modules/ -type f '(' -name '*.gyp' -o -name '*.gypi' ')' \ + | xargs grep -F "$changeFrom" | cut -d: -f1 | sort --unique \ + | while IFS= read -r file + do + sed -r "s/$changeFrom/$changeTo/g" -i "$file" + done +fi diff --git a/scripts/rebuild-native-modules.sh b/scripts/rebuild-native-modules.sh index a9daf99f75..1360ee5d6f 100755 --- a/scripts/rebuild-native-modules.sh +++ b/scripts/rebuild-native-modules.sh @@ -3,6 +3,8 @@ set -o errexit set -o pipefail +SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)" + # XXX: From the very beginning we have problems with `*.node` native # extensions being built against Node.js ABI, and not # Electron’s. Let’s solve this once and for all. @@ -20,22 +22,7 @@ nix run -L .#internal."${system:-x86_64-darwin}".common.patchElectronRebuild # XXX: Electron 24.2 requires c++17, not 14 (or old 1y): sed -r 's,std=c\+\+(14|1y),std=c++17,g' -i node_modules/usb/binding.gyp -# x86_64 cross-compilation won’t fly in this pure derivation: -if [[ $system == *darwin* ]]; then - if [[ $system == *aarch64* ]] ; then - changeFrom="x86_64" - changeTo="arm64" - else - changeFrom="arm64" - changeTo="x86_64" - fi - find node_modules/ -type f '(' -name '*.gyp' -o -name '*.gypi' ')' \ - | xargs grep -F "$changeFrom" | cut -d: -f1 | sort --unique \ - | while IFS= read -r file - do - sed -r "s/$changeFrom/$changeTo/g" -i "$file" - done -fi +"$SCRIPT_DIR"/darwin-no-x-compile.sh # TODO: do we really need to run `electron-rebuild` 3×?