Skip to content

Commit f512d6e

Browse files
ci: Use Linebender standard CI. Add Cargo.lock. (linebender#357)
This is copied from Peniko with minor adjustments: * `RUST_STABLE_VER` is 1.79 as Kurbo needs fixes for 1.80. * `RUST_MIN_VER` is 1.65. * `RUST_MIN_VER_PKGS` checks `kurbo`. * `FEATURES_DEPENDING_ON_STD` added `schemars`. * Change the authors check in the copyright step. * Changes to handle not saving the cache when doing a merge_group. These come from Vello. The dependencies are all updated to their current versions and a `Cargo.lock` is now used in accordance with other Linebender projects.
1 parent 16cb9af commit f512d6e

File tree

5 files changed

+580
-68
lines changed

5 files changed

+580
-68
lines changed

.github/copyright.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# If there are new files with headers that can't match the conditions here,
4+
# then the files can be ignored by an additional glob argument via the -g flag.
5+
# For example:
6+
# -g "!src/special_file.rs"
7+
# -g "!src/special_directory"
8+
9+
# Check all the standard Rust source files
10+
output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Kurbo Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0 OR MIT$\n\n" --files-without-match --multiline -g "*.rs" .)
11+
12+
if [ -n "$output" ]; then
13+
echo -e "The following files lack the correct copyright header:\n"
14+
echo $output
15+
echo -e "\n\nPlease add the following header:\n"
16+
echo "// Copyright $(date +%Y) the Kurbo Authors"
17+
echo "// SPDX-License-Identifier: Apache-2.0 OR MIT"
18+
echo -e "\n... rest of the file ...\n"
19+
exit 1
20+
fi
21+
22+
echo "All files have correct copyright headers."
23+
exit 0
24+

.github/workflows/ci.yml

+199-59
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,268 @@
1+
env:
2+
# We aim to always test with the latest stable Rust toolchain, however we pin to a specific
3+
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
4+
# come automatically. If the version specified here is no longer the latest stable version,
5+
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
6+
RUST_STABLE_VER: "1.79" # In quotes because otherwise (e.g.) 1.70 would be interpreted as 1.7
7+
# The purpose of checking with the minimum supported Rust toolchain is to detect its staleness.
8+
# If the compilation fails, then the version specified here needs to be bumped up to reality.
9+
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
10+
# plus all the README.md files of the affected packages.
11+
RUST_MIN_VER: "1.65"
12+
# List of packages that will be checked with the minimum supported Rust version.
13+
# This should be limited to packages that are intended for publishing.
14+
RUST_MIN_VER_PKGS: "-p kurbo"
15+
# List of features that depend on the standard library and will be excluded from no_std checks.
16+
FEATURES_DEPENDING_ON_STD: "std,default,schemars"
17+
18+
19+
# Rationale
20+
#
21+
# We don't run clippy with --all-targets because then even --lib and --bins are compiled with
22+
# dev dependencies enabled, which does not match how they would be compiled by users.
23+
# A dev dependency might enable a feature that we need for a regular dependency,
24+
# and checking with --all-targets would not find our feature requirements lacking.
25+
# This problem still applies to cargo resolver version 2.
26+
# Thus we split all the targets into two steps, one with --lib --bins
27+
# and another with --tests --benches --examples.
28+
# Also, we can't give --lib --bins explicitly because then cargo will error on binary-only packages.
29+
# Luckily the default behavior of cargo with no explicit targets is the same but without the error.
30+
#
31+
# We use cargo-hack for a similar reason. Cargo's --workspace will do feature unification across
32+
# the whole workspace. While cargo-hack will instead check each workspace package separately.
33+
#
34+
# Using cargo-hack also allows us to more easily test the feature matrix of our packages.
35+
# We use --each-feature & --optional-deps which will run a separate check for every feature.
36+
#
37+
# The MSRV jobs run only cargo check because different clippy versions can disagree on goals and
38+
# running tests introduces dev dependencies which may require a higher MSRV than the bare package.
39+
#
40+
# For no_std checks we target x86_64-unknown-none, because this target doesn't support std
41+
# and as such will error out if our dependency tree accidentally tries to use std.
42+
# https://doc.rust-lang.org/stable/rustc/platform-support/x86_64-unknown-none.html
43+
#
44+
# We don't save caches in the merge-group cases, because those caches will never be re-used (apart
45+
# from the very rare cases where there are multiple PRs in the merge queue).
46+
# This is because GitHub doesn't share caches between merge queues and `main`.
47+
148
name: CI
249

350
on:
51+
pull_request:
52+
merge_group:
53+
# We run on push, even though the commit is the same as when we ran in merge_group.
54+
# This allows the cache to be primed.
55+
# See https://github.com/orgs/community/discussions/66430
456
push:
557
branches:
658
- main
7-
pull_request:
859

960
jobs:
10-
rustfmt:
11-
runs-on: ubuntu-latest
61+
fmt:
1262
name: cargo fmt
63+
runs-on: ubuntu-latest
1364
steps:
14-
- uses: actions/checkout@v3
65+
- uses: actions/checkout@v4
1566

1667
- name: install stable toolchain
1768
uses: dtolnay/rust-toolchain@master
1869
with:
19-
toolchain: "stable"
70+
toolchain: ${{ env.RUST_STABLE_VER }}
2071
components: rustfmt
2172

2273
- name: cargo fmt
23-
run: cargo fmt --all -- --check
74+
run: cargo fmt --all --check
2475

25-
test-stable:
76+
- name: install ripgrep
77+
run: |
78+
sudo apt update
79+
sudo apt install ripgrep
80+
81+
- name: check copyright headers
82+
run: bash .github/copyright.sh
83+
84+
clippy-stable:
85+
name: cargo clippy
2686
runs-on: ${{ matrix.os }}
2787
strategy:
2888
matrix:
29-
os: [macOS-latest, windows-2019, ubuntu-latest]
30-
name: cargo clippy+test
89+
os: [windows-latest, macos-latest, ubuntu-latest]
3190
steps:
32-
- uses: actions/checkout@v3
91+
- uses: actions/checkout@v4
92+
93+
- name: restore cache
94+
uses: Swatinem/rust-cache@v2
95+
with:
96+
save-if: ${{ github.event_name != 'merge_group' }}
3397

3498
- name: install stable toolchain
3599
uses: dtolnay/rust-toolchain@master
36100
with:
37-
toolchain: "stable"
101+
toolchain: ${{ env.RUST_STABLE_VER }}
102+
targets: x86_64-unknown-none
38103
components: clippy
39104

40-
- run: rustup target add thumbv7m-none-eabi
105+
- name: install cargo-hack
106+
uses: taiki-e/install-action@v2
107+
with:
108+
tool: cargo-hack
109+
110+
- name: cargo clippy (no_std)
111+
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target x86_64-unknown-none -- -D warnings
41112

42113
- name: cargo clippy
43-
run: cargo clippy --all-features --all-targets -- -D warnings
114+
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features std -- -D warnings
44115

45-
- name: cargo test
46-
run: cargo test --all-features
116+
- name: cargo clippy (auxiliary)
117+
run: cargo hack clippy --workspace --locked --optional-deps --each-feature --features std --tests --benches --examples -- -D warnings
47118

48-
- name: Build with no default features
49-
# Use no-std target to ensure we don't link to std.
50-
run: cargo build --no-default-features --features libm --target thumbv7m-none-eabi
119+
clippy-stable-wasm:
120+
name: cargo clippy (wasm32)
121+
runs-on: ubuntu-latest
122+
steps:
123+
- uses: actions/checkout@v4
51124

52-
- name: cargo test --features=serde
53-
run: cargo test --features=serde
125+
- name: restore cache
126+
uses: Swatinem/rust-cache@v2
127+
with:
128+
save-if: ${{ github.event_name != 'merge_group' }}
54129

55-
test-stable-wasm:
130+
- name: install stable toolchain
131+
uses: dtolnay/rust-toolchain@master
132+
with:
133+
toolchain: ${{ env.RUST_STABLE_VER }}
134+
targets: wasm32-unknown-unknown
135+
components: clippy
136+
137+
- name: install cargo-hack
138+
uses: taiki-e/install-action@v2
139+
with:
140+
tool: cargo-hack
141+
142+
- name: cargo clippy
143+
run: cargo hack clippy --workspace --locked --target wasm32-unknown-unknown --optional-deps --each-feature --features std -- -D warnings
144+
145+
- name: cargo clippy (auxiliary)
146+
run: cargo hack clippy --workspace --locked --target wasm32-unknown-unknown --optional-deps --each-feature --features std --tests --benches --examples -- -D warnings
147+
148+
test-stable:
149+
name: cargo test
56150
runs-on: ${{ matrix.os }}
57151
strategy:
58152
matrix:
59-
os: [macOS-latest, windows-2019, ubuntu-latest]
60-
61-
name: cargo clippy+test (wasm32)
153+
os: [windows-latest, macos-latest, ubuntu-latest]
62154
steps:
63-
- uses: actions/checkout@v3
155+
- uses: actions/checkout@v4
156+
157+
- name: restore cache
158+
uses: Swatinem/rust-cache@v2
159+
with:
160+
save-if: ${{ github.event_name != 'merge_group' }}
64161

65162
- name: install stable toolchain
66163
uses: dtolnay/rust-toolchain@master
67164
with:
68-
toolchain: "stable"
69-
target: wasm32-unknown-unknown
70-
components: clippy
165+
toolchain: ${{ env.RUST_STABLE_VER }}
71166

72-
- name: cargo clippy
73-
run: cargo clippy --all-features --all-targets --target wasm32-unknown-unknown -- -D warnings
74-
75-
# TODO: Find a way to make tests work. Until then the tests are merely compiled.
76-
- name: cargo test compile
77-
run: cargo test --all-features --no-run --target wasm32-unknown-unknown
167+
- name: cargo test
168+
run: cargo test --workspace --locked --all-features
78169

79-
test-msrv:
170+
test-stable-wasm:
171+
name: cargo test (wasm32)
80172
runs-on: ubuntu-latest
81-
name: cargo test msrv
82173
steps:
83-
- uses: actions/checkout@v3
174+
- uses: actions/checkout@v4
84175

85-
- name: install msrv toolchain
176+
- name: restore cache
177+
uses: Swatinem/rust-cache@v2
178+
with:
179+
save-if: ${{ github.event_name != 'merge_group' }}
180+
181+
- name: install stable toolchain
86182
uses: dtolnay/rust-toolchain@master
87183
with:
88-
toolchain: "1.65"
184+
toolchain: ${{ env.RUST_STABLE_VER }}
185+
targets: wasm32-unknown-unknown
89186

90-
- name: cargo test
91-
run: cargo test --all-features
187+
# TODO: Find a way to make tests work. Until then the tests are merely compiled.
188+
- name: cargo test compile
189+
run: cargo test --workspace --locked --target wasm32-unknown-unknown --all-features --no-run
92190

93-
test-nightly:
191+
check-msrv:
192+
name: cargo check (msrv)
94193
runs-on: ${{ matrix.os }}
95194
strategy:
96195
matrix:
97-
os: [macOS-latest, windows-2019, ubuntu-latest]
98-
name: cargo test nightly
196+
os: [windows-latest, macos-latest, ubuntu-latest]
99197
steps:
100-
- uses: actions/checkout@v3
198+
- uses: actions/checkout@v4
101199

102-
- name: install nightly toolchain
200+
- name: restore cache
201+
uses: Swatinem/rust-cache@v2
202+
with:
203+
save-if: ${{ github.event_name != 'merge_group' }}
204+
205+
- name: install msrv toolchain
103206
uses: dtolnay/rust-toolchain@master
104207
with:
105-
toolchain: "nightly"
208+
toolchain: ${{ env.RUST_MIN_VER }}
209+
targets: x86_64-unknown-none
106210

107-
- name: cargo test
108-
run: cargo test --all-features
211+
- name: install cargo-hack
212+
uses: taiki-e/install-action@v2
213+
with:
214+
tool: cargo-hack
109215

110-
check-docs:
111-
name: Docs
112-
runs-on: ${{ matrix.os }}
113-
strategy:
114-
matrix:
115-
os: [macOS-latest, windows-2019, ubuntu-latest]
216+
- name: cargo check (no_std)
217+
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --features libm --exclude-features ${{ env.FEATURES_DEPENDING_ON_STD }} --target x86_64-unknown-none
218+
219+
- name: cargo check
220+
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature --features std
221+
222+
check-msrv-wasm:
223+
name: cargo check (msrv) (wasm32)
224+
runs-on: ubuntu-latest
116225
steps:
117-
- uses: actions/checkout@v3
226+
- uses: actions/checkout@v4
118227

119-
- name: install stable toolchain
228+
- name: restore cache
229+
uses: Swatinem/rust-cache@v2
230+
with:
231+
save-if: ${{ github.event_name != 'merge_group' }}
232+
233+
- name: install msrv toolchain
120234
uses: dtolnay/rust-toolchain@master
121235
with:
122-
toolchain: "stable"
236+
toolchain: ${{ env.RUST_MIN_VER }}
237+
targets: wasm32-unknown-unknown
238+
239+
- name: install cargo-hack
240+
uses: taiki-e/install-action@v2
241+
with:
242+
tool: cargo-hack
243+
244+
- name: cargo check
245+
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature --features std
246+
247+
doc:
248+
name: cargo doc
249+
# NOTE: We don't have any platform specific docs in this workspace, so we only run on Ubuntu.
250+
# If we get per-platform docs (win/macos/linux/wasm32/..) then doc jobs should match that.
251+
runs-on: ubuntu-latest
252+
steps:
253+
- uses: actions/checkout@v4
254+
255+
- name: restore cache
256+
uses: Swatinem/rust-cache@v2
257+
with:
258+
save-if: ${{ github.event_name != 'merge_group' }}
259+
260+
- name: install nightly toolchain
261+
uses: dtolnay/rust-toolchain@nightly
123262

263+
# We test documentation using nightly to match docs.rs. This prevents potential breakages
124264
- name: cargo doc
125-
run: cargo doc --all-features --document-private-items
265+
run: cargo doc --workspace --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples
126266

127267
# If this fails, consider changing your text or adding something to .typos.toml
128268
typos:

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
/target
44
**/*.rs.bk
5-
Cargo.lock

0 commit comments

Comments
 (0)