Fix externref/anyref ownership in C/C++ API (#11799)* Fix externref/anyref ownership in C/C++ APIThis commit is a follow-up to #11514 which was discovered throughfailing tests in the wasmtime-py
Fix externref/anyref ownership in C/C++ API (#11799)* Fix externref/anyref ownership in C/C++ APIThis commit is a follow-up to #11514 which was discovered throughfailing tests in the wasmtime-py repository when updating to Wasmtime37.0.0. Effectively a combination of bugs in the Rust API meant that itwasn't possible to use `externref` or `anyref` bindings correctly. TheRust changes in this commit are:* `wasmtime_val_unroot` correctly drops the value now as opposed to effectively being a noop from before (typo of using `as_externref` vs `from_externref`).* `wasmtime_{anyref,externref,val}_t` now have a `Drop` implementation in Rust to correctly drop them if a value in Rust is dropped. This is required to correctly manage memory in the `wasmtime_func_{call,new}` implementations, for example.* `wasmtime_{anyref,externref,val}_clone` no longer have an unnecessary context parameter.* `wasmtime_{anyref,externref,val}_unroot` no longer have an unnecessary context parameter.Changes in the C/C++ APIs are:* `Result::{ok,err}_ref` APIs were added in addition to the preexisting rvalue accessors.* Loading/storing typed arguments now has an overload for `const T&` and `T&&` which behaves differently. Notably transferring ownership for `T&&` and not for `const T&`. This means that passing parameters when calling a wasm function uses `const T&`, but passing results from a host import uses `T&&`.* `TypedFunc::call` now uses `const Params&` instead of `Params` to explicitly specify it doesn't modify the parameters and forces using the `const T&` store method.* `Store::gc` is now a convenience method for `store.context().gc()`* `ExternRef`, `AnyRef`, and `Val` now have ownership semantics and destructors. This matches the spirit of #11514 for Rust but models it in C++ as well. This required filling out move/copy constructors/assignments.* The explicit `ExternRef` now takes `std::any` instead of `T`.* Minor issues related to ownership are fixed in `Val` bindings.Valgrind was used to ensure that there were no leaks for the test suitewhich additionally resulted in a number of `*_delete` calls being addedto tests using the C API (accidental omissions).The original goal of this change was to be a patch release for 37.0.1 toenable updating wasmtime-py to the 37.0.x releases of Wasmtime. In theend though the changes here were broad enough that I no longer feel thatthis is a good idea, so wasmtime-py will be skipping the 37 version ofWasmtime.* Run `clang-format`prtest:full
show more ...
[docs] Add C++ chapter and missing examples (#11569)* [docs] Add C++ chapter and missing examplesThis adds a chapter for C++ embedding. The chapter intro is rudimentary, but there are a bunch mor
[docs] Add C++ chapter and missing examples (#11569)* [docs] Add C++ chapter and missing examplesThis adds a chapter for C++ embedding. The chapter intro is rudimentary, but there are a bunch more examples now: I added C++ ports for everything that already had both a Rust and a C version available, matching the Rust version's behavior where applicable.* [example] Fix paths in `examples/wasip1/main.c`* [docs] Add entries for additional Rust and C embedding examplesThese examples already existed, but didn't have entries in the docs.It'll probably make sense to restructure all of this at some point and move the examples into language-specific folders.* [docs] Remove references to Conan packages from README.mdThese packages haven't been updated since Wasmtime 18, so we shouldn't link to them for now.* Format cpp files* Format even more cpp files* Fix some warnings in C++ headers* Simplify threads.cc example* Update docs/examples-c-serialize.mdCo-authored-by: Nick Fitzgerald <[email protected]>* [example] Don't try, do.* [docs] Restore CMake link in README* [docs] Improve examples/README.md* [docs] Address review feedback---------Co-authored-by: Alex Crichton <[email protected]>Co-authored-by: Nick Fitzgerald <[email protected]>
Rename "preview{0,1}" in `wasmtime-wasi` to "p{0,1}" (#11380)* Rename "preview{0,1}" in `wasmtime-wasi` to "p{0,1}"This commit renames the `preview1` module and features to `p1` and doesthe same
Rename "preview{0,1}" in `wasmtime-wasi` to "p{0,1}" (#11380)* Rename "preview{0,1}" in `wasmtime-wasi` to "p{0,1}"This commit renames the `preview1` module and features to `p1` and doesthe same for `preview0`. This additionally cleans up the test suite abit to share more code amongst all the implementaitons and to also movethe p1 tests out of the p2 folder.This additionally adds a `p2` feature to the `wasmtime-wasi` crate butit does not currently gate the `p2` module because that'll require somemore refactoring an annotations to get that working.* Fix build of the CLI* Fix build of the C API* Fix bench-api build* Fix build of examples* More renamings
Unify WASIp{2,3} context structures (#11370)This removes `wasmtime_wasi::p{2,3}::{WasiCtx, WasiCtxBuilder,WasiView}` in favor of only having `wasmtime_wasi::{WasiCtx,WasiCtxBuilder, WasiView}` in
Unify WASIp{2,3} context structures (#11370)This removes `wasmtime_wasi::p{2,3}::{WasiCtx, WasiCtxBuilder,WasiView}` in favor of only having `wasmtime_wasi::{WasiCtx,WasiCtxBuilder, WasiView}` instead. Conceptually these revisions of WASIall provide the same functionality just with a different veneer that thecomponent model offers, so having only one way to configure host-sidebehavior will make it easier to both organize implementations internally(e.g. more sharing of code) as well as for embedders to configure (onlyone context to create/manage).
Revamp wasi example and related docs (#9788)* update examples/wasi/main.rs and related doc with a runtime issue* simplify building instruction* fix runtime issue* add a comment and cargo fmt
Revamp wasi example and related docs (#9788)* update examples/wasi/main.rs and related doc with a runtime issue* simplify building instruction* fix runtime issue* add a comment and cargo fmt* revamped wasi-async* remove the example of custom host states and add references* add calling function dynamically* cargo fmt* add post_return* update wording* add expects* change wording from "module" to "component"* fix CMakeLists.txt* compile wasi example with wasip1 to make the outdated WASIp1 C example happy* rename wasi examples* fix wording* fix format* add wasm32-wasip2 target* Revert "add wasm32-wasip2 target"This reverts commit 0aa610f6ce8c2617889238db2961f545b661ca27.* add wasm32-wasip2 target for test_capi job