Skip to content
Merged
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
6 changes: 1 addition & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,12 @@ regalloc2 = "0.15.1"
wasip1 = { version = "1.0.0", default-features = false }

# cap-std family:
#
# Note that `cap-fs-ext` should be avoided where possible to use
# `cap-primitives` instead.
target-lexicon = "0.13.5"
cap-std = "4.0.2"
cap-fs-ext = "4.0.2"
io-lifetimes = { version = "3.0.1", default-features = false }
cap-primitives = "4.0.2"
cap-fs-ext-avoid-using-this = { version = "4.0.2", package = 'cap-fs-ext' }
rustix = "1.1.4"
# wit-bindgen:
wit-bindgen = { version = "0.59.0", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion crates/bench-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ wasmtime-cli-flags = { workspace = true, default-features = true, features = [
] }
wasmtime-wasi = { workspace = true, features = ['p1', 'p2'] }
wasmtime-wasi-nn = { workspace = true, optional = true }
cap-std = { workspace = true }
clap = { workspace = true }

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ tracing = { workspace = true }
wat = { workspace = true, optional = true }

# Optional dependencies for the `wasi` feature
cap-std = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, features = ["fs"] }
wasmtime-wasi = { workspace = true, optional = true, features = ["p1"] }
wasmtime-wasi-http = { workspace = true, optional = true, features = ["p2", "default-send-request"] }
Expand All @@ -47,7 +46,7 @@ async = ['wasmtime/async', 'futures']
profiling = ["wasmtime/profiling"]
cache = ["wasmtime/cache"]
parallel-compilation = ['wasmtime/parallel-compilation']
wasi = ['cap-std', 'wasmtime-wasi', 'wasmtime-wasi-io', 'tokio', 'async-trait', 'bytes']
wasi = ['wasmtime-wasi', 'wasmtime-wasi-io', 'tokio', 'async-trait', 'bytes']
wasi-http = ['wasi', 'wasmtime-wasi-http']
logging = ['dep:env_logger']
disable-logging = ["log/max_level_off", "tracing/max_level_off"]
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-nn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ optional = true
walkdir = { workspace = true }

[dev-dependencies]
cap-std = { workspace = true }
libtest-mimic = { workspace = true }
test-programs-artifacts = { workspace = true }
wasmtime-wasi = { workspace = true, features = ["p1"] }
Expand Down
5 changes: 2 additions & 3 deletions crates/wasi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ tokio = { workspace = true, features = ["time", "sync", "io-std", "io-util", "r
bytes = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true, features = ["std", "attributes"] }
cap-std = { workspace = true }
cap-fs-ext = { workspace = true }
io-lifetimes = { workspace = true }
cap-primitives = { workspace = true }
cap-fs-ext-avoid-using-this = { workspace = true }
bitflags = { workspace = true }
async-trait = { workspace = true }
futures = { workspace = true }
Expand Down
44 changes: 14 additions & 30 deletions crates/wasi/src/clocks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cap_std::time::{Duration, Instant, SystemClock, SystemTime};
use cap_std::{AmbientAuthority, ambient_authority};
use std::error::Error;
use std::fmt;
use std::time::{Duration, Instant, SystemTime};
use wasmtime::component::{HasData, ResourceTable};

/// A helper struct which implements [`HasData`] for the `wasi:clocks` APIs.
Expand Down Expand Up @@ -81,22 +80,12 @@ pub trait HostMonotonicClock: Send {
fn now(&self) -> u64;
}

pub struct WallClock {
/// The underlying system clock.
clock: cap_std::time::SystemClock,
}

impl Default for WallClock {
fn default() -> Self {
Self::new(ambient_authority())
}
}
#[derive(Default)]
pub struct WallClock;

impl WallClock {
pub fn new(ambient_authority: AmbientAuthority) -> Self {
Self {
clock: cap_std::time::SystemClock::new(ambient_authority),
}
pub fn new() -> Self {
Self
}
}

Expand All @@ -122,33 +111,29 @@ impl HostWallClock for WallClock {

fn now(&self) -> Duration {
// WASI defines wall clocks to return "Unix time".
self.clock
.now()
.duration_since(SystemClock::UNIX_EPOCH)
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
}
}

pub struct MonotonicClock {
/// The underlying system clock.
clock: cap_std::time::MonotonicClock,

/// The `Instant` this clock was created. All returned times are
/// durations since that time.
initial: Instant,
}

impl Default for MonotonicClock {
fn default() -> Self {
Self::new(ambient_authority())
Self::new()
}
}

impl MonotonicClock {
pub fn new(ambient_authority: AmbientAuthority) -> Self {
let clock = cap_std::time::MonotonicClock::new(ambient_authority);
let initial = clock.now();
Self { clock, initial }
pub fn new() -> Self {
Self {
initial: Instant::now(),
}
}
}

Expand Down Expand Up @@ -179,8 +164,7 @@ impl HostMonotonicClock for MonotonicClock {
fn now(&self) -> u64 {
// Unwrap here and in `resolution` above; a `u64` is wide enough to
// hold over 584 years of nanoseconds.
self.clock
.now()
Instant::now()
.duration_since(self.initial)
.as_nanos()
.try_into()
Expand All @@ -205,7 +189,7 @@ impl TryFrom<SystemTime> for Datetime {
type Error = DatetimeError;

fn try_from(time: SystemTime) -> Result<Self, Self::Error> {
let epoch = SystemTime::from_std(std::time::SystemTime::UNIX_EPOCH);
let epoch = SystemTime::UNIX_EPOCH;

if time >= epoch {
let duration = time.duration_since(epoch)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/wasi/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::filesystem::{Dir, WasiFilesystemCtx};
use crate::random::WasiRandomCtx;
use crate::sockets::{SocketAddrCheck, SocketAddrUse, WasiSocketsCtx};
use crate::{DirPerms, FilePerms, OpenMode};
use cap_std::ambient_authority;
use cap_primitives::ambient_authority;
use rand::Rng;
use std::future::Future;
use std::mem;
Expand Down Expand Up @@ -304,7 +304,7 @@ impl WasiCtxBuilder {
dir_perms: DirPerms,
file_perms: FilePerms,
) -> Result<&mut Self> {
let dir = cap_std::fs::Dir::open_ambient_dir(host_path.as_ref(), ambient_authority())?;
let dir = cap_primitives::fs::open_ambient_dir(host_path.as_ref(), ambient_authority())?;
let mut open_mode = OpenMode::empty();
if dir_perms.contains(DirPerms::READ) {
open_mode |= OpenMode::READ;
Expand Down
Loading
Loading