Commit Graph

51 Commits

Author SHA1 Message Date
Nick Lewycky
197d0f7a49 Initial commit of C API for metering and middleware. 2021-02-09 01:20:34 -08:00
Ivan Enderlin
30095e1600 fix(c-api) Do not run build.rs if the scripts/publish.py script is running. 2021-02-02 14:26:58 +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
Ivan Enderlin
e379fd79fb chore(c-api) Merge _CBINDGEN_IS_RUNNING with DOCS_RS. 2021-02-01 12:03:38 +01:00
Ivan Enderlin
79b5d5c032 chore(c-api) Exclude more functions from Wasm C API for the Wasmer C API. 2021-02-01 12:02:12 +01:00
Ivan Enderlin
8b29156d2d fixup 2021-02-01 12:01:30 +01:00
Ivan Enderlin
ffd07bcfd7 feat(c-api) Expand macros of the crate when generating C bindings. 2021-02-01 12:01:27 +01:00
Ivan Enderlin
c1092864e1 doc(c-api) Improve wasmer_wasm.h intro to explain stability and documentation. 2021-02-01 11:49:03 +01:00
Ivan Enderlin
3ecd71940f doc(c-api) Remove auto-doc from wasmer_wasm.h. 2021-02-01 11:48:55 +01:00
Ivan Enderlin
dc9f8fc82c chore(c-api) Update headers. 2021-01-29 14:34:59 +01:00
Nick Lewycky
95887af4da Include 'extern "C"' in our C header files when included in a C++ build. 2021-01-27 11:41:31 -08:00
Ivan Enderlin
79e55927b4 chore(c-api) Update headers. 2021-01-26 14:28:12 +01:00
Ivan Enderlin
70858eb201 feat(c-api) Do not build C headers if the env var DOCS_RS exists. 2021-01-22 14:22:28 +01:00
Mark McCaskey
ef8bf91e6a Handle cross-compilation in c-api build.rs 2020-12-16 12:35:16 -08:00
Mark McCaskey
eb19ffdfbe Clarify new logic with a comment 2020-12-16 11:52:37 -08:00
Mark McCaskey
dd226b1dab Add fixes from publishing 2020-12-16 10:53:09 -08:00
Ivan Enderlin
2ce2c9c7d5 feat(c-api) Add the WASMER_VERSION_{MAJOR|MINOR|PATCH|PRE} constants in C. 2020-12-11 11:03:01 +01:00
Ivan Enderlin
fdeb4a6845 feat(c-api) Add the WASMER_VERSION constant in C. 2020-12-11 10:51:40 +01:00
jubianchi
96a0d73ef8 fix(c-api): Remove the use of to link to Wasmer C API. 2020-11-13 21:09:04 +01:00
Ivan Enderlin
458daebe8c fix(c-api) Add -rpath to the linker only on Linux. 2020-11-13 17:04:10 +01:00
Ivan Enderlin
7cfd2ad161 fix(c-api) Use latest version of inline-c-rs and fix rpath on Linux. 2020-11-13 15:23:21 +01:00
Ivan Enderlin
637862dcdc test(c-api) Enable debug mode for C tests. 2020-11-09 15:45:17 +01:00
Ivan Enderlin
f02b8510d8 chore(c-api) Assert that shared object directory is well constructed.
Before `pop`ing the filename, let's check whether it's what we expect!
2020-11-06 08:59:37 +01:00
Ivan Enderlin
1d208af530 test(c-api) Create a tests/wasmer_wasm.h file.
Remove the `build.rs` hack to add helper functions that are used only
in our tests. Now the tests can use the `tests/wasmer_wasm.h` file,
which simplifies the test workflow: No need to hack the build script
or anything if we want to add a helper function.
2020-11-03 10:41:00 +01:00
Ivan Enderlin
ffba18d7b5 feat(c-api) Add a wasm_byte_vec_new_from_string helper.
It's very similar to `wasm_name_new_from_string` but for
`wasm_byte_vec_t`. It does not make sense to get that in the standard,
but it's very useful when writing tests.
2020-11-02 16:23:56 +01:00
Ivan Enderlin
6b75648d82 test(c-api) Configure and start using inline-c-rs. 2020-11-02 15:49:52 +01:00
Nick Lewycky
1b3254cf6a Move the generated-by comment up to the first comment. 2020-10-23 11:16:30 -07:00
Nick Lewycky
e28fd7e755 Add a comment indicating what generates this file. 2020-10-23 11:10:21 -07:00
Syrus
bb1b89f4f7 Removed all usages of wasm_instance_get_vmctx_ptr 2020-10-16 21:39:23 -07: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
Mark McCaskey
fd63ddb101 Merge branch 'master' into feature/wasmer-create-exe 2020-10-12 15:54:54 -07:00
Ivan Enderlin
b9f98ce1f6 feat(c-api) Update .h files. 2020-10-12 17:54:21 +02:00
Mark McCaskey
ba7b24f696 Add --dir and --mapdir support to native executable 2020-10-09 17:38:14 -07:00
Mark McCaskey
02c0df5101 Update to cbindgen 0.15.0
Manually specify that items should be sorted by name in the header
file. We do this because cbindgen 0.15.0 removed sorting by default.
2020-10-08 14:42:00 -07:00
Mark McCaskey
ea8bb1ee79 Merge branch 'master' into feature/engine-object-file 2020-10-06 17:50:55 -07:00
Ivan Enderlin
ded3132b44 feat(c-api) Implement wat2wasm. 2020-10-06 11:09:35 +02:00
Mark McCaskey
0f8d68652f Finish merge with C API refactor 2020-10-05 12:30:58 -07:00
Ivan Enderlin
2fdd9ea692 feat(c-api) Simplify the build.rs script. 2020-10-02 10:10:24 +02:00
Ivan Enderlin
a2854ebfea fix(c-api) Adjust cbindgen metadata for header files. 2020-10-01 21:20:13 +02:00
Ivan Enderlin
5ea1f1eb25 feat(c-api) Always generate _all_ C headers. Include the deprecated API per default. 2020-10-01 09:52:23 +02:00
Ivan Enderlin
f5a57b84e9 fix(c-api) Exclude non-standard WASI API from wasmer.h. 2020-09-29 16:21:16 +02:00
Ivan Enderlin
cab0854d99 feat(c-api) Rename the include-deprecated feature to deprecated, and change strategy.
When `deprecated` is enabled, the `deprecated` module is included in
the crate.

When `deprecated` is enabled, **only** the `wasmer.h*` header files
will be generated.

When `deprecated` is disabled, **only** the `wasmer_wasm.h` header
file will be generated.
2020-09-29 16:04:25 +02:00
Ivan Enderlin
570b174fb5 fix(c-api) Polish deprecated API. 2020-09-28 15:45:52 +02:00
Ivan Enderlin
b59db4cee2 feat(c-api) wasmer_wasm.h includes wasm.h. 2020-09-28 14:52:27 +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
3514988462 feat(c-api) Generate wasmer_wasm.h automatically. First draft. 2020-09-22 16:54:22 +02:00
Ivan Enderlin
9e8b80c2f6 feat(c-api) Ensure Rust documentation is used as C's. 2020-09-22 13:18:18 +02:00
Ivan Enderlin
8c03da87a9 feat(c-api) Reorganize the build.rs script. 2020-09-22 13:14:48 +02:00