mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-15 18:01:22 +00:00
Add first c test to test the C api
This commit is contained in:
@ -1,4 +1,8 @@
|
|||||||
# Wasmer Runtime C API
|
# Wasmer Runtime C API
|
||||||
|
|
||||||
## Generating header files
|
## Generating header files
|
||||||
Run `make capi`
|
Run `make capi` from wasmer project root directory
|
||||||
|
|
||||||
|
## Running tests
|
||||||
|
`cmake . && make && make test` from runtime-c-api/tests directory
|
||||||
|
(TODO run this within a rust test)
|
@ -15,8 +15,10 @@ fn main() {
|
|||||||
fn build() {
|
fn build() {
|
||||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
|
||||||
|
use cbindgen::Language;
|
||||||
cbindgen::Builder::new()
|
cbindgen::Builder::new()
|
||||||
.with_crate(crate_dir)
|
.with_crate(crate_dir)
|
||||||
|
.with_language(Language::C)
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate bindings")
|
.expect("Unable to generate bindings")
|
||||||
.write_to_file("wasmer.h");
|
.write_to_file("wasmer.h");
|
||||||
|
@ -23,6 +23,7 @@ pub extern "C" fn wasmer_import_object_new() -> *mut wasmer_import_object_t {
|
|||||||
Box::into_raw(Box::new(ImportObject::new())) as *mut wasmer_import_object_t
|
Box::into_raw(Box::new(ImportObject::new())) as *mut wasmer_import_object_t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasmer_import_object_destroy(import_object: *mut wasmer_import_object_t) {
|
pub extern "C" fn wasmer_import_object_destroy(import_object: *mut wasmer_import_object_t) {
|
||||||
if !import_object.is_null() {
|
if !import_object.is_null() {
|
||||||
@ -30,6 +31,7 @@ pub extern "C" fn wasmer_import_object_destroy(import_object: *mut wasmer_import
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasmer_instantiate(
|
pub extern "C" fn wasmer_instantiate(
|
||||||
mut instance: *mut wasmer_instance_t,
|
mut instance: *mut wasmer_instance_t,
|
||||||
|
12
lib/runtime-c-api/tests/.gitignore
vendored
Normal file
12
lib/runtime-c-api/tests/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
test-instantiate
|
11
lib/runtime-c-api/tests/CMakeLists.txt
Normal file
11
lib/runtime-c-api/tests/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
cmake_minimum_required (VERSION 2.6)
|
||||||
|
project (WasmerCApiTests)
|
||||||
|
|
||||||
|
add_executable(test-instantiate test-instantiate.c)
|
||||||
|
|
||||||
|
target_link_libraries(test-instantiate
|
||||||
|
general "${CMAKE_SOURCE_DIR}/../../../target/debug/libwasmer_runtime_c_api.dylib")
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(test-instantiate test-instantiate)
|
||||||
|
|
4
lib/runtime-c-api/tests/runtime_c_api_tests.rs
Normal file
4
lib/runtime-c-api/tests/runtime_c_api_tests.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_c_api() {
|
||||||
|
// TODO run `cmake . && make && make test`
|
||||||
|
}
|
9
lib/runtime-c-api/tests/test-instantiate.c
Normal file
9
lib/runtime-c-api/tests/test-instantiate.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "../wasmer.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
wasmer_import_object_t *import_object = wasmer_import_object_new();
|
||||||
|
wasmer_import_object_destroy(import_object);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,24 +1,21 @@
|
|||||||
#include <cstdarg>
|
#include <stdarg.h>
|
||||||
#include <cstdint>
|
#include <stdbool.h>
|
||||||
#include <cstdlib>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
enum class wasmer_compile_result_t {
|
typedef enum {
|
||||||
WASMER_COMPILE_OK = 1,
|
WASMER_COMPILE_OK = 1,
|
||||||
WASMER_COMPILE_ERROR = 2,
|
WASMER_COMPILE_ERROR = 2,
|
||||||
};
|
} wasmer_compile_result_t;
|
||||||
|
|
||||||
struct wasmer_import_object_t;
|
typedef struct wasmer_import_object_t wasmer_import_object_t;
|
||||||
|
|
||||||
struct wasmer_instance_t;
|
typedef struct wasmer_instance_t wasmer_instance_t;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void wasmer_import_object_destroy(wasmer_import_object_t *import_object);
|
void wasmer_import_object_destroy(wasmer_import_object_t *import_object);
|
||||||
|
|
||||||
wasmer_import_object_t *wasmer_import_object_new();
|
wasmer_import_object_t *wasmer_import_object_new(void);
|
||||||
|
|
||||||
wasmer_compile_result_t wasmer_instantiate(wasmer_instance_t *instance,
|
wasmer_compile_result_t wasmer_instantiate(wasmer_instance_t *instance,
|
||||||
const char *bytes,
|
const char *bytes,
|
||||||
wasmer_import_object_t *import_object);
|
wasmer_import_object_t *import_object);
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
|
Reference in New Issue
Block a user