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 1.x. #377

Open
wants to merge 8 commits into
base: 1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# at revision 7f4774e76bd5cb9ccb7140d71ef9be9c16009cdf.

task:
name: stable x86_64-unknown-freebsd-13
name: stable x86_64-unknown-freebsd-15-snap
freebsd_instance:
image_family: freebsd-13-0-snap
image_family: freebsd-15-0-snap
setup_script:
- pkg install -y curl
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain stable -y --profile=minimal
- . $HOME/.cargo/env
Expand All @@ -16,11 +15,23 @@ task:
- cargo test --features=fs_utf8 --workspace

task:
name: stable x86_64-unknown-freebsd-12
name: stable x86_64-unknown-freebsd-14
freebsd_instance:
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
- . $HOME/.cargo/env
- rustup default stable
test_script:
- . $HOME/.cargo/env
- cargo test --features=fs_utf8 --workspace

task:
name: stable x86_64-unknown-freebsd-13
freebsd_instance:
image_family: freebsd-12-1
image_family: freebsd-13-3
setup_script:
- pkg install -y curl
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh --default-toolchain stable -y --profile=minimal
- . $HOME/.cargo/env
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-10.15, 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-10.15
os: macos-10.15
- 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.58

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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ libc = "0.2.100"
io-lifetimes = "1.0.0"

[target.'cfg(not(windows))'.dev-dependencies]
rustix = { version = "0.37.0", features = ["fs"] }
rustix = { version = "0.38.0", features = ["fs"] }

[target.'cfg(windows)'.dev-dependencies]
# nt_version uses internal Windows APIs, however we're only using it
# for testing here.
nt_version = "0.1.3"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.45.0"
version = "0.52.0"
features = [
"Win32_Storage_FileSystem",
"Win32_Foundation",
"Win32_System_IO",
"Win32_System_Ioctl",
"Win32_System_SystemServices",
]

Expand Down
16 changes: 10 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 @@ -28,6 +31,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 @@ -36,7 +40,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 @@ -46,12 +50,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 @@ -70,8 +73,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
2 changes: 1 addition & 1 deletion cap-async-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ io-extras = { version = "0.17.0", features = ["use_async_std"] }
camino = { version = "1.0.5", optional = true }

[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.37.0", features = ["fs"] }
rustix = { version = "0.38.0", features = ["fs"] }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion cap-directories/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cap-std = { path = "../cap-std", version = "^1.0.9" }
directories-next = "2.0.0"

[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.37.0" }
rustix = { version = "0.38.0" }

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.45.0"
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 = "1.0.0", default-features = false }
cap-tempfile = { path = "../cap-tempfile" }

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

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