Skip to content

Commit

Permalink
Merge #856
Browse files Browse the repository at this point in the history
856: Add WASI support to C API r=MarkMcCaskey a=MarkMcCaskey

This is an additive change (with one unrelated clean up of `*mut ptr -> *const ptr`).  It exposes the functions to get a WASI import object.  It also implements a function on import object to get an `import` with namespace and name.

These changes should be okay to ship now, we can follow up to finish adding methods to ImportObject on the C API side and start migrating away from  `*imports`.

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <[email protected]>
Co-authored-by: Ivan Enderlin <[email protected]>
Co-authored-by: Mark McCaskey <[email protected]>
Co-authored-by: nlewycky <[email protected]>
  • Loading branch information
5 people authored Oct 29, 2019
2 parents d46e5d4 + d87e81c commit 2dbe80a
Show file tree
Hide file tree
Showing 21 changed files with 1,140 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## **[Unreleased]**

- [#883](https://github.com/wasmerio/wasmer/pull/883) Allow floating point operations to have arbitrary inputs, even including SNaNs.
- [#856](https://github.com/wasmerio/wasmer/pull/856) Expose methods in the runtime C API to get a WASI import object

## 0.9.0 - 2019-10-23

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ capi:
test-capi: capi
cargo test -p wasmer-runtime-c-api --release

capi-test: test-capi

test-rest:
cargo test --release --all --exclude wasmer-runtime-c-api --exclude wasmer-emscripten --exclude wasmer-spectests --exclude wasmer-wasi --exclude wasmer-middleware-common --exclude wasmer-middleware-common-tests --exclude wasmer-singlepass-backend --exclude wasmer-clif-backend --exclude wasmer-llvm-backend --exclude wasmer-wasi-tests --exclude wasmer-emscripten-tests

Expand Down
9 changes: 8 additions & 1 deletion lib/runtime-c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ default-features = false
path = "../runtime-core"
version = "0.9.0"

[dependencies.wasmer-wasi]
default-features = false
path = "../wasi"
version = "0.9.0"
optional = true

[features]
default = ["cranelift-backend"]
default = ["cranelift-backend", "wasi"]
debug = ["wasmer-runtime/debug"]
cranelift-backend = ["wasmer-runtime/cranelift", "wasmer-runtime/default-backend-cranelift"]
llvm-backend = ["wasmer-runtime/llvm", "wasmer-runtime/default-backend-llvm"]
singlepass-backend = ["wasmer-runtime/singlepass", "wasmer-runtime/default-backend-singlepass"]
wasi = ["wasmer-wasi"]

[build-dependencies]
cbindgen = "0.9"
39 changes: 34 additions & 5 deletions lib/runtime-c-api/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,41 @@ pub union wasmer_import_export_value {
/// List of export/import kinds.
#[allow(non_camel_case_types)]
#[repr(u32)]
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
// ================
// ! DANGER !
// ================
// Do not modify these values without updating the `TryFrom` implementation below
pub enum wasmer_import_export_kind {
WASM_FUNCTION,
WASM_GLOBAL,
WASM_MEMORY,
WASM_TABLE,
WASM_FUNCTION = 0,
WASM_GLOBAL = 1,
WASM_MEMORY = 2,
WASM_TABLE = 3,
}

impl wasmer_import_export_kind {
pub fn to_str(&self) -> &'static str {
match self {
Self::WASM_FUNCTION => "function",
Self::WASM_GLOBAL => "global",
Self::WASM_MEMORY => "memory",
Self::WASM_TABLE => "table",
}
}
}

impl std::convert::TryFrom<u32> for wasmer_import_export_kind {
type Error = ();

fn try_from(value: u32) -> Result<Self, Self::Error> {
Ok(match value {
0 => Self::WASM_FUNCTION,
1 => Self::WASM_GLOBAL,
2 => Self::WASM_MEMORY,
3 => Self::WASM_TABLE,
_ => return Err(()),
})
}
}

/// Gets export descriptors for the given module
Expand Down
Loading

0 comments on commit 2dbe80a

Please sign in to comment.