forked from prefix-dev/rattler-build
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (171 loc) · 6.06 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
on:
push:
branches: [main]
tags:
- 'v*.*.*'
pull_request:
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.73.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 --all-features --verbose -- --nocapture
- name: Format
run: cargo fmt --all -- --check
- uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-check'
github_token: ${{ secrets.GITHUB_TOKEN }}
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: 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
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Extract version
shell: bash
id: metadata
run: |
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.73.0'
targets: ${{ matrix.target }}
- name: Install musl-gcc
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt install musl-tools
- 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
--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 --locked --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-v${{ steps.metadata.outputs.project-version }}-${{ 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}" >> $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@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: |
${{ steps.package.outputs.pkg-path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}