Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Engine::clone to c-api #8907

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/c-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For more information you can find the documentation for this library
To use Wasmtime from a C or C++ project, you can use Cargo to build the Wasmtime C bindings. From the root of the Wasmtime repository, run the following command:

```
cargo build --release wasmtime-c-api
cargo build --release -p wasmtime-c-api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! We'll need to update this documentation further nowadays because some headers are generated as part of the build now so CMake is primarily needed to get the headers right.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```

This will create static and dynamic libraries called `libwasmtime` in the `target/release` directory.
Expand Down
8 changes: 8 additions & 0 deletions crates/c-api/include/wasmtime/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
extern "C" {
#endif

/**
* \brief Create a new reference to the same underlying engine.
*
* This function clones the reference-counted pointer to the internal object,
* and must be freed using #wasm_engine_delete.
*/
WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine);

/**
* \brief Increments the engine-local epoch variable.
*
Expand Down
8 changes: 8 additions & 0 deletions crates/c-api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {

#[no_mangle]
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
#[cfg(feature = "logging")]
drop(env_logger::try_init());

let config = c.config;
Box::new(wasm_engine_t {
engine: Engine::new(&config).unwrap(),
})
}

#[no_mangle]
pub extern "C" fn wasmtime_engine_clone(engine: &wasm_engine_t) -> Box<wasm_engine_t> {
Box::new(engine.clone())
}

#[no_mangle]
pub extern "C" fn wasmtime_engine_increment_epoch(engine: &wasm_engine_t) {
engine.engine.increment_epoch();
Expand Down