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.
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.
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.
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.
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.
`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.