Browse Source

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.
pull/605/head
Josh Triplett 5 years ago
committed by Dan Gohman
parent
commit
2635ccb742
  1. 12
      .github/workflows/main.yml
  2. 2
      crates/api/Cargo.toml
  3. 2
      crates/api/c-examples/Makefile
  4. 2
      crates/api/examples/gcd.rs
  5. 2
      crates/api/examples/hello.rs
  6. 2
      crates/api/examples/memory.rs
  7. 2
      crates/api/examples/multi.rs
  8. 2
      crates/api/tests/import_calling_export.rs
  9. 11
      crates/interface-types/src/lib.rs
  10. 47
      crates/misc/py/src/function.rs
  11. 7
      crates/misc/py/src/instance.rs
  12. 19
      crates/misc/py/src/lib.rs
  13. 3
      crates/misc/py/src/memory.rs
  14. 3
      crates/misc/py/src/module.rs
  15. 4
      crates/misc/rust/macro/src/lib.rs
  16. 2
      crates/misc/rust/src/lib.rs
  17. 2
      crates/test-programs/tests/wasm_tests/runtime.rs
  18. 9
      crates/wasi/src/instantiate.rs
  19. 9
      crates/wasi/src/old/snapshot_0/instantiate.rs
  20. 4
      docs/embed-rust.md
  21. 2
      src/bin/wasmtime.rs

12
.github/workflows/main.yml

@ -191,7 +191,7 @@ jobs:
name: wheels-${{ matrix.os }}
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.
# Note that we also run tests here to test exactly what we're deploying.
build:
@ -215,7 +215,7 @@ jobs:
# Build `wasmtime` and executables
- run: $CENTOS cargo build --release --bin wasmtime --bin wasm2obj
shell: bash
# Build `libwasmtime_api.so`
# Build `libwasmtime.so`
- run: $CENTOS cargo build --release --manifest-path crates/api/Cargo.toml
shell: bash
# Test what we just built
@ -237,12 +237,12 @@ jobs:
shell: bash
if: matrix.os == 'windows-latest'
# Move libwasmtime_api dylib to dist folder
- run: cp target/release/libwasmtime_api.{so,a} dist
# Move libwasmtime dylib to dist folder
- run: cp target/release/libwasmtime.{so,a} dist
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'
- run: cp target/release/wasmtime_api.{dll,lib} dist
- run: cp target/release/wasmtime.{dll,lib} dist
shell: bash
if: matrix.os == 'windows-latest'

2
crates/api/Cargo.toml

@ -9,7 +9,7 @@ readme = "README.md"
edition = "2018"
[lib]
name = "wasmtime_api"
name = "wasmtime"
crate-type = ["lib", "staticlib", "cdylib"]
[dependencies]

2
crates/api/c-examples/Makefile

@ -65,7 +65,7 @@ endif
WASMTIME_BIN_DIR = ${WASMTIME_API_DIR}/../target/${WASMTIME_API_MODE}
WASMTIME_C_LIB_DIR = ${WASMTIME_BIN_DIR}
WASMTIME_C_LIBS = wasmtime_api
WASMTIME_C_LIBS = wasmtime
WASMTIME_CC_LIBS = $(error unsupported c++)
WASMTIME_C_BINS = ${WASMTIME_C_LIBS:%=${WASMTIME_C_LIB_DIR}/lib%.a}

2
crates/api/examples/gcd.rs

@ -2,7 +2,7 @@
//! invoking its exported function.
use anyhow::{format_err, Result};
use wasmtime_api::*;
use wasmtime::*;
const WAT: &str = r#"
(module

2
crates/api/examples/hello.rs

@ -3,7 +3,7 @@
use anyhow::{ensure, format_err, Context as _, Result};
use std::cell::Ref;
use std::rc::Rc;
use wasmtime_api::*;
use wasmtime::*;
struct HelloCallback;

2
crates/api/examples/memory.rs

@ -2,7 +2,7 @@
use anyhow::{bail, ensure, Context as _, Error};
use std::cell::Ref;
use wasmtime_api::*;
use wasmtime::*;
fn get_export_memory(exports: &[Extern], i: usize) -> Result<HostRef<Memory>, Error> {
if exports.len() <= i {

2
crates/api/examples/multi.rs

@ -3,7 +3,7 @@
use anyhow::{ensure, format_err, Context as _, Result};
use std::cell::Ref;
use std::rc::Rc;
use wasmtime_api::*;
use wasmtime::*;
struct Callback;

2
crates/api/tests/import_calling_export.rs

@ -1,6 +1,6 @@
use std::cell::{Ref, RefCell};
use std::rc::Rc;
use wasmtime_api::*;
use wasmtime::*;
#[test]
fn test_import_calling_export() {

11
crates/interface-types/src/lib.rs

@ -12,7 +12,6 @@ use cranelift_codegen::ir;
use std::convert::TryFrom;
use std::str;
use wasm_webidl_bindings::ast;
use wasmtime_api as api;
use wasmtime_jit::RuntimeValue;
use wasmtime_runtime::{Export, InstanceHandle};
@ -126,7 +125,7 @@ impl ModuleData {
/// wasm interface types.
pub fn invoke_export(
&self,
instance: &api::HostRef<api::Instance>,
instance: &wasmtime::HostRef<wasmtime::Instance>,
export: &str,
args: &[Value],
) -> Result<Vec<Value>> {
@ -153,7 +152,7 @@ impl ModuleData {
Ok(values) => values
.to_vec()
.into_iter()
.map(|v: api::Val| v.into())
.map(|v: wasmtime::Val| v.into())
.collect::<Vec<RuntimeValue>>(),
Err(trap) => bail!("trapped: {:?}", trap),
};
@ -316,7 +315,7 @@ trait TranslateContext {
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 {
fn invoke_alloc(&mut self, alloc_func_name: &str, len: i32) -> Result<i32> {
@ -328,7 +327,7 @@ impl TranslateContext for InstanceTranslateContext {
.func()
.ok_or_else(|| format_err!("`{}` is not a (alloc) function", alloc_func_name))?
.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) {
Ok(values) => values,
Err(trap) => bail!("trapped: {:?}", trap),
@ -337,7 +336,7 @@ impl TranslateContext for InstanceTranslateContext {
bail!("allocator function wrong number of results");
}
Ok(match results[0] {
api::Val::I32(i) => i,
wasmtime::Val::I32(i) => i,
_ => bail!("allocator function bad return type"),
})
}

47
crates/misc/py/src/function.rs

@ -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))
}

7
crates/misc/py/src/instance.rs

@ -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 {

19
crates/misc/py/src/lib.rs

@ -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)))?,
);

3
crates/misc/py/src/memory.rs

@ -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]

3
crates/misc/py/src/module.rs

@ -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>,
}

4
crates/misc/rust/macro/src/lib.rs

@ -34,7 +34,7 @@ fn generate_struct(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
let root = root();
Ok(quote! {
#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,
}
})
@ -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> {
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};
let mut config = Config::new();

2
crates/misc/rust/src/lib.rs

@ -4,7 +4,7 @@ pub use wasmtime_rust_macro::wasmtime;
#[doc(hidden)]
pub mod __rt {
pub use anyhow;
pub use wasmtime_api;
pub use wasmtime;
pub use wasmtime_interface_types;
pub use wasmtime_jit;
pub use wasmtime_wasi;

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

@ -2,7 +2,7 @@ use anyhow::{bail, Context};
use cranelift_codegen::settings::{self, Configurable};
use std::fs::File;
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<()> {
// Prepare runtime

9
crates/wasi/src/instantiate.rs

@ -9,20 +9,19 @@ use std::fs::File;
use std::rc::Rc;
use target_lexicon::HOST;
use wasi_common::{WasiCtx, WasiCtxBuilder};
use wasmtime_api as api;
use wasmtime_environ::{translate_signature, Export, Module};
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(
store: &api::HostRef<api::Store>,
store: &wasmtime::HostRef<wasmtime::Store>,
preopened_dirs: &[(String, File)],
argv: &[String],
environ: &[(String, String)],
) -> Result<api::Instance, InstantiationError> {
) -> Result<wasmtime::Instance, InstantiationError> {
let global_exports = store.borrow().global_exports().clone();
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)
}

9
crates/wasi/src/old/snapshot_0/instantiate.rs

@ -9,20 +9,19 @@ use std::fs::File;
use std::rc::Rc;
use target_lexicon::HOST;
use wasi_common::old::snapshot_0::{WasiCtx, WasiCtxBuilder};
use wasmtime_api as api;
use wasmtime_environ::{translate_signature, Export, Module};
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(
store: &api::HostRef<api::Store>,
store: &wasmtime::HostRef<wasmtime::Store>,
preopened_dirs: &[(String, File)],
argv: &[String],
environ: &[(String, String)],
) -> Result<api::Instance, InstantiationError> {
) -> Result<wasmtime::Instance, InstantiationError> {
let global_exports = store.borrow().global_exports().clone();
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)
}

4
docs/embed-rust.md

@ -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:
```rust
use wasmtime_api::*;
use wasmtime::*;
let engine = HostRef::new(Engine::default());
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
use std::fs::read;
use wasmtime_api::*;
use wasmtime::*;
fn main() {
let engine = HostRef::new(Engine::default());

2
src/bin/wasmtime.rs

@ -37,7 +37,7 @@ use serde::Deserialize;
use std::path::{Component, Path};
use std::{collections::HashMap, ffi::OsStr, fs::File, process::exit};
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_environ::{cache_create_new_config, cache_init};
use wasmtime_interface_types::ModuleData;

Loading…
Cancel
Save