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

Add support for Apple Silicon (arm64) binaries #46

Merged
merged 5 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,32 @@ jobs:
- uses: actions/checkout@v1

- name: Install Rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
rustup target install aarch64-apple-darwin
rustup target install x86_64-apple-darwin

- name: Build release binary
- name: Build x86_64 release binary
run: |
source $HOME/.cargo/env
cargo build --verbose --locked --release
cargo build --verbose --locked --release --target x86_64-apple-darwin

- name: Upload artifacts
- name: Upload x86_64 artifacts
uses: actions/upload-artifact@v1
with:
name: foreman-macos-x86_64
path: target/x86_64-apple-darwin/release/foreman

- name: Build arm64 release binary
run: |
source $HOME/.cargo/env
cargo build --verbose --locked --release --target aarch64-apple-darwin

- name: Upload arm64 artifacts
uses: actions/upload-artifact@v1
with:
name: foreman-macos
path: target/release/foreman
name: foreman-macos-arm64
path: target/arm64-apple-darwin/release/foreman

linux:
runs-on: ubuntu-latest
Expand Down
7 changes: 5 additions & 2 deletions src/artifact_choosing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#[cfg(target_os = "windows")]
static PLATFORM_KEYWORDS: &[&str] = &["win32", "win64", "windows"];

#[cfg(target_os = "macos")]
static PLATFORM_KEYWORDS: &[&str] = &["macos", "darwin"];
#[cfg(all(target_os = "macos", target_arch = "x86_64"))]
static PLATFORM_KEYWORDS: &[&str] = &["macos-x86_64", "darwin-x86_64", "macos", "darwin"];

#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
static PLATFORM_KEYWORDS: &[&str] = &["macos-arm64", "darwin-arm64", "macos-x86_64", "darwin-x86_64", "macos", "darwin"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming some of these won't work for M1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x86_64 apps work with Rosetta2 (with caveats), which most users will have installed, because we are in the transitory period right now https://support.apple.com/en-us/HT211861
The primary caveat is that dependencies installation can be tricky for x86_64. E.g. if x86_64 binary depends on OpenSSL, user would need to install x86_64 version of OpenSSL.
Thus we should prefer to use arm binaries.
If x86_64 binary has no runtime dependecies, it should work just fine if Rosetta2 is installed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think it's all good because foreman will try to find the first asset in that list, which will make it prioritize the correct specific binaries. Thanks for your contribution 👍


#[cfg(target_os = "linux")]
static PLATFORM_KEYWORDS: &[&str] = &["linux"];
Expand Down