Skip to content

Commit

Permalink
Update the docs for building the C API (bytecodealliance#8960)
Browse files Browse the repository at this point in the history
* Update the docs for building the C API

Suggest `cmake` since that is what we test in CI and keep working.

* Review comments
  • Loading branch information
fitzgen authored Jul 15, 2024
1 parent af95475 commit 158a8f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
35 changes: 30 additions & 5 deletions crates/c-api/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
# Wasmtime's C API

For more information you can find the documentation for this library
[online](https://bytecodealliance.github.io/wasmtime/c-api/).
## API Documentation

[The API documentation for the Wasmtime C library is hosted
here.](https://bytecodealliance.github.io/wasmtime/c-api/).

## Using in a C Project

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:
### Using a Pre-Built Static or Dynamic Library

Each release on Wasmtime's [GitHub Releases
page](https://github.com/bytecodealliance/wasmtime/releases) has pre-built
binaries for both static and dynamic libraries for a variety of architectures
and operating systems attached, as well as header files you can include.

### Building Wasmtime's C API from Source

To use Wasmtime from a C or C++ project, you must have
[CMake](https://cmake.org/) and [a Rust
toolchain](https://www.rust-lang.org/tools/install) installed.

From the root of the Wasmtime repository, run the following commands:

```
cargo build --release -p wasmtime-c-api
$ cmake -S crates/c-api -B target/c-api --install-prefix "$(pwd)/artifacts"
$ cmake --build target/c-api
$ cmake --install target/c-api
```

This will create static and dynamic libraries called `libwasmtime` in the `target/release` directory.
These commands will produce the following files:

* `artifacts/lib/libwasmtime.{a,lib}`: Static Wasmtime library. Exact extension
depends on your operating system.

* `artifacts/lib/libwasmtime.{so,dylib,dll}`: Dynamic Wasmtime library. Exact
extension depends on your operating system.

* `artifacts/include/**.h`: Header files for working with Wasmtime.

## Using in a Rust Project

Expand Down
13 changes: 3 additions & 10 deletions docs/contributing-building.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@ with `cargo run`.

## Building the Wasmtime C API

To build the C API of Wasmtime you can run:

```shell
cargo build --release -p wasmtime-c-api
```

This will place the shared library inside of `target/release`. On Linux it will
be called `libwasmtime.{a,so}`, on macOS it will be called
`libwasmtime.{a,dylib}`, and on Windows it will be called
`wasmtime.{lib,dll,dll.lib}`.
See
[`crates/c-api/README.md`](https://github.com/bytecodealliance/wasmtime/blob/main/crates/c-api/README.md)
for details.

## Building Other Wasmtime Crates

Expand Down

0 comments on commit 158a8f5

Please sign in to comment.