Skip to content

Commit a837f8b

Browse files
committed
Portability fixes
prtest:full
1 parent 9af284c commit a837f8b

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wasi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async-trait = { workspace = true }
3737
futures = { workspace = true }
3838
url = { workspace = true }
3939
rand = { workspace = true, features = ['std_rng', 'thread_rng'] }
40+
cfg-if = { workspace = true }
4041

4142
[dev-dependencies]
4243
tokio = { workspace = true, features = ["time", "sync", "io-std", "io-util", "rt", "rt-multi-thread", "net", "macros", "fs"] }

crates/wasi/src/filesystem/unix.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustix::fs::{OFlags, fcntl_getfl, fcntl_setfl};
44
use rustix::io::write;
55
use std::fs::File;
66
use std::io;
7-
use std::num::NonZeroU64;
87
use std::os::fd::AsFd;
98
use std::os::unix::fs::FileExt;
109

@@ -19,6 +18,7 @@ pub(crate) fn get_flags(file: impl AsFd) -> io::Result<DescriptorFlags> {
1918
DescriptorFlags::FILE_INTEGRITY_SYNC,
2019
flags.contains(OFlags::SYNC),
2120
);
21+
#[cfg(not(any(target_vendor = "apple", target_os = "freebsd")))]
2222
ret.set(
2323
DescriptorFlags::DATA_INTEGRITY_SYNC,
2424
flags.contains(OFlags::RSYNC),
@@ -27,15 +27,33 @@ pub(crate) fn get_flags(file: impl AsFd) -> io::Result<DescriptorFlags> {
2727
}
2828

2929
pub(crate) fn advise(file: impl AsFd, offset: u64, len: u64, advice: Advice) -> io::Result<()> {
30-
let advice = match advice {
31-
Advice::Normal => rustix::fs::Advice::Normal,
32-
Advice::Sequential => rustix::fs::Advice::Sequential,
33-
Advice::Random => rustix::fs::Advice::Random,
34-
Advice::WillNeed => rustix::fs::Advice::WillNeed,
35-
Advice::DontNeed => rustix::fs::Advice::DontNeed,
36-
Advice::NoReuse => rustix::fs::Advice::NoReuse,
37-
};
38-
rustix::fs::fadvise(file, offset, NonZeroU64::new(len), advice)?;
30+
cfg_if::cfg_if! {
31+
if #[cfg(target_vendor = "apple")] {
32+
match advice {
33+
Advice::WillNeed => {
34+
rustix::fs::fcntl_rdadvise(file, offset, len)?;
35+
}
36+
Advice::Normal |
37+
Advice::Sequential |
38+
Advice::Random |
39+
Advice::DontNeed |
40+
Advice::NoReuse => {}
41+
}
42+
} else if #[cfg(target_os = "linux")] {
43+
use std::num::NonZeroU64;
44+
let advice = match advice {
45+
Advice::Normal => rustix::fs::Advice::Normal,
46+
Advice::Sequential => rustix::fs::Advice::Sequential,
47+
Advice::Random => rustix::fs::Advice::Random,
48+
Advice::WillNeed => rustix::fs::Advice::WillNeed,
49+
Advice::DontNeed => rustix::fs::Advice::DontNeed,
50+
Advice::NoReuse => rustix::fs::Advice::NoReuse,
51+
};
52+
rustix::fs::fadvise(file, offset, NonZeroU64::new(len), advice)?;
53+
} else {
54+
// noop on other platforms
55+
}
56+
}
3957
Ok(())
4058
}
4159

0 commit comments

Comments
 (0)