Skip to content

Commit

Permalink
feat: universal builds for macOS (#1820)
Browse files Browse the repository at this point in the history
* Nightly build generates macOS universal binary.

For macOS (Darwin), some users are running on Intel silicon (x86_64),
some on Apple silicon (aarch64). The purpose of this commit is to
generate a universal binary of alr for macOS, so that users won't need
to specify which version they need -- the loader will select the
appropriate binary.

To do this, a new job 'build-macos-universal' runs after the 'build'
job has completed (which implies completion of its runs on macos-13
(x86_64) and macos-14 (aarch64)).

This job dowloads & unpacks the x86_64 build to x86_64/, and the
aarch64 build to aarch64/. It then copies aarch64/ to universal/ (so
as to include the additional information, and runs lipo to create the
universal binary in universal/bin/alr. The new binary has to be marked
as executable, don't know why.

alr-nightly-bin-universal-macos.zip is created and uploaded to the
release directory.

  * .github/workflows/nightly.yml (build-macos-universal): new.

* Release build generates macOS universal binary.

For macOS (Darwin), some users are running on Intel silicon (x86_64),
some on Apple silicon (aarch64). The purpose of this commit is to
generate a universal binary of alr for macOS, so that users won't need
to specify which version they need -- the loader will select the
appropriate binary.

To do this, a new job 'build-macos-universal' runs after the 'build'
job has completed (which implies completion of its runs on macos-13
(x86_64) and macos-latest (aarch64)).

This job dowloads & unpacks the latest prerelease x86_64 build to
x86_64/, and the latest prerelease aarch64 build to aarch64/. It then
runs lipo to create the universal binary in ./bin/alr. The new binary
has to be marked as executable, don't know why.

alr-<release]-bin-universal-macos.zip is created and uploaded to the
release directory.

  * .github/workflows/ci-macos.yml (build-macos-universal): new.

* Remove superseded investigative steps.

Remove two steps that were inserted to check that no
com.apple.quarantine attributes were applied when the individual
architecture builds were downloaded (none were applied).

  * .github/workflows/nightly.yml (build-macos-universal):
      (check x86_64 attributes): remove.
      (check aarch64 attributes): remove.
  • Loading branch information
simonjwright authored Jan 14, 2025
1 parent 09b3893 commit 3d280a5
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,67 @@ jobs:
asset_path: alr-bin-macos.zip
asset_name: alr-${{ steps.get_version.outputs.version-without-v }}-bin-${{ steps.get_arch.outputs.arch }}-macos.zip
asset_content_type: application/zip

build-macos-universal:
runs-on: macos-latest
needs: [build]
steps:
- name: Install Python 3.x (required for releaser)
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: download x86_64
uses: robinraju/release-downloader@v1
with:
fileName: '*-x86_64-macos.zip'
latest: true
preRelease: true
out-file-path: 'x86_64'
extract: true

- name: download aarch64
uses: robinraju/release-downloader@v1
with:
latest: true
preRelease: true
fileName: '*-aarch64-macos.zip'
out-file-path: 'aarch64'
extract: true

- name: Create universal binary
run: |
mkdir bin
lipo x86_64/bin/alr aarch64/bin/alr -create -output bin/alr
chmod +x bin/alr
cp aarch64/LICENSE.txt .
zip alr-bin-macos.zip bin/alr LICENSE.txt
# Release steps

# I think I have to run these first two again, because
# the previous uses are in a different job?

- name: Retrieve upload URL for the release
if: github.event_name == 'release'
id: get_release
uses: bruceadams/get-release@v1.3.2
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Get release version
id: get_version
if: github.event_name == 'release'
uses: battila7/get-version-action@v2

- name: Upload release assets
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: alr-bin-macos.zip
asset_name: alr-${{ steps.get_version.outputs.version-without-v }}-bin-universal-macos.zip
asset_content_type: application/zip

47 changes: 47 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
- name: Package binaries (macOS/x64)
if: startsWith(matrix.os, 'macos') && runner.arch == 'X64'
run: zip alr-nightly-bin-x86_64-macos.zip bin/alr* LICENSE.txt alr-*.txt

- name: Package binaries (macOS/arm64)
if: startsWith(matrix.os, 'macos') && runner.arch == 'ARM64'
run: zip alr-nightly-bin-aarch64-macos.zip bin/alr* LICENSE.txt alr-*.txt
Expand All @@ -113,3 +114,49 @@ jobs:
alr-nightly-*.zip
tag: nightly
rm: false

build-macos-universal:
runs-on: macos-latest
needs: [build]
steps:
- name: Install Python 3.x (required for releaser)
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: download x86_64
uses: robinraju/release-downloader@v1
with:
fileName: '*-x86_64-macos.zip'
latest: true
preRelease: true
out-file-path: 'x86_64'
extract: true

- name: download aarch64
uses: robinraju/release-downloader@v1
with:
latest: true
preRelease: true
fileName: '*-aarch64-macos.zip'
out-file-path: 'aarch64'
extract: true

- name: Create universal binary
run: |
mkdir universal
# copy extra files from aarch64 (and bin/alr, to be overwritten)
cp -pR aarch64/* universal
lipo x86_64/bin/alr aarch64/bin/alr -create -output universal/bin/alr
ls -l universal/bin/alr
chmod +x universal/bin/alr
(cd universal; zip ../alr-nightly-bin-universal-macos.zip bin/alr LICENSE.txt alr-*.txt)
- name: Upload to release
uses: pyTooling/Actions/releaser/composite@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: |
alr-nightly-bin-universal-macos.zip
tag: nightly
rm: false

0 comments on commit 3d280a5

Please sign in to comment.