From 64d654a74d24d323f2f3bbe6ec361dbea9309795 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Mar 2024 12:25:12 -0700 Subject: [PATCH 1/5] Sync with rustix' build.rs changes (#58) io-lifetimes and rustix and a few other crates I maintain have similar build.rs scripts. Port some of the changes from rustix here to keep them in sync. --- build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 02dc64fa..33a6803e 100644 --- a/build.rs +++ b/build.rs @@ -34,7 +34,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 )) @@ -48,8 +48,8 @@ fn can_compile>(test: T) -> bool { 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() From 11025751683f455334762256e9a4c58d58042d6f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Mar 2024 12:36:49 -0700 Subject: [PATCH 2/5] Fix warnings with `TimezoneError`. --- cap-time-ext/src/lib.rs | 2 +- cap-time-ext/src/timezone.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cap-time-ext/src/lib.rs b/cap-time-ext/src/lib.rs index 99a3de81..255bb0c7 100644 --- a/cap-time-ext/src/lib.rs +++ b/cap-time-ext/src/lib.rs @@ -15,4 +15,4 @@ mod timezone; pub use monotonic_clock::MonotonicClockExt; pub use system_clock::SystemClockExt; -pub use timezone::Timezone; +pub use timezone::{Timezone, TimezoneError}; diff --git a/cap-time-ext/src/timezone.rs b/cap-time-ext/src/timezone.rs index 4cc440e8..7002452d 100644 --- a/cap-time-ext/src/timezone.rs +++ b/cap-time-ext/src/timezone.rs @@ -4,9 +4,18 @@ use iana_time_zone::get_timezone; /// A reference to a timezone resource. pub struct Timezone(()); +/// An error type returned by `Timezone::timezone_name`. #[derive(Debug)] pub struct TimezoneError(String); +impl std::error::Error for TimezoneError {} + +impl std::fmt::Display for TimezoneError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } +} + impl Timezone { /// Constructs a new instance of `Self`. /// From 8208adb803653bb3c14e4cb99a7fd42cf8927f5c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Mar 2024 12:41:44 -0700 Subject: [PATCH 3/5] Fix another warning. --- tests/sys_common/symlink_junction.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sys_common/symlink_junction.rs b/tests/sys_common/symlink_junction.rs index 3bfe2ec3..6a7f0b20 100644 --- a/tests/sys_common/symlink_junction.rs +++ b/tests/sys_common/symlink_junction.rs @@ -54,6 +54,7 @@ pub fn symlink_junction_utf8, Q: AsRef>( /// /// This is enough for almost all of the buffers we're likely to work with in /// the Windows APIs we use. +#[cfg(windows)] #[repr(C, align(8))] #[derive(Copy, Clone)] struct Align8(pub T); From dc96cc8da8865f9f2b0117544cc8f93c4af21902 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Mar 2024 13:22:48 -0700 Subject: [PATCH 4/5] Fix another warning. --- cap-tempfile/src/tempfile.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cap-tempfile/src/tempfile.rs b/cap-tempfile/src/tempfile.rs index 6dbd2a2c..2b5d2f05 100644 --- a/cap-tempfile/src/tempfile.rs +++ b/cap-tempfile/src/tempfile.rs @@ -215,7 +215,6 @@ impl<'d> Drop for TempFile<'d> { #[cfg(test)] mod test { use super::*; - use std::io; /// On Unix, calling `umask()` actually *mutates* the process global state. /// This uses Linux `/proc` to read the current value. From 6735f121f3a505ef5d142d0ae00d083bb2a0721d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Mar 2024 13:29:10 -0700 Subject: [PATCH 5/5] Fix another warning. --- cap-primitives/Cargo.toml | 2 +- cap-primitives/src/rustix/fs/metadata_ext.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cap-primitives/Cargo.toml b/cap-primitives/Cargo.toml index 7e0bc9eb..5e387d2a 100644 --- a/cap-primitives/Cargo.toml +++ b/cap-primitives/Cargo.toml @@ -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.32", features = ["fs", "process", "procfs", "termios", "time"] } [target.'cfg(windows)'.dependencies] winx = "0.36.0" diff --git a/cap-primitives/src/rustix/fs/metadata_ext.rs b/cap-primitives/src/rustix/fs/metadata_ext.rs index 0cd9de03..5330637d 100644 --- a/cap-primitives/src/rustix/fs/metadata_ext.rs +++ b/cap-primitives/src/rustix/fs/metadata_ext.rs @@ -102,6 +102,9 @@ impl ImplMetadataExt { #[inline] #[allow(unused_comparisons)] // NB: rust-lang/rust#115823 requires this here instead of on `st_dev` processing below pub(crate) fn from_rustix(stat: Stat) -> Metadata { + #[cfg(not(target_os = "wasi"))] + use rustix::fs::StatExt; + Metadata { file_type: ImplFileTypeExt::from_raw_mode(stat.st_mode as RawMode), len: u64::try_from(stat.st_size).unwrap(), @@ -112,12 +115,12 @@ impl ImplMetadataExt { #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] modified: system_time_from_rustix( - stat.st_mtime.try_into().unwrap(), + stat.mtime().try_into().unwrap(), stat.st_mtime_nsec as _, ), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] accessed: system_time_from_rustix( - stat.st_atime.try_into().unwrap(), + stat.atime().try_into().unwrap(), stat.st_atime_nsec as _, ), @@ -191,19 +194,19 @@ impl ImplMetadataExt { rdev: u64::try_from(stat.st_rdev).unwrap(), size: u64::try_from(stat.st_size).unwrap(), #[cfg(not(target_os = "wasi"))] - atime: i64::try_from(stat.st_atime).unwrap(), + atime: i64::try_from(stat.atime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] atime_nsec: stat.st_atime_nsec as _, #[cfg(target_os = "netbsd")] atime_nsec: stat.st_atimensec as _, #[cfg(not(target_os = "wasi"))] - mtime: i64::try_from(stat.st_mtime).unwrap(), + mtime: i64::try_from(stat.mtime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] mtime_nsec: stat.st_mtime_nsec as _, #[cfg(target_os = "netbsd")] mtime_nsec: stat.st_mtimensec as _, #[cfg(not(target_os = "wasi"))] - ctime: i64::try_from(stat.st_ctime).unwrap(), + ctime: i64::try_from(stat.ctime()).unwrap(), #[cfg(not(any(target_os = "netbsd", target_os = "wasi")))] ctime_nsec: stat.st_ctime_nsec as _, #[cfg(target_os = "netbsd")]