-
Notifications
You must be signed in to change notification settings - Fork 1
210 lines (184 loc) · 7.54 KB
/
Copy pathrust.yml
File metadata and controls
210 lines (184 loc) · 7.54 KB
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
# SPDX-License-Identifier: BSD-3-Clause
#
# Rust bindings CI. Mirrors what scripts/build-rust.ps1 does locally:
# codegen → cmake → fmt → clippy → test.
#
# The corpus tests skip themselves when Corpus/ is absent, which it is on a
# fresh clone, so this exercises the synthesised fixtures only. Corpus
# coverage stays a local / release-gate concern.
name: rust
# Deliberately not triggered on push: the vendored path builds the whole
# C++ library on three runners, which is too slow to want on every commit.
# It runs on pull requests, and on demand from the Actions tab.
on:
pull_request:
paths:
- 'bindings/rust/**'
- 'bindings/c/**'
- 'tools/codegen/**'
- 'include/whiteout/**'
- 'src/**'
- '.github/workflows/rust.yml'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
workspaces: bindings/rust
- name: Build whiteout_native
shell: bash
run: |
cmake -S . -B build-rust \
-DCMAKE_BUILD_TYPE=Release \
-DWHITEOUT_BUILD_C_BINDINGS=ON \
-DWHITEOUT_ENABLE_CASC=ON \
-DWHITEOUT_ENABLE_MPQ=ON \
-DWHITEOUT_BUILD_TESTS=OFF \
-DWHITEOUT_BUILD_EXAMPLES=OFF
cmake --build build-rust --config Release --target whiteout_c
# Multi-config generators nest the output by config; single-config
# ones do not. Everything here stays on relative paths inside bash,
# because Git-bash's $PWD on Windows is a POSIX path (/d/a/...) that
# native tooling cannot resolve — WHITEOUT_LIB_DIR is read by rustc,
# so it must be spelled the way the platform expects. GITHUB_WORKSPACE
# is already in native form on every runner.
- name: Locate and stage the native library
shell: bash
run: |
if [ -d build-rust/c-dist/Release ]; then
rel=build-rust/c-dist/Release
else
rel=build-rust/c-dist
fi
echo "WHITEOUT_LIB_DIR=$GITHUB_WORKSPACE/$rel" >> "$GITHUB_ENV"
# A dynamically-linked test binary needs the library on its
# search path: beside the executable on Windows, LD_/DYLD_
# elsewhere. Those two are only consulted by POSIX loaders, so
# $PWD is the right spelling for them.
mkdir -p bindings/rust/target/debug/deps
cp "$rel"/*whiteout_native* bindings/rust/target/debug/deps/ 2>/dev/null || true
echo "LD_LIBRARY_PATH=$PWD/$rel:${LD_LIBRARY_PATH:-}" >> "$GITHUB_ENV"
echo "DYLD_LIBRARY_PATH=$PWD/$rel:${DYLD_LIBRARY_PATH:-}" >> "$GITHUB_ENV"
- name: Check that the committed generated code is up to date
shell: bash
run: |
python -m pip install --quiet libclang
export PYTHONIOENCODING=utf-8
for backend in rust-abi-header rust-abi-source rust-math; do
python -m tools.codegen.codegen textures --backend "$backend"
done
for mod in textures mdx m2 m3 host casc mpq; do
python -m tools.codegen.codegen "$mod" --backend rust
done
# Regenerating must be a no-op. A diff here means someone edited
# generated code by hand, or the emitter changed without the
# output being refreshed.
git diff --exit-code -- bindings/rust/whiteout/src bindings/c/whiteout_v.h bindings/c/whiteout_v.cpp
continue-on-error: true # libclang availability varies per runner
- name: fmt
working-directory: bindings/rust
run: cargo fmt --all -- --check
# WHITEOUT_LIB_DIR is set, so build.rs links the library built above
# and the vendored path is not taken — but `vendored` is still a
# default feature, so its code is compiled and linted here.
- name: clippy
working-directory: bindings/rust
run: cargo clippy --all-targets --features casc,mpq -- -D warnings
- name: clippy (no default features)
working-directory: bindings/rust
run: cargo clippy --all-targets --no-default-features --features casc,mpq -- -D warnings
- name: test
working-directory: bindings/rust
run: cargo test --features casc,mpq
# Without the optional format features, to catch `#[cfg]` rot in the
# casc/mpq gating.
- name: test (core only)
working-directory: bindings/rust
run: cargo test --no-default-features
docs:
name: docs.rs build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
# docs.rs has no native library, so the crate must document without
# one. build.rs short-circuits on DOCS_RS; this proves it.
- name: cargo doc without a native library
working-directory: bindings/rust
env:
DOCS_RS: '1'
run: cargo doc --no-deps --all-features
msrv:
name: MSRV (rust-version)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Read the floor from Cargo.toml rather than repeating it here, so
# the two cannot drift.
- name: Resolve rust-version
id: msrv
shell: bash
run: |
v=$(grep -m1 'rust-version' bindings/rust/Cargo.toml | sed 's/[^0-9.]*//g')
echo "version=$v" >> "$GITHUB_OUTPUT"
echo "MSRV floor: $v"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.msrv.outputs.version }}
- name: Build whiteout_native
shell: bash
run: |
cmake -S . -B build-rust \
-DCMAKE_BUILD_TYPE=Release \
-DWHITEOUT_BUILD_C_BINDINGS=ON \
-DWHITEOUT_ENABLE_CASC=ON \
-DWHITEOUT_ENABLE_MPQ=ON \
-DWHITEOUT_BUILD_TESTS=OFF \
-DWHITEOUT_BUILD_EXAMPLES=OFF
cmake --build build-rust --config Release --target whiteout_c
# `cargo check` rather than `test`: the point is that the crate
# compiles on the floor, not that dev-dependencies do.
- name: check on the MSRV floor
working-directory: bindings/rust
env:
WHITEOUT_LIB_DIR: ${{ github.workspace }}/build-rust/c-dist
run: cargo check --no-default-features --features casc,mpq
package:
name: publishable crate builds unaided
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
# The acceptance test for publishing: stage the vendored sources,
# package, then build the extracted .crate with no repository and no
# environment — exactly what `cargo add whiteoutlib` gives a user.
- name: Stage and package
shell: bash
run: |
mkdir -p bindings/rust/whiteout/native
for item in CMakeLists.txt cmake include src bindings/c; do
mkdir -p "bindings/rust/whiteout/native/$(dirname "$item")"
cp -r "$item" "bindings/rust/whiteout/native/$item"
done
cd bindings/rust/whiteout
cargo package --allow-dirty --no-verify
- name: Build the extracted crate unaided
shell: bash
run: |
tmp=$(mktemp -d)
tar xzf bindings/rust/target/package/whiteoutlib-*.crate -C "$tmp"
cd "$tmp"/whiteoutlib-*
cargo build --features casc,mpq