Skip to content

Commit

Permalink
Sync with rustix' build.rs changes (bytecodealliance#58) (bytecodeall…
Browse files Browse the repository at this point in the history
…iance#350)

* Sync with rustix' build.rs changes (bytecodealliance#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.

* Fix warnings with `TimezoneError`.

* Fix another warning.

* Fix another warning.

* Fix another warning.
  • Loading branch information
sunfishcode authored Mar 29, 2024
1 parent a1f3ea2 commit 8f2f60f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand All @@ -48,8 +48,8 @@ fn can_compile<T: AsRef<str>>(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()
Expand Down
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.32", features = ["fs", "process", "procfs", "termios", "time"] }

[target.'cfg(windows)'.dependencies]
winx = "0.36.0"
Expand Down
13 changes: 8 additions & 5 deletions cap-primitives/src/rustix/fs/metadata_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 _,
),

Expand Down Expand Up @@ -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")]
Expand Down
1 change: 0 additions & 1 deletion cap-tempfile/src/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cap-time-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
9 changes: 9 additions & 0 deletions cap-time-ext/src/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down
1 change: 1 addition & 0 deletions tests/sys_common/symlink_junction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn symlink_junction_utf8<P: AsRef<Utf8Path>, Q: AsRef<Utf8Path>>(
///
/// 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<T: ?Sized>(pub T);
Expand Down

0 comments on commit 8f2f60f

Please sign in to comment.