Skip to content

Commit fe0091d

Browse files
committed
Backport build.rs fixes to 1.x.
* Backport build.rs fixes to 1.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 1.x. * Implement `change_time` for windows' `MetadataExt`.
1 parent 9e6e17e commit fe0091d

File tree

14 files changed

+254
-59
lines changed

14 files changed

+254
-59
lines changed

.cirrus.yml

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

44
task:
5-
name: stable x86_64-unknown-freebsd-13
5+
name: stable x86_64-unknown-freebsd-15-snap
66
freebsd_instance:
7-
image_family: freebsd-13-0-snap
7+
image_family: freebsd-15-0-snap
88
setup_script:
9-
- pkg install -y curl
109
- curl https://sh.rustup.rs -sSf --output rustup.sh
1110
- sh rustup.sh --default-toolchain stable -y --profile=minimal
1211
- . $HOME/.cargo/env
@@ -16,11 +15,23 @@ task:
1615
- cargo test --features=fs_utf8 --workspace
1716

1817
task:
19-
name: stable x86_64-unknown-freebsd-12
18+
name: stable x86_64-unknown-freebsd-14
19+
freebsd_instance:
20+
image_family: freebsd-14-0
21+
setup_script:
22+
- curl https://sh.rustup.rs -sSf --output rustup.sh
23+
- sh rustup.sh --default-toolchain stable -y --profile=minimal
24+
- . $HOME/.cargo/env
25+
- rustup default stable
26+
test_script:
27+
- . $HOME/.cargo/env
28+
- cargo test --features=fs_utf8 --workspace
29+
30+
task:
31+
name: stable x86_64-unknown-freebsd-13
2032
freebsd_instance:
21-
image_family: freebsd-12-1
33+
image_family: freebsd-13-3
2234
setup_script:
23-
- pkg install -y curl
2435
- curl https://sh.rustup.rs -sSf --output rustup.sh
2536
- sh rustup.sh --default-toolchain stable -y --profile=minimal
2637
- . $HOME/.cargo/env

.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-10.15, 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-10.15
219-
os: macos-10.15
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.58
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
@@ -19,6 +19,9 @@ fn main() {
1919
// https://doc.rust-lang.org/unstable-book/library-features/windows-file-type-ext.html
2020
use_feature_or_nothing("windows_file_type_ext");
2121

22+
// Cfgs that users may set.
23+
println!("cargo:rustc-check-cfg=cfg(racy_asserts)");
24+
2225
// Don't rerun this on changes other than build.rs, as we only depend on
2326
// the rustc version.
2427
println!("cargo:rerun-if-changed=build.rs");
@@ -28,6 +31,7 @@ fn use_feature_or_nothing(feature: &str) {
2831
if has_feature(feature) {
2932
use_feature(feature);
3033
}
34+
println!("cargo:rustc-check-cfg=cfg({})", feature);
3135
}
3236

3337
fn use_feature(feature: &str) {
@@ -36,7 +40,7 @@ fn use_feature(feature: &str) {
3640

3741
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
3842
fn has_feature(feature: &str) -> bool {
39-
can_compile(&format!(
43+
can_compile(format!(
4044
"#![allow(stable_features)]\n#![feature({})]",
4145
feature
4246
))
@@ -46,12 +50,11 @@ fn has_feature(feature: &str) -> bool {
4650
fn can_compile<T: AsRef<str>>(test: T) -> bool {
4751
use std::process::Stdio;
4852

49-
let out_dir = var("OUT_DIR").unwrap();
5053
let rustc = var("RUSTC").unwrap();
5154
let target = var("TARGET").unwrap();
5255

53-
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string,
54-
// as documented [here].
56+
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, as
57+
// documented [here].
5558
// [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
5659
let wrapper = var("RUSTC_WRAPPER")
5760
.ok()
@@ -70,8 +73,9 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
7073
.arg("--emit=metadata") // Do as little as possible but still parse.
7174
.arg("--target")
7275
.arg(target)
73-
.arg("--out-dir")
74-
.arg(out_dir); // Put the output somewhere inconsequential.
76+
.arg("-o")
77+
.arg("-")
78+
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)
7579

7680
// If Cargo wants to set RUSTFLAGS, use that.
7781
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
}

0 commit comments

Comments
 (0)