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
39 changes: 0 additions & 39 deletions Cargo.lock

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

8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ blake3 = { version = "1.8.2" }
async-trait = { version = "0.1.89" }
rand = { version = "0.10", default-features = false }
rand_core = { version = "0.10", default-features = false }
io-extras = "0.18.4"
softbuffer = "0.4.8"
ico = "0.5.0"
tar = "0.4"
Expand All @@ -199,15 +198,8 @@ rustls = { version = "0.23", default-features = false }
bitflags = "2.9.4"

# To remove
cap-fs-ext = "3.4.5"
cap-time-ext = "3.4.5"
fs-set-times = "0.20.3"
io-lifetimes = { version = "2.0.3", default-features = false }
system-interface = { version = "0.27.3", features = ["cap_std_impls"] }
thiserror = "2.0.17"
tempfile = "3.27.0"
test-log = { version = "0.2.18", default-features = false, features = ["trace"] }
cap-std = "3.4.5"

[profile.dev]
panic = "abort"
Expand Down
5 changes: 5 additions & 0 deletions android/runtime/launcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ impl LauncherConfig for LauncherConfigImpl {
let sdp_answer = rx.recv().await.unwrap();
on_sdp_answer(sdp_answer);
};
#[cfg(not(target_os = "android"))]
{
let _ = sdp_offer;
let _ = on_sdp_answer;
}
Ok(())
}
}
Expand Down
42 changes: 3 additions & 39 deletions crates/wasi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,11 @@ log = { workspace = true }
rand = { workspace = true, features = ['std_rng', 'thread_rng'] }
async-trait = { workspace = true }

# Optional, enabled by wasmtime feature:
wasmtime = { workspace = true, optional = true, features = ['runtime', 'component-model', 'std'] }
# Optional, enabled by sync feature:
cap-fs-ext = { workspace = true, optional = true }
cap-time-ext = { workspace = true, optional = true }
fs-set-times = { workspace = true, optional = true }
system-interface = { workspace = true, features = ["cap_std_impls"], optional = true }
io-lifetimes = { workspace = true, optional = true }
# Optional, enabled by tokio feature:
tokio = { workspace = true, features = [ "rt", "fs", "time", "io-util", "net", "io-std", "rt-multi-thread"], optional = true }

cap-std = { workspace = true, optional = true }

# Optional, enabled by exit feature:
libc = { workspace = true, optional = true }
tokio = { workspace = true, features = ["time"], optional = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["fs", "event"] }

[target.'cfg(windows)'.dependencies]
io-extras = { workspace = true }
rustix = { workspace = true, features = ["net"] }
rustix = { workspace = true }

[target.'cfg(windows)'.dependencies.windows-sys]
workspace = true
Expand All @@ -52,38 +35,19 @@ features = [
]

[features]
default = ["trace_log", "wasmtime", "sync"]
default = ["trace_log", "sync"]
# This feature enables the `tracing` logs in the calls to target the `log`
# ecosystem of backends (e.g. `env_logger`. Disable this if you want to use
# `tracing-subscriber`.
trace_log = [ "wiggle/tracing_log", "tracing/log" ]
# Need to make the wiggle_metadata feature available to consumers of this
# crate if they want the snapshots to have metadata available.
wiggle_metadata = ["wiggle/wiggle_metadata"]
# This feature enables integration with wasmtime.
wasmtime = [
"dep:wasmtime",
"wiggle/wasmtime",
]
# This feature enables an implementation of the Wasi traits for a
# synchronous wasmtime embedding.
sync = [
"dep:cap-fs-ext",
"dep:cap-time-ext",
"dep:fs-set-times",
"dep:system-interface",
"dep:io-lifetimes",
"use_cap_std",
]
tokio = [
"sync",
"wasmtime/async",
"wiggle/wasmtime_async",
"dep:tokio",
"use_cap_std",
]
use_cap_std = ["dep:cap-std"]
exit = [ "wasmtime", "dep:libc" ]

[package.metadata.docs.rs]
all-features = true
6 changes: 0 additions & 6 deletions crates/wasi-common/src/clocks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{Error, ErrorExt};
#[cfg(feature = "use_cap_std")]
use cap_std::time::{Duration, Instant, SystemTime};
#[cfg(not(feature = "use_cap_std"))]
use std::time::{Duration, Instant, SystemTime};

pub enum SystemTimeSpec {
Expand All @@ -20,9 +17,6 @@ pub trait WasiMonotonicClock: Send + Sync {
}

pub struct WasiMonotonicOffsetClock {
#[cfg(feature = "use_cap_std")]
pub creation_time: cap_std::time::Instant,
#[cfg(not(feature = "use_cap_std"))]
pub creation_time: std::time::Instant,
pub abs_clock: Box<dyn WasiMonotonicClock>,
}
Expand Down
10 changes: 0 additions & 10 deletions crates/wasi-common/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ pub trait WasiFile: Send + Sync {
fn as_any(&self) -> &dyn Any;
async fn get_filetype(&self) -> Result<FileType, Error>;

#[cfg(unix)]
fn pollable(&self) -> Option<rustix::fd::BorrowedFd<'_>> {
None
}

#[cfg(windows)]
fn pollable(&self) -> Option<io_extras::os::windows::RawHandleOrSocket> {
None
}

fn isatty(&self) -> bool {
false
}
Expand Down
81 changes: 0 additions & 81 deletions crates/wasi-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ mod string_array;
#[cfg(feature = "sync")]
pub mod sync;
pub mod table;
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
#[cfg(feature = "tokio")]
pub mod tokio;

pub use clocks::{SystemTimeSpec, WasiClocks, WasiMonotonicClock, WasiSystemClock};
pub use ctx::WasiCtx;
Expand All @@ -99,81 +96,3 @@ pub use string_array::{StringArray, StringArrayError};
pub use table::Table;

pub(crate) use wasmtime_internal_core::error::Error as EnvError;

// The only difference between these definitions for sync vs async is whether
// the wasmtime::Funcs generated are async (& therefore need an async Store and an executor to run)
// or whether they have an internal "dummy executor" that expects the implementation of all
// the async funcs to poll to Ready immediately.
#[cfg(feature = "wasmtime")]
#[doc(hidden)]
#[macro_export]
macro_rules! define_wasi {
($async_mode:tt $($bounds:tt)*) => {

use wasmtime::Linker;
use wasmtime_internal_core::error::Result as EnvResult;

pub fn add_to_linker<T, U>(
linker: &mut Linker<T>,
get_cx: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> EnvResult<()>
where U: Send
+ crate::snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1,
T: 'static,
$($bounds)*
{
snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(linker, get_cx)?;
Ok(())
}

pub mod snapshots {
pub mod preview_1 {
wiggle::wasmtime_integration!({
// The wiggle code to integrate with lives here:
target: crate::snapshots::preview_1,
witx: ["witx/preview1/wasi_snapshot_preview1.witx"],
errors: { errno => trappable Error },
$async_mode: *
});
}
}
}}

/// Exit the process with a conventional OS error code as long as Wasmtime
/// understands the error. If the error is not an `I32Exit` or `Trap`, return
/// the error back to the caller for it to decide what to do.
///
/// Note: this function is designed for usage where it is acceptable for
/// Wasmtime failures to terminate the parent process, such as in the Wasmtime
/// CLI; this would not be suitable for use in multi-tenant embeddings.
#[cfg_attr(docsrs, doc(cfg(feature = "exit")))]
#[cfg(feature = "exit")]
pub fn maybe_exit_on_error(e: EnvError) -> EnvError {
use std::process;
use wasmtime::Trap;

// If a specific WASI error code was requested then that's
// forwarded through to the process here without printing any
// extra error information.
if let Some(exit) = e.downcast_ref::<crate::I32Exit>() {
process::exit(exit.0);
}

// If the program exited because of a trap, return an error code
// to the outside environment indicating a more severe problem
// than a simple failure.
if e.is::<Trap>() {
eprintln!("Error: {e:?}");

if cfg!(unix) {
// On Unix, return the error code of an abort.
process::exit(128 + libc::SIGABRT);
} else if cfg!(windows) {
// On Windows, return 3.
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/abort?view=vs-2019
process::exit(3);
}
}

e
}
8 changes: 1 addition & 7 deletions crates/wasi-common/src/sched.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use crate::Error;
use crate::clocks::WasiMonotonicClock;
use crate::file::WasiFile;
#[cfg(feature = "use_cap_std")]
use cap_std::time::Instant;
#[cfg(not(feature = "use_cap_std"))]
use crate::Error;
use std::time::Instant;
pub mod subscription;
#[cfg(feature = "use_cap_std")]
pub use cap_std::time::Duration;
#[cfg(not(feature = "use_cap_std"))]
pub use std::time::Duration;

pub use subscription::{
Expand Down
5 changes: 1 addition & 4 deletions crates/wasi-common/src/sched/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::Error;
use crate::clocks::WasiMonotonicClock;
use crate::file::WasiFile;
use crate::Error;
use bitflags::bitflags;
#[cfg(feature = "use_cap_std")]
use cap_std::time::{Duration, Instant};
#[cfg(not(feature = "use_cap_std"))]
use std::time::{Duration, Instant};

bitflags! {
Expand Down
15 changes: 2 additions & 13 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use crate::{
EnvError, I32Exit, SystemTimeSpec, WasiCtx,
dir::{DirEntry, OpenResult, ReaddirCursor, ReaddirEntity, TableDirExt},
file::{
Advice, FdFlags, FdStat, FileAccessMode, FileEntry, FileType, Filestat, OFlags, RiFlags,
RoFlags, SdFlags, SiFlags, TableFileExt, WasiFile,
},
sched::{
Poll, Userdata,
subscription::{RwEventFlags, SubscriptionResult},
Poll, Userdata,
},
EnvError, I32Exit, SystemTimeSpec, WasiCtx,
};
#[cfg(feature = "use_cap_std")]
use cap_std::time::{Duration, SystemClock};
use std::borrow::Cow;
use std::io::{IoSlice, IoSliceMut};
use std::ops::Deref;
use std::sync::Arc;
#[cfg(not(feature = "use_cap_std"))]
use std::time::Duration;
use wiggle::GuestMemory;
use wiggle::GuestPtr;
Expand Down Expand Up @@ -101,9 +98,6 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
let precision = Duration::from_nanos(precision);
match id {
types::Clockid::Realtime => {
#[cfg(feature = "use_cap_std")]
let now = self.clocks.system()?.now(precision).into_std();
#[cfg(not(feature = "use_cap_std"))]
let now = self.clocks.system()?.now(precision);
let d = now
.duration_since(std::time::SystemTime::UNIX_EPOCH)
Expand Down Expand Up @@ -1523,11 +1517,6 @@ fn systimespec(
if set && now {
Err(Error::invalid_argument())
} else if set {
#[cfg(feature = "use_cap_std")]
return Ok(Some(SystemTimeSpec::Absolute(
SystemClock::UNIX_EPOCH + Duration::from_nanos(ts),
)));
#[cfg(not(feature = "use_cap_std"))]
Ok(Some(SystemTimeSpec::Absolute(
std::time::SystemTime::UNIX_EPOCH + Duration::from_nanos(ts),
)))
Expand Down
Loading
Loading