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
@@ -5,20 +5,19 @@ use pyo3::exceptions::Exception;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::{PyAny, PyDict, PyTuple};
|
||||
use std::rc::Rc;
|
||||
use wasmtime_api as api;
|
||||
use wasmtime_interface_types::ModuleData;
|
||||
|
||||
// TODO support non-export functions
|
||||
#[pyclass]
|
||||
pub struct Function {
|
||||
pub instance: api::HostRef<api::Instance>,
|
||||
pub instance: wasmtime::HostRef<wasmtime::Instance>,
|
||||
pub export_name: String,
|
||||
pub args_types: Vec<api::ValType>,
|
||||
pub args_types: Vec<wasmtime::ValType>,
|
||||
pub data: Rc<ModuleData>,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn func(&self) -> api::HostRef<api::Func> {
|
||||
pub fn func(&self) -> wasmtime::HostRef<wasmtime::Func> {
|
||||
let e = self
|
||||
.instance
|
||||
.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 {
|
||||
"I32" | "i32" => api::ValType::I32,
|
||||
"I64" | "i64" => api::ValType::I64,
|
||||
"F32" | "f32" => api::ValType::F32,
|
||||
"F64" | "f64" => api::ValType::F64,
|
||||
"I32" | "i32" => wasmtime::ValType::I32,
|
||||
"I64" | "i64" => wasmtime::ValType::I64,
|
||||
"F32" | "f32" => wasmtime::ValType::F32,
|
||||
"F64" | "f64" => wasmtime::ValType::F64,
|
||||
_ => panic!("unknown type in annotations"),
|
||||
}
|
||||
}
|
||||
|
||||
struct WrappedFn {
|
||||
func: PyObject,
|
||||
returns_types: Vec<api::ValType>,
|
||||
returns_types: Vec<wasmtime::ValType>,
|
||||
}
|
||||
|
||||
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 {
|
||||
func,
|
||||
returns_types,
|
||||
@@ -78,20 +77,20 @@ impl WrappedFn {
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Callable for WrappedFn {
|
||||
impl wasmtime::Callable for WrappedFn {
|
||||
fn call(
|
||||
&self,
|
||||
params: &[api::Val],
|
||||
returns: &mut [api::Val],
|
||||
) -> Result<(), api::HostRef<api::Trap>> {
|
||||
params: &[wasmtime::Val],
|
||||
returns: &mut [wasmtime::Val],
|
||||
) -> Result<(), wasmtime::HostRef<wasmtime::Trap>> {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let params = params
|
||||
.iter()
|
||||
.map(|p| match p {
|
||||
api::Val::I32(i) => i.clone().into_py(py),
|
||||
api::Val::I64(i) => i.clone().into_py(py),
|
||||
wasmtime::Val::I32(i) => i.clone().into_py(py),
|
||||
wasmtime::Val::I64(i) => i.clone().into_py(py),
|
||||
_ => {
|
||||
panic!();
|
||||
}
|
||||
@@ -115,8 +114,8 @@ impl api::Callable for WrappedFn {
|
||||
for (i, ty) in self.returns_types.iter().enumerate() {
|
||||
let result_item = result.get_item(i);
|
||||
returns[i] = match ty {
|
||||
api::ValType::I32 => api::Val::I32(result_item.extract::<i32>().unwrap()),
|
||||
api::ValType::I64 => api::Val::I64(result_item.extract::<i64>().unwrap()),
|
||||
wasmtime::ValType::I32 => wasmtime::Val::I32(result_item.extract::<i32>().unwrap()),
|
||||
wasmtime::ValType::I64 => wasmtime::Val::I64(result_item.extract::<i64>().unwrap()),
|
||||
_ => {
|
||||
panic!();
|
||||
}
|
||||
@@ -127,9 +126,9 @@ impl api::Callable for WrappedFn {
|
||||
}
|
||||
|
||||
pub fn wrap_into_pyfunction(
|
||||
store: &api::HostRef<api::Store>,
|
||||
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||
callable: &PyAny,
|
||||
) -> PyResult<api::HostRef<api::Func>> {
|
||||
) -> PyResult<wasmtime::HostRef<wasmtime::Func>> {
|
||||
if !callable.hasattr("__annotations__")? {
|
||||
// TODO support calls without annotations?
|
||||
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(),
|
||||
returns.clone().into_boxed_slice(),
|
||||
);
|
||||
|
||||
let gil = Python::acquire_gil();
|
||||
let wrapped = WrappedFn::new(callable.to_object(gil.python()), returns);
|
||||
let f = api::Func::new(store, ft, Rc::new(wrapped));
|
||||
Ok(api::HostRef::new(f))
|
||||
let f = wasmtime::Func::new(store, ft, Rc::new(wrapped));
|
||||
Ok(wasmtime::HostRef::new(f))
|
||||
}
|
||||
|
||||
@@ -5,12 +5,11 @@ use crate::memory::Memory;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyDict;
|
||||
use std::rc::Rc;
|
||||
use wasmtime_api as api;
|
||||
use wasmtime_interface_types::ModuleData;
|
||||
|
||||
#[pyclass]
|
||||
pub struct Instance {
|
||||
pub instance: api::HostRef<api::Instance>,
|
||||
pub instance: wasmtime::HostRef<wasmtime::Instance>,
|
||||
pub data: Rc<ModuleData>,
|
||||
}
|
||||
|
||||
@@ -24,7 +23,7 @@ impl Instance {
|
||||
let module = self.instance.borrow().module().clone();
|
||||
for (i, e) in module.borrow().exports().iter().enumerate() {
|
||||
match e.r#type() {
|
||||
api::ExternType::ExternFunc(ft) => {
|
||||
wasmtime::ExternType::ExternFunc(ft) => {
|
||||
let mut args_types = Vec::new();
|
||||
for ty in ft.params().iter() {
|
||||
args_types.push(ty.clone());
|
||||
@@ -40,7 +39,7 @@ impl Instance {
|
||||
)?;
|
||||
exports.set_item(e.name().to_string(), f)?;
|
||||
}
|
||||
api::ExternType::ExternMemory(_) => {
|
||||
wasmtime::ExternType::ExternMemory(_) => {
|
||||
let f = Py::new(
|
||||
py,
|
||||
Memory {
|
||||
|
||||
@@ -9,7 +9,6 @@ use pyo3::prelude::*;
|
||||
use pyo3::types::{PyAny, PyBytes, PyDict, PySet};
|
||||
use pyo3::wrap_pyfunction;
|
||||
use std::rc::Rc;
|
||||
use wasmtime_api as api;
|
||||
use wasmtime_interface_types::ModuleData;
|
||||
use wasmtime_jit::Features;
|
||||
|
||||
@@ -48,9 +47,9 @@ impl InstantiateResultObject {
|
||||
|
||||
fn find_export_in(
|
||||
obj: &PyAny,
|
||||
store: &api::HostRef<api::Store>,
|
||||
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||
name: &str,
|
||||
) -> PyResult<api::Extern> {
|
||||
) -> PyResult<wasmtime::Extern> {
|
||||
let obj = obj.cast_as::<PyDict>()?;
|
||||
|
||||
Ok(if let Some(item) = obj.get_item(name) {
|
||||
@@ -87,16 +86,16 @@ pub fn instantiate(
|
||||
) -> PyResult<Py<InstantiateResultObject>> {
|
||||
let wasm_data = buffer_source.as_bytes();
|
||||
|
||||
let mut config = api::Config::new();
|
||||
let mut config = wasmtime::Config::new();
|
||||
config.features(Features {
|
||||
multi_value: true,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let engine = api::HostRef::new(api::Engine::new(&config));
|
||||
let store = api::HostRef::new(api::Store::new(&engine));
|
||||
let engine = wasmtime::HostRef::new(wasmtime::Engine::new(&config));
|
||||
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)?);
|
||||
|
||||
@@ -110,7 +109,7 @@ pub fn instantiate(
|
||||
None
|
||||
};
|
||||
|
||||
let mut imports: Vec<api::Extern> = Vec::new();
|
||||
let mut imports: Vec<wasmtime::Extern> = Vec::new();
|
||||
for i in module.borrow().imports() {
|
||||
let module_name = i.module().as_str();
|
||||
if let Some(m) = import_obj.get_item(module_name) {
|
||||
@@ -137,8 +136,8 @@ pub fn instantiate(
|
||||
}
|
||||
}
|
||||
|
||||
let instance = api::HostRef::new(
|
||||
api::Instance::new(&store, &module, &imports)
|
||||
let instance = wasmtime::HostRef::new(
|
||||
wasmtime::Instance::new(&store, &module, &imports)
|
||||
.map_err(|t| PyErr::new::<Exception, _>(format!("instantiated with trap {:?}", t)))?,
|
||||
);
|
||||
|
||||
|
||||
@@ -7,11 +7,10 @@ use pyo3::prelude::*;
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::{c_int, c_void};
|
||||
use std::ptr;
|
||||
use wasmtime_api as api;
|
||||
|
||||
#[pyclass]
|
||||
pub struct Memory {
|
||||
pub memory: api::HostRef<api::Memory>,
|
||||
pub memory: wasmtime::HostRef<wasmtime::Memory>,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
//! WebAssembly Module API object.
|
||||
|
||||
use pyo3::prelude::*;
|
||||
use wasmtime_api as api;
|
||||
|
||||
#[pyclass]
|
||||
pub struct Module {
|
||||
pub module: api::HostRef<api::Module>,
|
||||
pub module: wasmtime::HostRef<wasmtime::Module>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user