Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: install arm brew on MacOS Arm to install libsodium #542

Merged
merged 8 commits into from
Dec 5, 2022
13 changes: 11 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ jobs:
architecture: ${{ matrix.node_arch }}
cache: "pnpm"

- name: Install Mac-OS Dependencies
if: contains(matrix.os, 'macos')
- name: Install Mac-OS x86_64 Dependencies
if: ${{ contains(matrix.os, 'macos') && matrix.ARCH == 'x86_64' }}
run: |
brew install libsodium gnutls

- name: Install Mac-OS arm64 Dependencies
if: ${{ contains(matrix.os, 'macos') && matrix.ARCH == 'arm64' }}
run: |
brew uninstall libsodium --force --ignore-dependencies
source ./script/macos-arm-deps.sh
echo "PATH=$PATH" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
echo "npm_config_target_arch=$npm_config_target_arch" >> $GITHUB_ENV

- name: Install Dependencies and Build
if: ${{ !matrix.docker }}
run: pnpm install
Expand Down
47 changes: 47 additions & 0 deletions script/macos-arm-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
set -e

#! Install arm-brew on x86 MacOS Arm
#! Based on https://github.com/Homebrew/discussions/discussions/2843#discussioncomment-2243610

bottle_tag="arm64_big_sur" # Macos 11 is big sure
dependencies="libsodium"

mkdir -p ~/arm-target/bin
mkdir -p ~/arm-target/brew-cache
export PATH="$HOME/arm-target/bin:$PATH"

# Download Homebrew under ~/arm-target
PREV_PWD="$PWD"
cd ~/arm-target
mkdir -p arm-homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C arm-homebrew
cd "$PREV_PWD"

# Add arm-brew binary
ln -sf ~/arm-target/arm-homebrew/bin/brew ~/arm-target/bin/arm-brew

# Homebrew env variables
export HOMEBREW_CACHE=~/arm-target/brew-cache
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1

# Install the given dependencies for the given bottle_tag
arm-brew fetch --deps --bottle-tag=$bottle_tag $dependencies |
grep -E "(Downloaded to:|Already downloaded:)" |
grep -E ".tar.gz" |
grep -v pkg-config |
awk '{ print $3 }' |
xargs -n 1 arm-brew install --force-bottle || true

# Install host version of pkg-config so we can call it in the build system
arm-brew install pkg-config || true

# Add the installed binaries/libraries to the path
export PATH="$HOME/arm-target/bin/:$PATH"
export PATH="$HOME/arm-target/lib/:$PATH"

# libsodium
SODIUM_PATH=$(~/arm-target/bin/pkg-config libsodium --libs-only-L | sed -e 's/-L//g') # print only -L and replace "-L" itself
export PATH="$SODIUM_PATH:$PATH"
export PKG_CONFIG_PATH="$SODIUM_PATH:$PKG_CONFIG_PATH"
export npm_config_target_arch=arm64