Skip to content

Commit 8f2f60f

Browse files
authored
Sync with rustix' build.rs changes (#58) (#350)
* 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. * Fix warnings with `TimezoneError`. * Fix another warning. * Fix another warning. * Fix another warning.
1 parent a1f3ea2 commit 8f2f60f

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn use_feature(feature: &str) {
3434

3535
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
3636
fn has_feature(feature: &str) -> bool {
37-
can_compile(&format!(
37+
can_compile(format!(
3838
"#![allow(stable_features)]\n#![feature({})]",
3939
feature
4040
))
@@ -48,8 +48,8 @@ fn can_compile<T: AsRef<str>>(test: T) -> bool {
4848
let rustc = var("RUSTC").unwrap();
4949
let target = var("TARGET").unwrap();
5050

51-
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string,
52-
// as documented [here].
51+
// Use `RUSTC_WRAPPER` if it's set, unless it's set to an empty string, as
52+
// documented [here].
5353
// [here]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-reads
5454
let wrapper = var("RUSTC_WRAPPER")
5555
.ok()

cap-primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ io-lifetimes = { version = "2.0.0", default-features = false }
2525
cap-tempfile = { path = "../cap-tempfile" }
2626

2727
[target.'cfg(not(windows))'.dependencies]
28-
rustix = { version = "0.38.0", features = ["fs", "process", "procfs", "termios", "time"] }
28+
rustix = { version = "0.38.32", features = ["fs", "process", "procfs", "termios", "time"] }
2929

3030
[target.'cfg(windows)'.dependencies]
3131
winx = "0.36.0"

cap-primitives/src/rustix/fs/metadata_ext.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl ImplMetadataExt {
102102
#[inline]
103103
#[allow(unused_comparisons)] // NB: rust-lang/rust#115823 requires this here instead of on `st_dev` processing below
104104
pub(crate) fn from_rustix(stat: Stat) -> Metadata {
105+
#[cfg(not(target_os = "wasi"))]
106+
use rustix::fs::StatExt;
107+
105108
Metadata {
106109
file_type: ImplFileTypeExt::from_raw_mode(stat.st_mode as RawMode),
107110
len: u64::try_from(stat.st_size).unwrap(),
@@ -112,12 +115,12 @@ impl ImplMetadataExt {
112115

113116
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
114117
modified: system_time_from_rustix(
115-
stat.st_mtime.try_into().unwrap(),
118+
stat.mtime().try_into().unwrap(),
116119
stat.st_mtime_nsec as _,
117120
),
118121
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
119122
accessed: system_time_from_rustix(
120-
stat.st_atime.try_into().unwrap(),
123+
stat.atime().try_into().unwrap(),
121124
stat.st_atime_nsec as _,
122125
),
123126

@@ -191,19 +194,19 @@ impl ImplMetadataExt {
191194
rdev: u64::try_from(stat.st_rdev).unwrap(),
192195
size: u64::try_from(stat.st_size).unwrap(),
193196
#[cfg(not(target_os = "wasi"))]
194-
atime: i64::try_from(stat.st_atime).unwrap(),
197+
atime: i64::try_from(stat.atime()).unwrap(),
195198
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
196199
atime_nsec: stat.st_atime_nsec as _,
197200
#[cfg(target_os = "netbsd")]
198201
atime_nsec: stat.st_atimensec as _,
199202
#[cfg(not(target_os = "wasi"))]
200-
mtime: i64::try_from(stat.st_mtime).unwrap(),
203+
mtime: i64::try_from(stat.mtime()).unwrap(),
201204
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
202205
mtime_nsec: stat.st_mtime_nsec as _,
203206
#[cfg(target_os = "netbsd")]
204207
mtime_nsec: stat.st_mtimensec as _,
205208
#[cfg(not(target_os = "wasi"))]
206-
ctime: i64::try_from(stat.st_ctime).unwrap(),
209+
ctime: i64::try_from(stat.ctime()).unwrap(),
207210
#[cfg(not(any(target_os = "netbsd", target_os = "wasi")))]
208211
ctime_nsec: stat.st_ctime_nsec as _,
209212
#[cfg(target_os = "netbsd")]

cap-tempfile/src/tempfile.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ impl<'d> Drop for TempFile<'d> {
215215
#[cfg(test)]
216216
mod test {
217217
use super::*;
218-
use std::io;
219218

220219
/// On Unix, calling `umask()` actually *mutates* the process global state.
221220
/// This uses Linux `/proc` to read the current value.

cap-time-ext/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ mod timezone;
1515

1616
pub use monotonic_clock::MonotonicClockExt;
1717
pub use system_clock::SystemClockExt;
18-
pub use timezone::Timezone;
18+
pub use timezone::{Timezone, TimezoneError};

cap-time-ext/src/timezone.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@ use iana_time_zone::get_timezone;
44
/// A reference to a timezone resource.
55
pub struct Timezone(());
66

7+
/// An error type returned by `Timezone::timezone_name`.
78
#[derive(Debug)]
89
pub struct TimezoneError(String);
910

11+
impl std::error::Error for TimezoneError {}
12+
13+
impl std::fmt::Display for TimezoneError {
14+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15+
self.0.fmt(f)
16+
}
17+
}
18+
1019
impl Timezone {
1120
/// Constructs a new instance of `Self`.
1221
///

tests/sys_common/symlink_junction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn symlink_junction_utf8<P: AsRef<Utf8Path>, Q: AsRef<Utf8Path>>(
5454
///
5555
/// This is enough for almost all of the buffers we're likely to work with in
5656
/// the Windows APIs we use.
57+
#[cfg(windows)]
5758
#[repr(C, align(8))]
5859
#[derive(Copy, Clone)]
5960
struct Align8<T: ?Sized>(pub T);

0 commit comments

Comments
 (0)