Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wasi-common self-contained, deprecate exports from wasmtime-wasi #7881

Merged
merged 22 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dc5b37a
WIP: try to make wasi-common self contained.
pchickey Jan 29, 2024
5be5c66
rebase: cargo.lock
pchickey Jan 30, 2024
60d51dc
remove all dependencies between wasi-common and wasmtime-wasi
pchickey Jan 30, 2024
b458975
use wasi-common directly throughout tests, benches, examples, cli run
pchickey Feb 5, 2024
b3ad4dd
wasi-threads: use wasi-common's maybe_exit_on_error in spawned thread
pchickey Feb 6, 2024
00071e7
fix wasmtime's docs
pchickey Feb 6, 2024
807ae18
re-introduce wasmtime-wasi's exports of wasi-common definitions behin…
Feb 6, 2024
94f089f
factor out determining i32 process exit code
Feb 6, 2024
6bd9492
commands/run: inline the logic about aborting on trap
Feb 6, 2024
b0ad370
Merge remote-tracking branch 'origin/main' into pch/wasi-common-self-…
Feb 6, 2024
882fac2
Add high-level summary to wasi-common's top-level doc comment.
pchickey Feb 9, 2024
9697614
c-api: fix use of wasi_cap_std_sync => wasi_common::sync, wasmtime_wa…
pchickey Feb 9, 2024
e6dec9e
fix tokio example
pchickey Feb 9, 2024
d5c376a
think better of combining downcast and masking into one method
pchickey Feb 9, 2024
69aaa4a
Merge remote-tracking branch 'origin/main' into pch/wasi-common-self-…
pchickey Feb 9, 2024
19ea4a1
fix references to wasmtime_wasi in docs
pchickey Feb 10, 2024
1772dca
benches: use wasi-common
Feb 12, 2024
0343c73
cfg-if around use of rustix::process because that doesnt exist on win…
Feb 12, 2024
a0d862b
wasi-common: include tests, caught by verify-publish
Feb 12, 2024
ffb27fd
fix another bench
Feb 12, 2024
a25b31b
exit requires wasmtime dep. caught by verify-publish.
Feb 12, 2024
9d17f11
Merge remote-tracking branch 'origin/main' into pch/wasi-common-self-…
Feb 13, 2024
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
72 changes: 10 additions & 62 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ wasmtime-cranelift = { workspace = true, optional = true }
wasmtime-environ = { workspace = true }
wasmtime-explorer = { workspace = true, optional = true }
wasmtime-wast = { workspace = true, optional = true }
wasi-common = { workspace = true, default-features = true, features = [
"exit",
] }
wasmtime-wasi = { workspace = true, default-features = true, features = [
"exit",
] }
Expand All @@ -55,13 +58,14 @@ humantime = { workspace = true }

async-trait = { workspace = true }
bytes = { workspace = true }
cfg-if = { workspace = true }
tokio = { workspace = true, optional = true, features = [ "signal", "macros" ] }
hyper = { workspace = true, optional = true }
http = { workspace = true, optional = true }
http-body-util = { workspace = true, optional = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["mm", "param"] }
rustix = { workspace = true, features = ["mm", "param", "process"] }

[dev-dependencies]
# depend again on wasmtime to activate its default features for tests
Expand Down Expand Up @@ -181,8 +185,6 @@ wiggle = { path = "crates/wiggle", version = "=19.0.0", default-features = false
wiggle-macro = { path = "crates/wiggle/macro", version = "=19.0.0" }
wiggle-generate = { path = "crates/wiggle/generate", version = "=19.0.0" }
wasi-common = { path = "crates/wasi-common", version = "=19.0.0", default-features = false }
wasi-tokio = { path = "crates/wasi-common/tokio", version = "=19.0.0" }
wasi-cap-std-sync = { path = "crates/wasi-common/cap-std-sync", version = "=19.0.0" }
wasmtime-fuzzing = { path = "crates/fuzzing" }
wasmtime-jit-icache-coherence = { path = "crates/jit-icache-coherence", version = "=19.0.0" }
wasmtime-wit-bindgen = { path = "crates/wit-bindgen", version = "=19.0.0" }
Expand Down Expand Up @@ -358,7 +360,7 @@ disable-logging = ["log/max_level_off", "tracing/max_level_off"]
# the internal mapping for what they enable in Wasmtime itself.
wasi-nn = ["dep:wasmtime-wasi-nn"]
wasi-threads = ["dep:wasmtime-wasi-threads"]
wasi-http = ["component-model", "dep:wasmtime-wasi-http", "dep:tokio", "dep:hyper", "wasmtime-wasi-http?/sync"]
wasi-http = ["component-model", "dep:wasmtime-wasi-http", "dep:tokio", "dep:hyper"]
pooling-allocator = ["wasmtime/pooling-allocator", "wasmtime-cli-flags/pooling-allocator"]
component-model = [
"wasmtime/component-model",
Expand Down
6 changes: 3 additions & 3 deletions benches/instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::process::Command;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use std::thread;
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
use wasmtime::*;
use wasmtime_wasi::{sync::WasiCtxBuilder, WasiCtx};

fn store(engine: &Engine) -> Store<WasiCtx> {
let wasi = WasiCtxBuilder::new().build();
Expand Down Expand Up @@ -48,7 +48,7 @@ fn bench_sequential(c: &mut Criterion, path: &Path) {
// benchmark programs.
linker.func_wrap("bench", "start", || {}).unwrap();
linker.func_wrap("bench", "end", || {}).unwrap();
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |cx| cx).unwrap();
let pre = linker
.instantiate_pre(&module)
.expect("failed to pre-instantiate");
Expand Down Expand Up @@ -82,7 +82,7 @@ fn bench_parallel(c: &mut Criterion, path: &Path) {
// benchmark programs.
linker.func_wrap("bench", "start", || {}).unwrap();
linker.func_wrap("bench", "end", || {}).unwrap();
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |cx| cx).unwrap();
let pre = Arc::new(
linker
.instantiate_pre(&module)
Expand Down
8 changes: 4 additions & 4 deletions benches/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use criterion::{criterion_group, criterion_main, Criterion};
use std::{fs::File, path::Path, time::Instant};
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
use wasmtime::{Engine, Linker, Module, Store, TypedFunc};
use wasmtime_wasi::{sync::WasiCtxBuilder, WasiCtx};

criterion_group!(benches, bench_wasi);
criterion_main!(benches);
Expand Down Expand Up @@ -53,7 +53,7 @@ fn instantiate(wat: &[u8]) -> (Store<WasiCtx>, TypedFunc<u64, u64>) {
let mut store = Store::new(&engine, wasi);
let module = Module::new(&engine, wat).unwrap();
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
wasi_common::sync::add_to_linker(&mut linker, |cx| cx).unwrap();
let instance = linker.instantiate(&mut store, &module).unwrap();
let run = instance.get_typed_func(&mut store, "run").unwrap();
(store, run)
Expand All @@ -77,9 +77,9 @@ fn wasi_context() -> WasiCtx {
])
.unwrap()
.preopened_dir(
wasmtime_wasi::Dir::open_ambient_dir(
wasi_common::sync::Dir::open_ambient_dir(
"benches/wasi",
wasmtime_wasi::ambient_authority(),
wasi_common::sync::ambient_authority(),
)
.unwrap(),
"/",
Expand Down
3 changes: 1 addition & 2 deletions crates/bench-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ wasmtime = { workspace = true, default-features = true }
wasmtime-cli-flags = { workspace = true, default-features = true, features = [
"cranelift",
] }
wasmtime-wasi = { workspace = true, default-features = true }
wasi-common = { workspace = true, default-features = true }
wasmtime-wasi-nn = { workspace = true, optional = true }
wasi-cap-std-sync = { workspace = true }
cap-std = { workspace = true }
clap = { workspace = true }

Expand Down
10 changes: 5 additions & 5 deletions crates/bench-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ use std::os::raw::{c_int, c_void};
use std::slice;
use std::{env, path::PathBuf};
use target_lexicon::Triple;
use wasi_common::{sync::WasiCtxBuilder, I32Exit, WasiCtx};
use wasmtime::{Engine, Instance, Linker, Module, Store};
use wasmtime_cli_flags::CommonOptions;
use wasmtime_wasi::{sync::WasiCtxBuilder, I32Exit, WasiCtx};

pub type ExitCode = c_int;
pub const OK: ExitCode = 0;
Expand Down Expand Up @@ -304,20 +304,20 @@ pub extern "C" fn wasm_bench_create(
let stdout = std::fs::File::create(&stdout_path)
.with_context(|| format!("failed to create {}", stdout_path.display()))?;
let stdout = cap_std::fs::File::from_std(stdout);
let stdout = wasi_cap_std_sync::file::File::from_cap_std(stdout);
let stdout = wasi_common::sync::file::File::from_cap_std(stdout);
cx.stdout(Box::new(stdout));

let stderr = std::fs::File::create(&stderr_path)
.with_context(|| format!("failed to create {}", stderr_path.display()))?;
let stderr = cap_std::fs::File::from_std(stderr);
let stderr = wasi_cap_std_sync::file::File::from_cap_std(stderr);
let stderr = wasi_common::sync::file::File::from_cap_std(stderr);
cx.stderr(Box::new(stderr));

if let Some(stdin_path) = &stdin_path {
let stdin = std::fs::File::open(stdin_path)
.with_context(|| format!("failed to open {}", stdin_path.display()))?;
let stdin = cap_std::fs::File::from_std(stdin);
let stdin = wasi_cap_std_sync::file::File::from_cap_std(stdin);
let stdin = wasi_common::sync::file::File::from_cap_std(stdin);
cx.stdin(Box::new(stdin));
}

Expand Down Expand Up @@ -460,7 +460,7 @@ impl BenchState {
let fuel = options.wasm.fuel;

if options.wasi.common != Some(false) {
wasmtime_wasi::add_to_linker(&mut linker, |cx| &mut cx.wasi)?;
wasi_common::sync::add_to_linker(&mut linker, |cx| &mut cx.wasi)?;
}

#[cfg(feature = "wasi-nn")]
Expand Down
5 changes: 2 additions & 3 deletions crates/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ tracing = { workspace = true }
wat = { workspace = true, optional = true }

# Optional dependencies for the `wasi` feature
wasi-cap-std-sync = { workspace = true, optional = true }
wasmtime-wasi = { workspace = true, default-features = true, optional = true }
cap-std = { workspace = true, optional = true }
wasi-common = { workspace = true, optional = true }
wasi-common = { workspace = true, optional = true, features = ["sync"] }

# Optional dependencies for the `async` feature
futures = { workspace = true, optional = true }
Expand All @@ -44,7 +43,7 @@ async = ['wasmtime/async', 'futures']
profiling = ["wasmtime/profiling"]
cache = ["wasmtime/cache"]
parallel-compilation = ['wasmtime/parallel-compilation']
wasi = ['wasi-cap-std-sync', 'wasmtime-wasi', 'cap-std', 'wasi-common']
wasi = ['wasmtime-wasi', 'cap-std', 'wasi-common']
logging = ['dep:env_logger']
disable-logging = ["log/max_level_off", "tracing/max_level_off"]
coredump = ["wasmtime/coredump"]
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub extern "C" fn wasmtime_error_message(error: &wasmtime_error_t, message: &mut
#[no_mangle]
pub extern "C" fn wasmtime_error_exit_status(raw: &wasmtime_error_t, status: &mut i32) -> bool {
#[cfg(feature = "wasi")]
if let Some(exit) = raw.error.downcast_ref::<wasmtime_wasi::I32Exit>() {
if let Some(exit) = raw.error.downcast_ref::<wasi_common::I32Exit>() {
*status = exit.0;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/c-api/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub type CStoreContextMut<'a> = StoreContextMut<'a, StoreData>;
pub struct StoreData {
foreign: crate::ForeignData,
#[cfg(feature = "wasi")]
pub(crate) wasi: Option<wasmtime_wasi::WasiCtx>,
pub(crate) wasi: Option<wasi_common::WasiCtx>,

/// Temporary storage for usage during a wasm->host call to store values
/// in a slice we pass to the C API.
Expand Down
Loading
Loading