Skip to content

Commit

Permalink
Build 64-bit universal binaries on macos (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
pathorn committed Dec 19, 2023
1 parent 1388734 commit 1f964d2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
[target.x86_64-apple-darwin]
linker = "x86_64-apple-darwin14-clang"
ar = "x86_64-apple-darwin14-ar"
[target.aarch64-apple-darwin]
linker = "arm64-apple-darwin14-clang"
ar = "arm64-apple-darwin14-ar"
[target.arm64-apple-darwin]
linker = "arm64-apple-darwin14-clang"
ar = "arm64-apple-darwin14-ar"
42 changes: 30 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Rust
uses: ATiltedTree/setup-rust@v1
with:
targets: x86_64-apple-darwin x86_64-unknown-linux-musl
targets: x86_64-apple-darwin x86_64-unknown-linux-musl aarch64-apple-darwin
rust-version: stable

# Use the v1 of this action
Expand All @@ -38,12 +38,21 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.0

- name: Build for Linux
- name: Build for x86 Linux
run: cargo build --release --target x86_64-unknown-linux-musl

- name: Build for MacOSX
- name: Build for x86 macOS
run: cargo build --release --target x86_64-apple-darwin

- name: Build for ARM macOS
run: cargo build --release --target aarch64-apple-darwin
env:
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER: aarch64-apple-darwin21.4-clang
CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS: -Car=aarch64-apple-darwin21.4-ar,-Clink-arg=-undefined,-Clink-arg=dynamic_lookup

- name: Build for Universal macOS
run: lipo -create -output target/deepctl-macos target/x86_64-apple-darwin/release/deepctl target/aarch64-apple-darwin/release/deepctl

- uses: actions/upload-artifact@v3
with:
name: deepctl-linux
Expand All @@ -52,7 +61,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: deepctl-macos
path: target/x86_64-apple-darwin/release/deepctl
path: target/deepctl-macos

release:
name: Release
Expand All @@ -71,7 +80,7 @@ jobs:
- name: Setup Rust
uses: ATiltedTree/setup-rust@v1
with:
targets: x86_64-apple-darwin x86_64-unknown-linux-musl
targets: x86_64-apple-darwin x86_64-unknown-linux-musl aarch64-apple-darwin
rust-version: stable

# Use the v1 of this action
Expand All @@ -92,11 +101,20 @@ jobs:
run: cargo install apple-codesign

# Build your code for apple-darwin based release
- name: Build for MacOSX
- name: Build for x86 macOS
run: cargo build --release --target x86_64-apple-darwin

- name: Build for ARM macOS
run: cargo build --release --target aarch64-apple-darwin
env:
CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER: aarch64-apple-darwin21.4-clang
CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS: -Car=aarch64-apple-darwin21.4-ar,-Clink-arg=-undefined,-Clink-arg=dynamic_lookup

- name: Build for Universal macOS
run: lipo -create -output target/deepctl-macos target/x86_64-apple-darwin/release/deepctl target/aarch64-apple-darwin/release/deepctl

# Build your code for apple-darwin based release
- name: Build for Linux
- name: Build for x86 Linux
run: cargo build --release --target x86_64-unknown-linux-musl

- name: Get secrets
Expand All @@ -110,21 +128,21 @@ jobs:
echo $SIGNING_CERTIFICATE | base64 -di > signing_certificate.p12
- name: Sign the MacOS binary
run: |
ls -la target/*/release/deepctl
ls -la target/*/release/deepctl target/deepctl-macos
echo "Signing the MacOS binary"
rcodesign sign \
--p12-file signing_certificate.p12 --p12-password-file cert_password \
--code-signature-flags runtime \
target/x86_64-apple-darwin/release/deepctl
target/deepctl-macos
echo "Zipping"
zip target/x86_64-apple-darwin/release/deepctl.zip target/x86_64-apple-darwin/release/deepctl
zip target/deepctl-macos.zip target/deepctl-macos
echo "Notarizing"
rcodesign notary-submit \
--api-key-path app_store_connect.json \
--wait \
target/x86_64-apple-darwin/release/deepctl.zip
target/deepctl-macos.zip
echo "Done notarizing"
- name: Cleanup secrets
Expand All @@ -137,7 +155,7 @@ jobs:
- name: Prepare Release
run: |
mkdir release
cp target/x86_64-apple-darwin/release/deepctl release/deepctl-macos
cp target/deepctl-macos release/deepctl-macos
cp target/x86_64-unknown-linux-musl/release/deepctl release/deepctl-linux
- name: Release
Expand Down

0 comments on commit 1f964d2

Please sign in to comment.