Rename the wasmtime_api library to match the containing wasmtime crate (#594)
* Rename the `wasmtime_api` library to match the containing `wasmtime` crate
Commit d9ca508f80 renamed the
`wasmtime-api` crate to `wasmtime`, but left the name of the library it
contains as `wasmtime_api`.
It's fairly unusual for a crate to contain a library with a different
name, and it results in rather confusing error messages for a user; if
you list `wasmtime = "0.7"` in `Cargo.toml`, you can't `use
wasmtime::*`, you have to `use wasmtime_api::*;`.
Rename the `wasmtime_api` library to `wasmtime`.
* Stop renaming wasmtime to api on imports
Various users renamed the crate formerly known as wasmtime_api to api,
and then used api:: prefixes everywhere; change those all to wasmtime::
and drop the renaming.
This commit is contained in:
committed by
Dan Gohman
parent
58dd4c6c88
commit
2635ccb742
12
.github/workflows/main.yml
vendored
12
.github/workflows/main.yml
vendored
@@ -191,7 +191,7 @@ jobs:
|
|||||||
name: wheels-${{ matrix.os }}
|
name: wheels-${{ matrix.os }}
|
||||||
path: crates/misc/py/wheelhouse
|
path: crates/misc/py/wheelhouse
|
||||||
|
|
||||||
# Perform release builds of `wasmtime` and `libwasmtime_api.so`. Builds on
|
# Perform release builds of `wasmtime` and `libwasmtime.so`. Builds on
|
||||||
# Windows/Mac/Linux, and artifacts are uploaded after the build is finished.
|
# Windows/Mac/Linux, and artifacts are uploaded after the build is finished.
|
||||||
# Note that we also run tests here to test exactly what we're deploying.
|
# Note that we also run tests here to test exactly what we're deploying.
|
||||||
build:
|
build:
|
||||||
@@ -215,7 +215,7 @@ jobs:
|
|||||||
# Build `wasmtime` and executables
|
# Build `wasmtime` and executables
|
||||||
- run: $CENTOS cargo build --release --bin wasmtime --bin wasm2obj
|
- run: $CENTOS cargo build --release --bin wasmtime --bin wasm2obj
|
||||||
shell: bash
|
shell: bash
|
||||||
# Build `libwasmtime_api.so`
|
# Build `libwasmtime.so`
|
||||||
- run: $CENTOS cargo build --release --manifest-path crates/api/Cargo.toml
|
- run: $CENTOS cargo build --release --manifest-path crates/api/Cargo.toml
|
||||||
shell: bash
|
shell: bash
|
||||||
# Test what we just built
|
# Test what we just built
|
||||||
@@ -237,12 +237,12 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
|
|
||||||
# Move libwasmtime_api dylib to dist folder
|
# Move libwasmtime dylib to dist folder
|
||||||
- run: cp target/release/libwasmtime_api.{so,a} dist
|
- run: cp target/release/libwasmtime.{so,a} dist
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
- run: cp target/release/libwasmtime_api.{dylib,a} dist
|
- run: cp target/release/libwasmtime.{dylib,a} dist
|
||||||
if: matrix.os == 'macos-latest'
|
if: matrix.os == 'macos-latest'
|
||||||
- run: cp target/release/wasmtime_api.{dll,lib} dist
|
- run: cp target/release/wasmtime.{dll,lib} dist
|
||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ readme = "README.md"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "wasmtime_api"
|
name = "wasmtime"
|
||||||
crate-type = ["lib", "staticlib", "cdylib"]
|
crate-type = ["lib", "staticlib", "cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ endif
|
|||||||
|
|
||||||
WASMTIME_BIN_DIR = ${WASMTIME_API_DIR}/../target/${WASMTIME_API_MODE}
|
WASMTIME_BIN_DIR = ${WASMTIME_API_DIR}/../target/${WASMTIME_API_MODE}
|
||||||
WASMTIME_C_LIB_DIR = ${WASMTIME_BIN_DIR}
|
WASMTIME_C_LIB_DIR = ${WASMTIME_BIN_DIR}
|
||||||
WASMTIME_C_LIBS = wasmtime_api
|
WASMTIME_C_LIBS = wasmtime
|
||||||
WASMTIME_CC_LIBS = $(error unsupported c++)
|
WASMTIME_CC_LIBS = $(error unsupported c++)
|
||||||
|
|
||||||
WASMTIME_C_BINS = ${WASMTIME_C_LIBS:%=${WASMTIME_C_LIB_DIR}/lib%.a}
|
WASMTIME_C_BINS = ${WASMTIME_C_LIBS:%=${WASMTIME_C_LIB_DIR}/lib%.a}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//! invoking its exported function.
|
//! invoking its exported function.
|
||||||
|
|
||||||
use anyhow::{format_err, Result};
|
use anyhow::{format_err, Result};
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
const WAT: &str = r#"
|
const WAT: &str = r#"
|
||||||
(module
|
(module
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use anyhow::{ensure, format_err, Context as _, Result};
|
use anyhow::{ensure, format_err, Context as _, Result};
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
struct HelloCallback;
|
struct HelloCallback;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use anyhow::{bail, ensure, Context as _, Error};
|
use anyhow::{bail, ensure, Context as _, Error};
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
fn get_export_memory(exports: &[Extern], i: usize) -> Result<HostRef<Memory>, Error> {
|
fn get_export_memory(exports: &[Extern], i: usize) -> Result<HostRef<Memory>, Error> {
|
||||||
if exports.len() <= i {
|
if exports.len() <= i {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use anyhow::{ensure, format_err, Context as _, Result};
|
use anyhow::{ensure, format_err, Context as _, Result};
|
||||||
use std::cell::Ref;
|
use std::cell::Ref;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
struct Callback;
|
struct Callback;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::cell::{Ref, RefCell};
|
use std::cell::{Ref, RefCell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_import_calling_export() {
|
fn test_import_calling_export() {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use cranelift_codegen::ir;
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::str;
|
use std::str;
|
||||||
use wasm_webidl_bindings::ast;
|
use wasm_webidl_bindings::ast;
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_jit::RuntimeValue;
|
use wasmtime_jit::RuntimeValue;
|
||||||
use wasmtime_runtime::{Export, InstanceHandle};
|
use wasmtime_runtime::{Export, InstanceHandle};
|
||||||
|
|
||||||
@@ -126,7 +125,7 @@ impl ModuleData {
|
|||||||
/// wasm interface types.
|
/// wasm interface types.
|
||||||
pub fn invoke_export(
|
pub fn invoke_export(
|
||||||
&self,
|
&self,
|
||||||
instance: &api::HostRef<api::Instance>,
|
instance: &wasmtime::HostRef<wasmtime::Instance>,
|
||||||
export: &str,
|
export: &str,
|
||||||
args: &[Value],
|
args: &[Value],
|
||||||
) -> Result<Vec<Value>> {
|
) -> Result<Vec<Value>> {
|
||||||
@@ -153,7 +152,7 @@ impl ModuleData {
|
|||||||
Ok(values) => values
|
Ok(values) => values
|
||||||
.to_vec()
|
.to_vec()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v: api::Val| v.into())
|
.map(|v: wasmtime::Val| v.into())
|
||||||
.collect::<Vec<RuntimeValue>>(),
|
.collect::<Vec<RuntimeValue>>(),
|
||||||
Err(trap) => bail!("trapped: {:?}", trap),
|
Err(trap) => bail!("trapped: {:?}", trap),
|
||||||
};
|
};
|
||||||
@@ -316,7 +315,7 @@ trait TranslateContext {
|
|||||||
unsafe fn get_memory(&mut self) -> Result<&mut [u8]>;
|
unsafe fn get_memory(&mut self) -> Result<&mut [u8]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InstanceTranslateContext(pub api::HostRef<api::Instance>);
|
struct InstanceTranslateContext(pub wasmtime::HostRef<wasmtime::Instance>);
|
||||||
|
|
||||||
impl TranslateContext for InstanceTranslateContext {
|
impl TranslateContext for InstanceTranslateContext {
|
||||||
fn invoke_alloc(&mut self, alloc_func_name: &str, len: i32) -> Result<i32> {
|
fn invoke_alloc(&mut self, alloc_func_name: &str, len: i32) -> Result<i32> {
|
||||||
@@ -328,7 +327,7 @@ impl TranslateContext for InstanceTranslateContext {
|
|||||||
.func()
|
.func()
|
||||||
.ok_or_else(|| format_err!("`{}` is not a (alloc) function", alloc_func_name))?
|
.ok_or_else(|| format_err!("`{}` is not a (alloc) function", alloc_func_name))?
|
||||||
.clone();
|
.clone();
|
||||||
let alloc_args = vec![api::Val::I32(len)];
|
let alloc_args = vec![wasmtime::Val::I32(len)];
|
||||||
let results = match alloc.borrow().call(&alloc_args) {
|
let results = match alloc.borrow().call(&alloc_args) {
|
||||||
Ok(values) => values,
|
Ok(values) => values,
|
||||||
Err(trap) => bail!("trapped: {:?}", trap),
|
Err(trap) => bail!("trapped: {:?}", trap),
|
||||||
@@ -337,7 +336,7 @@ impl TranslateContext for InstanceTranslateContext {
|
|||||||
bail!("allocator function wrong number of results");
|
bail!("allocator function wrong number of results");
|
||||||
}
|
}
|
||||||
Ok(match results[0] {
|
Ok(match results[0] {
|
||||||
api::Val::I32(i) => i,
|
wasmtime::Val::I32(i) => i,
|
||||||
_ => bail!("allocator function bad return type"),
|
_ => bail!("allocator function bad return type"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,19 @@ use pyo3::exceptions::Exception;
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::{PyAny, PyDict, PyTuple};
|
use pyo3::types::{PyAny, PyDict, PyTuple};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_interface_types::ModuleData;
|
use wasmtime_interface_types::ModuleData;
|
||||||
|
|
||||||
// TODO support non-export functions
|
// TODO support non-export functions
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub instance: api::HostRef<api::Instance>,
|
pub instance: wasmtime::HostRef<wasmtime::Instance>,
|
||||||
pub export_name: String,
|
pub export_name: String,
|
||||||
pub args_types: Vec<api::ValType>,
|
pub args_types: Vec<wasmtime::ValType>,
|
||||||
pub data: Rc<ModuleData>,
|
pub data: Rc<ModuleData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
pub fn func(&self) -> api::HostRef<api::Func> {
|
pub fn func(&self) -> wasmtime::HostRef<wasmtime::Func> {
|
||||||
let e = self
|
let e = self
|
||||||
.instance
|
.instance
|
||||||
.borrow()
|
.borrow()
|
||||||
@@ -54,23 +53,23 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_annotation_type(s: &str) -> api::ValType {
|
fn parse_annotation_type(s: &str) -> wasmtime::ValType {
|
||||||
match s {
|
match s {
|
||||||
"I32" | "i32" => api::ValType::I32,
|
"I32" | "i32" => wasmtime::ValType::I32,
|
||||||
"I64" | "i64" => api::ValType::I64,
|
"I64" | "i64" => wasmtime::ValType::I64,
|
||||||
"F32" | "f32" => api::ValType::F32,
|
"F32" | "f32" => wasmtime::ValType::F32,
|
||||||
"F64" | "f64" => api::ValType::F64,
|
"F64" | "f64" => wasmtime::ValType::F64,
|
||||||
_ => panic!("unknown type in annotations"),
|
_ => panic!("unknown type in annotations"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WrappedFn {
|
struct WrappedFn {
|
||||||
func: PyObject,
|
func: PyObject,
|
||||||
returns_types: Vec<api::ValType>,
|
returns_types: Vec<wasmtime::ValType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WrappedFn {
|
impl WrappedFn {
|
||||||
pub fn new(func: PyObject, returns_types: Vec<api::ValType>) -> Self {
|
pub fn new(func: PyObject, returns_types: Vec<wasmtime::ValType>) -> Self {
|
||||||
WrappedFn {
|
WrappedFn {
|
||||||
func,
|
func,
|
||||||
returns_types,
|
returns_types,
|
||||||
@@ -78,20 +77,20 @@ impl WrappedFn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl api::Callable for WrappedFn {
|
impl wasmtime::Callable for WrappedFn {
|
||||||
fn call(
|
fn call(
|
||||||
&self,
|
&self,
|
||||||
params: &[api::Val],
|
params: &[wasmtime::Val],
|
||||||
returns: &mut [api::Val],
|
returns: &mut [wasmtime::Val],
|
||||||
) -> Result<(), api::HostRef<api::Trap>> {
|
) -> Result<(), wasmtime::HostRef<wasmtime::Trap>> {
|
||||||
let gil = Python::acquire_gil();
|
let gil = Python::acquire_gil();
|
||||||
let py = gil.python();
|
let py = gil.python();
|
||||||
|
|
||||||
let params = params
|
let params = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| match p {
|
.map(|p| match p {
|
||||||
api::Val::I32(i) => i.clone().into_py(py),
|
wasmtime::Val::I32(i) => i.clone().into_py(py),
|
||||||
api::Val::I64(i) => i.clone().into_py(py),
|
wasmtime::Val::I64(i) => i.clone().into_py(py),
|
||||||
_ => {
|
_ => {
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
@@ -115,8 +114,8 @@ impl api::Callable for WrappedFn {
|
|||||||
for (i, ty) in self.returns_types.iter().enumerate() {
|
for (i, ty) in self.returns_types.iter().enumerate() {
|
||||||
let result_item = result.get_item(i);
|
let result_item = result.get_item(i);
|
||||||
returns[i] = match ty {
|
returns[i] = match ty {
|
||||||
api::ValType::I32 => api::Val::I32(result_item.extract::<i32>().unwrap()),
|
wasmtime::ValType::I32 => wasmtime::Val::I32(result_item.extract::<i32>().unwrap()),
|
||||||
api::ValType::I64 => api::Val::I64(result_item.extract::<i64>().unwrap()),
|
wasmtime::ValType::I64 => wasmtime::Val::I64(result_item.extract::<i64>().unwrap()),
|
||||||
_ => {
|
_ => {
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
@@ -127,9 +126,9 @@ impl api::Callable for WrappedFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_into_pyfunction(
|
pub fn wrap_into_pyfunction(
|
||||||
store: &api::HostRef<api::Store>,
|
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||||
callable: &PyAny,
|
callable: &PyAny,
|
||||||
) -> PyResult<api::HostRef<api::Func>> {
|
) -> PyResult<wasmtime::HostRef<wasmtime::Func>> {
|
||||||
if !callable.hasattr("__annotations__")? {
|
if !callable.hasattr("__annotations__")? {
|
||||||
// TODO support calls without annotations?
|
// TODO support calls without annotations?
|
||||||
return Err(PyErr::new::<Exception, _>(
|
return Err(PyErr::new::<Exception, _>(
|
||||||
@@ -148,13 +147,13 @@ pub fn wrap_into_pyfunction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ft = api::FuncType::new(
|
let ft = wasmtime::FuncType::new(
|
||||||
params.into_boxed_slice(),
|
params.into_boxed_slice(),
|
||||||
returns.clone().into_boxed_slice(),
|
returns.clone().into_boxed_slice(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let gil = Python::acquire_gil();
|
let gil = Python::acquire_gil();
|
||||||
let wrapped = WrappedFn::new(callable.to_object(gil.python()), returns);
|
let wrapped = WrappedFn::new(callable.to_object(gil.python()), returns);
|
||||||
let f = api::Func::new(store, ft, Rc::new(wrapped));
|
let f = wasmtime::Func::new(store, ft, Rc::new(wrapped));
|
||||||
Ok(api::HostRef::new(f))
|
Ok(wasmtime::HostRef::new(f))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ use crate::memory::Memory;
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyDict;
|
use pyo3::types::PyDict;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_interface_types::ModuleData;
|
use wasmtime_interface_types::ModuleData;
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
pub instance: api::HostRef<api::Instance>,
|
pub instance: wasmtime::HostRef<wasmtime::Instance>,
|
||||||
pub data: Rc<ModuleData>,
|
pub data: Rc<ModuleData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ impl Instance {
|
|||||||
let module = self.instance.borrow().module().clone();
|
let module = self.instance.borrow().module().clone();
|
||||||
for (i, e) in module.borrow().exports().iter().enumerate() {
|
for (i, e) in module.borrow().exports().iter().enumerate() {
|
||||||
match e.r#type() {
|
match e.r#type() {
|
||||||
api::ExternType::ExternFunc(ft) => {
|
wasmtime::ExternType::ExternFunc(ft) => {
|
||||||
let mut args_types = Vec::new();
|
let mut args_types = Vec::new();
|
||||||
for ty in ft.params().iter() {
|
for ty in ft.params().iter() {
|
||||||
args_types.push(ty.clone());
|
args_types.push(ty.clone());
|
||||||
@@ -40,7 +39,7 @@ impl Instance {
|
|||||||
)?;
|
)?;
|
||||||
exports.set_item(e.name().to_string(), f)?;
|
exports.set_item(e.name().to_string(), f)?;
|
||||||
}
|
}
|
||||||
api::ExternType::ExternMemory(_) => {
|
wasmtime::ExternType::ExternMemory(_) => {
|
||||||
let f = Py::new(
|
let f = Py::new(
|
||||||
py,
|
py,
|
||||||
Memory {
|
Memory {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use pyo3::prelude::*;
|
|||||||
use pyo3::types::{PyAny, PyBytes, PyDict, PySet};
|
use pyo3::types::{PyAny, PyBytes, PyDict, PySet};
|
||||||
use pyo3::wrap_pyfunction;
|
use pyo3::wrap_pyfunction;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_interface_types::ModuleData;
|
use wasmtime_interface_types::ModuleData;
|
||||||
use wasmtime_jit::Features;
|
use wasmtime_jit::Features;
|
||||||
|
|
||||||
@@ -48,9 +47,9 @@ impl InstantiateResultObject {
|
|||||||
|
|
||||||
fn find_export_in(
|
fn find_export_in(
|
||||||
obj: &PyAny,
|
obj: &PyAny,
|
||||||
store: &api::HostRef<api::Store>,
|
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> PyResult<api::Extern> {
|
) -> PyResult<wasmtime::Extern> {
|
||||||
let obj = obj.cast_as::<PyDict>()?;
|
let obj = obj.cast_as::<PyDict>()?;
|
||||||
|
|
||||||
Ok(if let Some(item) = obj.get_item(name) {
|
Ok(if let Some(item) = obj.get_item(name) {
|
||||||
@@ -87,16 +86,16 @@ pub fn instantiate(
|
|||||||
) -> PyResult<Py<InstantiateResultObject>> {
|
) -> PyResult<Py<InstantiateResultObject>> {
|
||||||
let wasm_data = buffer_source.as_bytes();
|
let wasm_data = buffer_source.as_bytes();
|
||||||
|
|
||||||
let mut config = api::Config::new();
|
let mut config = wasmtime::Config::new();
|
||||||
config.features(Features {
|
config.features(Features {
|
||||||
multi_value: true,
|
multi_value: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let engine = api::HostRef::new(api::Engine::new(&config));
|
let engine = wasmtime::HostRef::new(wasmtime::Engine::new(&config));
|
||||||
let store = api::HostRef::new(api::Store::new(&engine));
|
let store = wasmtime::HostRef::new(wasmtime::Store::new(&engine));
|
||||||
|
|
||||||
let module = api::HostRef::new(api::Module::new(&store, wasm_data).map_err(err2py)?);
|
let module = wasmtime::HostRef::new(wasmtime::Module::new(&store, wasm_data).map_err(err2py)?);
|
||||||
|
|
||||||
let data = Rc::new(ModuleData::new(wasm_data).map_err(err2py)?);
|
let data = Rc::new(ModuleData::new(wasm_data).map_err(err2py)?);
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ pub fn instantiate(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut imports: Vec<api::Extern> = Vec::new();
|
let mut imports: Vec<wasmtime::Extern> = Vec::new();
|
||||||
for i in module.borrow().imports() {
|
for i in module.borrow().imports() {
|
||||||
let module_name = i.module().as_str();
|
let module_name = i.module().as_str();
|
||||||
if let Some(m) = import_obj.get_item(module_name) {
|
if let Some(m) = import_obj.get_item(module_name) {
|
||||||
@@ -137,8 +136,8 @@ pub fn instantiate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let instance = api::HostRef::new(
|
let instance = wasmtime::HostRef::new(
|
||||||
api::Instance::new(&store, &module, &imports)
|
wasmtime::Instance::new(&store, &module, &imports)
|
||||||
.map_err(|t| PyErr::new::<Exception, _>(format!("instantiated with trap {:?}", t)))?,
|
.map_err(|t| PyErr::new::<Exception, _>(format!("instantiated with trap {:?}", t)))?,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ use pyo3::prelude::*;
|
|||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::os::raw::{c_int, c_void};
|
use std::os::raw::{c_int, c_void};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use wasmtime_api as api;
|
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
pub memory: api::HostRef<api::Memory>,
|
pub memory: wasmtime::HostRef<wasmtime::Memory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
//! WebAssembly Module API object.
|
//! WebAssembly Module API object.
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use wasmtime_api as api;
|
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
pub module: api::HostRef<api::Module>,
|
pub module: wasmtime::HostRef<wasmtime::Module>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fn generate_struct(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
|||||||
let root = root();
|
let root = root();
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#vis struct #name {
|
#vis struct #name {
|
||||||
instance: #root::wasmtime_api::HostRef<#root::wasmtime_api::Instance>,
|
instance: #root::wasmtime::HostRef<#root::wasmtime::Instance>,
|
||||||
data: #root::wasmtime_interface_types::ModuleData,
|
data: #root::wasmtime_interface_types::ModuleData,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -48,7 +48,7 @@ fn generate_load(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
|||||||
#vis fn load_file(path: impl AsRef<std::path::Path>) -> #root::anyhow::Result<#name> {
|
#vis fn load_file(path: impl AsRef<std::path::Path>) -> #root::anyhow::Result<#name> {
|
||||||
let bytes = std::fs::read(path)?;
|
let bytes = std::fs::read(path)?;
|
||||||
|
|
||||||
use #root::wasmtime_api::{HostRef, Config, Extern, Engine, Store, Instance, Module};
|
use #root::wasmtime::{HostRef, Config, Extern, Engine, Store, Instance, Module};
|
||||||
use #root::anyhow::{bail, format_err};
|
use #root::anyhow::{bail, format_err};
|
||||||
|
|
||||||
let mut config = Config::new();
|
let mut config = Config::new();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ pub use wasmtime_rust_macro::wasmtime;
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod __rt {
|
pub mod __rt {
|
||||||
pub use anyhow;
|
pub use anyhow;
|
||||||
pub use wasmtime_api;
|
pub use wasmtime;
|
||||||
pub use wasmtime_interface_types;
|
pub use wasmtime_interface_types;
|
||||||
pub use wasmtime_jit;
|
pub use wasmtime_jit;
|
||||||
pub use wasmtime_wasi;
|
pub use wasmtime_wasi;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use anyhow::{bail, Context};
|
|||||||
use cranelift_codegen::settings::{self, Configurable};
|
use cranelift_codegen::settings::{self, Configurable};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
|
use wasmtime::{Config, Engine, HostRef, Instance, Module, Store};
|
||||||
|
|
||||||
pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> {
|
pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> {
|
||||||
// Prepare runtime
|
// Prepare runtime
|
||||||
|
|||||||
@@ -9,20 +9,19 @@ use std::fs::File;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use target_lexicon::HOST;
|
use target_lexicon::HOST;
|
||||||
use wasi_common::{WasiCtx, WasiCtxBuilder};
|
use wasi_common::{WasiCtx, WasiCtxBuilder};
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_environ::{translate_signature, Export, Module};
|
use wasmtime_environ::{translate_signature, Export, Module};
|
||||||
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
||||||
|
|
||||||
/// Creates `api::Instance` object implementing the "wasi" interface.
|
/// Creates `wasmtime::Instance` object implementing the "wasi" interface.
|
||||||
pub fn create_wasi_instance(
|
pub fn create_wasi_instance(
|
||||||
store: &api::HostRef<api::Store>,
|
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||||
preopened_dirs: &[(String, File)],
|
preopened_dirs: &[(String, File)],
|
||||||
argv: &[String],
|
argv: &[String],
|
||||||
environ: &[(String, String)],
|
environ: &[(String, String)],
|
||||||
) -> Result<api::Instance, InstantiationError> {
|
) -> Result<wasmtime::Instance, InstantiationError> {
|
||||||
let global_exports = store.borrow().global_exports().clone();
|
let global_exports = store.borrow().global_exports().clone();
|
||||||
let wasi = instantiate_wasi(global_exports, preopened_dirs, argv, environ)?;
|
let wasi = instantiate_wasi(global_exports, preopened_dirs, argv, environ)?;
|
||||||
let instance = api::Instance::from_handle(&store, wasi);
|
let instance = wasmtime::Instance::from_handle(&store, wasi);
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,20 +9,19 @@ use std::fs::File;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use target_lexicon::HOST;
|
use target_lexicon::HOST;
|
||||||
use wasi_common::old::snapshot_0::{WasiCtx, WasiCtxBuilder};
|
use wasi_common::old::snapshot_0::{WasiCtx, WasiCtxBuilder};
|
||||||
use wasmtime_api as api;
|
|
||||||
use wasmtime_environ::{translate_signature, Export, Module};
|
use wasmtime_environ::{translate_signature, Export, Module};
|
||||||
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
||||||
|
|
||||||
/// Creates `api::Instance` object implementing the "wasi" interface.
|
/// Creates `wasmtime::Instance` object implementing the "wasi" interface.
|
||||||
pub fn create_wasi_instance(
|
pub fn create_wasi_instance(
|
||||||
store: &api::HostRef<api::Store>,
|
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||||
preopened_dirs: &[(String, File)],
|
preopened_dirs: &[(String, File)],
|
||||||
argv: &[String],
|
argv: &[String],
|
||||||
environ: &[(String, String)],
|
environ: &[(String, String)],
|
||||||
) -> Result<api::Instance, InstantiationError> {
|
) -> Result<wasmtime::Instance, InstantiationError> {
|
||||||
let global_exports = store.borrow().global_exports().clone();
|
let global_exports = store.borrow().global_exports().clone();
|
||||||
let wasi = instantiate_wasi(global_exports, preopened_dirs, argv, environ)?;
|
let wasi = instantiate_wasi(global_exports, preopened_dirs, argv, environ)?;
|
||||||
let instance = api::Instance::from_handle(&store, wasi);
|
let instance = wasmtime::Instance::from_handle(&store, wasi);
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ where "<current version>" is the current version number of the `wasmtime` crate.
|
|||||||
It is time to add code to the `src/main.rs`. First, the engine and storage need to be activated:
|
It is time to add code to the `src/main.rs`. First, the engine and storage need to be activated:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
let engine = HostRef::new(Engine::default());
|
let engine = HostRef::new(Engine::default());
|
||||||
let store = HostRef::new(Store::new(&engine));
|
let store = HostRef::new(Store::new(&engine));
|
||||||
@@ -83,7 +83,7 @@ The names of the WebAssembly module's imports and exports can be discovered by m
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
use std::fs::read;
|
use std::fs::read;
|
||||||
use wasmtime_api::*;
|
use wasmtime::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let engine = HostRef::new(Engine::default());
|
let engine = HostRef::new(Engine::default());
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ use serde::Deserialize;
|
|||||||
use std::path::{Component, Path};
|
use std::path::{Component, Path};
|
||||||
use std::{collections::HashMap, ffi::OsStr, fs::File, process::exit};
|
use std::{collections::HashMap, ffi::OsStr, fs::File, process::exit};
|
||||||
use wasi_common::preopen_dir;
|
use wasi_common::preopen_dir;
|
||||||
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
|
use wasmtime::{Config, Engine, HostRef, Instance, Module, Store};
|
||||||
use wasmtime_cli::pick_compilation_strategy;
|
use wasmtime_cli::pick_compilation_strategy;
|
||||||
use wasmtime_environ::{cache_create_new_config, cache_init};
|
use wasmtime_environ::{cache_create_new_config, cache_init};
|
||||||
use wasmtime_interface_types::ModuleData;
|
use wasmtime_interface_types::ModuleData;
|
||||||
|
|||||||
Reference in New Issue
Block a user