Skip to content

Commit 327bec4

Browse files
authored
Backport build.rs fixes to 2.x. (#376)
* Backport build.rs fixes to 2.x. * Fix warnings on recent Rust compilers. * Fix the build of timezone.rs on recent Rust versions. * Use docsrs instead of doc_cfg. * Update CI for 2.x. * Implement `change_time` for windows' `MetadataExt`.
1 parent e0af518 commit 327bec4

File tree

18 files changed

+262
-65
lines changed

18 files changed

+262
-65
lines changed

.cirrus.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# at revision 7f4774e76bd5cb9ccb7140d71ef9be9c16009cdf.
33

44
task:
5-
name: stable x86_64-unknown-freebsd-14-snap
5+
name: stable x86_64-unknown-freebsd-15-snap
66
freebsd_instance:
7-
image_family: freebsd-14-0-snap
7+
image_family: freebsd-15-0-snap
88
setup_script:
99
- curl https://sh.rustup.rs -sSf --output rustup.sh
1010
- sh rustup.sh --default-toolchain stable -y --profile=minimal
@@ -15,9 +15,9 @@ task:
1515
- cargo test --features=fs_utf8 --workspace
1616

1717
task:
18-
name: stable x86_64-unknown-freebsd-13
18+
name: stable x86_64-unknown-freebsd-14
1919
freebsd_instance:
20-
image_family: freebsd-13-2
20+
image_family: freebsd-14-0
2121
setup_script:
2222
- curl https://sh.rustup.rs -sSf --output rustup.sh
2323
- sh rustup.sh --default-toolchain stable -y --profile=minimal
@@ -28,9 +28,9 @@ task:
2828
- cargo test --features=fs_utf8 --workspace
2929

3030
task:
31-
name: stable x86_64-unknown-freebsd-12
31+
name: stable x86_64-unknown-freebsd-13
3232
freebsd_instance:
33-
image_family: freebsd-12-4
33+
image_family: freebsd-13-3
3434
setup_script:
3535
- curl https://sh.rustup.rs -sSf --output rustup.sh
3636
- sh rustup.sh --default-toolchain stable -y --profile=minimal

.github/actions/install-rust/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ inputs:
88
default: 'stable'
99

1010
runs:
11-
using: node16
11+
using: node20
1212
main: 'main.js'

.github/workflows/main.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Rustfmt
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
with:
1616
submodules: true
1717
- uses: ./.github/actions/install-rust
@@ -34,7 +34,7 @@ jobs:
3434
rust: beta
3535

3636
steps:
37-
- uses: actions/checkout@v3
37+
- uses: actions/checkout@v4
3838
with:
3939
submodules: true
4040
- uses: ./.github/actions/install-rust
@@ -88,7 +88,7 @@ jobs:
8888
rust: beta
8989

9090
steps:
91-
- uses: actions/checkout@v3
91+
- uses: actions/checkout@v4
9292
with:
9393
submodules: true
9494
- uses: ./.github/actions/install-rust
@@ -116,7 +116,7 @@ jobs:
116116
rust: nightly
117117

118118
steps:
119-
- uses: actions/checkout@v3
119+
- uses: actions/checkout@v4
120120
with:
121121
submodules: true
122122
- uses: ./.github/actions/install-rust
@@ -150,7 +150,7 @@ jobs:
150150
riscv64gc-unknown-linux-gnu
151151
arm-unknown-linux-gnueabihf
152152
aarch64-linux-android
153-
wasm32-wasi
153+
wasm32-wasip1
154154
- run: cargo check --workspace --all-targets --all-features --release -vv
155155
- run: cargo check --workspace --all-targets --all-features --release -vv --target=x86_64-unknown-linux-musl
156156
- run: cargo check --workspace --all-targets --all-features --release -vv --target=x86_64-unknown-linux-gnux32
@@ -164,7 +164,7 @@ jobs:
164164
- run: cargo check --workspace --all-targets --all-features --release -vv --target=riscv64gc-unknown-linux-gnu
165165
- run: cargo check --workspace --all-targets --all-features --release -vv --target=arm-unknown-linux-gnueabihf
166166
- run: cargo check --workspace --all-targets --all-features --release -vv --target=aarch64-linux-android
167-
- run: cd cap-std && cargo check --features=fs_utf8 --release -vv --target=wasm32-wasi
167+
- run: cd cap-std && cargo check --features=fs_utf8 --release -vv --target=wasm32-wasip1
168168

169169
check_cross_nightly_windows:
170170
name: Check Cross-Compilation on Rust nightly on Windows
@@ -178,7 +178,7 @@ jobs:
178178
rust: nightly
179179

180180
steps:
181-
- uses: actions/checkout@v3
181+
- uses: actions/checkout@v4
182182
with:
183183
submodules: true
184184
- uses: ./.github/actions/install-rust
@@ -201,7 +201,7 @@ jobs:
201201
runs-on: ${{ matrix.os }}
202202
strategy:
203203
matrix:
204-
build: [stable, windows-latest, windows-2019, macos-latest, macos-11, beta, ubuntu-20.04, aarch64-ubuntu]
204+
build: [stable, windows-latest, windows-2019, macos-latest, macos-12, beta, ubuntu-20.04, aarch64-ubuntu]
205205
include:
206206
- build: stable
207207
os: ubuntu-latest
@@ -215,8 +215,8 @@ jobs:
215215
- build: macos-latest
216216
os: macos-latest
217217
rust: stable
218-
- build: macos-11
219-
os: macos-11
218+
- build: macos-12
219+
os: macos-12
220220
rust: stable
221221
- build: beta
222222
os: ubuntu-latest
@@ -234,7 +234,7 @@ jobs:
234234
qemu_target: aarch64-linux-user
235235

236236
steps:
237-
- uses: actions/checkout@v3
237+
- uses: actions/checkout@v4
238238
with:
239239
submodules: true
240240
- uses: ./.github/actions/install-rust
@@ -291,7 +291,7 @@ jobs:
291291
rust: nightly
292292

293293
steps:
294-
- uses: actions/checkout@v3
294+
- uses: actions/checkout@v4
295295
with:
296296
submodules: true
297297
- uses: ./.github/actions/install-rust
@@ -311,7 +311,7 @@ jobs:
311311
rust: stable
312312

313313
steps:
314-
- uses: actions/checkout@v3
314+
- uses: actions/checkout@v4
315315
with:
316316
submodules: true
317317
- uses: ./.github/actions/install-rust
@@ -345,7 +345,7 @@ jobs:
345345
RUSTFLAGS: --cfg linux_raw
346346
RUSTDOCFLAGS: --cfg linux_raw
347347
steps:
348-
- uses: actions/checkout@v3
348+
- uses: actions/checkout@v4
349349
with:
350350
submodules: true
351351
- uses: ./.github/actions/install-rust
@@ -365,7 +365,7 @@ jobs:
365365
rust: 1.63
366366

367367
steps:
368-
- uses: actions/checkout@v3
368+
- uses: actions/checkout@v4
369369
with:
370370
submodules: true
371371
- uses: ./.github/actions/install-rust
@@ -381,7 +381,7 @@ jobs:
381381
name: Fuzz Targets
382382
runs-on: ubuntu-latest
383383
steps:
384-
- uses: actions/checkout@v3
384+
- uses: actions/checkout@v4
385385
with:
386386
submodules: true
387387
- uses: ./.github/actions/install-rust

build.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ fn main() {
1717
// https://doc.rust-lang.org/unstable-book/library-features/windows-file-type-ext.html
1818
use_feature_or_nothing("windows_file_type_ext");
1919

20+
// Cfgs that users may set.
21+
println!("cargo:rustc-check-cfg=cfg(racy_asserts)");
22+
2023
// Don't rerun this on changes other than build.rs, as we only depend on
2124
// the rustc version.
2225
println!("cargo:rerun-if-changed=build.rs");
@@ -26,6 +29,7 @@ fn use_feature_or_nothing(feature: &str) {
2629
if has_feature(feature) {
2730
use_feature(feature);
2831
}
32+
println!("cargo:rustc-check-cfg=cfg({})", feature);
2933
}
3034

3135
fn use_feature(feature: &str) {
@@ -34,7 +38,7 @@ fn use_feature(feature: &str) {
3438

3539
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
3640
fn has_feature(feature: &str) -> bool {
37-
can_compile(&format!(
41+
can_compile(format!(
3842
"#![allow(stable_features)]\n#![feature({})]",
3943
feature
4044
))
@@ -44,12 +48,11 @@ fn has_feature(feature: &str) -> bool {
4448
fn can_compile<T: AsRef<str>>(test: T) -> bool {
4549
use std::process::Stdio;
4650

47-
let out_dir = var("OUT_DIR").unwrap();
4851
let rustc = var("RUSTC").unwrap();
4952
let target = var("TARGET").unwrap();
5053

51-
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string,
52-
// as documented [here].
54+
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, as
55+
// documented [here].
5356
// [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
5457
let wrapper = var("RUSTC_WRAPPER")
5558
.ok()
@@ -68,8 +71,9 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
6871
.arg("--emit=metadata") // Do as little as possible but still parse.
6972
.arg("--target")
7073
.arg(target)
71-
.arg("--out-dir")
72-
.arg(out_dir); // Put the output somewhere inconsequential.
74+
.arg("-o")
75+
.arg("-")
76+
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)
7377

7478
// If Cargo wants to set RUSTFLAGS, use that.
7579
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {

cap-fs-ext/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ features = [
4040

4141
[dev-dependencies]
4242
cap-tempfile = { path = "../cap-tempfile" }
43+
44+
[lints.rust.unexpected_cfgs]
45+
level = "warn"
46+
check-cfg = [
47+
'cfg(feature, values("async_std"))'
48+
]

cap-fs-ext/build.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn use_feature_or_nothing(feature: &str) {
1313
if has_feature(feature) {
1414
use_feature(feature);
1515
}
16+
println!("cargo:rustc-check-cfg=cfg({})", feature);
1617
}
1718

1819
fn use_feature(feature: &str) {
@@ -21,20 +22,60 @@ fn use_feature(feature: &str) {
2122

2223
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
2324
fn has_feature(feature: &str) -> bool {
24-
let out_dir = var("OUT_DIR").unwrap();
25+
can_compile(&format!(
26+
"#![allow(stable_features)]\n#![feature({})]",
27+
feature
28+
))
29+
}
30+
31+
/// Test whether the rustc at `var("RUSTC")` can compile the given code.
32+
fn can_compile<T: AsRef<str>>(test: T) -> bool {
33+
use std::process::Stdio;
34+
2535
let rustc = var("RUSTC").unwrap();
36+
let target = var("TARGET").unwrap();
37+
38+
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string,
39+
// as documented [here].
40+
// [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
41+
let wrapper = var("RUSTC_WRAPPER")
42+
.ok()
43+
.and_then(|w| if w.is_empty() { None } else { Some(w) });
2644

27-
let mut child = std::process::Command::new(rustc)
28-
.arg("--crate-type=rlib") // Don't require `main`.
45+
let mut cmd = if let Some(wrapper) = wrapper {
46+
let mut cmd = std::process::Command::new(wrapper);
47+
// The wrapper's first argument is supposed to be the path to rustc.
48+
cmd.arg(rustc);
49+
cmd
50+
} else {
51+
std::process::Command::new(rustc)
52+
};
53+
54+
cmd.arg("--crate-type=rlib") // Don't require `main`.
2955
.arg("--emit=metadata") // Do as little as possible but still parse.
30-
.arg("--out-dir")
31-
.arg(out_dir) // Put the output somewhere inconsequential.
56+
.arg("--target")
57+
.arg(target)
58+
.arg("-o")
59+
.arg("-")
60+
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)
61+
62+
// If Cargo wants to set RUSTFLAGS, use that.
63+
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {
64+
if !rustflags.is_empty() {
65+
for arg in rustflags.split('\x1f') {
66+
cmd.arg(arg);
67+
}
68+
}
69+
}
70+
71+
let mut child = cmd
3272
.arg("-") // Read from stdin.
33-
.stdin(std::process::Stdio::piped()) // Stdin is a pipe.
73+
.stdin(Stdio::piped()) // Stdin is a pipe.
74+
.stderr(Stdio::null()) // Errors from feature detection aren't interesting and can be confusing.
3475
.spawn()
3576
.unwrap();
3677

37-
writeln!(child.stdin.take().unwrap(), "#![feature({})]", feature).unwrap();
78+
writeln!(child.stdin.take().unwrap(), "{}", test.as_ref()).unwrap();
3879

3980
child.wait().unwrap().success()
4081
}

cap-primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ io-lifetimes = { version = "2.0.0", default-features = false }
2525
cap-tempfile = { path = "../cap-tempfile" }
2626

2727
[target.'cfg(not(windows))'.dependencies]
28-
rustix = { version = "0.38.0", features = ["fs", "process", "procfs", "termios", "time"] }
28+
rustix = { version = "0.38.31", features = ["fs", "process", "procfs", "termios", "time"] }
2929

3030
[target.'cfg(windows)'.dependencies]
3131
winx = "0.36.0"

0 commit comments

Comments
 (0)