mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
676bccff3c
Each time `make capi` is run, there is a flaky error: ``` Running target/release/deps/runtime_c_api_tests-3df0f74fcea1252d running 1 test test test_c_api ... FAILED failures: ---- test_c_api stdout ---- Running command: `cmake` arg: Some(".") output: status: 0 stdout: -- Configuring done -- Generating done -- Build files have been written to: /Users/syrusakbary/Development/wasmer/lib/runtime-c-api/tests stderr: Running command: `make` arg: Some("-Wdev -Werror=dev") output: status: 0 stdout: [ 7%] Built target test-tables [ 15%] Built target test-module-exports [ 23%] Built target test-module-imports [ 30%] Built target test-globals [ 38%] Built target test-imports [ 46%] Built target test-module [ 53%] Built target test-module-serialize [ 61%] Built target test-memory [ 69%] Built target test-validate [ 76%] Built target test-import-function [ 84%] Built target test-instantiate [ 92%] Built target test-exports [100%] Built target test-exported-memory stderr: Running command: `make` arg: Some("test") output: status: 2 stdout: Running tests... Test project /Users/syrusakbary/Development/wasmer/lib/runtime-c-api/tests Start 1: test-exported-memory 1/13 Test #1: test-exported-memory .............Child aborted***Exception: 0.00 sec Start 2: test-exports 2/13 Test #2: test-exports ..................... Passed 0.01 sec Start 3: test-globals 3/13 Test #3: test-globals ..................... Passed 0.00 sec Start 4: test-import-function 4/13 Test #4: test-import-function ............. Passed 0.01 sec Start 5: test-imports 5/13 Test #5: test-imports ..................... Passed 0.01 sec Start 6: test-instantiate 6/13 Test #6: test-instantiate ................. Passed 0.01 sec Start 7: test-memory 7/13 Test #7: test-memory ...................... Passed 0.00 sec Start 8: test-module 8/13 Test #8: test-module ...................... Passed 0.01 sec Start 9: test-module-exports 9/13 Test #9: test-module-exports .............. Passed 0.01 sec Start 10: test-module-imports 10/13 Test #10: test-module-imports .............. Passed 0.01 sec Start 11: test-module-serialize 11/13 Test #11: test-module-serialize ............ Passed 0.01 sec Start 12: test-tables 12/13 Test #12: test-tables ...................... Passed 0.00 sec Start 13: test-validate 13/13 Test #13: test-validate .................... Passed 0.00 sec 92% tests passed, 1 tests failed out of 13 Total Test time (real) = 0.08 sec The following tests FAILED: 1 - test-exported-memory (Child aborted) stderr: Errors while running CTest make[1]: *** [test] Error 8 thread 'test_c_api' panicked at 'Command failed with exit status: ExitStatus(ExitStatus(512))', lib/runtime-c-api/tests/runtime_c_api_tests.rs:43:17 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ``` |
||
---|---|---|
.. | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml | ||
README.md | ||
wasmer.h | ||
wasmer.hh |
Wasmer Runtime C API
Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully compatible with Emscripten, Rust and Go. Learn more.
This crate exposes a C and a C++ API for the Wasmer runtime.
Usage
The C and C++ header files can be found in the source tree of this
crate, respectively wasmer.h
and
wasmer.hh
. They are automatically generated, and always
up-to-date in this repository.
Here is a simple example to use the C API:
#include <stdio.h>
#include "../wasmer.h"
#include <assert.h>
#include <stdint.h>
int main()
{
// Read the Wasm file bytes.
FILE *file = fopen("sum.wasm", "r");
fseek(file, 0, SEEK_END);
long len = ftell(file);
uint8_t *bytes = malloc(len);
fseek(file, 0, SEEK_SET);
fread(bytes, 1, len, file);
fclose(file);
// Prepare the imports.
wasmer_import_t imports[] = {};
// Instantiate!
wasmer_instance_t *instance = NULL;
wasmer_result_t instantiation_result = wasmer_instantiate(&instance, bytes, len, imports, 0);
assert(instantiation_result == WASMER_OK);
// Let's call a function.
// Start by preparing the arguments.
// Value of argument #1 is `7i32`.
wasmer_value_t argument_one;
argument_one.tag = WASM_I32;
argument_one.value.I32 = 7;
// Value of argument #2 is `8i32`.
wasmer_value_t argument_two;
argument_two.tag = WASM_I32;
argument_two.value.I32 = 8;
// Prepare the arguments.
wasmer_value_t arguments[] = {argument_one, argument_two};
// Prepare the return value.
wasmer_value_t result_one;
wasmer_value_t results[] = {result_one};
// Call the `sum` function with the prepared arguments and the return value.
wasmer_result_t call_result = wasmer_instance_call(instance, "sum", arguments, 2, results, 1);
// Let's display the result.
printf("Call result: %d\n", call_result);
printf("Result: %d\n", results[0].value.I32);
// `sum(7, 8) == 15`.
assert(results[0].value.I32 == 15);
assert(call_result == WASMER_OK);
wasmer_instance_destroy(instance);
return 0;
}
Testing
The tests can be run via cargo test
, such as:
$ cargo test -- --nocapture
To run tests manually, enter the lib/runtime-c-api/tests
directory
and run the following commands:
$ cmake .
$ make
$ make test
License
Wasmer is primarily distributed under the terms of the MIT license (LICENSE).