Skip to content

Commit 2a8fa3b

Browse files
committed
Refactor build
1 parent a2c12b9 commit 2a8fa3b

File tree

2 files changed

+69
-79
lines changed

2 files changed

+69
-79
lines changed

.github/workflows/rust-inner.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
architecture:
5+
description: "The ONE architecture to build for, e.g. amd64 or arm64"
6+
required: true
7+
type: string
8+
features:
9+
required: true
10+
type: string
11+
profile:
12+
required: true
13+
type: string
14+
15+
jobs:
16+
build-rust:
17+
runs-on: ${{ inputs.architecture == 'arm64' && 'ubuntu-22.04-arm' || 'ubuntu-22.04' }}
18+
steps:
19+
- uses: actions/checkout@v5
20+
- name: Set profile ${{ inputs.profile }}
21+
env:
22+
PROFILE: ${{ inputs.profile }}
23+
run: |
24+
if [ "${PROFILE}" == "release" ]; then
25+
echo "profilestr=--release" >> $GITHUB_ENV
26+
elif [ "${PROFILE}" == "debug" ]; then
27+
echo "profilestr=" >> $GITHUB_ENV
28+
else
29+
echo "profilestr=--profile $PROFILE" >> $GITHUB_ENV
30+
fi
31+
- uses: Swatinem/rust-cache@v2
32+
with:
33+
key: ${{ inputs.architecture }}-${{ inputs.profile }}
34+
prefix-key: ${{ inputs.cache-version }}-rust-${{ inputs.features && format('features_{0}', inputs.features) || 'nofeatures' }} # Increase to invalidate old caches.
35+
- name: Build
36+
run: |
37+
OUT=$(cargo build --tests --bins --message-format=json ${{ inputs.features && format('--features {0}', inputs.features) }} ${{ env.profilestr }})
38+
TESTS=$(echo "$OUT" | jq -r 'select(.profile.test == true) | .executable | select(. != null)')
39+
mkdir -p testbinaries/
40+
for testbin in $TESTS; do
41+
mv -v $testbin testbinaries/
42+
done
43+
- name: Prepare bins
44+
run: |
45+
{
46+
echo 'bins<<EOF'
47+
find target/ -type d -name ${{ inputs.profile }} -exec find {} -maxdepth 1 -type f -executable \;
48+
echo EOF
49+
} >> "$GITHUB_ENV"
50+
- name: Upload (bins)
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: binaries-${{ inputs.arch }}-${{ inputs.features }}
54+
if-no-files-found: error
55+
path: |
56+
${{ env.bins }}
57+
- name: Upload (test, native only)
58+
if: inputs.arch == 'amd64'
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: testbinaries-${{ inputs.arch }}-${{ inputs.features }}
62+
if-no-files-found: error
63+
path: |
64+
testbinaries/*

.github/workflows/rust.yml

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -110,86 +110,12 @@ jobs:
110110
run: |
111111
echo "Arch: ${{ matrix.arch }}"
112112
echo "Features: ${{ matrix.features }}"
113-
- name: Set arch ${{ matrix.arch }}
114-
env:
115-
ARCH: ${{ matrix.arch }}
116-
run: |
117-
if [ "${ARCH}" == "arm64" ]; then
118-
echo "rustarch=aarch64-unknown-linux-gnu" >> $GITHUB_ENV
119-
elif [ "${ARCH}" == "amd64" ]; then
120-
echo "rustarch=x86_64-unknown-linux-gnu" >> $GITHUB_ENV
121-
else
122-
exit 1
123-
fi
124-
if [ "$(dpkg --print-architecture)" != "${ARCH}" ]; then
125-
echo "Cross-compiling to ${ARCH}."
126-
echo "is_cross=true" >> $GITHUB_ENV
127-
else
128-
echo "Natively compiling to ${ARCH}."
129-
echo "is_cross=false" >> $GITHUB_ENV
130-
fi
131-
- name: Set profile ${{ env.PROFILE }}
132-
env:
133-
PROFILE: ${{ env.PROFILE }}
134-
run: |
135-
if [ "${PROFILE}" == "release" ]; then
136-
echo "profilestr=--release" >> $GITHUB_ENV
137-
elif [ "${PROFILE}" == "debug" ]; then
138-
echo "profilestr=" >> $GITHUB_ENV
139-
else
140-
echo "profilestr=--profile $PROFILE" >> $GITHUB_ENV
141-
fi
142-
- uses: actions/checkout@v4
143-
# - uses: actions-rs/toolchain@v1
144-
# if: false
145-
# with:
146-
# toolchain: stable
147-
# override: true
148-
# target: ${{ env.rustarch }}
149-
- uses: Swatinem/rust-cache@v2
150-
with:
151-
key: ${{ matrix.arch }}-${{ env.PROFILE }}
152-
prefix-key: ${{ inputs.cache-version }}-rust-${{ matrix.features && format('features_{0}', matrix.features) || 'nofeatures' }} # Increase to invalidate old caches.
153-
- name: Build (cross to ${{ matrix.arch }})
154-
if: env.is_cross == 'true'
155-
uses: actions-rs/cargo@v1
156-
with:
157-
use-cross: ${{ env.is_cross }}
158-
command: build
159-
args: --target ${{ env.rustarch }} ${{ matrix.features && format('--features {0}', matrix.features) }} ${{ env.profilestr }}
160-
- name: Build (native)
161-
if: env.is_cross == 'false'
162-
run: |
163-
OUT=$(cargo build --tests --bins --message-format=json --target ${{ env.rustarch }} ${{ matrix.features && format('--features {0}', matrix.features) }} ${{ env.profilestr }})
164-
TESTS=$(echo "$OUT" | jq -r 'select(.profile.test == true) | .executable | select(. != null)')
165-
mkdir -p testbinaries/
166-
for testbin in $TESTS; do
167-
mv -v $testbin testbinaries/
168-
done
169-
- name: Prepare bins
170-
env:
171-
PROFILE: ${{ env.PROFILE }}
172-
run: |
173-
{
174-
echo 'bins<<EOF'
175-
find target/ -type d -name ${{ env.PROFILE }} -exec find {} -maxdepth 1 -type f -executable \;
176-
echo EOF
177-
} >> "$GITHUB_ENV"
178-
- name: Upload (bins)
179-
uses: actions/upload-artifact@v4
180-
with:
181-
name: binaries-${{ matrix.arch }}-${{ matrix.features }}
182-
if-no-files-found: error
183-
path: |
184-
${{ env.bins }}
185-
- name: Upload (test, native only)
186-
if: matrix.arch == 'amd64'
187-
uses: actions/upload-artifact@v4
113+
- name: Build
114+
uses: samply/github-workflows/.github/workflows/rust-inner.yml@faster
188115
with:
189-
name: testbinaries-${{ matrix.arch }}-${{ matrix.features }}
190-
if-no-files-found: error
191-
path: |
192-
testbinaries/*
116+
architecture: ${{ matrix.arch }}
117+
features: ${{ matrix.features }}
118+
profile: ${{ inputs.profile }}
193119

194120
test:
195121
name: Test

0 commit comments

Comments
 (0)