Commit Graph

861 Commits

Author SHA1 Message Date
Ivan Enderlin
d92c4831bf Merge branch 'master' into test-capi 2021-07-13 12:06:37 +02: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
Syrus Akbary
44a83cbdba Merge branch 'master' into feat-capi-cbindgen-0.19 2021-07-06 20:25:00 -05:00
Ivan Enderlin
0d6f9f41b1 doc(changelog) Add #2449. 2021-07-06 14:44:51 +02:00
Ivan Enderlin
4b783ffd17 feat: Configure soname, install_name, out-implib etc. for the C API.
This patch uses `cdylib-link-lines` to “configure” the cdylib
correctly.
2021-07-06 14:43:30 +02:00
Ivan Enderlin
413ead61fe feat(c-api) Update cbindgen to 0.19. 2021-07-01 14:19:37 +02:00
Ivan Enderlin
d63ffcd78f doc(c-api) Write documentation for the trap module. 2021-06-25 13:38:26 +02:00
Ivan Enderlin
a4349f8719 doc(changelog) Add #2444. 2021-06-25 13:26:02 +02:00
Ivan Enderlin
eea75e7862 fix(c-api) Trap's messages are always null terminated.
`wasm_trap_new` expects a `wasm_message_t`. It's a type alias to
`wasm_name_t` with the exception that it represents a null-terminated
string.

When calling `wasm_trap_new`, no check was present to ensure the
string was well-formed. That's a first issue. But in the best
scenario, the string was correctly formed and was
null-terminated. This string was transformed to a Rust `String` —with
the null byte!— and passed to `RuntimeError`.

Then in `wasm_trap_message`, another null byte was pushed at the end
of the message. It's been introduced in
https://github.com/wasmerio/wasmer/pull/1947. It results in a
doubly-null-terminated string, which is incorrect.

This patch does the following:

1. It checks that the string given to `wasm_trap_new` contains a
   null-terminated string or not, and will act accordingly. Note that
   it's possible to pass a non-null-terminated string, and it will
   still work because this detail is vicious. The idea is to get a
   well-formed `RuntimeError` in anycase.

  * If no null byte is found, the string is passed to `RuntimeError`
    as a valid Rust string,

  * If a null byte is found at the end of the string, a new string is
    passed to `RuntimeError` but without the final null byte,

  * If a null byte is found but not at the end, it's considered as an
    error,

  * If the string contains invalid UTF-8 bytes, it's considered as an
    error.

2. It updates `wasm_trap_message` to always add a null byte at the end
   of the returned owned string.

3. It adds test cases when passing a null-terminated or a
   non-null-terminated string to `wasm_trap_new` and to compare the
   results to `wasm_trap_message`.
2021-06-25 11:42:04 +02:00
Ivan Enderlin
29d7b4a5f1 doc(c-api) Update links to documentation. 2021-06-18 10:22:11 +02:00
Mark McCaskey
0c0fdad3d2 Prepare for 2.0.0 release 2021-06-15 11:26:46 -07:00
Ivan Enderlin
7193282de5 test(c-api) Clean up the tests/Makefile.
1. Use single tabs rather than three, it fits in a small terminal
   window,
2. `CAPI_WASMER_TESTS` has been removed in
   https://github.com/wasmerio/wasmer/pull/2375, but partially. This
   patch finishes the work.
3. The `test-%: %.o` rule is a remainder of some older code, it's no
   longer needed.
2021-06-08 12:01:19 +02:00
Ivan Enderlin
6572ee4537 doc(c-api) Fix markdown markup. 2021-06-08 11:30:56 +02:00
Mark McCaskey
80a8658e5a Prepare for 2.0.0-rc2 release 2021-06-03 09:19:16 -07:00
Ivan Enderlin
aec4a8a7dc doc(changelog) Add missing entries. 2021-06-03 09:29:38 +02:00
Mark McCaskey
cfc1a5fc26 Fix typo 2.0.0-rc -> 2.0.0-rc1 2021-06-02 08:32:46 -07:00
Mark McCaskey
2897a5b05e Bump version number to 2.0.0-rc1 2021-06-02 08:21:34 -07:00
Syrus Akbary
2b69176a86 Added API compatibility layer 2021-06-02 00:29:55 -07:00
Syrus Akbary
b520a5f58a Renamed wasmer_wasm.h to wasmer.h 2021-06-01 21:47:37 -07:00
Ivan Enderlin
c2579c1140 fix(c-api) Update based on feedbacks. 2021-06-01 16:38:08 +02:00
Ivan Enderlin
192b93fb0a Merge branch 'master' into feat-c-api-remove-deprecated 2021-05-31 18:09:05 +02: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
bors[bot]
7d09f94148 Merge #2364
2364: feat: Rename `wasmer-engine-object-file` to `wasmer-engine-staticlib`. r=Hywan a=Hywan

# Description

This PR renames the `wasmer-engine-object-file` crate into `wasmer-engine-staticlib`. We believe it conveys a better meaning of what it does. This PR is similar to its siblings, #2340 and #2356.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2021-05-31 14:32:50 +00:00
bors[bot]
c0d3a8f7fc Merge #2161
2161: feat(llvm): Make NaN canonicalization configurable r=jubianchi a=jubianchi

compiler-llvm now uses the experimental.constrained intrinsics to ensure
correct behavior on FP operations when full-canonicalization is
disabled.
    
This patch requires TheDan64/inkwell#247

# Review

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


Co-authored-by: jubianchi <julien@wasmer.io>
2021-05-31 13:21:54 +00:00
Ivan Enderlin
5d302f0d4a feat: Rename wasmer-engine-object-file to wasmer-engine-staticlib. 2021-05-31 14:19:14 +02:00
Ivan Enderlin
3d66a2e360 feat: Rename wasmer-engine-native to wasmer-engine-dylib. 2021-05-28 14:13:24 +02:00
Ivan Enderlin
79d5f20301 feat: Rename wasmer-engine-native to wasmer-engine-shared-object. 2021-05-28 14:13:24 +02:00
jubianchi
6a99268895 feat(llvm): Make NaN canonicalization configurable
compiler-llvm now uses the experimental.constrained intrinsics to ensure
correct behavior on FP operations when full-canonicalization is
disabled.

This patch requires TheDan64/inkwell#247
2021-05-28 11:40:10 +02:00
Ivan Enderlin
39842c67e7 Update lib/c-api/src/wasm_c_api/engine.rs
Co-authored-by: Julien BIANCHI <contact@jubianchi.Fr>
2021-05-27 13:07:04 +02:00
Ivan Enderlin
23e52b7c1d !fixup 2021-05-27 13:05:21 +02:00
Ivan Enderlin
14f469f718 Merge branch 'master' into feat-rename-jit-engine 2021-05-27 13:01:02 +02:00
Mark McCaskey
3151cc945e Update changelog 2021-05-26 08:57:11 -07:00
Mark McCaskey
810cb5d96a Implement missing C API function wasm_func_copy 2021-05-26 08:47:01 -07:00
Ivan Enderlin
e5a784a006 feat: Rename wasmer-engine-jit to wasmer-engine-universal.
This (small) patch renames the `wasmer-engine-jit` crate into
`wasmer-engine-universal`.
2021-05-25 16:12:06 +02:00
Syrus Akbary
2e90db6967 Addressed comments 2021-05-18 14:32:21 -07:00
Syrus Akbary
71176cca7a Unified C API tests 2021-05-15 09:15:50 -07:00
Mark McCaskey
9a0d0b3dac Update wasmparser in the c-api too 2021-04-29 09:42:54 -07:00
k-nasa
40ee361586 fix favicon 2021-04-24 15:34:44 +09:00
bors[bot]
caf98ef450 Merge #2092
2092: Add reference types r=MarkMcCaskey a=MarkMcCaskey

This PR adds support for reference types in the API and in our compilers.

Wasm C API support should probably be a separate PR after this one lands.

# Status
- [x] spectests passing
  - [x] compiler-cranelift
  - [x] compiler-singlepass
  - [x] compiler-llvm
- [x] Tables work with references
- [x] Globals work with references
- [x] FuncRefs for local functions
- [x] FuncRefs for imported functions
- [ ] ExternRefs
  - [x] Work as values in Wasm
  - [x] Tests showing it being passed to/from host functions
  - [x] Top level API for interacting with ExternRefs
  - [ ] Reference counting works as expected, fully tested
- [ ] ~~Wasm C API support (should be done on a PR branched off of this branch)~~ (not going to do this in this PR)
- [x] ~Host info (see Wasm C API and wasmer Rust API)~ (not going to do this in this PR. The value of this feature seems low and the cost seems high; unclear if we even want it at the Rust API level)

# Review
<!--
## High priority things to review

- [ ] ExternRef reference counting behavior (blocked on implementation, but feedback of what's there is welcome)
  - [ ] That we're counting in all the places that matter (we're not yet)
  - [ ] The manual `ref_clone` and `ref_drop` in order to make putting `VMExternRef` in a `union` work.
- [ ] FuncRef storage
  - [ ] Distinction between imported and local FuncRef
  - [x] Duplicating data rather than storing it inline in the dynamic part of the `Instance`
- [ ] Changes to `wasmer_types::Value`
  - [ ] ExternRef
  - [ ] FuncRef / ValueEnumType
  - [ ] Passing a store via `&dyn Any` to some methods and the garbage placeholder values we pass when we don't have a store.
  - [ ] The location of the `Option` for `FuncRef` 
- [x] Implementation of new instructions (bug check)
- [ ] API changes
  - [ ] Changes in the wasmer crate
  - [ ] Changes in the core traits for example `vm::Table`
- [ ] Use of `repr(C)` union `vm::table::TableElement` in `extern "C"` / FFI contexts. I just assumed `repr(C)` on a union of all usize sized things would just be passed like a usize.
- [ ] WAST test runner updates

## Lower priority things to review

These are things that I think we can fix with follow-up PRs. Let me know if you think anything on this list is too important to fix later.

- [ ] Implementation of new instructions (calling functions rather than doing it inline)
- [ ] Use of libcalls distinguishing between imported vs local in cases where it probably doesn't matter
-->
# misc

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


Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Nick Lewycky <nick@wasmer.io>
2021-04-06 19:27:20 +00:00
Mark McCaskey
269df82043 Merge branch 'master' into fix/c-api-allocation 2021-04-06 10:16:02 -04:00
Mark McCaskey
12406d64b3 Add a new CHANGELOG.md for the C API 2021-04-06 07:15:21 -07:00
Mark McCaskey
0fad04f63f Add test for tag offset 2021-04-06 07:04:47 -07:00
Mark McCaskey
8149453ff5 Merge branch 'master' into feature/reference-types 2021-03-31 08:42:26 -07:00
Mark McCaskey
bc8cb68d84 Update examples to not free things cast from extern 2021-03-30 08:47:18 -07:00
Mark McCaskey
f266f830f2 Implement wasm_extern_t with type casting 2021-03-26 13:55:24 -07:00
bors[bot]
2948bc79b6 Merge #2210
2210: Fix memory leak in C API in some uses of `wasm_name_t` r=MarkMcCaskey a=MarkMcCaskey

This PR fixes a bug relating to `wasm_importtype_t` leaking memory, particularly on the path where `String` is converted into `wasm_name_t`. It fixes this by introducing a new type, `owned_wasm_name_t`, which is identical to `wasm_name_t` but has RAII and calls the destructor if it goes out of scope.

I'm not confident that the use of `owned_wasm_name_t` on the FFI boundary is correct though, we'll have to thoroughly review that before shipping this PR.

# Review

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


Co-authored-by: Mark McCaskey <mark@wasmer.io>
2021-03-26 15:39:09 +00:00
Mark McCaskey
7ef7bf0c48 Simplify as_ref() code due to lack of Box 2021-03-25 12:55:45 -07:00
Mark McCaskey
e3eb1b6ad1 Explicitly convert to owned_wasm_name_t in export and wasi too 2021-03-25 12:46:43 -07:00
Mark McCaskey
769707a51d Explicitly convert to owned_wasm_name_t 2021-03-25 10:55:26 -07:00
François Garillot
b832de05df Simplifies a few pattern-matches
... which have a direct combinator equivalent on Option / Result.

Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust).
2021-03-24 07:18:26 -07:00