Skip to content

Commit bc1fcaa

Browse files
author
Jakub Konka
committed
Should use OsOther to wrap custom stdio
1 parent 3fd4e62 commit bc1fcaa

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

crates/c-api/src/wasi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn create_snapshot0_instance(store: &Store, config: wasi_config_t) -> Result<Was
238238

239239
fn wasi_preview_builder(config: wasi_config_t) -> Result<WasiPreview1CtxBuilder> {
240240
use std::convert::TryFrom;
241-
use wasi_common::OsFile;
241+
use wasi_common::OsOther;
242242
let mut builder = WasiPreview1CtxBuilder::new();
243243
if config.inherit_args {
244244
builder.inherit_args();
@@ -253,17 +253,17 @@ fn wasi_preview_builder(config: wasi_config_t) -> Result<WasiPreview1CtxBuilder>
253253
if config.inherit_stdin {
254254
builder.inherit_stdin();
255255
} else if let Some(file) = config.stdin {
256-
builder.stdin(OsFile::try_from(file)?);
256+
builder.stdin(OsOther::try_from(file)?);
257257
}
258258
if config.inherit_stdout {
259259
builder.inherit_stdout();
260260
} else if let Some(file) = config.stdout {
261-
builder.stdout(OsFile::try_from(file)?);
261+
builder.stdout(OsOther::try_from(file)?);
262262
}
263263
if config.inherit_stderr {
264264
builder.inherit_stderr();
265265
} else if let Some(file) = config.stderr {
266-
builder.stderr(OsFile::try_from(file)?);
266+
builder.stderr(OsOther::try_from(file)?);
267267
}
268268
for preopen in config.preopens {
269269
builder.preopened_dir(preopen.0, preopen.1);

crates/test-programs/tests/wasm_tests/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::{bail, Context};
22
use std::convert::TryFrom;
33
use std::fs::File;
44
use std::path::Path;
5-
use wasi_common::{OsFile, VirtualDirEntry};
5+
use wasi_common::{OsOther, VirtualDirEntry};
66
use wasmtime::{Instance, Module, Store};
77

88
#[derive(Clone, Copy, Debug)]
@@ -48,7 +48,7 @@ pub fn instantiate(
4848
// stdin is closed which causes tests to fail.
4949
let (reader, _writer) = os_pipe::pipe()?;
5050
let file = reader_to_file(reader);
51-
let handle = OsFile::try_from(file).context("failed to create OsFile from PipeReader")?;
51+
let handle = OsOther::try_from(file).context("failed to create OsOther from PipeReader")?;
5252
builder.stdin(handle);
5353
let snapshot1 = wasmtime_wasi::Wasi::new(&store, builder.build()?);
5454
let module = Module::new(&store, &data).context("failed to create wasm module")?;

crates/wasi-common/src/entry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::rc::Rc;
88
pub(crate) struct EntryHandle(Rc<dyn Handle>);
99

1010
impl EntryHandle {
11+
#[allow(dead_code)]
1112
pub(crate) fn new<T: Handle + 'static>(handle: T) -> Self {
1213
Self(Rc::new(handle))
1314
}

crates/wasi-common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub use ctx::{WasiCtx, WasiCtxBuilder, WasiCtxBuilderError};
3939
pub use handle::{Handle, HandleRights};
4040
pub use sys::osdir::OsDir;
4141
pub use sys::osfile::OsFile;
42+
pub use sys::osother::{OsOther, OsOtherExt};
4243
pub use sys::preopen_dir;
4344
pub use sys::stdio::{Stdio, StdioExt};
4445
pub use virtfs::{FileContents, VirtualDirEntry};

crates/wasi-common/src/sys/osother.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use std::fs::File;
1010
use std::io::{self, Read, Write};
1111
use std::ops::Deref;
1212

13-
pub(crate) trait OsOtherExt {
13+
pub trait OsOtherExt {
1414
/// Create `OsOther` as `dyn Handle` from null device.
1515
fn from_null() -> io::Result<Box<dyn Handle>>;
1616
}
1717

1818
#[derive(Debug)]
19-
pub(crate) struct OsOther {
19+
pub struct OsOther {
2020
file_type: Filetype,
2121
rights: Cell<HandleRights>,
2222
handle: OsHandle,

0 commit comments

Comments
 (0)