Skip to content

Commit 058218c

Browse files
committed
chore: rename WasiCtx -> WasiP2Ctx
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 867d190 commit 058218c

File tree

64 files changed

+367
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+367
-350
lines changed

benches/instantiation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use std::process::Command;
66
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst};
77
use std::sync::Arc;
88
use std::thread;
9-
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
9+
use wasi_common::{sync::WasiP2CtxBuilder, WasiP2Ctx};
1010
use wasmtime::*;
1111

12-
fn store(engine: &Engine) -> Store<WasiCtx> {
13-
let wasi = WasiCtxBuilder::new().build();
12+
fn store(engine: &Engine) -> Store<WasiP2Ctx> {
13+
let wasi = WasiP2CtxBuilder::new().build();
1414
Store::new(engine, wasi)
1515
}
1616

17-
fn instantiate(pre: &InstancePre<WasiCtx>, engine: &Engine) -> Result<()> {
17+
fn instantiate(pre: &InstancePre<WasiP2Ctx>, engine: &Engine) -> Result<()> {
1818
let mut store = store(engine);
1919
let _instance = pre.instantiate(&mut store)?;
2020
Ok(())

benches/wasi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use criterion::{criterion_group, criterion_main, Criterion};
44
use std::{fs::File, path::Path, time::Instant};
5-
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
5+
use wasi_common::{sync::WasiP2CtxBuilder, WasiP2Ctx};
66
use wasmtime::{Engine, Linker, Module, Store, TypedFunc};
77

88
criterion_group!(benches, bench_wasi);
@@ -47,7 +47,7 @@ fn bench_wasi(c: &mut Criterion) {
4747
/// - execute the body of the function for that number of loop iterations
4848
/// - return a single `u64` indicating how many loop iterations were executed
4949
/// (to double-check)
50-
fn instantiate(wat: &[u8]) -> (Store<WasiCtx>, TypedFunc<u64, u64>) {
50+
fn instantiate(wat: &[u8]) -> (Store<WasiP2Ctx>, TypedFunc<u64, u64>) {
5151
let engine = Engine::default();
5252
let wasi = wasi_context();
5353
let mut store = Store::new(&engine, wasi);
@@ -60,8 +60,8 @@ fn instantiate(wat: &[u8]) -> (Store<WasiCtx>, TypedFunc<u64, u64>) {
6060
}
6161

6262
/// Build a WASI context with some actual data to retrieve.
63-
fn wasi_context() -> WasiCtx {
64-
WasiCtxBuilder::new()
63+
fn wasi_context() -> WasiP2Ctx {
64+
WasiP2CtxBuilder::new()
6565
.envs(&[
6666
("a".to_string(), "b".to_string()),
6767
("b".to_string(), "c".to_string()),

crates/bench-api/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ use clap::Parser;
141141
use std::os::raw::{c_int, c_void};
142142
use std::slice;
143143
use std::{env, path::PathBuf};
144-
use wasi_common::{sync::WasiCtxBuilder, I32Exit, WasiCtx};
144+
use wasi_common::{sync::WasiP2CtxBuilder, I32Exit, WasiP2Ctx};
145145
use wasmtime::{Engine, Instance, Linker, Module, Store};
146146
use wasmtime_cli_flags::CommonOptions;
147147

@@ -298,7 +298,7 @@ pub extern "C" fn wasm_bench_create(
298298
config.execution_start,
299299
config.execution_end,
300300
move || {
301-
let mut cx = WasiCtxBuilder::new();
301+
let mut cx = WasiP2CtxBuilder::new();
302302

303303
let stdout = std::fs::File::create(&stdout_path)
304304
.with_context(|| format!("failed to create {}", stdout_path.display()))?;
@@ -407,15 +407,15 @@ struct BenchState {
407407
instantiation_timer: *mut u8,
408408
instantiation_start: extern "C" fn(*mut u8),
409409
instantiation_end: extern "C" fn(*mut u8),
410-
make_wasi_cx: Box<dyn FnMut() -> Result<WasiCtx>>,
410+
make_wasi_cx: Box<dyn FnMut() -> Result<WasiP2Ctx>>,
411411
module: Option<Module>,
412412
store_and_instance: Option<(Store<HostState>, Instance)>,
413413
epoch_interruption: bool,
414414
fuel: Option<u64>,
415415
}
416416

417417
struct HostState {
418-
wasi: WasiCtx,
418+
wasi: WasiP2Ctx,
419419
#[cfg(feature = "wasi-nn")]
420420
wasi_nn: wasmtime_wasi_nn::witx::WasiNnCtx,
421421
}
@@ -432,7 +432,7 @@ impl BenchState {
432432
execution_timer: *mut u8,
433433
execution_start: extern "C" fn(*mut u8),
434434
execution_end: extern "C" fn(*mut u8),
435-
make_wasi_cx: impl FnMut() -> Result<WasiCtx> + 'static,
435+
make_wasi_cx: impl FnMut() -> Result<WasiP2Ctx> + 'static,
436436
) -> Result<Self> {
437437
let mut config = options.config(None)?;
438438
// NB: always disable the compilation cache.

crates/c-api/src/wasi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ffi::{c_char, CStr};
66
use std::fs::File;
77
use std::path::Path;
88
use std::slice;
9-
use wasmtime_wasi::p2::WasiCtxBuilder;
9+
use wasmtime_wasi::p2::WasiP2CtxBuilder;
1010
use wasmtime_wasi::preview1::WasiP1Ctx;
1111

1212
unsafe fn cstr_to_path<'a>(path: *const c_char) -> Option<&'a Path> {
@@ -27,7 +27,7 @@ unsafe fn create_file(path: *const c_char) -> Option<File> {
2727

2828
#[repr(C)]
2929
pub struct wasi_config_t {
30-
builder: WasiCtxBuilder,
30+
builder: WasiP2CtxBuilder,
3131
}
3232

3333
wasmtime_c_api_macros::declare_own!(wasi_config_t);
@@ -41,7 +41,7 @@ impl wasi_config_t {
4141
#[unsafe(no_mangle)]
4242
pub extern "C" fn wasi_config_new() -> Box<wasi_config_t> {
4343
Box::new(wasi_config_t {
44-
builder: WasiCtxBuilder::new(),
44+
builder: WasiP2CtxBuilder::new(),
4545
})
4646
}
4747

crates/wasi-common/src/ctx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use std::sync::{Arc, Mutex};
1616
/// improvements that can be made (TODO:
1717
/// <https://github.com/bytecodealliance/wasmtime/issues/5643)>.
1818
#[derive(Clone)]
19-
pub struct WasiCtx(Arc<WasiCtxInner>);
19+
pub struct WasiP2Ctx(Arc<WasiP2CtxInner>);
2020

21-
pub struct WasiCtxInner {
21+
pub struct WasiP2CtxInner {
2222
pub args: StringArray,
2323
pub env: StringArray,
2424
// TODO: this mutex should not be necessary, it forces threads to serialize
@@ -30,14 +30,14 @@ pub struct WasiCtxInner {
3030
pub table: Table,
3131
}
3232

33-
impl WasiCtx {
33+
impl WasiP2Ctx {
3434
pub fn new(
3535
random: Box<dyn RngCore + Send + Sync>,
3636
clocks: WasiClocks,
3737
sched: Box<dyn WasiSched>,
3838
table: Table,
3939
) -> Self {
40-
let s = WasiCtx(Arc::new(WasiCtxInner {
40+
let s = WasiP2Ctx(Arc::new(WasiP2CtxInner {
4141
args: StringArray::new(),
4242
env: StringArray::new(),
4343
random: Mutex::new(random),
@@ -120,8 +120,8 @@ impl WasiCtx {
120120
}
121121
}
122122

123-
impl Deref for WasiCtx {
124-
type Target = WasiCtxInner;
123+
impl Deref for WasiP2Ctx {
124+
type Target = WasiP2CtxInner;
125125
fn deref(&self) -> &Self::Target {
126126
&self.0
127127
}

crates/wasi-common/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
//! `sched_yield` and `poll_oneoff` functions.
6464
//!
6565
//! Users can provide implementations of each of these interfaces to the
66-
//! `WasiCtx::builder(...)` function. The
67-
//! `wasi_cap_std_sync::WasiCtxBuilder::new()` function uses this public
66+
//! `WasiP2Ctx::builder(...)` function. The
67+
//! `wasi_cap_std_sync::WasiP2CtxBuilder::new()` function uses this public
6868
//! interface to plug in its own implementations of each of these resources.
6969
7070
#![warn(clippy::cast_sign_loss)]
@@ -91,7 +91,7 @@ pub mod tokio;
9191

9292
pub use cap_rand::RngCore;
9393
pub use clocks::{SystemTimeSpec, WasiClocks, WasiMonotonicClock, WasiSystemClock};
94-
pub use ctx::WasiCtx;
94+
pub use ctx::WasiP2Ctx;
9595
pub use dir::WasiDir;
9696
pub use error::{Error, ErrorExt, I32Exit};
9797
pub use file::WasiFile;

crates/wasi-common/src/pipe.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ use std::sync::{Arc, RwLock};
2020
/// A variety of `From` impls are provided so that common pipe types are easy to create. For example:
2121
///
2222
/// ```no_run
23-
/// use wasi_common::{pipe::ReadPipe, WasiCtx, Table};
23+
/// use wasi_common::{pipe::ReadPipe, WasiP2Ctx, Table};
2424
/// let stdin = ReadPipe::from("hello from stdin!");
2525
/// // Brint these instances from elsewhere (e.g. wasi-cap-std-sync):
2626
/// let random = todo!();
2727
/// let clocks = todo!();
2828
/// let sched = todo!();
2929
/// let table = Table::new();
30-
/// let mut ctx = WasiCtx::new(random, clocks, sched, table);
30+
/// let mut ctx = WasiP2Ctx::new(random, clocks, sched, table);
3131
/// ctx.set_stdin(Box::new(stdin.clone()));
3232
/// ```
3333
#[derive(Debug)]
@@ -116,14 +116,14 @@ impl<R: Read + Any + Send + Sync> WasiFile for ReadPipe<R> {
116116
/// A virtual pipe write end.
117117
///
118118
/// ```no_run
119-
/// use wasi_common::{pipe::WritePipe, WasiCtx, Table};
119+
/// use wasi_common::{pipe::WritePipe, WasiP2Ctx, Table};
120120
/// let stdout = WritePipe::new_in_memory();
121121
/// // Brint these instances from elsewhere (e.g. wasi-cap-std-sync):
122122
/// let random = todo!();
123123
/// let clocks = todo!();
124124
/// let sched = todo!();
125125
/// let table = Table::new();
126-
/// let mut ctx = WasiCtx::new(random, clocks, sched, table);
126+
/// let mut ctx = WasiP2Ctx::new(random, clocks, sched, table);
127127
/// ctx.set_stdout(Box::new(stdout.clone()));
128128
/// // use ctx in an instance, then make sure it is dropped:
129129
/// drop(ctx);

crates/wasi-common/src/snapshots/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! One goal of `wasi-common` is for multiple WASI snapshots to provide an
2-
//! interface to the same underlying `crate::WasiCtx`. This provides us a path
2+
//! interface to the same underlying `crate::WasiP2Ctx`. This provides us a path
33
//! to evolve WASI by allowing the same WASI Command to import functions from
44
//! different snapshots - e.g. the user could use Rust's `std` which imports
55
//! snapshot 1, but also depend directly on the `wasi` crate which imports
@@ -10,14 +10,14 @@
1010
//!
1111
//! * Snapshots are arranged into modules under `crate::snapshots::`.
1212
//! * Each snapshot should invoke `wiggle::from_witx!` with `ctx:
13-
//! crate::WasiCtx` in its module, and impl all of the required traits.
13+
//! crate::WasiP2Ctx` in its module, and impl all of the required traits.
1414
//! * Snapshots can be implemented in terms of other snapshots. For example,
1515
//! snapshot 0 is mostly implemented by calling the snapshot 1 implementation,
1616
//! and converting its own types back and forth with the snapshot 1 types. In a
1717
//! few cases, that is not feasible, so snapshot 0 carries its own
1818
//! implementations in terms of the `WasiFile` and `WasiSched` traits.
1919
//! * Snapshots can be implemented in terms of the `Wasi*` traits given by
20-
//! `WasiCtx`. No further downcasting via the `as_any` escape hatch is
20+
//! `WasiP2Ctx`. No further downcasting via the `as_any` escape hatch is
2121
//! permitted.
2222
2323
pub mod preview_0;

crates/wasi-common/src/snapshots/preview_0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::sched::{
55
};
66
use crate::snapshots::preview_1::types as snapshot1_types;
77
use crate::snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1 as Snapshot1;
8-
use crate::{ErrorExt, WasiCtx};
8+
use crate::{ErrorExt, WasiP2Ctx};
99
use cap_std::time::Duration;
1010
use std::collections::HashSet;
1111
use wiggle::{GuestMemory, GuestPtr};
@@ -384,7 +384,7 @@ convert_flags_bidirectional!(
384384
// This implementation, wherever possible, delegates directly to the Snapshot1 implementation,
385385
// performing the no-op type conversions along the way.
386386
#[wiggle::async_trait]
387-
impl wasi_unstable::WasiUnstable for WasiCtx {
387+
impl wasi_unstable::WasiUnstable for WasiP2Ctx {
388388
async fn args_get(
389389
&mut self,
390390
memory: &mut GuestMemory<'_>,

crates/wasi-common/src/snapshots/preview_1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
subscription::{RwEventFlags, SubscriptionResult},
99
Poll, Userdata,
1010
},
11-
I32Exit, SystemTimeSpec, WasiCtx,
11+
I32Exit, SystemTimeSpec, WasiP2Ctx,
1212
};
1313
use cap_std::time::{Duration, SystemClock};
1414
use std::borrow::Cow;
@@ -42,7 +42,7 @@ impl wiggle::GuestErrorType for types::Errno {
4242
}
4343

4444
#[wiggle::async_trait]
45-
impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
45+
impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiP2Ctx {
4646
async fn args_get(
4747
&mut self,
4848
memory: &mut GuestMemory<'_>,

crates/wasi-common/src/sync/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//! exception of the `sched` implementation, which is provided for both unix
77
//! and windows in separate modules.
88
//!
9-
//! Any `wasi_common::{WasiCtx, WasiCtxBuilder}` is interoperable with the
9+
//! Any `wasi_common::{WasiP2Ctx, WasiP2CtxBuilder}` is interoperable with the
1010
//! implementations provided in `wasi_common::sync`. However, for convenience,
11-
//! this module provides its own `WasiCtxBuilder` that hooks up to all of the
11+
//! this module provides its own `WasiP2CtxBuilder` that hooks up to all of the
1212
//! crate's components, i.e. it fills in all of the arguments to
13-
//! `WasiCtx::builder(...)`, presents `preopen_dir` in terms of
13+
//! `WasiP2Ctx::builder(...)`, presents `preopen_dir` in terms of
1414
//! `cap_std::fs::Dir`, and provides convenience methods for inheriting the
1515
//! parent process's stdio, args, and env.
1616
@@ -28,20 +28,20 @@ pub use clocks::clocks_ctx;
2828
pub use sched::sched_ctx;
2929

3030
use self::net::Socket;
31-
use crate::{file::FileAccessMode, table::Table, Error, WasiCtx, WasiFile};
31+
use crate::{file::FileAccessMode, table::Table, Error, WasiFile, WasiP2Ctx};
3232
use cap_rand::{Rng, RngCore, SeedableRng};
3333
use std::mem;
3434
use std::path::Path;
3535

36-
pub struct WasiCtxBuilder {
37-
ctx: WasiCtx,
36+
pub struct WasiP2CtxBuilder {
37+
ctx: WasiP2Ctx,
3838
built: bool,
3939
}
4040

41-
impl WasiCtxBuilder {
41+
impl WasiP2CtxBuilder {
4242
pub fn new() -> Self {
43-
WasiCtxBuilder {
44-
ctx: WasiCtx::new(random_ctx(), clocks_ctx(), sched_ctx(), Table::new()),
43+
WasiP2CtxBuilder {
44+
ctx: WasiP2Ctx::new(random_ctx(), clocks_ctx(), sched_ctx(), Table::new()),
4545
built: false,
4646
}
4747
}
@@ -121,9 +121,9 @@ impl WasiCtxBuilder {
121121
.insert_file(fd, file, FileAccessMode::READ | FileAccessMode::WRITE);
122122
Ok(self)
123123
}
124-
pub fn build(&mut self) -> WasiCtx {
124+
pub fn build(&mut self) -> WasiP2Ctx {
125125
assert!(!self.built);
126-
let WasiCtxBuilder { ctx, .. } = mem::replace(self, Self::new());
126+
let WasiP2CtxBuilder { ctx, .. } = mem::replace(self, Self::new());
127127
self.built = true;
128128
ctx
129129
}

crates/wasi-common/src/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::collections::HashMap;
44
use std::sync::{Arc, RwLock};
55

66
/// The `Table` type is designed to map u32 handles to resources. The table is now part of the
7-
/// public interface to a `WasiCtx` - it is reference counted so that it can be shared beyond a
8-
/// `WasiCtx` with other WASI proposals (e.g. `wasi-crypto` and `wasi-nn`) to manage their
7+
/// public interface to a `WasiP2Ctx` - it is reference counted so that it can be shared beyond a
8+
/// `WasiP2Ctx` with other WASI proposals (e.g. `wasi-crypto` and `wasi-nn`) to manage their
99
/// resources. Elements in the `Table` are `Any` typed.
1010
///
1111
/// The `Table` type is intended to model how the Interface Types concept of Resources is shaping

crates/wasi-common/src/tokio/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ pub mod stdio;
77
use self::sched::sched_ctx;
88
use crate::sync::net::Socket;
99
pub use crate::sync::{clocks_ctx, random_ctx};
10-
use crate::{file::FileAccessMode, Error, Table, WasiCtx, WasiFile};
10+
use crate::{file::FileAccessMode, Error, Table, WasiFile, WasiP2Ctx};
1111
pub use dir::Dir;
1212
pub use file::File;
1313
pub use net::*;
1414
use std::future::Future;
1515
use std::mem;
1616
use std::path::Path;
1717

18-
pub struct WasiCtxBuilder {
19-
ctx: WasiCtx,
18+
pub struct WasiP2CtxBuilder {
19+
ctx: WasiP2Ctx,
2020
built: bool,
2121
}
2222

23-
impl WasiCtxBuilder {
23+
impl WasiP2CtxBuilder {
2424
pub fn new() -> Self {
25-
WasiCtxBuilder {
26-
ctx: WasiCtx::new(random_ctx(), clocks_ctx(), sched_ctx(), Table::new()),
25+
WasiP2CtxBuilder {
26+
ctx: WasiP2Ctx::new(random_ctx(), clocks_ctx(), sched_ctx(), Table::new()),
2727
built: false,
2828
}
2929
}
@@ -104,9 +104,9 @@ impl WasiCtxBuilder {
104104
Ok(self)
105105
}
106106

107-
pub fn build(&mut self) -> WasiCtx {
107+
pub fn build(&mut self) -> WasiP2Ctx {
108108
assert!(!self.built);
109-
let WasiCtxBuilder { ctx, .. } = mem::replace(self, Self::new());
109+
let WasiP2CtxBuilder { ctx, .. } = mem::replace(self, Self::new());
110110
self.built = true;
111111
ctx
112112
}

crates/wasi-common/tests/all/async_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22
use test_programs_artifacts::*;
3-
use wasi_common::tokio::{add_to_linker, WasiCtxBuilder};
3+
use wasi_common::tokio::{add_to_linker, WasiP2CtxBuilder};
44

55
foreach_preview1!(assert_test_exists);
66

@@ -25,7 +25,7 @@ async fn run(path: &str, inherit_stdio: bool) -> Result<()> {
2525

2626
// Create our wasi context.
2727
// Additionally register any preopened directories if we have them.
28-
let mut builder = WasiCtxBuilder::new();
28+
let mut builder = WasiP2CtxBuilder::new();
2929

3030
if inherit_stdio {
3131
builder.inherit_stdio();

0 commit comments

Comments
 (0)