-
Notifications
You must be signed in to change notification settings - Fork 50
272 lines (238 loc) · 9.63 KB
/
rust.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
on:
push:
branches: [main]
tags:
- "v*.*.*"
pull_request:
paths:
- "src/**"
- "Cargo.*"
workflow_dispatch:
name: CI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUST_LOG: info
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
CARGO_TERM_COLOR: always
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.80.0"
components: clippy,rustfmt
- uses: Swatinem/rust-cache@v2
- name: Check
run: cargo check
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --features=tui,recipe-generation --verbose -- --nocapture
- name: Format
run: cargo fmt --all -- --check
- uses: giraffate/clippy-action@v1
with:
reporter: "github-pr-check"
github_token: ${{ secrets.GITHUB_TOKEN }}
clippy_flags: "--all-targets --workspace"
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-22.04
- target: aarch64-unknown-linux-musl
os: ubuntu-22.04
use-cross: true
# - target: powerpc64le-unknown-linux-musl
# os: ubuntu-22.04
# use-cross: true
- target: powerpc64le-unknown-linux-gnu
os: ubuntu-22.04
use-cross: true
- target: x86_64-apple-darwin
os: macos-13
- target: aarch64-apple-darwin
os: macos-13
- target: x86_64-pc-windows-gnu
os: windows-2022
- target: x86_64-pc-windows-msvc
os: windows-2022
env:
#
# These are some environment variables that configure the build so that the binary size is reduced.
# Inspiration was taken from this blog: https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
# They're only enable it on main and releases.
#
# Enable Link Time Optimization (LTO) for our release builds. This increases link time but drastically reduces
# binary size.
CARGO_PROFILE_RELEASE_LTO: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && 'true' || 'false' }}
# Use a single code gen unit, this effectively disables parallel linking but ensures that everything is linked
# together in a single unit which reduces the file-size at the cost of link time.
# Default for a release build is 16
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && 1 || 16 }}
# Strip the binaries. This reduces the filesize of the final release.
CARGO_PROFILE_RELEASE_STRIP: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && 'symbols' || 'false' }}
# Optimize the binary for size. This reduces the filesize at the cost of a slower binary.
CARGO_PROFILE_OPT_LEVEL: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) && 's' || '0' }}
# Sets the default features which are always used also when `--no-default` is used.
REQUIRED_FEATURES: recipe-generation
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Extract version
shell: bash
id: metadata
run:
| # also call this step outside of $(...) to make sure the status code is propagated
${{ startsWith(matrix.os, 'windows') && 'choco install yq' || '' }}
yq '.package.version' Cargo.toml
echo "project-version=$(yq '.package.version' Cargo.toml)" >> $GITHUB_OUTPUT
- name: Assert version in release
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
if [[ "v${{ steps.metadata.outputs.project-version }}" != "${{ github.ref_name }}" ]]; then
echo ::error file=Cargo.toml::"Version mismatch: Cargo.toml: v${{ steps.metadata.outputs.project-version }} != ${{ github.ref_name }}"
exit 1
fi
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.80.0"
targets: ${{ matrix.target }}
- name: Install musl-gcc
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt install musl-tools
- name: Install gnu-openssl
if: matrix.target == 'powerpc64le-unknown-linux-gnu'
run: sudo apt install libssl-dev
- uses: Swatinem/rust-cache@v2
- name: Install cross
if: matrix.use-cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Add macOS cross build capability
if: matrix.target == 'aarch64-apple-darwin'
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
rustup default stable-aarch64-apple-darwin
- name: Show version information (Rust, cargo, GCC)
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Set build options
id: options
shell: bash
run: |
unset CARGO_BUILD_OPTIONS
case ${{ matrix.target }} in
*-musl) CARGO_BUILD_OPTIONS="--no-default-features --features rustls-tls" ;;
*) CARGO_BUILD_OPTIONS="" ;;
esac
echo "cargo-build-options=${CARGO_BUILD_OPTIONS}" >> "$GITHUB_OUTPUT"
# test only library unit tests and binary for arm-type targets
unset CARGO_TEST_OPTIONS
case ${{ matrix.target }} in
arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin rattler-build" ;;
esac
echo "cargo-test-options=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
- name: Build
run: >-
${{ matrix.use-cross && 'cross' || 'cargo' }}
build
--locked
--release
--features ${{ env.REQUIRED_FEATURES }}
--target=${{ matrix.target }}
${{ steps.options.outputs.cargo-build-options }}
- name: Run tests
shell: bash
if: matrix.target != 'aarch64-apple-darwin'
run: >-
${{ matrix.use-cross && 'cross' || 'cargo' }}
test
--release
--locked
--features ${{ env.REQUIRED_FEATURES }}
--target=${{ matrix.target }}
${{ steps.options.outputs.cargo-build-options }}
${{ steps.options.outputs.cargo-test-options }}
- name: Create tarball
id: package
shell: bash
run: |
PKG_BASENAME=rattler-build-${{ matrix.target }}
PKG_NAME=${PKG_BASENAME}${{ contains(matrix.target, 'pc-windows') && '.zip' || '.tar.gz' }}
ARCHIVE_DIR="pkg/${PKG_BASENAME}"
mkdir -p "${ARCHIVE_DIR}"
cp "target/${{ matrix.target }}/release/rattler-build${{ contains(matrix.target, 'pc-windows') && '.exe' || '' }}" "$ARCHIVE_DIR"
cp README.md LICENSE "$ARCHIVE_DIR"
pushd pkg >/dev/null
case ${{ matrix.target }} in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac;
popd >/dev/null
echo "pkg-name=${PKG_NAME}" >> $GITHUB_OUTPUT
echo pkg-path="${ARCHIVE_DIR}${{ contains(matrix.target, 'pc-windows') && '.zip' || '.tar.gz' }}" >> $GITHUB_OUTPUT
mkdir -p binaries
cp "target/${{ matrix.target }}/release/rattler-build${{ contains(matrix.target, 'pc-windows') && '.exe' || '' }}" "binaries/rattler-build-${{ matrix.target }}${{ contains(matrix.target, 'pc-windows') && '.exe' || '' }}"
echo "binary-path=binaries/rattler-build-${{ matrix.target }}${{ contains(matrix.target, 'pc-windows') && '.exe' || '' }}" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package.outputs.pkg-name }}
path: ${{ steps.package.outputs.pkg-path }}
- name: Publish archives and packages
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: |
${{ steps.package.outputs.pkg-path }}
${{ steps.package.outputs.binary-path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create issue on failure
if: startsWith(github.ref, 'refs/tags/v') && failure()
uses: dacbd/create-issue-action@cdb57ab6ff8862aa09fee2be6ba77a59581921c2
with:
token: ${{ github.token }}
title: GitHub release failed
body: |
Creating a release failed. Please check the logs for more information.
[Failed Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
build-post:
name: Post-process
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set as latest release
if: startsWith(github.ref, 'refs/tags/v')
run: |
gh release edit "${{ github.ref_name }}" --draft=false
gh release edit "${{ github.ref_name }}" --latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}