Skip to content

Commit 931c1f2

Browse files
authored
fix(darwin-release): fix macOS release builds for x86_64 and aarch64 (#1737)
1 parent ebab105 commit 931c1f2

4 files changed

Lines changed: 103 additions & 54 deletions

File tree

.github/workflows/dre-release.yaml

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,77 @@ jobs:
2727
echo $STAGING_PRIVATE_KEY_PEM > ~/.config/dfx/identity/bootstrap-super-leader/identity.pem
2828
bazel test //rs/cli:unit_test --spawn_strategy=local --test_env=HOME=/home/runner
2929
30-
release:
30+
build-macos:
3131
needs: [test]
32+
runs-on: macos-14
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Determine Rust toolchain from rust-toolchain.toml
39+
id: rust
40+
run: |
41+
set -euo pipefail
42+
ver=$(awk -F\" '/^channel =/ {print $2}' rust-toolchain.toml)
43+
if [ -z "$ver" ]; then
44+
echo "Failed to parse Rust toolchain channel from rust-toolchain.toml" >&2
45+
exit 1
46+
fi
47+
echo "toolchain=$ver" >> "$GITHUB_OUTPUT"
48+
49+
- name: Set up Rust toolchain
50+
uses: dtolnay/rust-toolchain@master
51+
with:
52+
toolchain: ${{ steps.rust.outputs.toolchain }}
53+
54+
- name: Install protoc (protobuf) and export env
55+
run: |
56+
set -euo pipefail
57+
brew update
58+
brew install protobuf
59+
prefix=$(brew --prefix protobuf)
60+
echo "PROTOC=$prefix/bin/protoc" >> "$GITHUB_ENV"
61+
echo "PROTOC_INCLUDE=$prefix/include" >> "$GITHUB_ENV"
62+
"$prefix/bin/protoc" --version
63+
64+
- name: Add Rust targets
65+
run: |
66+
set -euo pipefail
67+
rustup target add aarch64-apple-darwin x86_64-apple-darwin
68+
69+
- name: Build dre (aarch64-apple-darwin)
70+
run: |
71+
set -euo pipefail
72+
cargo build --release -p dre --target aarch64-apple-darwin
73+
74+
- name: Upload macOS aarch64 artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: dre-aarch64-apple-darwin
78+
path: target/aarch64-apple-darwin/release/dre
79+
if-no-files-found: error
80+
81+
- name: Build dre (x86_64-apple-darwin) via Apple Silicon cross-linker
82+
run: |
83+
set -euo pipefail
84+
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
85+
export MACOSX_DEPLOYMENT_TARGET=11.0
86+
export CC_x86_64_apple_darwin="$(xcrun -f clang)"
87+
export CXX_x86_64_apple_darwin="$(xcrun -f clang++)"
88+
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER="$(xcrun -f clang)"
89+
export RUSTFLAGS="-C link-arg=-target -C link-arg=x86_64-apple-macos11.0 ${RUSTFLAGS:-}"
90+
cargo build --release -p dre --target x86_64-apple-darwin
91+
92+
- name: Upload macOS x86_64 artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: dre-x86_64-apple-darwin
96+
path: target/x86_64-apple-darwin/release/dre
97+
if-no-files-found: error
98+
99+
release:
100+
needs: [test, build-macos]
32101
runs-on:
33102
labels: dre-runner-custom
34103
container: ghcr.io/dfinity/dre/actions-runner:6413f2909a49329ecbf5371ee7ddf07a9799b625
@@ -76,17 +145,34 @@ jobs:
76145
- name: Build artifacts
77146
shell: bash
78147
run: |
79-
rustup target add x86_64-apple-darwin
80-
rustup target add aarch64-apple-darwin
81148
CARGO_BAZEL_REPIN=true bazel build --config=ci //rs/cli:dre
82-
cargo cross-x86
83-
cargo cross-aarch
84149
85150
mkdir -p release/artifacts
86151
cp --dereference bazel-out/k8-opt/bin/rs/cli/dre release/artifacts/dre-x86_64-unknown-linux
87-
cp target/x86_64-apple-darwin/release/dre release/artifacts/dre-x86_64-apple-darwin
88-
cp target/aarch64-apple-darwin/release/dre release/artifacts/dre-aarch64-apple-darwin
89152
153+
- name: Download macOS x86_64 artifact
154+
uses: actions/download-artifact@v4
155+
with:
156+
name: dre-x86_64-apple-darwin
157+
path: release/artifacts/
158+
159+
- name: Rename macOS x86_64 artifact
160+
shell: bash
161+
run: mv release/artifacts/dre release/artifacts/dre-x86_64-apple-darwin
162+
163+
- name: Download macOS aarch64 artifact
164+
uses: actions/download-artifact@v4
165+
with:
166+
name: dre-aarch64-apple-darwin
167+
path: release/artifacts/
168+
169+
- name: Rename macOS aarch64 artifact
170+
shell: bash
171+
run: mv release/artifacts/dre release/artifacts/dre-aarch64-apple-darwin
172+
173+
- name: Generate changelog
174+
shell: bash
175+
run: |
90176
git cliff --current --sort newest > release/CHANGELOG.md
91177
92178
- name: "🆕 📢 Prepare release"

docker/runner.Dockerfile

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,12 @@ RUN apt-get update && \
1212
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev libncurses5-dev libncursesw5-dev \
1313
xz-utils tk-dev libffi-dev liblzma-dev python-openssl protobuf-compiler libdbus-1-dev softhsm2 libsofthsm2 opensc -y
1414

15-
RUN curl -L https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz | tar -xJ && \
16-
mv zig-linux-x86_64-0.13.0 /zig
15+
RUN curl -L https://ziglang.org/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz | tar -xJ && \
16+
mv zig-x86_64-linux-0.15.1 /zig
1717
ENV PATH="$PATH:/zig"
1818

19-
RUN curl -L https://github.com/roblabla/MacOSX-SDKs/releases/download/13.3/MacOSX13.3.sdk.tar.xz | tar xJ
20-
ENV SDKROOT=/MacOSX13.3.sdk/
21-
22-
RUN mkdir -p openssl && \
23-
curl -o openssl/openssl-1.1.1w.tar.gz -L https://www.openssl.org/source/old/1.1.1/openssl-1.1.1w.tar.gz && \
24-
tar -xzvf openssl/openssl-1.1.1w.tar.gz -C openssl && \
25-
cd openssl/openssl-1.1.1w && \
26-
./config && \
27-
make && \
28-
make install
29-
RUN ln -s /usr/local/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1 && \
30-
ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1 && \
31-
ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 && \
32-
ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1 && \
33-
rm -rf openssl
34-
19+
RUN curl -L https://github.com/roblabla/MacOSX-SDKs/releases/download/macosx14.5/MacOSX14.5.sdk.tar.xz | tar xJ
20+
ENV SDKROOT=/MacOSX14.5.sdk/
3521

3622
ENV RYE_HOME="/opt/rye"
3723
ENV PATH="$RYE_HOME/shims:$PATH"
@@ -100,4 +86,4 @@ ENV PATH="/home/runner/.cargo/bin:$PATH"
10086
ENV PATH="$PATH:/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/"
10187
ENV CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=rust-lld
10288

103-
RUN cargo install --quiet cargo-zigbuild && rustup toolchain install 1.85.0 && cargo +1.85.0 install git-cliff
89+
RUN cargo install --quiet cargo-zigbuild && rustup toolchain install 1.86.0 && cargo +1.86.0 install git-cliff

rs/cli/README.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ sudo ln -s /usr/local/homebrew/Cellar/openssl@3/3.0.8 /usr/local/opt/openssl@3
3434
cargo install --git https://github.com/dfinity/dre.git dre
3535
```
3636

37-
Make sure you have `libssl.so.1.1` on your system (Ubuntu 22.04 and later
38-
will not carry it). See below under *Troubleshooting* to get that going.
39-
4037
## Usage
4138

4239
```shell
@@ -45,27 +42,3 @@ dre --help
4542

4643
## Troubleshooting
4744

48-
If you get an error like (observed on ubuntu 22.04)
49-
50-
``` shell
51-
...ic-admin: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
52-
```
53-
54-
you will need to install libssl 1.1.x. A simple solution is to install it from source directly from the OpenSSL website
55-
https://www.openssl.org/source/.
56-
57-
Once downloaded and extracted, you can install it by running
58-
59-
``` shell
60-
./config
61-
make
62-
make test
63-
sudo make install
64-
# The following adds the libraries to your system
65-
# path, where Cargo will look for them.
66-
sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
67-
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1
68-
# If you would rather not modify anything under /usr,
69-
# you can instead set the LD_LIBRARY_PATH= variable
70-
# to /usr/local in your ~/.bashrc.
71-
```

rs/cli/src/store.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ impl Store {
170170

171171
async fn download_ic_admin(&self, version: &str, path: &PathBuf) -> anyhow::Result<()> {
172172
let url = if std::env::consts::OS == "macos" {
173-
format!("https://download.dfinity.systems/ic/{version}/binaries/x86_64-darwin/ic-admin.gz")
173+
let darwin_arch = match std::env::consts::ARCH {
174+
"aarch64" => "aarch64-darwin",
175+
_ => "x86_64-darwin",
176+
};
177+
format!("https://download.dfinity.systems/ic/{version}/binaries/{darwin_arch}/ic-admin.gz")
174178
} else {
175179
format!("https://download.dfinity.systems/ic/{version}/binaries/x86_64-linux/ic-admin.gz")
176180
};

0 commit comments

Comments
 (0)