8
8
- master
9
9
schedule :
10
10
- cron : ' 00 01 * * *'
11
+
12
+ # The section is needed to drop write-all permissions that are granted on
13
+ # `schedule` event. By specifying any permission explicitly all others are set
14
+ # to none. By using the principle of least privilege the damage a compromised
15
+ # workflow can do (because of an injection or compromised third party tool or
16
+ # action) is restricted. Currently the worklow doesn't need any additional
17
+ # permission except for pulling the code. Adding labels to issues, commenting
18
+ # on pull-requests, etc. may need additional permissions:
19
+ #
20
+ # Syntax for this section:
21
+ # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
22
+ #
23
+ # Reference for how to assign permissions on a job-by-job basis:
24
+ # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
25
+ #
26
+ # Reference for available permissions that we can enable if needed:
27
+ # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
28
+ permissions :
29
+ # to fetch code (actions/checkout)
30
+ contents : read
31
+
11
32
jobs :
33
+ # Baseline testing across a number of different targets.
12
34
test :
13
- name : test
14
35
env :
15
36
# For some builds, we use cross to test on 32-bit and big-endian
16
37
# systems.
17
38
CARGO : cargo
18
39
# When CARGO is set to CROSS, TARGET is set to `--target matrix.target`.
40
+ # Note that we only use cross on Linux, so setting a target on a
41
+ # different OS will just use normal cargo.
19
42
TARGET :
43
+ # Bump this as appropriate. We pin to a version to make sure CI
44
+ # continues to work as cross releases in the past have broken things
45
+ # in subtle ways.
46
+ CROSS_VERSION : v0.2.5
20
47
# Make quickcheck run more tests for hopefully better coverage.
21
48
QUICKCHECK_TESTS : 100000
22
49
runs-on : ${{ matrix.os }}
23
50
strategy :
51
+ fail-fast : false
24
52
matrix :
25
53
build :
26
- - pinned
27
54
- stable
28
- - stable-32
29
- - stable-mips
30
- - wasm
31
55
- beta
32
56
- nightly
33
57
- macos
34
58
- win-msvc
35
59
- win-gnu
60
+ - stable-x86
61
+ - stable-aarch64
62
+ - stable-powerpc64
63
+ - stable-s390x
36
64
include :
37
- - build : pinned
38
- os : ubuntu-latest
39
- rust : 1.41.1
40
65
- build : stable
41
66
os : ubuntu-latest
42
67
rust : stable
43
- - build : stable-32
44
- os : ubuntu-latest
45
- rust : stable
46
- target : i686-unknown-linux-gnu
47
- - build : stable-mips
48
- os : ubuntu-latest
49
- rust : stable
50
- target : mips64-unknown-linux-gnuabi64
51
68
- build : beta
52
69
os : ubuntu-latest
53
70
rust : beta
@@ -63,10 +80,24 @@ jobs:
63
80
- build : win-gnu
64
81
os : windows-latest
65
82
rust : stable-x86_64-gnu
66
- - build : wasm
83
+ - build : stable-x86
67
84
os : ubuntu-latest
68
- rust : stable-x86_64-gnu
69
- wasm : true
85
+ rust : stable
86
+ target : i686-unknown-linux-gnu
87
+ # This is kind of a stand-in for Apple silicon since we can't currently
88
+ # use GitHub Actions with Apple silicon.
89
+ - build : stable-aarch64
90
+ os : ubuntu-latest
91
+ rust : stable
92
+ target : aarch64-unknown-linux-gnu
93
+ - build : stable-powerpc64
94
+ os : ubuntu-latest
95
+ rust : stable
96
+ target : powerpc64-unknown-linux-gnu
97
+ - build : stable-s390x
98
+ os : ubuntu-latest
99
+ rust : stable
100
+ target : s390x-unknown-linux-gnu
70
101
steps :
71
102
- name : Checkout repository
72
103
uses : actions/checkout@v3
@@ -75,83 +106,78 @@ jobs:
75
106
with :
76
107
toolchain : ${{ matrix.rust }}
77
108
- name : Use Cross
78
- if : matrix.target != ''
109
+ if : matrix.os == 'ubuntu-latest' && matrix. target != ''
79
110
run : |
80
- # We used to install 'cross' from master, but it kept failing. So now
81
- # we build from a known-good version until 'cross' becomes more stable
82
- # or we find an alternative. Notably, between v0.2.1 and current
83
- # master (2022-06-14), the number of Cross's dependencies has doubled.
84
- cargo install --bins --git https://github.com/rust-embedded/cross --tag v0.2.1
111
+ # In the past, new releases of 'cross' have broken CI. So for now, we
112
+ # pin it. We also use their pre-compiled binary releases because cross
113
+ # has over 100 dependencies and takes a bit to compile.
114
+ dir="$RUNNER_TEMP/cross-download"
115
+ mkdir "$dir"
116
+ echo "$dir" >> $GITHUB_PATH
117
+ cd "$dir"
118
+ curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
119
+ tar xf cross-x86_64-unknown-linux-musl.tar.gz
85
120
echo "CARGO=cross" >> $GITHUB_ENV
86
121
echo "TARGET=--target ${{ matrix.target }}" >> $GITHUB_ENV
87
- - name : Download Wasmtime
88
- if : matrix.wasm
89
- run : |
90
- rustup target add wasm32-wasi
91
- echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
92
- echo "RUSTFLAGS=-Ctarget-feature=+simd128" >> $GITHUB_ENV
93
- curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v0.32.0/wasmtime-v0.32.0-x86_64-linux.tar.xz
94
- tar xvf wasmtime-v0.32.0-x86_64-linux.tar.xz
95
- echo `pwd`/wasmtime-v0.32.0-x86_64-linux >> $GITHUB_PATH
96
- echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --wasm-features simd --" >> $GITHUB_ENV
97
122
- name : Show command used for Cargo
98
123
run : |
99
124
echo "cargo command is: ${{ env.CARGO }}"
100
125
echo "target flag is: ${{ env.TARGET }}"
101
126
- name : Show CPU info for debugging
102
127
if : matrix.os == 'ubuntu-latest'
103
128
run : lscpu
104
- - run : ${{ env.CARGO }} build --verbose $TARGET
105
- - run : ${{ env.CARGO }} build --verbose $TARGET --no-default-features
106
- - run : ${{ env.CARGO }} doc --verbose $TARGET
107
- # Our dev dependencies evolve more rapidly than we'd like, so only run
108
- # tests when we aren't pinning the Rust version.
109
- - if : matrix.build != 'pinned'
110
- name : Show byte order for debugging
129
+ - name : Basic build
130
+ run : ${{ env.CARGO }} build --verbose $TARGET
131
+ - name : Build docs
132
+ run : ${{ env.CARGO }} doc --verbose $TARGET
133
+ - name : Show byte order for debugging
111
134
run : ${{ env.CARGO }} test --verbose $TARGET byte_order -- --nocapture
112
- - if : matrix.build != 'pinned'
113
- name : Run tests under default configuration
114
- run : ${{ env.CARGO }} test --verbose $TARGET
115
- - if : matrix.build != 'pinned'
116
- name : Run tests with just alloc feature
117
- run : ${{ env.CARGO }} test --verbose --no-default-features --features alloc $TARGET
118
- - if : matrix.build == 'stable'
119
- name : Run under different SIMD configurations
120
- run : |
121
- set -x
122
-
123
- # Enable libc while using SIMD, libc won't be used.
124
- # (This is to ensure valid logic in the picking process.)
125
- cargo test --verbose --features libc
126
-
127
- preamble="--cfg memchr_disable_auto_simd"
135
+ - name : Run tests
136
+ run : cargo test --verbose
137
+ - name : Run with only 'alloc' enabled
138
+ run : cargo test --verbose --no-default-features --features alloc
139
+ - name : Run tests without any features enabled (core-only)
140
+ run : cargo test --verbose --no-default-features
141
+ - name : Run tests with miscellaneous features
142
+ run : cargo test --verbose --features logging
128
143
129
- # Force use of fallback without libc.
130
- RUSTFLAGS="$preamble" cargo test --verbose
131
-
132
- # Force use of libc.
133
- RUSTFLAGS="$preamble" cargo test --verbose --features libc
134
-
135
- preamble="$preamble --cfg memchr_runtime_simd"
136
- # Force use of fallback even when SIMD is enabled.
137
- RUSTFLAGS="$preamble" cargo test --verbose
138
-
139
- # For some reason, cargo seems to get confused which results in
140
- # link errors. So wipe the slate clean.
141
- cargo clean
142
- # Force use of sse2 only
143
- RUSTFLAGS="$preamble --cfg memchr_runtime_sse2" cargo test --verbose
144
-
145
- # ... and wipe it again. So weird.
146
- cargo clean
147
- # Force use of avx only
148
- RUSTFLAGS="$preamble --cfg memchr_runtime_avx" cargo test --verbose
149
- - if : matrix.build == 'nightly'
150
- name : Run benchmarks as tests
151
- run : cargo bench --manifest-path bench/Cargo.toml --verbose -- --test
144
+ # Setup and run tests on the wasm32-wasi target via wasmtime.
145
+ wasm :
146
+ runs-on : ubuntu-latest
147
+ env :
148
+ # The version of wasmtime to download and install.
149
+ WASMTIME_VERSION : 12.0.1
150
+ steps :
151
+ - name : Checkout repository
152
+ uses : actions/checkout@v3
153
+ - name : Install Rust
154
+ uses : dtolnay/rust-toolchain@master
155
+ with :
156
+ toolchain : stable
157
+ - name : Add wasm32-wasi target
158
+ run : rustup target add wasm32-wasi
159
+ - name : Download and install Wasmtime
160
+ run : |
161
+ echo "CARGO_BUILD_TARGET=wasm32-wasi" >> $GITHUB_ENV
162
+ echo "RUSTFLAGS=-Ctarget-feature=+simd128" >> $GITHUB_ENV
163
+ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
164
+ tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
165
+ echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
166
+ echo "CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime run --wasm-features simd --" >> $GITHUB_ENV
167
+ - name : Basic build
168
+ run : cargo build --verbose
169
+ - name : Run tests
170
+ run : cargo test --verbose
171
+ - name : Run with only 'alloc' enabled
172
+ run : cargo test --verbose --no-default-features --features alloc
173
+ - name : Run tests without any features enabled (core-only)
174
+ run : cargo test --verbose --no-default-features
152
175
153
- build-for-non_sse-target :
154
- name : build for non-SSE target
176
+ # This job uses a custom target file to build the memchr crate on x86-64
177
+ # but *without* SSE/AVX target features. This is a somewhat strange
178
+ # configuration, but it pops up now and then. Particularly in kernels that
179
+ # don't support SSE/AVX registers.
180
+ build-for-x86-64-but-non-sse-target :
155
181
runs-on : ubuntu-latest
156
182
steps :
157
183
- name : Checkout repository
@@ -163,25 +189,78 @@ jobs:
163
189
components : rust-src
164
190
- run : cargo build -Z build-std=core --target=src/tests/x86_64-soft_float.json --verbose --no-default-features
165
191
166
- test-with-miri :
167
- name : test with miri
192
+ # This job runs a stripped down version of CI to test the MSRV. The specific
193
+ # reason for doing this is that dev-dependencies tend to evolve more quickly.
194
+ # There isn't as tight of a control on them because, well, they're only used
195
+ # in tests and their MSRV doesn't matter as much.
196
+ #
197
+ # It is a bit unfortunate that our MSRV test is basically just "build it"
198
+ # and pass if that works. But usually MSRV is broken by compilation problems
199
+ # and not runtime behavior. So this is in practice good enough.
200
+ msrv :
168
201
runs-on : ubuntu-latest
169
202
steps :
170
203
- name : Checkout repository
171
204
uses : actions/checkout@v3
172
205
- name : Install Rust
173
206
uses : dtolnay/rust-toolchain@master
174
207
with :
208
+ toolchain : 1.60.0
209
+ - name : Basic build
210
+ run : cargo build --verbose
211
+ - name : Build docs
212
+ run : cargo doc --verbose
213
+
214
+ # Runs miri on memchr's test suite. This doesn't quite cover everything. Some
215
+ # tests (especially quickcheck) are disabled when building with miri because
216
+ # of how slow miri runs. But it still gives us decent coverage.
217
+ miri :
218
+ runs-on : ubuntu-latest
219
+ steps :
220
+ - name : Checkout repository
221
+ uses : actions/checkout@v3
222
+ - name : Install Rust
223
+ uses : dtolnay/rust-toolchain@master
224
+ with :
225
+ # We use nightly here so that we can use miri I guess?
175
226
toolchain : nightly
176
227
components : miri
177
- - name : Show CPU info for debugging
178
- run : lscpu
179
- - run : cargo miri test --verbose
180
- - run : cargo miri test --verbose --no-default-features
181
- - run : cargo miri test --verbose --features libc
228
+ - name : Run full test suite
229
+ run : cargo miri test --verbose
182
230
231
+ # Tests that memchr's benchmark suite builds and passes all tests.
232
+ rebar :
233
+ runs-on : ubuntu-latest
234
+ env :
235
+ # The version of wasmtime to download and install.
236
+ WASMTIME_VERSION : 12.0.1
237
+ steps :
238
+ - name : Checkout repository
239
+ uses : actions/checkout@v3
240
+ - name : Install Rust
241
+ uses : dtolnay/rust-toolchain@master
242
+ with :
243
+ toolchain : stable
244
+ - name : Add wasm32-wasi target
245
+ run : rustup target add wasm32-wasi
246
+ - name : Download and install Wasmtime
247
+ run : |
248
+ # Note that we don't have to set CARGO_BUILD_TARGET and other
249
+ # environment variables like we do for the `wasm` job. This is because
250
+ # `rebar` knows how to set them itself and only when running the wasm
251
+ # engines.
252
+ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v$WASMTIME_VERSION/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
253
+ tar xvf wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz
254
+ echo `pwd`/wasmtime-v$WASMTIME_VERSION-x86_64-linux >> $GITHUB_PATH
255
+ - name : Install rebar
256
+ run : cargo install --git https://github.com/BurntSushi/rebar rebar
257
+ - name : Build all rebar engines
258
+ run : rebar build
259
+ - name : Run all benchmarks as tests
260
+ run : rebar measure --test
261
+
262
+ # Tests that everything is formatted correctly.
183
263
rustfmt :
184
- name : rustfmt
185
264
runs-on : ubuntu-latest
186
265
steps :
187
266
- name : Checkout repository
@@ -193,7 +272,4 @@ jobs:
193
272
components : rustfmt
194
273
- name : Check formatting
195
274
run : |
196
- cargo fmt -- --check
197
- - name : Check formatting on benchmarks
198
- run : |
199
- cargo fmt --manifest-path bench/Cargo.toml -- --check
275
+ cargo fmt --all -- --check
0 commit comments