Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport build.rs fixes to 2.x. #376

Merged
merged 11 commits into from
Nov 22, 2024
12 changes: 6 additions & 6 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# at revision 7f4774e76bd5cb9ccb7140d71ef9be9c16009cdf.

task:
name: stable x86_64-unknown-freebsd-14-snap
name: stable x86_64-unknown-freebsd-15-snap
freebsd_instance:
image_family: freebsd-14-0-snap
image_family: freebsd-15-0-snap
setup_script:
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain stable -y --profile=minimal
Expand All @@ -15,9 +15,9 @@ task:
- cargo test --features=fs_utf8 --workspace

task:
name: stable x86_64-unknown-freebsd-13
name: stable x86_64-unknown-freebsd-14
freebsd_instance:
image_family: freebsd-13-2
image_family: freebsd-14-0
setup_script:
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain stable -y --profile=minimal
Expand All @@ -28,9 +28,9 @@ task:
- cargo test --features=fs_utf8 --workspace

task:
name: stable x86_64-unknown-freebsd-12
name: stable x86_64-unknown-freebsd-13
freebsd_instance:
image_family: freebsd-12-4
image_family: freebsd-13-3
setup_script:
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain stable -y --profile=minimal
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ inputs:
default: 'stable'

runs:
using: node16
using: node20
main: 'main.js'
32 changes: 16 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand All @@ -34,7 +34,7 @@ jobs:
rust: beta

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
rust: beta

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
rust: nightly

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
riscv64gc-unknown-linux-gnu
arm-unknown-linux-gnueabihf
aarch64-linux-android
wasm32-wasi
wasm32-wasip1
- run: cargo check --workspace --all-targets --all-features --release -vv
- run: cargo check --workspace --all-targets --all-features --release -vv --target=x86_64-unknown-linux-musl
- run: cargo check --workspace --all-targets --all-features --release -vv --target=x86_64-unknown-linux-gnux32
Expand All @@ -164,7 +164,7 @@ jobs:
- run: cargo check --workspace --all-targets --all-features --release -vv --target=riscv64gc-unknown-linux-gnu
- run: cargo check --workspace --all-targets --all-features --release -vv --target=arm-unknown-linux-gnueabihf
- run: cargo check --workspace --all-targets --all-features --release -vv --target=aarch64-linux-android
- run: cd cap-std && cargo check --features=fs_utf8 --release -vv --target=wasm32-wasi
- run: cd cap-std && cargo check --features=fs_utf8 --release -vv --target=wasm32-wasip1

check_cross_nightly_windows:
name: Check Cross-Compilation on Rust nightly on Windows
Expand All @@ -178,7 +178,7 @@ jobs:
rust: nightly

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand All @@ -201,7 +201,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [stable, windows-latest, windows-2019, macos-latest, macos-11, beta, ubuntu-20.04, aarch64-ubuntu]
build: [stable, windows-latest, windows-2019, macos-latest, macos-12, beta, ubuntu-20.04, aarch64-ubuntu]
include:
- build: stable
os: ubuntu-latest
Expand All @@ -215,8 +215,8 @@ jobs:
- build: macos-latest
os: macos-latest
rust: stable
- build: macos-11
os: macos-11
- build: macos-12
os: macos-12
rust: stable
- build: beta
os: ubuntu-latest
Expand All @@ -234,7 +234,7 @@ jobs:
qemu_target: aarch64-linux-user

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down Expand Up @@ -291,7 +291,7 @@ jobs:
rust: nightly

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand All @@ -311,7 +311,7 @@ jobs:
rust: stable

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down Expand Up @@ -345,7 +345,7 @@ jobs:
RUSTFLAGS: --cfg linux_raw
RUSTDOCFLAGS: --cfg linux_raw
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand All @@ -365,7 +365,7 @@ jobs:
rust: 1.63

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand All @@ -381,7 +381,7 @@ jobs:
name: Fuzz Targets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
Expand Down
16 changes: 10 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ fn main() {
// https://doc.rust-lang.org/unstable-book/library-features/windows-file-type-ext.html
use_feature_or_nothing("windows_file_type_ext");

// Cfgs that users may set.
println!("cargo:rustc-check-cfg=cfg(racy_asserts)");

// Don't rerun this on changes other than build.rs, as we only depend on
// the rustc version.
println!("cargo:rerun-if-changed=build.rs");
Expand All @@ -26,6 +29,7 @@ fn use_feature_or_nothing(feature: &str) {
if has_feature(feature) {
use_feature(feature);
}
println!("cargo:rustc-check-cfg=cfg({})", feature);
}

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

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

let out_dir = var("OUT_DIR").unwrap();
let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

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

// If Cargo wants to set RUSTFLAGS, use that.
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {
Expand Down
6 changes: 6 additions & 0 deletions cap-fs-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ features = [

[dev-dependencies]
cap-tempfile = { path = "../cap-tempfile" }

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(feature, values("async_std"))'
]
55 changes: 48 additions & 7 deletions cap-fs-ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn use_feature_or_nothing(feature: &str) {
if has_feature(feature) {
use_feature(feature);
}
println!("cargo:rustc-check-cfg=cfg({})", feature);
}

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

/// Test whether the rustc at `var("RUSTC")` supports the given feature.
fn has_feature(feature: &str) -> bool {
let out_dir = var("OUT_DIR").unwrap();
can_compile(&format!(
"#![allow(stable_features)]\n#![feature({})]",
feature
))
}

/// Test whether the rustc at `var("RUSTC")` can compile the given code.
fn can_compile<T: AsRef<str>>(test: T) -> bool {
use std::process::Stdio;

let rustc = var("RUSTC").unwrap();
let target = var("TARGET").unwrap();

// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string,
// as documented [here].
// [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
let wrapper = var("RUSTC_WRAPPER")
.ok()
.and_then(|w| if w.is_empty() { None } else { Some(w) });

let mut child = std::process::Command::new(rustc)
.arg("--crate-type=rlib") // Don't require `main`.
let mut cmd = if let Some(wrapper) = wrapper {
let mut cmd = std::process::Command::new(wrapper);
// The wrapper's first argument is supposed to be the path to rustc.
cmd.arg(rustc);
cmd
} else {
std::process::Command::new(rustc)
};

cmd.arg("--crate-type=rlib") // Don't require `main`.
.arg("--emit=metadata") // Do as little as possible but still parse.
.arg("--out-dir")
.arg(out_dir) // Put the output somewhere inconsequential.
.arg("--target")
.arg(target)
.arg("-o")
.arg("-")
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)

// If Cargo wants to set RUSTFLAGS, use that.
if let Ok(rustflags) = var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
for arg in rustflags.split('\x1f') {
cmd.arg(arg);
}
}
}

let mut child = cmd
.arg("-") // Read from stdin.
.stdin(std::process::Stdio::piped()) // Stdin is a pipe.
.stdin(Stdio::piped()) // Stdin is a pipe.
.stderr(Stdio::null()) // Errors from feature detection aren't interesting and can be confusing.
.spawn()
.unwrap();

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

child.wait().unwrap().success()
}
2 changes: 1 addition & 1 deletion cap-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ io-lifetimes = { version = "2.0.0", default-features = false }
cap-tempfile = { path = "../cap-tempfile" }

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

[target.'cfg(windows)'.dependencies]
winx = "0.36.0"
Expand Down
Loading
Loading