Skip to content

Commit 8bd680a

Browse files
authored
ci/release: Fix broken cross-compilation setup (#100)
Changes in the ecosystem since last release have broken the cross-compilation setup. Fix it again, use the 'cross' tool to cross-compile. Unfortunately, it seems that the musl build for Linux ARM64 doesn't work anymore so switching back to gnu for that target.
1 parent ebab554 commit 8bd680a

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Changed
2+
body: 'linux-arm64: Binary is no longer statically linked.'
3+
time: 2024-08-02T07:16:33.678855-07:00

.github/workflows/release.yml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,18 @@ jobs:
2424
- slug: linux-amd64
2525
target: x86_64-unknown-linux-musl
2626
os: ubuntu-latest
27-
extra_pkgs: musl-tools
27+
strip: x86_64-linux-musl-strip
2828

2929
- slug: linux-arm64
30-
target: aarch64-unknown-linux-musl
30+
target: aarch64-unknown-linux-gnu
3131
os: ubuntu-latest
32-
linker: aarch64-linux-musl-gcc
33-
musl-cross: aarch64-linux-musl-cross
34-
strip: aarch64-linux-musl-strip
32+
strip: aarch64-linux-gnu-strip
3533
no-build-std: true
3634

3735
- slug: linux-armv7
3836
target: armv7-unknown-linux-musleabihf
3937
os: ubuntu-latest
40-
linker: armv7l-linux-musleabihf-gcc
41-
musl-cross: armv7l-linux-musleabihf-cross
42-
strip: armv7l-linux-musleabihf-strip
38+
strip: arm-linux-musleabihf-strip
4339
no-build-std: true
4440

4541
# macOS
@@ -50,6 +46,10 @@ jobs:
5046
target: aarch64-apple-darwin
5147
os: macos-latest
5248

49+
env:
50+
CARGO: cargo
51+
CROSS_VERSION: v0.2.5
52+
5353
steps:
5454

5555
- name: Checkout code
@@ -74,33 +74,21 @@ jobs:
7474
--no-self-update
7575
- uses: Swatinem/rust-cache@v2
7676

77-
- name: Install extra packages
78-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.extra_pkgs != '' }}
79-
run: |
80-
sudo apt-get update
81-
sudo apt-get install -y ${{ matrix.extra_pkgs }}
82-
83-
- name: Install musl cross-compilation toolchain
84-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.musl-cross != '' }}
77+
- name: Install Cross
78+
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
8579
run: |
86-
mkdir -p "$HOME/.local"
87-
curl -o /tmp/musl.tgz https://musl.cc/${{ matrix.musl-cross }}.tgz
88-
tar -xzf /tmp/musl.tgz -C "$HOME/.local"
89-
echo "$HOME/.local/${{ matrix.musl-cross }}/bin" >> "$GITHUB_PATH"
90-
91-
- name: Configure linker
92-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.linker != '' }}
93-
run: |
94-
mkdir -p .cargo
95-
cat > .cargo/config.toml <<EOF
96-
[target.${{ matrix.target }}]
97-
linker = "${{ matrix.linker }}"
98-
EOF
80+
dir="$RUNNER_TEMP/cross-download"
81+
mkdir "$dir"
82+
echo "$dir" >> "$GITHUB_PATH"
83+
cd "$dir"
84+
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
85+
tar xf cross-x86_64-unknown-linux-musl.tar.gz
86+
echo "CARGO=cross" >> "$GITHUB_ENV"
9987
10088
- name: Build (build-std)
10189
if: ${{ !matrix.no-build-std }}
10290
run: |
103-
cargo build \
91+
${{ env.CARGO }} build \
10492
--target ${{ matrix.target }} \
10593
--locked \
10694
--release \
@@ -110,19 +98,30 @@ jobs:
11098
- name: Build (no-build-std)
11199
if: ${{ matrix.no-build-std }}
112100
run: |
113-
cargo build \
101+
${{ env.CARGO }} build \
114102
--target ${{ matrix.target }} \
115103
--locked \
116104
--release
117105
118-
- name: Strip binary
106+
- name: Strip release binary (macos)
107+
if: matrix.os == 'macos-latest'
119108
run: |
120109
strip=${{ matrix.strip || 'strip' }}
121110
exe=target/${{ matrix.target }}/release/restack
122111
echo "Before: $(wc -c < "$exe") bytes"
123112
"$strip" target/${{ matrix.target }}/release/restack
124113
echo "After: $(wc -c < "$exe") bytes"
125114
115+
- name: Strip release binary (cross)
116+
if: env.CARGO == 'cross'
117+
shell: bash
118+
run: |
119+
docker run --rm -v \
120+
"$PWD/target:/target:Z" \
121+
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
122+
"${{ matrix.strip }}" \
123+
"/target/${{ matrix.target }}/release/restack"
124+
126125
- name: Prepare archive
127126
run: |
128127
tar -cvzf restack-${{ matrix.slug }}.tar.gz \
@@ -132,7 +131,7 @@ jobs:
132131
- name: Upload archive
133132
uses: actions/upload-artifact@v4
134133
with:
135-
name: restack-archive
134+
name: restack-${{ matrix.slug }}
136135
path: restack-*.tar.gz
137136

138137
release:
@@ -169,7 +168,9 @@ jobs:
169168
- name: Download archives
170169
uses: actions/download-artifact@v4
171170
with:
172-
name: restack-archive
171+
path: .
172+
pattern: restack-*
173+
merge-multiple: true
173174

174175
- name: Determine version number (push)
175176
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

0 commit comments

Comments
 (0)