Merge remote-tracking branch 'origin/main' into pch/wiggle_sync_shimming
This commit is contained in:
@@ -28,7 +28,7 @@ lazy_static::lazy_static! {
|
||||
Compiling for a specific platform (Linux) and CPU preset (Skylake):\n\
|
||||
\n \
|
||||
wasmtime compile --target x86_64-unknown-linux --cranelift-enable skylake foo.wasm\n",
|
||||
crate::WASM_FEATURES.as_str()
|
||||
crate::FLAG_EXPLANATIONS.as_str()
|
||||
)
|
||||
};
|
||||
}
|
||||
@@ -126,7 +126,8 @@ mod test {
|
||||
command.execute()?;
|
||||
|
||||
let engine = Engine::default();
|
||||
let module = Module::from_file(&engine, output_path)?;
|
||||
let contents = std::fs::read(output_path)?;
|
||||
let module = unsafe { Module::deserialize(&engine, contents)? };
|
||||
let store = Store::new(&engine);
|
||||
let instance = Instance::new(&store, &module, &[])?;
|
||||
let f = instance.get_typed_func::<i32, i32>("f")?;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The module that implements the `wasmtime run` command.
|
||||
|
||||
use crate::CommonOptions;
|
||||
use crate::{CommonOptions, WasiModules};
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -67,7 +67,7 @@ fn parse_preloads(s: &str) -> Result<(String, PathBuf)> {
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref AFTER_HELP: String = {
|
||||
crate::WASM_FEATURES.to_string()
|
||||
crate::FLAG_EXPLANATIONS.to_string()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -143,7 +143,13 @@ impl RunCommand {
|
||||
let argv = self.compute_argv();
|
||||
|
||||
let mut linker = Linker::new(&store);
|
||||
populate_with_wasi(&mut linker, preopen_dirs, &argv, &self.vars)?;
|
||||
populate_with_wasi(
|
||||
&mut linker,
|
||||
preopen_dirs,
|
||||
&argv,
|
||||
&self.vars,
|
||||
&self.common.wasi_modules.unwrap_or(WasiModules::default()),
|
||||
)?;
|
||||
|
||||
// Load the preload wasm modules.
|
||||
for (name, path) in self.preloads.iter() {
|
||||
@@ -348,6 +354,7 @@ fn populate_with_wasi(
|
||||
preopen_dirs: Vec<(String, Dir)>,
|
||||
argv: &[String],
|
||||
vars: &[(String, String)],
|
||||
wasi_modules: &WasiModules,
|
||||
) -> Result<()> {
|
||||
// Add the current snapshot to the linker.
|
||||
let mut builder = WasiCtxBuilder::new();
|
||||
@@ -357,25 +364,40 @@ fn populate_with_wasi(
|
||||
builder = builder.preopened_dir(dir, name)?;
|
||||
}
|
||||
|
||||
Wasi::new(linker.store(), builder.build()?).add_to_linker(linker)?;
|
||||
|
||||
#[cfg(feature = "wasi-nn")]
|
||||
{
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
let wasi_nn = WasiNn::new(linker.store(), Rc::new(RefCell::new(WasiNnCtx::new()?)));
|
||||
wasi_nn.add_to_linker(linker)?;
|
||||
if wasi_modules.wasi_common {
|
||||
Wasi::new(linker.store(), builder.build()?).add_to_linker(linker)?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "wasi-crypto")]
|
||||
{
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
let cx_crypto = Rc::new(RefCell::new(WasiCryptoCtx::new()));
|
||||
WasiCryptoCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
|
||||
WasiCryptoAsymmetricCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
|
||||
WasiCryptoSignatures::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
|
||||
WasiCryptoSymmetric::new(linker.store(), cx_crypto).add_to_linker(linker)?;
|
||||
if wasi_modules.wasi_nn {
|
||||
#[cfg(not(feature = "wasi-nn"))]
|
||||
{
|
||||
bail!("Cannot enable wasi-nn when the binary is not compiled with this feature.");
|
||||
}
|
||||
#[cfg(feature = "wasi-nn")]
|
||||
{
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
let wasi_nn = WasiNn::new(linker.store(), Rc::new(RefCell::new(WasiNnCtx::new()?)));
|
||||
wasi_nn.add_to_linker(linker)?;
|
||||
}
|
||||
}
|
||||
|
||||
if wasi_modules.wasi_crypto {
|
||||
#[cfg(not(feature = "wasi-crypto"))]
|
||||
{
|
||||
bail!("Cannot enable wasi-crypto when the binary is not compiled with this feature.");
|
||||
}
|
||||
#[cfg(feature = "wasi-crypto")]
|
||||
{
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
let cx_crypto = Rc::new(RefCell::new(WasiCryptoCtx::new()));
|
||||
WasiCryptoCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
|
||||
WasiCryptoAsymmetricCommon::new(linker.store(), cx_crypto.clone())
|
||||
.add_to_linker(linker)?;
|
||||
WasiCryptoSignatures::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
|
||||
WasiCryptoSymmetric::new(linker.store(), cx_crypto).add_to_linker(linker)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -18,7 +18,7 @@ lazy_static::lazy_static! {
|
||||
The default is a dummy environment that produces placeholder values.\n\
|
||||
\n\
|
||||
{}",
|
||||
crate::WASM_FEATURES.as_str()
|
||||
crate::FLAG_EXPLANATIONS.as_str()
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use wasmtime_wast::WastContext;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref AFTER_HELP: String = {
|
||||
crate::WASM_FEATURES.to_string()
|
||||
crate::FLAG_EXPLANATIONS.to_string()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user