Commit Graph

86 Commits

Author SHA1 Message Date
Ivan Enderlin
a73e457976 Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-19 08:01:00 +02:00
Ivan Enderlin
d7d40e542f Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-16 10:18:46 +02:00
Ivan Enderlin
e29ea25dcd feat(c-api) Simplify code with unwrap_or_default. 2020-10-16 10:17:23 +02:00
Ivan Enderlin
2f692a1e2c fix(c-api) Fix merge issue. 2020-10-16 09:42:12 +02:00
Ivan Enderlin
ffff0441bc feat(c-api) Implement wasm_func_type.
This patch creates a `wasm_functype_t::new` constructor, that is used
by the new `wasm_func_type` function, and the existing
`wasm_functype_new_inner` function.
2020-10-15 15:05:26 +02:00
bors[bot]
193d7c8ce1 Merge #1715
1715: fix(c-api) Register errors from `wasm_module_serialize` r=Hywan a=Hywan

This patch updates `wasm_module_serialize` to register errors with`update_last_error` if any.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-15 06:31:12 +00:00
bors[bot]
c5d5ac7bfe Merge #1693
1693: Add `wasmer create-exe` r=MarkMcCaskey a=MarkMcCaskey

This adds the `wasmer create-exe` subcommand.  This subcommand is a combination of `wasmer compile --object-file` and linking that compiled Wasm with a main function and libwasmer.  Put more plainly: it lets us transform Wasm modules into native executables in one step.

In order for this to work we need:
- [x] Ship wasm.h with Wasmer or use different mechanism to find it
- [x] Ship wasmer_wasm.h with Wasmer
- [x] Requires up to date libwasmer... had to build one and copy it over, may fail in CI because of this... will be fixed with next release though
- [x] More gracefully handle wasmer installed without WASMER_DIR, etc (even if just error messages, should be tested)
- [x] Add tests

# Review

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


Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <5770194+MarkMcCaskey@users.noreply.github.com>
2020-10-13 21:46:16 +00:00
Ivan Enderlin
599c473d34 Merge branch 'master' into fix-c-api-module-serialize 2020-10-13 11:24:35 +02:00
bors[bot]
9c309ea3f3 Merge #1689
1689: feat(c-api) Use `Option<NonNull<wasm_valtype_t>>` in `wasm_valtype_kind` r=syrusakbary a=Hywan

A more Rust-FFI idiomatic way to handle null pointer.

Note: In `wasm_valtype_kind`, it's tricky to handle the error because
we _must_ return a `wasm_valtype_kind` value. For the moment, it
continues to panic, which is probably the best tradeoff.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-13 09:06:29 +00:00
Ivan Enderlin
7cc4d5adbe fix(c-api) Simplify NonNull<T> by &T. 2020-10-13 10:51:58 +02:00
Ivan Enderlin
954e5e8495 fix(c-api) Register errors from wasm_module_serialize. 2020-10-13 10:26:32 +02:00
Mark McCaskey
fd63ddb101 Merge branch 'master' into feature/wasmer-create-exe 2020-10-12 15:54:54 -07:00
Ivan Enderlin
fe70330772 fixup 2020-10-12 18:02:32 +02:00
Ivan Enderlin
750a1c3645 feat(c-api) Implement wasm_module_name and wasm_module_set_name.
I submited a proposal to the official `wasm.h` by the way,
https://github.com/WebAssembly/wasm-c-api/pull/157. For the moment,
let's keep that as a vendor specific implementation.
2020-10-12 17:52:40 +02:00
Ivan Enderlin
bf389f96b9 Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-12 13:48:17 +02:00
Ivan Enderlin
122ba837a1 Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-12 13:36:42 +02:00
bors[bot]
bb9149bfe3 Merge #1685
1685: feat(c-api) Implement `wasm_exporttype_delete` r=Hywan a=Hywan

This PR implements the destructor for `wasm_exporttype_t`.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-12 11:16:06 +00:00
Ivan Enderlin
4584a53840 fix(c-api) Remove rustc warnings. 2020-10-12 13:12:37 +02:00
Ivan Enderlin
202ffe7771 fix(c-api) Fix wasm_func_call when params are empty.
`wasm_$name_vec_t.into_slice` returns `None` if the vec is empty. So
an empty vec of `wasm_extern_t` given to `wasm_func_call` was raising
an error. This patch fixes this.
2020-10-12 12:20:29 +02:00
Ivan Enderlin
fea156defa feat(c-api) Update wasi_get_imports to use a wasm_extern_vec_t
… so that it matches the definition of `wasm_instance_new`, which is
much simpler and consistent.
2020-10-12 11:58:53 +02:00
Ivan Enderlin
fa7fe83bc0 feat(c-api) Update wasm_instance_new.
The `CArrayIter` type is no longer needed. This patch removes it.
2020-10-12 11:45:31 +02:00
Ivan Enderlin
e9cd710506 feat(c-api) Update wasm_func_call. 2020-10-12 11:25:17 +02:00
Ivan Enderlin
7f098387e8 faet(c-api) Update wasm_func_new_with_env. 2020-10-12 11:24:59 +02:00
Ivan Enderlin
5dffd976f5 feat(c-api) Update wasm_func_new. 2020-10-12 11:24:30 +02:00
Ivan Enderlin
d8dcb4133a feat(c-api) Update the definitions of wasm_func_callback*_t. 2020-10-12 11:23:52 +02:00
Ivan Enderlin
8b38dd575e feat(c-api) Implement wasm_val_vec_t. 2020-10-12 11:22:54 +02:00
Ivan Enderlin
1ecb4ca250 feat(c-api) Implement wasm_externtype_copy. 2020-10-12 09:54:05 +02:00
Mark McCaskey
ba7b24f696 Add --dir and --mapdir support to native executable 2020-10-09 17:38:14 -07:00
Ivan Enderlin
709f1c9f87 Merge branch 'master' into feat-c-api-exporttype-delete 2020-10-09 09:27:12 +02:00
Mark McCaskey
d687dd5bd6 Add system-libffi feature to wasmer C API crate 2020-10-08 14:59:42 -07:00
Ivan Enderlin
80459f3ae0 feat(c-api) Replace the max limit sentinel value by a constant.
In the `wasm.h` header file, it is defined by `wasm_limits_max_default`.
2020-10-08 17:24:12 +02:00
Ivan Enderlin
f6595cdd33 fix(c-api) Fix the sentinel value returned by wasm_memorytype_limits. 2020-10-08 17:23:59 +02:00
Ivan Enderlin
5d19813e63 fix(c-api) wasm_limits_t contains Pages, not Bytes.
When building a `wasm_memorytype_t` with `wasm_memorytype_new`, we
pass a `wasm_limits_t`, where `min` and `max` represent `Pages`. This
semantics is set by `wasm_memorytype_new` itself where `min` and `max`
from `wasm_limits_t` are used to compute `Pages`, which are then passed
to `MemoryType`.

Then, in `wasm_memorytype_limits`, we expect to get the same
`wasm_limits_t` given to `wasm_memorytype_new`. But it's not!

The same `MemoryType` is read, good. The `minimum` and `maximum`
fields are `Pages`, good. Then, we compute the `min` and `max` values
for the resulting `wasm_limits_t`, which receive `Page.bytes().0`, not
good! We don't want the number of bytes, but the number of pages.

This patch fixes that.
2020-10-08 17:14:45 +02:00
Ivan Enderlin
5dbab5655e feat(c-api) Use Option<NonNull<wasm_valtype_t>> in wasm_valtype_kind.
A more Rust-FFI idiomatic way to handle null pointer.

Note: In `wasm_valtype_kind`, it's tricky to handle the error because
we _must_ return a `wasm_valtype_kind` value. For the moment, it
continues to panic, which is probably the best tradeoff.
2020-10-08 15:08:08 +02:00
Ivan Enderlin
3ebff74263 doc(c-api) Update inline API documentation. 2020-10-08 13:43:59 +02:00
Ivan Enderlin
f24a34b6cf feat(c-api) Implement Drop for wasm_exporttype_t.
`wasm_exporttype_t` has 2 fields: `name` and `extern_type`. Both are
of kind `NonNull`. When `wasm_exporttype_t` is dropped, nor `name` nor
`extern_type` are going to be dropped.

To avoid leaking data, this patch adds a new field: `owns_fields`:

* When `wasm_exporttype_t` is built from `wasm_exportype_new`, this
  field is set to `false` because `name` and `extern_type` are
  received by pointer, and its the responsibility of the caller to
  free them,

* When `wasm_exporttype_t` is built from the `From<&ExportType>`
  implementation, _we_ create `name` and `extern_type` to then leak
  them. In this case, it is safe to reconstruct proper `Box`es to
  finally drop them.
2020-10-08 13:38:01 +02:00
Mark McCaskey
f7d5a11b39 Fix sentinel value in wasm_limits_t for memory in wasm_c_api 2020-10-07 16:38:23 -07:00
Mark McCaskey
ea8bb1ee79 Merge branch 'master' into feature/engine-object-file 2020-10-06 17:50:55 -07:00
Mark McCaskey
e6bc138b10 Remove ability to use object file engine with compiler from C API
Due to the way object file engine works, it only makes sense to use in
headless mode from the C API.
2020-10-06 17:39:51 -07:00
Ivan Enderlin
fdb077236a feat(c-api) Implement wasm_exporttype_delete. 2020-10-06 22:22:00 +02:00
Mark McCaskey
aa2e8f7b4d Address more feedback, clean up code 2020-10-06 12:13:59 -07:00
Ivan Enderlin
264ed836ac feat(c-api) Use c_try! and From implementations to simplify wat2wasm. 2020-10-06 20:56:21 +02:00
Ivan Enderlin
78887c378e chore(c-api) Simplify code. 2020-10-06 11:14:46 +02:00
Ivan Enderlin
ded3132b44 feat(c-api) Implement wat2wasm. 2020-10-06 11:09:35 +02:00
Mark McCaskey
ab153fc642 Improve error messages around memory creation 2020-10-05 15:45:52 -07:00
Mark McCaskey
0f8d68652f Finish merge with C API refactor 2020-10-05 12:30:58 -07:00
Ivan Enderlin
3edcc89698 feat(c-api) Redefine wasm_store_t.
`wasm_store_t` is now a proper struct (rather than an opaque type) of
kind:

```rs
struct wasm_store_t {
    inner: Store
}
```

The rest of the patch updates the code accordingly.
2020-10-05 21:16:43 +02:00
Ivan Enderlin
ff4cb6d412 feat(c-api) Implement wasm_module_validate. 2020-10-05 14:49:23 +02:00
Mark McCaskey
f0487763bf Readd functionality from object file engine 2020-10-02 17:31:18 -07:00
Mark McCaskey
e6c61c74ff Update boxed_vec to deal with boxed values 2020-10-02 16:33:03 -07:00