Skip to content

Commit

Permalink
readme: Mention public C and Rust APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jan 8, 2021
1 parent c7ed699 commit 2eee52e
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,40 @@ $ cmake ..
$ cmake --build .
```

This will build Fizzy as a library and since there is no public API
(the so called *embedder API* in WebAssembly) yet, this is not very useful.
This will build Fizzy as a library. [C API] is provided for embedding Fizzy engine in applications.

A small example of using C API, that loads a wasm binary and executes a function:

```c
#include <fizzy/fizzy.h>

bool execute_main(const uint8_t* wasm_binary, size_t wasm_binary_size)
{
// Parse and validate binary module.
const FizzyModule* module = fizzy_parse(wasm_binary, wasm_binary_size);

// Find main function.
uint32_t main_fn_index;
if (!fizzy_find_exported_function_index(module, "main", &main_fn_index))
return false;

// Instantiate module without imports.
FizzyInstance* instance = fizzy_instantiate(module, NULL, 0, NULL, NULL, NULL, 0);

// Execute main function without arguments.
const FizzyExecutionResult result = fizzy_execute(instance, main_fn_index, NULL, 0);
if (result.trapped)
return false;

fizzy_free_instance(instance);
return true;
}
```
Fizzy also provides CMake package for easy integration in the projects that use it:
```cmake
find_package(fizzy CONFIG REQUIRED)
```

## WASI

Expand Down Expand Up @@ -181,6 +213,8 @@ Licensed under the [Apache License, Version 2.0].
[@chfast]: https://github.com/chfast
[@gumb0]: https://github.com/gumb0

[C API]: ./include/fizzy/fizzy.h

[WASI]: https://github.com/WebAssembly/WASI
[uvwasi]: https://github.com/cjihrig/uvwasi
[wasi_snapshot_preview1]: https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/wasi_snapshot_preview1.witx
Expand Down

0 comments on commit 2eee52e

Please sign in to comment.