Commit Graph

32 Commits

Author SHA1 Message Date
Ivan Enderlin
446a76312b feat(c-api) Create OrderedResolver from a parallel iterator.
This patch adds `rayon` to `wasmer-c-api` so that we can create an
`OrderedResolver` from a `ParallelIterator`. For modules with a long
list of imports, it's interesting to parallelize the work.
2021-08-16 14:38:35 +02:00
Felipe Gasper
4255387f49 Rename wasm_instance_new()’s “traps” argument to “trap”.
Issue #2472
2021-07-17 22:12:04 -04:00
Ivan Enderlin
09f1b9103a fix(c-api) Rename lib's name to wasmer.
This patch does several things.

1. For the crate `wasmer-c-api`, the library name is modified from
   `wasmer_c_api` to `wasmer` in `Cargo.toml`. That way, the new
   library files are named `libwasmer.*` rather than
   `libwasmer_c_api.*`. That's the primaly goal of this patch. The
   rest is a consequence of this point. Why do we want that? Because
   the `build.rs` script of the `wasmer-c-api` crate will configure
   the `soname` (on Linux), the `install_name` + `current_version` +
   `compatibility_version` (on macOS), and the `out-implib` +
   `output-def` (on Windows) for a library named `libwasmer`, which is
   the name we provide in the Wasmer package for the Wasmer
   libraries. If we want everything to be testable, we cannot use
   `libwasmer` in `soname` for a file named `libwasmer_c_api` for
   example. If we rename the file when packaging (as it's done prior
   this patch), we would need to re-update all those information in
   the `Makefile`. It implies to duplicate the code in 2 places. So
   let's do things right directly and only once: We want the library
   to be named `libwasmer`, let's do that.

2. For the crate `wasmer-c-api`, since the library name has been
   renamed to `wasmer`, it creates a conflict with the `wasmer` crate
   which is a dependency. Consequently, this patch also updates the
   `Cargo.toml` file to modifiy the dependency name with the special
   `package` attribute (see
   https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml
   to learn more). So now, the `wasmer` refers to the `wasmer_c_api`
   crate, and `wasmer-api` refers to the `wasmer` crate.

3. The code of the `wasmer-c-api` crate is updated accordingly. The
   `WasmerEnv` derive procedural macro fails because it expects a
   crate named `wasmer` (which is now `wasmer_api`), so we implement
   the `WasmerEnv` trait by hand.

4. The patch updates the `build.rs` script of the `wasmer-c-api`
   crate:

  1. In the `build_cdylib_link_arg` function: The dependency to the
     `cdylib-link-lines` crate has been removed because the output is
     not exactly the one we expect. So we compute all the
     `cargo:rustc-cdylib-link-arg=…` lines by hand. The version number
     no longer appears in the library file name for example.

  2. In the `build_inline_c_env_vars` function: Values passed to
     `LDFLAGS` have been updated to be `libwasmer` rather than
     `libwasmer_c_api`.

  3. A new `shared_object_dir` helper function has been created
     because it's used in `build_inline_c_env_vars` and in
     `build_cdylib_link_arg`.

5. The `Makefile` has been updated:

  1. In `package-capi`, we no longer rename `libwasmer_c_api` to
     `libwasmer` since the name is correctly defined since the
     beginning now.

     Calling `install_name_tool` on macOS is no longer required since
     `install_name` is correctly set by the linker in the `build.rs`
     script of `wasmer-c-api`.

  2. In `package-docs`, some stuffs have been fixed, like the
     `SOURCE_VERSION` variable that didn't exist, so removed, or the
     `mkdir` command that was incorrect etc.

  3. In `build-docs`, the `wasmer-c-api` crate is excluded from the
     list of crates to generate the documentation for. Mostly because
     the `build-docs-capi` recipe exists, and we must use it to
     generate the documentation of `wasmer-c-api` now.

  4. In `build-docs-capi`, we generate the documentation for the
     `wasmer-c-api` crate. But `rustdoc` uses the library name for the
     directory name in the `target/doc/` directory. Since the library
     name is now `wasmer`, it creates a conflict with the `wasmer`
     crate. Consequently, we update the library name by using `sed` on
     the `Cargo.toml` file before running `cargo doc`, to finally
     restore `Cargo.toml` as it was previously.
2021-07-08 13:30:20 +02:00
Ivan Enderlin
d63ffcd78f doc(c-api) Write documentation for the trap module. 2021-06-25 13:38:26 +02:00
Syrus Akbary
b520a5f58a Renamed wasmer_wasm.h to wasmer.h 2021-06-01 21:47:37 -07:00
Ivan Enderlin
f5a7ac960f feat(c-api) Remove the deprecated API.
Until this patch, our C API comes in 2 flavors: `deprecated` and
`wasm_c_api`. With the coming 2.x version of Wasmer, we would like to
remove the `deprecated` API, and keep the `wasm_c_api` only.

This patch removes the `deprecated` API from the `wasmer-c-api`
crate. It also cleans up the `Makefile` and the documentation
system. Previously, the documentation for the `deprecated` API was
relying on Doxygen, which was one new dependency the user had to
install. For the `wasm_c_api`, it relies on `rustdoc`, which is way
better because all examples are run and tested as part of our test
suite.

This clean up also removes the need to deal with `system-libffi` both
in the crate itself and in the `Makefile`, which was an edge case for
macOS on aarch64, and a needle in the foot for some of our users.

Finally, the `build.rs` is now simplified because we no longer need to
exclude symbols from one header to another. It also means that we only
provide the `wasmer_wasm.h` header file now; the `wasmer.h` and
`wasmer.hh` headers are removed.
2021-05-31 17:59:19 +02:00
Mark McCaskey
f266f830f2 Implement wasm_extern_t with type casting 2021-03-26 13:55:24 -07:00
Mark McCaskey
9868c0f297 Add wip solution to wasm_extern_as_ no allocation 2021-03-23 09:01:01 -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
fb7ce4ad9a doc(c-api) Specify where examples are for wasm_instance_new. 2020-12-15 16:07:13 +01:00
Ivan Enderlin
7a30c31a6f test+doc(c-api) Add test for wasm_instance_exports. 2020-12-15 15:59:57 +01:00
Ivan Enderlin
6d74163462 doc(c-api) Specify that the code does not panic. 2020-12-10 16:18:32 +01:00
Ivan Enderlin
4740202e90 test(c-api) Fix tests. 2020-12-10 16:14:13 +01:00
Ivan Enderlin
f2a2cf4265 Merge branch 'master' into test-c-api 2020-12-01 11:37:41 +01:00
Ivan Enderlin
37240bdc10 test(c-api) Start testing the instance module. 2020-11-30 16:56:56 +01:00
Ivan Enderlin
eb01733839 doc(c-api) Document the instance module. 2020-11-30 16:56:45 +01:00
Mark McCaskey
a19705ae11 Remove free method, call finalizers in C API 2020-11-16 16:36:58 -08:00
Ivan Enderlin
69c23fd78f doc(c-api) Add the own annotation when necessary. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
ce10285be2 fix(c-api) Remove done TODO. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
152f1d980c feat(c-api) wasm_instance_new handles null pointers. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
9583a91678 fix(c-api) wasm_trap_t** in wasm_instance_new does not represent an array.
The `wasm_trap_t**` argument of `wasm_instance_new` represents an
output pointer to a `wasm_trap_t*`, not an array of
`wasm_trap_t*`. This patch updates the code accordingly.
2020-10-30 09:37:05 +01:00
Ivan Enderlin
4102dcb9ac feat(c-api) Shrink vector of traps.
Ensure that the size of the vector of the instance's traps equals its
capacity by shrinking it.
2020-10-27 11:49:01 +01:00
Ivan Enderlin
452181326a fix(c-api) Remove a debug_assert macro. 2020-10-27 11:44:38 +01:00
Ivan Enderlin
a2d96d9ba7 feat(c-api) Implement the traps argument of wasm_instance_new.
When running `Instance::new`, it can error with an
`InstantiationError`. There is 2 scenarii:

1. Either it's a `InstantiationError::Link`. In this case, the
   `wasm_instance_new` function must return `NULL` and register the
   error in the Wasmer error registry.

2. Either it's a `InstantiationError::Start`. In this case, the
   `wasm_instance_new` function must return `NULL` and the error must be
   converted into a `wasm_trap_t`, which is stored in the `wasm_trap_t**`
   array. This array is initialized by `wasm_instance_new` itself.
2020-10-26 15:27:20 +01: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
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
ae1a50b5d7 chore(c-api) Move cbindgen:ignore from functions/types to modules.
This patch removes the amount of `cbindgen:ignore` instructions by
moving this instruction onto the parent module.
2020-10-02 09:51:48 +02:00
Ivan Enderlin
8f627d9834 feat(c-api) Instruct cbindgen to ignore all functions and types defined in wasm.h. 2020-09-28 14:49:44 +02:00
Ivan Enderlin
174b03f4e9 feat(c-api) Use our fork of cbindgen.
Our fork contains incoming PR. It helps for example to skip struct
fields.
2020-09-24 16:15:04 +02:00
Ivan Enderlin
1a0527af78 feat(c-api) Move all types into their own modules. 2020-09-24 11:41:04 +02:00
Ivan Enderlin
44559a9f04 feat(c-api) Move as_extern APIs into the externals module. 2020-09-24 09:48:56 +02:00
Ivan Enderlin
50fbb9766d feat(c-api) Move instance into its own module. 2020-09-24 09:19:53 +02:00