mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 16:41:21 +00:00
Add first c test to test the C api
This commit is contained in:
@ -1,4 +1,8 @@
|
||||
# Wasmer Runtime C API
|
||||
|
||||
## 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() {
|
||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
|
||||
use cbindgen::Language;
|
||||
cbindgen::Builder::new()
|
||||
.with_crate(crate_dir)
|
||||
.with_language(Language::C)
|
||||
.generate()
|
||||
.expect("Unable to generate bindings")
|
||||
.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
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_import_object_destroy(import_object: *mut wasmer_import_object_t) {
|
||||
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]
|
||||
pub extern "C" fn wasmer_instantiate(
|
||||
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 <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
enum class wasmer_compile_result_t {
|
||||
typedef enum {
|
||||
WASMER_COMPILE_OK = 1,
|
||||
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;
|
||||
|
||||
extern "C" {
|
||||
typedef struct wasmer_instance_t wasmer_instance_t;
|
||||
|
||||
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,
|
||||
const char *bytes,
|
||||
wasmer_import_object_t *import_object);
|
||||
|
||||
} // extern "C"
|
||||
|
Reference in New Issue
Block a user