Use preopen_dir handlers exposed in wasi-common
This commit is contained in:
@@ -31,6 +31,7 @@ wasmtime-jit = { path = "wasmtime-jit" }
|
|||||||
wasmtime-obj = { path = "wasmtime-obj" }
|
wasmtime-obj = { path = "wasmtime-obj" }
|
||||||
wasmtime-wast = { path = "wasmtime-wast" }
|
wasmtime-wast = { path = "wasmtime-wast" }
|
||||||
wasmtime-wasi = { path = "wasmtime-wasi" }
|
wasmtime-wasi = { path = "wasmtime-wasi" }
|
||||||
|
wasi-common = { git = "https://github.com/CraneStation/wasi-common" }
|
||||||
docopt = "1.0.1"
|
docopt = "1.0.1"
|
||||||
serde = "1.0.75"
|
serde = "1.0.75"
|
||||||
serde_derive = "1.0.75"
|
serde_derive = "1.0.75"
|
||||||
@@ -45,9 +46,6 @@ errno = "0.2.4"
|
|||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
wasmtime-wasi-c = { path = "wasmtime-wasi-c" }
|
wasmtime-wasi-c = { path = "wasmtime-wasi-c" }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
|
||||||
winapi = "0.3"
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ use std::path::Component;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use wabt;
|
use wabt;
|
||||||
|
use wasi_common::preopen_dir;
|
||||||
use wasmtime_jit::{ActionOutcome, Context};
|
use wasmtime_jit::{ActionOutcome, Context};
|
||||||
use wasmtime_wasi::instantiate_wasi;
|
use wasmtime_wasi::instantiate_wasi;
|
||||||
use wasmtime_wast::instantiate_spectest;
|
use wasmtime_wast::instantiate_spectest;
|
||||||
@@ -118,33 +119,6 @@ fn read_wasm(path: PathBuf) -> Result<Vec<u8>, String> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preopen_dir<P: AsRef<Path>>(path: P) -> io::Result<File> {
|
|
||||||
#[cfg(windows)]
|
|
||||||
{
|
|
||||||
use std::fs::OpenOptions;
|
|
||||||
use std::os::windows::fs::OpenOptionsExt;
|
|
||||||
use winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS;
|
|
||||||
|
|
||||||
// To open a directory using CreateFile2, specify the
|
|
||||||
// FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFileFlags...
|
|
||||||
// cf. https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfile2
|
|
||||||
OpenOptions::new()
|
|
||||||
.create(false)
|
|
||||||
.write(true)
|
|
||||||
.read(true)
|
|
||||||
.attributes(FILE_FLAG_BACKUP_SEMANTICS)
|
|
||||||
.open(path)
|
|
||||||
}
|
|
||||||
#[cfg(unix)]
|
|
||||||
{
|
|
||||||
File::open(path)
|
|
||||||
}
|
|
||||||
#[cfg(not(any(windows, unix)))]
|
|
||||||
{
|
|
||||||
unimplemented!("this OS is currently not supported by Wasmtime")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(String, File)> {
|
fn compute_preopen_dirs(flag_dir: &[String], flag_mapdir: &[String]) -> Vec<(String, File)> {
|
||||||
let mut preopen_dirs = Vec::new();
|
let mut preopen_dirs = Vec::new();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user