Skip to content

Commit

Permalink
[LW-10808] Fix *-darwin builds
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrus committed Aug 2, 2024
1 parent b822e4f commit aee37e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let
darwin.apple_sdk.frameworks.AppKit
darwin.cctools
xcbuild
perl
] else [
internal.electronBin
winePackages.minimal
Expand Down
6 changes: 4 additions & 2 deletions nix/internal/any-darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions scripts/darwin-no-x-compile.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 3 additions & 16 deletions scripts/rebuild-native-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand 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×?

Expand Down

0 comments on commit aee37e5

Please sign in to comment.