Commit Graph

354 Commits

Author SHA1 Message Date
Bo Yao
24bcc9349e cargo fmt 2021-04-21 15:42:47 -07:00
Bo Yao
92af25a585 resolve conflict, replace two primary map to hash map 2021-04-20 16:50:05 -07:00
Mark McCaskey
5650e12f40 Fix wasm_instance_exports exports memory leak in C API tests 2021-03-18 08:30:11 -07:00
Ivan Enderlin
d3f7b7ef70 chore(c-api) Change operator to wasm_operator (reserved keyword in C++). 2021-03-05 00:57:40 +01:00
Ivan Enderlin
06a00d9bd0 doc(c-api) Update documentation for clarity. 2021-03-05 00:56:18 +01:00
Ivan Enderlin
1700c2d056 feat(c-api) Return ~1 if metering are exhausted. Add wasmer_metering_points_are_exhausted. 2021-03-05 00:49:13 +01:00
Ivan Enderlin
2d20f44365 fix(c-api) Remove useless unsafe marker. 2021-03-04 23:39:43 +01:00
Ivan Enderlin
f233ca444e chore(api) The compiler feature enables wasmer-compiler/translator. 2021-03-04 23:17:14 +01:00
Ivan Enderlin
4f2ba728dd feat(c-api) Simplify the metering API.
This patch removes the following type and functions:

* `wasmer_metering_points_t`,
* `wasmer_metering_points_delete`,
* `wasmer_metering_points_is_exhausted`,
* `wasmer_metering_points_t`,
* `wasmer_metering_points_unwrap_or`.

Now, `wasmer_metering_get_remaining_points` returns the number of
points, with zero to represent `MeteringPoints::Exhausted`.

The API is greatly simplified as there is no longer need to allocate
and deallocate a `wasmer_metering_points_t` type.
2021-03-04 22:53:02 +01:00
Ivan Enderlin
f0024c5994 doc(c-api) Fix typos. 2021-03-04 22:34:04 +01:00
Ivan Enderlin
072066acaf Merge branch 'master' into feature/metering-c-api 2021-03-04 22:31:12 +01:00
Ivan Enderlin
e7c78e77ee test(c-api) Update tests for the metering API. 2021-03-04 21:49:39 +01:00
Ivan Enderlin
0163b33ff3 test(c-api) Update the test to use a custom user-defined cost function. 2021-03-04 17:29:39 +01:00
Ivan Enderlin
e2c4f1ee69 feat(c-api) Rename Operator to wasmer_parser_operator_t. 2021-03-04 17:15:28 +01:00
Ivan Enderlin
7780423c81 feat(c-api) wasmer_metering_t contains a closure to the cost function. 2021-03-04 17:07:47 +01:00
Ivan Enderlin
902f58e32d !tmp 2021-03-02 17:42:43 +01:00
Ivan Enderlin
19c04124b1 doc(c-api) Write more documentation and tests. 2021-03-02 16:32:02 +01:00
Ivan Enderlin
798dd888c4 feat(c-api) Simplify a compilation condition. 2021-03-02 15:24:48 +01:00
Ivan Enderlin
31669b8cdc feat(c-api) Rename wasmer_module_middleware_t to wasmer_middleware_t.
Also, move it into the `unstable::middleware` module.
2021-03-02 15:20:23 +01:00
Ivan Enderlin
fb973b2af1 fix(c-api) wasmer_module_middleware_t is an opaque type. 2021-03-02 14:58:18 +01:00
Ivan Enderlin
8f1a4f3406 feat(c-api) Add wasmer_metering_delete. 2021-03-01 17:31:04 +01:00
Ivan Enderlin
cb02694abc test(c-api) Add tests for the wasmer_metering_* API. 2021-03-01 17:11:09 +01:00
Ivan Enderlin
8b30ae9d41 feat(c-api) Add _delete and rename _value to wasmer_metering_points_unwrap_or. 2021-03-01 17:10:27 +01:00
Ivan Enderlin
db4286d576 fix(c-api) Fix merge conflict. 2021-03-01 16:44:04 +01:00
Ivan Enderlin
0f43391b78 Merge branch 'master' into feature/metering-c-api 2021-03-01 16:43:16 +01:00
Ivan Enderlin
cbbdfdaefa temp 2021-03-01 16:41:44 +01:00
Ivan Enderlin
d1fc49d9c2 feat(c-api) Introduce the wasmer_features_t unstable API.
This API is a wrapper around the `wasmer_types::Features` API. A new
function `wasm_config_set_features` allows to define features for the
engine and the compiler.
2021-03-01 16:02:43 +01:00
Ivan Enderlin
2bc502bd47 fix(c-api) Move the middleware API into the unstable module. 2021-03-01 15:27:56 +01:00
Ivan Enderlin
bd25fafeb5 Merge branch 'master' into chore-c-api-formalization 2021-02-18 15:15:11 +01:00
Ivan Enderlin
830efaac17 fix(c-api) Use the name wasm_config_set_.
See the discussion here
https://github.com/wasmerio/wasmer/pull/2117#discussion_r575303872.
2021-02-18 15:04:21 +01:00
Ivan Enderlin
fbe4e07476 test(c-api) Remove no_run for 2 doctests. 2021-02-12 10:44:14 +01:00
Ivan Enderlin
93a427505e doc(c-api) Add documentation. 2021-02-12 10:35:54 +01:00
Ivan Enderlin
bdcc95925c test(c-api) Add tests for the wasmer_is_*_available API. 2021-02-12 10:29:58 +01:00
Ivan Enderlin
17dbb32e5a feat(c-api) Do not rename wat2wasm for the moment. 2021-02-12 00:26:53 +01:00
Ivan Enderlin
359873c1a1 feat(c-api) Add an unstable non-standard API to query available engines and compilers. 2021-02-12 00:20:23 +01:00
Ivan Enderlin
fd6689c580 chore(c-api) Formalize API prefixes.
The new rule is the following:

* `wasm_` for the standard C API,
* `wasmer_` or `wasi_` for the Wasmer non-standard C API.

For all symbols inside the `unstable` module, the renaming `wasm_` to
`wasmer_` is done without deprecations. It was clear that those API
were unstable.

For all the other symbols, symbols have been renamed to `wasmer_` but
the old symbols have been kept with deprecation warnings.

Special note: The `wasm_named_extern_t` type (and associated
functions) was in `wasi` by mistake. Its place was in the `unstable`
module. This patch also fixes that.

The `wasm_declare_vec_*` macros have been updated to support a default
prefix, or a user-defined prefix. It's now possible to write
`wasm_declare_boxed_vec!(foo);` to get all the API prefixed by `wasm_`
(as previously), or `wasm_declare_boxed_vec!(foo, wasmer);` to prefix
with `wasmer_`.

A user not using symbols from the `unstable` module will continue to
get working code, modulo some deprecations, after this patch.
2021-02-11 23:56:36 +01:00
Nick Lewycky
197d0f7a49 Initial commit of C API for metering and middleware. 2021-02-09 01:20:34 -08:00
Ivan Enderlin
f85ebe1b21 fix(c-api) Fix how string's length is computed.
Obviously, it's just `feature.size`. Why did I do that…?
2021-02-05 10:09:43 +01:00
Ivan Enderlin
f0f1915c86 chore(c-api) Rename or add variables for more clarity. 2021-02-04 14:00:00 +01:00
Ivan Enderlin
698a26c7fe fix(c-api) Restore a bug with wasi_get_imports.
We said that `wasi_get_imports` was taking ownership of
`wasi_env_t`. It wasn't. In 9e63ba9a25,
we have fixed this. But it creates another bug when `wasi_env_t` is
used _after_ for example when calling `wasi_env_read_stdout`.

So this patch reverts the bug fix. And we will discuss about how to
fix that later.
2021-02-02 13:42:29 +01:00
Ivan Enderlin
e5d5303b50 Merge branch 'master' into feat-c-api-wasi-unordered-imports 2021-02-02 12:17:01 +01:00
Ivan Enderlin
995a2d4779 feat(c-api) No longer expand with cbindgen: drop dependency to Rust nightly.
So. Let's explain a dirty hack. `cbindgen` reads the code and collects
symbols. What symbols do we need? None of the one declared in
`wasm.h`, but for non-standard API, we need to collect all of
them. The problem is that `wasm_named_extern_t` is the only
non-standard type where extra symbols are generated by a macro
(`wasm_declare_boxed_vec!`). If we want those macro-generated symbols
to be collected by `cbindgen`, we need to _expand_ the crate
(i.e. running something like `rustc -- -Zunstable-options
--pretty=expanded`). Expanding code is unstable and available only on
nightly compiler. We _don't want_ to use a nightly compiler only for
that. So how can we help `cbindgen` to _see_ those symbols?

First solution: We write the C code directly in a file, which is then
included in the generated header file with the `cbindgen`
API. Problem, it's super easy to get it outdated, and it makes the
build process more complex.

Second solution: We write those symbols in a custom module, that is
just here for `cbindgen`, never used by our Rust code (otherwise it's
duplicated code), with no particular implementation.

And that's why we have the following `cbindgen_hack` module.

But this module must not be compiled by `rustc`. How to force `rustc`
to ignore a module? With conditional compilation. Because `cbindgen`
does not support conditional compilation, it will always _ignore_ the
`#[cfg]` attribute, and will always read the content of the module.

Sorry.
2021-02-02 12:05:47 +01:00
Ivan Enderlin
4725a5d623 Merge branch 'master' into feat-c-api-cross-compilation-2 2021-02-02 11:07:21 +01:00
bors[bot]
c4c7b2bb9b Merge #2083
2083: doc(c-api) Remove inline documentation in `wasmer_wasm.h`, clarification about stability… r=Hywan a=Hywan

# Description

As suggested in https://github.com/wasmerio/wasmer/pull/2053#discussion_r566692725, this PR removes the automatically generated documentation when building `wasmer_wasm.h`.

It also clarifies our position regarding stability, and add a section about the documentation.

This PR takes also the opportunity to mark `wasi_env_set_(instance|memory)` as deprecated functions.

# Review

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


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2021-02-02 09:24:37 +00:00
Ivan Enderlin
0826d3d722 Merge branch 'master' into feat-c-api-cross-compilation-2 2021-02-02 09:51:01 +01:00
Ivan Enderlin
7eb08399f2 fix(c-api) Include feedbacks from @MarkMcCaskey! 2021-02-02 09:49:39 +01:00
Ivan Enderlin
98bff43f35 chore(c-api) Remove useless unsafe keywords. 2021-02-01 15:49:53 +01:00
Ivan Enderlin
b954429ca6 fix(c-api) Avoid more than one call to the function environment finalizer.
A function environment `WrapperEnv` can be cloned. In case the
original and the cloned environments are being dropped, the
`self.finalizer` function —if any— is called twice. That's a bug. It
must be called only once.

This patch updates the code to apply the finalizer only once by taking
it —if any— the first time it's called.
2021-02-01 15:42:28 +01:00
Ivan Enderlin
7c63648eb7 Update lib/c-api/src/wasm_c_api/wasi/mod.rs
Co-authored-by: Julien BIANCHI <contact@jubianchi.Fr>
2021-02-01 15:06:26 +01:00
Ivan Enderlin
9a835a4fdc doc(c-api) Remove incorrect link. 2021-02-01 15:00:13 +01:00