From 8da2fdb6a596feb3996ecfdea3d44ed527651b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 13 Sep 2022 18:13:54 +0200 Subject: [PATCH 01/68] Fix Windows build with local dependency --- Cargo.lock | 8 ++------ lib/c-api/Cargo.toml | 2 +- lib/c-api/tests/wasm-c-api/include/wasm.h | 5 +++++ lib/c-api/tests/wasm.h | 4 ++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8703ce5106..2aa1d6ee332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1234,9 +1234,7 @@ dependencies = [ [[package]] name = "inline-c" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340dd3d6102fa919bd20987024a6d84954c36ec691ac1efea37742ee983c8dd5" +version = "0.1.0" dependencies = [ "assert_cmd", "cc", @@ -1251,9 +1249,7 @@ dependencies = [ [[package]] name = "inline-c-macro" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f5621ec7adacda881d7c2826c064f5c29c72fd44333f97df61b458a583ae15" +version = "0.1.6" dependencies = [ "proc-macro2", "quote", diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 072da4e3d9f..740c716ec46 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -41,7 +41,7 @@ paste = "1.0" [dev-dependencies] field-offset = "0.3.3" -inline-c = "0.1.5" +inline-c = { path = "../../../wasmer-inline-c-rs" } [features] default = [ diff --git a/lib/c-api/tests/wasm-c-api/include/wasm.h b/lib/c-api/tests/wasm-c-api/include/wasm.h index 78c9e727586..ac9ed75d81f 100644 --- a/lib/c-api/tests/wasm-c-api/include/wasm.h +++ b/lib/c-api/tests/wasm-c-api/include/wasm.h @@ -133,7 +133,12 @@ WASM_API_EXTERN own wasm_config_t* wasm_config_new(); WASM_DECLARE_OWN(engine) +#ifdef TEST_WASM +// During testing, we use a custom implementation of wasm_engine_new +wasm_engine_t* wasm_engine_new(); +#elif WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(); +#endif WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); diff --git a/lib/c-api/tests/wasm.h b/lib/c-api/tests/wasm.h index dcae9cf750b..1582dd0ec5c 100644 --- a/lib/c-api/tests/wasm.h +++ b/lib/c-api/tests/wasm.h @@ -9,6 +9,10 @@ #include #include +#if defined(_WIN32) || defined(_WIN64) +#define strtok_r strtok_s +#endif + wasm_engine_t *wasm_engine_new() { wasm_config_t *config = wasm_config_new(); From 59eb5f177e5e215241c625f8ca650a5703814c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 13 Sep 2022 18:58:29 +0200 Subject: [PATCH 02/68] Fixed compilation on Windows MSVC (first 20 tests) --- lib/c-api/tests/wasm-c-api/include/wasm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/c-api/tests/wasm-c-api/include/wasm.h b/lib/c-api/tests/wasm-c-api/include/wasm.h index ac9ed75d81f..087319398da 100644 --- a/lib/c-api/tests/wasm-c-api/include/wasm.h +++ b/lib/c-api/tests/wasm-c-api/include/wasm.h @@ -133,10 +133,10 @@ WASM_API_EXTERN own wasm_config_t* wasm_config_new(); WASM_DECLARE_OWN(engine) -#ifdef TEST_WASM // During testing, we use a custom implementation of wasm_engine_new +#if defined(TEST_WASM) || defined(TEST_WASMER) wasm_engine_t* wasm_engine_new(); -#elif +#else WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(); #endif WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); From 328a98edecc0b8c578c2c143ae7493d5fa986b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 13 Sep 2022 21:34:02 +0200 Subject: [PATCH 03/68] Fixup Makefile-based tests to be Rust-based instead --- Cargo.lock | 4 + Cargo.toml | 1 + lib/c-api/tests/Makefile | 18 +- .../tests/wasmer-c-api-test-runner/Cargo.toml | 6 + .../tests/wasmer-c-api-test-runner/src/lib.rs | 50 ++ lib/c-api/wasm.h | 728 +++++++++++++++++- 6 files changed, 792 insertions(+), 15 deletions(-) create mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml create mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 2aa1d6ee332..8ee3c3fb272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3032,6 +3032,10 @@ dependencies = [ "wasmer-wasi", ] +[[package]] +name = "wasmer-c-api-test-runner" +version = "0.1.0" + [[package]] name = "wasmer-cache" version = "3.0.0-beta" diff --git a/Cargo.toml b/Cargo.toml index 6ee42dd2c37..06ecf49d77f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ members = [ "lib/wasi-types", "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", + "lib/c-api/tests/wasmer-c-api-test-runner", "lib/types", "tests/wasi-wast", "tests/lib/wast", diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index ca17c83bd57..ae8bf99d666 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -17,6 +17,8 @@ endif $(info * CFLAGS: $(CFLAGS)) $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) +$(info * ROOT_DIR: $(ROOT_DIR)) +$(info * WASMER_DIR: $(WASMER_DIR)) CAPI_BASE_TESTS = \ wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \ @@ -29,20 +31,8 @@ CAPI_BASE_TESTS_NOT_WORKING = \ ALL = $(CAPI_BASE_TESTS) -.PHONY: all -all: $(ALL) - -.PHONY: test-capi-base -.SILENT: test-capi-base -test-capi-base: $(CAPI_BASE_TESTS) - set -o errexit; \ - $(foreach example,$?,echo Running \"$(example)\" example; cd $(shell dirname $(realpath $(example))) && ./$(shell basename $(example)); echo;) - -.PHONY: test-capi-base -.SILENT: test-capi-base -test-capi: test-capi-base - -test: test-capi +test: + WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml new file mode 100644 index 00000000000..bfcc6e6cb68 --- /dev/null +++ b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "wasmer-c-api-test-runner" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs new file mode 100644 index 00000000000..24b6bbf89a6 --- /dev/null +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -0,0 +1,50 @@ +#[derive(Debug)] +pub struct Config { + pub wasmer_dir: String, + pub root_dir: String, + pub cflags: String, + pub ldflags: String, + pub ldlibs: String, +} + +#[cfg(test)] +fn get_config() -> Config { + Config { + cflags: std::env::var("CFLAGS").unwrap(), + wasmer_dir: std::env::var("WASMER_DIR").unwrap(), + root_dir: std::env::var("ROOT_DIR").unwrap(), + ldflags: std::env::var("LDFLAGS").unwrap(), + ldlibs: std::env::var("LDLIBS").unwrap(), + } +} + +/* +CAPI_BASE_TESTS = \ + wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \ + wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \ + wasm-c-api/example/start wasm-c-api/example/trap wasm-c-api/example/multi + +CAPI_BASE_TESTS_NOT_WORKING = \ + wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/threads \ + wasm-c-api/example/table + +ALL = $(CAPI_BASE_TESTS) +*/ + +// Runs all the tests that are working in the /c directory +#[test] +fn test_ok() { + // let compiler = "cc" CFLAGS LDFLAGS LDLIBS + // for example in root_dir.join("").c { compiler.compile(...) } + + // target command on linux / mac: + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ + // -IC:/Users/felix/Development/wasmer/package/include + // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib + // wasm-c-api/example/callback.c + // -LC:/Users/felix/Development/wasmer/package/lib + // -lwasmer -o wasm-c-api/example/callback + + println!("config: {:#?}", get_config()); +} \ No newline at end of file diff --git a/lib/c-api/wasm.h b/lib/c-api/wasm.h index 14a5311999f..087319398da 120000 --- a/lib/c-api/wasm.h +++ b/lib/c-api/wasm.h @@ -1 +1,727 @@ -tests/wasm-c-api/include/wasm.h \ No newline at end of file +// WebAssembly C API + +#ifndef WASM_H +#define WASM_H + +#include +#include +#include +#include +#include + +#ifndef WASM_API_EXTERN +#ifdef _WIN32 +#define WASM_API_EXTERN __declspec(dllimport) +#else +#define WASM_API_EXTERN +#endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////// +// Auxiliaries + +// Machine types + +inline void assertions() { + static_assert(sizeof(float) == sizeof(uint32_t), "incompatible float type"); + static_assert(sizeof(double) == sizeof(uint64_t), "incompatible double type"); + static_assert(sizeof(intptr_t) == sizeof(uint32_t) || + sizeof(intptr_t) == sizeof(uint64_t), + "incompatible pointer type"); +} + +typedef char byte_t; +typedef float float32_t; +typedef double float64_t; + + +// Ownership + +#define own + +// The qualifier `own` is used to indicate ownership of data in this API. +// It is intended to be interpreted similar to a `const` qualifier: +// +// - `own wasm_xxx_t*` owns the pointed-to data +// - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx` +// - `own wasm_xxx_vec_t` owns the vector as well as its elements(!) +// - an `own` function parameter passes ownership from caller to callee +// - an `own` function result passes ownership from callee to caller +// - an exception are `own` pointer parameters named `out`, which are copy-back +// output parameters passing back ownership from callee to caller +// +// Own data is created by `wasm_xxx_new` functions and some others. +// It must be released with the corresponding `wasm_xxx_delete` function. +// +// Deleting a reference does not necessarily delete the underlying object, +// it merely indicates that this owner no longer uses it. +// +// For vectors, `const wasm_xxx_vec_t` is used informally to indicate that +// neither the vector nor its elements should be modified. +// TODO: introduce proper `wasm_xxx_const_vec_t`? + + +#define WASM_DECLARE_OWN(name) \ + typedef struct wasm_##name##_t wasm_##name##_t; \ + \ + WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*); + + +// Vectors + +#define WASM_DECLARE_VEC(name, ptr_or_none) \ + typedef struct wasm_##name##_vec_t { \ + size_t size; \ + wasm_##name##_t ptr_or_none* data; \ + } wasm_##name##_vec_t; \ + \ + WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \ + WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \ + own wasm_##name##_vec_t* out, size_t); \ + WASM_API_EXTERN void wasm_##name##_vec_new( \ + own wasm_##name##_vec_t* out, \ + size_t, own wasm_##name##_t ptr_or_none const[]); \ + WASM_API_EXTERN void wasm_##name##_vec_copy( \ + own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \ + WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*); + + +// Byte vectors + +typedef byte_t wasm_byte_t; +WASM_DECLARE_VEC(byte, ) + +typedef wasm_byte_vec_t wasm_name_t; + +#define wasm_name wasm_byte_vec +#define wasm_name_new wasm_byte_vec_new +#define wasm_name_new_empty wasm_byte_vec_new_empty +#define wasm_name_new_new_uninitialized wasm_byte_vec_new_uninitialized +#define wasm_name_copy wasm_byte_vec_copy +#define wasm_name_delete wasm_byte_vec_delete + +static inline void wasm_name_new_from_string( + own wasm_name_t* out, own const char* s +) { + wasm_name_new(out, strlen(s), s); +} + +static inline void wasm_name_new_from_string_nt( + own wasm_name_t* out, own const char* s +) { + wasm_name_new(out, strlen(s) + 1, s); +} + + +/////////////////////////////////////////////////////////////////////////////// +// Runtime Environment + +// Configuration + +WASM_DECLARE_OWN(config) + +WASM_API_EXTERN own wasm_config_t* wasm_config_new(); + +// Embedders may provide custom functions for manipulating configs. + + +// Engine + +WASM_DECLARE_OWN(engine) + +// During testing, we use a custom implementation of wasm_engine_new +#if defined(TEST_WASM) || defined(TEST_WASMER) +wasm_engine_t* wasm_engine_new(); +#else +WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(); +#endif +WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); + + +// Store + +WASM_DECLARE_OWN(store) + +WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*); + +/////////////////////////////////////////////////////////////////////////////// +// Type Representations + +// Type attributes + +typedef uint8_t wasm_mutability_t; +enum wasm_mutability_enum { + WASM_CONST, + WASM_VAR, +}; + +typedef struct wasm_limits_t { + uint32_t min; + uint32_t max; +} wasm_limits_t; + +static const uint32_t wasm_limits_max_default = 0xffffffff; + + +// Generic + +#define WASM_DECLARE_TYPE(name) \ + WASM_DECLARE_OWN(name) \ + WASM_DECLARE_VEC(name, *) \ + \ + WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(wasm_##name##_t*); + + +// Value Types + +WASM_DECLARE_TYPE(valtype) + +typedef uint8_t wasm_valkind_t; +enum wasm_valkind_enum { + WASM_I32, + WASM_I64, + WASM_F32, + WASM_F64, + WASM_ANYREF = 128, + WASM_FUNCREF, +}; + +WASM_API_EXTERN own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t); + +WASM_API_EXTERN wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*); + +static inline bool wasm_valkind_is_num(wasm_valkind_t k) { + return k < WASM_ANYREF; +} +static inline bool wasm_valkind_is_ref(wasm_valkind_t k) { + return k >= WASM_ANYREF; +} + +static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) { + return wasm_valkind_is_num(wasm_valtype_kind(t)); +} +static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) { + return wasm_valkind_is_ref(wasm_valtype_kind(t)); +} + + +// Function Types + +WASM_DECLARE_TYPE(functype) + +WASM_API_EXTERN own wasm_functype_t* wasm_functype_new( + own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results); + +WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t*); +WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t*); + + +// Global Types + +WASM_DECLARE_TYPE(globaltype) + +WASM_API_EXTERN own wasm_globaltype_t* wasm_globaltype_new( + own wasm_valtype_t*, wasm_mutability_t); + +WASM_API_EXTERN const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t*); +WASM_API_EXTERN wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t*); + + +// Table Types + +WASM_DECLARE_TYPE(tabletype) + +WASM_API_EXTERN own wasm_tabletype_t* wasm_tabletype_new( + own wasm_valtype_t*, const wasm_limits_t*); + +WASM_API_EXTERN const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t*); +WASM_API_EXTERN const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t*); + + +// Memory Types + +WASM_DECLARE_TYPE(memorytype) + +WASM_API_EXTERN own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*); + +WASM_API_EXTERN const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*); + + +// Extern Types + +WASM_DECLARE_TYPE(externtype) + +typedef uint8_t wasm_externkind_t; +enum wasm_externkind_enum { + WASM_EXTERN_FUNC, + WASM_EXTERN_GLOBAL, + WASM_EXTERN_TABLE, + WASM_EXTERN_MEMORY, +}; + +WASM_API_EXTERN wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*); + +WASM_API_EXTERN wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t*); +WASM_API_EXTERN wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t*); +WASM_API_EXTERN wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t*); +WASM_API_EXTERN wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t*); + +WASM_API_EXTERN wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*); +WASM_API_EXTERN wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t*); +WASM_API_EXTERN wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t*); +WASM_API_EXTERN wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t*); + +WASM_API_EXTERN const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t*); +WASM_API_EXTERN const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t*); +WASM_API_EXTERN const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t*); +WASM_API_EXTERN const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t*); + +WASM_API_EXTERN const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t*); +WASM_API_EXTERN const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t*); +WASM_API_EXTERN const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t*); +WASM_API_EXTERN const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t*); + + +// Import Types + +WASM_DECLARE_TYPE(importtype) + +WASM_API_EXTERN own wasm_importtype_t* wasm_importtype_new( + own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*); + +WASM_API_EXTERN const wasm_name_t* wasm_importtype_module(const wasm_importtype_t*); +WASM_API_EXTERN const wasm_name_t* wasm_importtype_name(const wasm_importtype_t*); +WASM_API_EXTERN const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t*); + + +// Export Types + +WASM_DECLARE_TYPE(exporttype) + +WASM_API_EXTERN own wasm_exporttype_t* wasm_exporttype_new( + own wasm_name_t*, own wasm_externtype_t*); + +WASM_API_EXTERN const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t*); +WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t*); + + +/////////////////////////////////////////////////////////////////////////////// +// Runtime Objects + +// Values + +struct wasm_ref_t; + +typedef struct wasm_val_t { + wasm_valkind_t kind; + union { + int32_t i32; + int64_t i64; + float32_t f32; + float64_t f64; + struct wasm_ref_t* ref; + } of; +} wasm_val_t; + +WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v); +WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*); + +WASM_DECLARE_VEC(val, ) + + +// References + +#define WASM_DECLARE_REF_BASE(name) \ + WASM_DECLARE_OWN(name) \ + \ + WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \ + WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \ + \ + WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \ + WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \ + WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \ + wasm_##name##_t*, void*, void (*)(void*)); + +#define WASM_DECLARE_REF(name) \ + WASM_DECLARE_REF_BASE(name) \ + \ + WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \ + WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \ + WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \ + WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*); + +#define WASM_DECLARE_SHARABLE_REF(name) \ + WASM_DECLARE_REF(name) \ + WASM_DECLARE_OWN(shared_##name) \ + \ + WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \ + WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*); + + +WASM_DECLARE_REF_BASE(ref) + + +// Frames + +WASM_DECLARE_OWN(frame) +WASM_DECLARE_VEC(frame, *) +WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*); + +WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*); +WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*); +WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*); +WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*); + + +// Traps + +typedef wasm_name_t wasm_message_t; // null terminated + +WASM_DECLARE_REF(trap) + +WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*); + +WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out); +WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*); +WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out); + + +// Foreign Objects + +WASM_DECLARE_REF(foreign) + +WASM_API_EXTERN own wasm_foreign_t* wasm_foreign_new(wasm_store_t*); + + +// Modules + +WASM_DECLARE_SHARABLE_REF(module) + +WASM_API_EXTERN own wasm_module_t* wasm_module_new( + wasm_store_t*, const wasm_byte_vec_t* binary); + +WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary); + +WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out); +WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out); + +WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out); +WASM_API_EXTERN own wasm_module_t* wasm_module_deserialize(wasm_store_t*, const wasm_byte_vec_t*); + + +// Function Instances + +WASM_DECLARE_REF(func) + +typedef own wasm_trap_t* (*wasm_func_callback_t)( + const wasm_val_vec_t* args, own wasm_val_vec_t* results); +typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)( + void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results); + +WASM_API_EXTERN own wasm_func_t* wasm_func_new( + wasm_store_t*, const wasm_functype_t*, wasm_func_callback_t); +WASM_API_EXTERN own wasm_func_t* wasm_func_new_with_env( + wasm_store_t*, const wasm_functype_t* type, wasm_func_callback_with_env_t, + void* env, void (*finalizer)(void*)); + +WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*); +WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*); +WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*); + +WASM_API_EXTERN own wasm_trap_t* wasm_func_call( + const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results); + + +// Global Instances + +WASM_DECLARE_REF(global) + +WASM_API_EXTERN own wasm_global_t* wasm_global_new( + wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*); + +WASM_API_EXTERN own wasm_globaltype_t* wasm_global_type(const wasm_global_t*); + +WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out); +WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*); + + +// Table Instances + +WASM_DECLARE_REF(table) + +typedef uint32_t wasm_table_size_t; + +WASM_API_EXTERN own wasm_table_t* wasm_table_new( + wasm_store_t*, const wasm_tabletype_t*, wasm_ref_t* init); + +WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*); + +WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index); +WASM_API_EXTERN bool wasm_table_set(wasm_table_t*, wasm_table_size_t index, wasm_ref_t*); + +WASM_API_EXTERN wasm_table_size_t wasm_table_size(const wasm_table_t*); +WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init); + + +// Memory Instances + +WASM_DECLARE_REF(memory) + +typedef uint32_t wasm_memory_pages_t; + +static const size_t MEMORY_PAGE_SIZE = 0x10000; + +WASM_API_EXTERN own wasm_memory_t* wasm_memory_new(wasm_store_t*, const wasm_memorytype_t*); + +WASM_API_EXTERN own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t*); + +WASM_API_EXTERN byte_t* wasm_memory_data(wasm_memory_t*); +WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*); + +WASM_API_EXTERN wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*); +WASM_API_EXTERN bool wasm_memory_grow(wasm_memory_t*, wasm_memory_pages_t delta); + + +// Externals + +WASM_DECLARE_REF(extern) +WASM_DECLARE_VEC(extern, *) + +WASM_API_EXTERN wasm_externkind_t wasm_extern_kind(const wasm_extern_t*); +WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); + +WASM_API_EXTERN wasm_extern_t* wasm_func_as_extern(wasm_func_t*); +WASM_API_EXTERN wasm_extern_t* wasm_global_as_extern(wasm_global_t*); +WASM_API_EXTERN wasm_extern_t* wasm_table_as_extern(wasm_table_t*); +WASM_API_EXTERN wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*); + +WASM_API_EXTERN wasm_func_t* wasm_extern_as_func(wasm_extern_t*); +WASM_API_EXTERN wasm_global_t* wasm_extern_as_global(wasm_extern_t*); +WASM_API_EXTERN wasm_table_t* wasm_extern_as_table(wasm_extern_t*); +WASM_API_EXTERN wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*); + +WASM_API_EXTERN const wasm_extern_t* wasm_func_as_extern_const(const wasm_func_t*); +WASM_API_EXTERN const wasm_extern_t* wasm_global_as_extern_const(const wasm_global_t*); +WASM_API_EXTERN const wasm_extern_t* wasm_table_as_extern_const(const wasm_table_t*); +WASM_API_EXTERN const wasm_extern_t* wasm_memory_as_extern_const(const wasm_memory_t*); + +WASM_API_EXTERN const wasm_func_t* wasm_extern_as_func_const(const wasm_extern_t*); +WASM_API_EXTERN const wasm_global_t* wasm_extern_as_global_const(const wasm_extern_t*); +WASM_API_EXTERN const wasm_table_t* wasm_extern_as_table_const(const wasm_extern_t*); +WASM_API_EXTERN const wasm_memory_t* wasm_extern_as_memory_const(const wasm_extern_t*); + + +// Module Instances + +WASM_DECLARE_REF(instance) + +WASM_API_EXTERN own wasm_instance_t* wasm_instance_new( + wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports, + own wasm_trap_t** +); + +WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out); + + +/////////////////////////////////////////////////////////////////////////////// +// Convenience + +// Vectors + +#define WASM_EMPTY_VEC {0, NULL} +#define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array} + + +// Value Type construction short-hands + +static inline own wasm_valtype_t* wasm_valtype_new_i32() { + return wasm_valtype_new(WASM_I32); +} +static inline own wasm_valtype_t* wasm_valtype_new_i64() { + return wasm_valtype_new(WASM_I64); +} +static inline own wasm_valtype_t* wasm_valtype_new_f32() { + return wasm_valtype_new(WASM_F32); +} +static inline own wasm_valtype_t* wasm_valtype_new_f64() { + return wasm_valtype_new(WASM_F64); +} + +static inline own wasm_valtype_t* wasm_valtype_new_anyref() { + return wasm_valtype_new(WASM_ANYREF); +} +static inline own wasm_valtype_t* wasm_valtype_new_funcref() { + return wasm_valtype_new(WASM_FUNCREF); +} + + +// Function Types construction short-hands + +static inline own wasm_functype_t* wasm_functype_new_0_0() { + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new_empty(¶ms); + wasm_valtype_vec_new_empty(&results); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_1_0( + own wasm_valtype_t* p +) { + wasm_valtype_t* ps[1] = {p}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 1, ps); + wasm_valtype_vec_new_empty(&results); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_2_0( + own wasm_valtype_t* p1, own wasm_valtype_t* p2 +) { + wasm_valtype_t* ps[2] = {p1, p2}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 2, ps); + wasm_valtype_vec_new_empty(&results); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_3_0( + own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3 +) { + wasm_valtype_t* ps[3] = {p1, p2, p3}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 3, ps); + wasm_valtype_vec_new_empty(&results); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_0_1( + own wasm_valtype_t* r +) { + wasm_valtype_t* rs[1] = {r}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new_empty(¶ms); + wasm_valtype_vec_new(&results, 1, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_1_1( + own wasm_valtype_t* p, own wasm_valtype_t* r +) { + wasm_valtype_t* ps[1] = {p}; + wasm_valtype_t* rs[1] = {r}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 1, ps); + wasm_valtype_vec_new(&results, 1, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_2_1( + own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r +) { + wasm_valtype_t* ps[2] = {p1, p2}; + wasm_valtype_t* rs[1] = {r}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 2, ps); + wasm_valtype_vec_new(&results, 1, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_3_1( + own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, + own wasm_valtype_t* r +) { + wasm_valtype_t* ps[3] = {p1, p2, p3}; + wasm_valtype_t* rs[1] = {r}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 3, ps); + wasm_valtype_vec_new(&results, 1, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_0_2( + own wasm_valtype_t* r1, own wasm_valtype_t* r2 +) { + wasm_valtype_t* rs[2] = {r1, r2}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new_empty(¶ms); + wasm_valtype_vec_new(&results, 2, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_1_2( + own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2 +) { + wasm_valtype_t* ps[1] = {p}; + wasm_valtype_t* rs[2] = {r1, r2}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 1, ps); + wasm_valtype_vec_new(&results, 2, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_2_2( + own wasm_valtype_t* p1, own wasm_valtype_t* p2, + own wasm_valtype_t* r1, own wasm_valtype_t* r2 +) { + wasm_valtype_t* ps[2] = {p1, p2}; + wasm_valtype_t* rs[2] = {r1, r2}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 2, ps); + wasm_valtype_vec_new(&results, 2, rs); + return wasm_functype_new(¶ms, &results); +} + +static inline own wasm_functype_t* wasm_functype_new_3_2( + own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, + own wasm_valtype_t* r1, own wasm_valtype_t* r2 +) { + wasm_valtype_t* ps[3] = {p1, p2, p3}; + wasm_valtype_t* rs[2] = {r1, r2}; + wasm_valtype_vec_t params, results; + wasm_valtype_vec_new(¶ms, 3, ps); + wasm_valtype_vec_new(&results, 2, rs); + return wasm_functype_new(¶ms, &results); +} + + +// Value construction short-hands + +static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) { +#if UINTPTR_MAX == UINT32_MAX + out->kind = WASM_I32; + out->of.i32 = (intptr_t)p; +#elif UINTPTR_MAX == UINT64_MAX + out->kind = WASM_I64; + out->of.i64 = (intptr_t)p; +#endif +} + +static inline void* wasm_val_ptr(const wasm_val_t* val) { +#if UINTPTR_MAX == UINT32_MAX + return (void*)(intptr_t)val->of.i32; +#elif UINTPTR_MAX == UINT64_MAX + return (void*)(intptr_t)val->of.i64; +#endif +} + +#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}} +#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}} +#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}} +#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}} +#define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .of = {.ref = r}} +#define WASM_INIT_VAL {.kind = WASM_ANYREF, .of = {.ref = NULL}} + + +/////////////////////////////////////////////////////////////////////////////// + +#undef own + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // #ifdef WASM_H From 05af38c9a5f2c2dcb66039827b818ba930149e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 14 Sep 2022 13:11:48 +0200 Subject: [PATCH 04/68] Port first Makefile to Rust + add MSVC flags --- Cargo.lock | 4 + Makefile | 4 + lib/c-api/tests/Makefile | 31 ++-- .../tests/wasmer-c-api-test-runner/Cargo.toml | 2 + .../wasmer-c-api-test-runner/callback.obj | Bin 0 -> 13002 bytes .../wasmer-c-api-test-runner/command.bat | 1 + .../tests/wasmer-c-api-test-runner/src/lib.rs | 175 ++++++++++++++---- 7 files changed, 171 insertions(+), 46 deletions(-) create mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/callback.obj create mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/command.bat diff --git a/Cargo.lock b/Cargo.lock index 8ee3c3fb272..cc3119b45da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3035,6 +3035,10 @@ dependencies = [ [[package]] name = "wasmer-c-api-test-runner" version = "0.1.0" +dependencies = [ + "cc", + "target-lexicon 0.11.2", +] [[package]] name = "wasmer-cache" diff --git a/Makefile b/Makefile index 7ad96636e9b..d229d7735fc 100644 --- a/Makefile +++ b/Makefile @@ -608,6 +608,10 @@ package-capi: if [ -f $(TARGET_DIR)/wasmer.dll ]; then \ cp $(TARGET_DIR)/wasmer.dll package/lib/wasmer.dll ;\ fi + + if [ -f $(TARGET_DIR)/wasmer.dll.lib ]; then \ + cp $(TARGET_DIR)/wasmer.dll.lib package/lib/wasmer.dll.lib ;\ + fi if [ -f $(TARGET_DIR)/wasmer.lib ]; then \ cp $(TARGET_DIR)/wasmer.lib package/lib/wasmer.lib ;\ fi diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index ae8bf99d666..91ba07f6e39 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -4,35 +4,38 @@ $(info Using provided WASMER_DIR=$(WASMER_DIR)) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +MSVC_CFLAGS:="" +MSVC_LDFLAGS:="" +MSVC_LDLIBS:="" + ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) CFLAGS = -g -I$(ROOT_DIR)/ -I$(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L$(WASMER_DIR)/lib -lwasmer + + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(WASMER_DIR)/include + MSVC_LDFLAGS:= "" + MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else CFLAGS = -g -I$(ROOT_DIR)/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) + + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + MSVC_LDFLAGS:= "" + MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config --libs) wasmer.dll.lib endif + +$(info * ROOT_DIR: $(ROOT_DIR)) +$(info * WASMER_DIR: $(WASMER_DIR)) +$(info * "") $(info * CFLAGS: $(CFLAGS)) $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) -$(info * ROOT_DIR: $(ROOT_DIR)) -$(info * WASMER_DIR: $(WASMER_DIR)) - -CAPI_BASE_TESTS = \ - wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \ - wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \ - wasm-c-api/example/start wasm-c-api/example/trap wasm-c-api/example/multi - -CAPI_BASE_TESTS_NOT_WORKING = \ - wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/threads \ - wasm-c-api/example/table - -ALL = $(CAPI_BASE_TESTS) test: - WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture + cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml index bfcc6e6cb68..6d63f720412 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml +++ b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml @@ -4,3 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] +cc = "1.0" +target-lexicon = "0.11" \ No newline at end of file diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/callback.obj b/lib/c-api/tests/wasmer-c-api-test-runner/callback.obj new file mode 100644 index 0000000000000000000000000000000000000000..2ca6322be44a244c54df34d6751f39bf2a7ae541 GIT binary patch literal 13002 zcma)C3wTpiw%#!jNHJdNH>-_uw z*V^xW9t3_qjcguM{^QPJgd8F)6$au#f1*9eFUbTjT>Ydg{x>(D6b6FL$pw}MsboDE zcV+Mdl3!UE5BL&3iA6|0nAhbh*Jueu5DF8)j)bK(B9-KTQ3||ioNItXd6!&-X9N62;C#z@ri<`iHxe?mKOs8@0s)c(e!az=2l(nigdBq(ratiNjfWjH z=5j)ozz-9+@0B+l@W+93;3s%4;GG6e#T8&cx|qKwq3kx`oaH=hc5n5=A)7at5I_7d z$^G1+9XBj)9)Y0yS*;O+eM{B`)m#xm~wl|D6|G^;HbZ)<7^hC>}qwqScO9F4UGBZ;QPzP8q2yeS-NZt{=!#X?Pq zU|XV%!{aG59-;B^WF!Jazb_na_W2hTMw{;-Q_0PPNHZb($Q5K1N#8}}zwVGf9&L-Z zB+O%H-e9heB|@#CrJ=|Ib5*o8777RBsGN4DT{T?RiB5xbf!Ibv7X zk}q~8ELY7DJHIJ%rVcq%=fu=0G4=IPeDIcPvIt@-Y!Ss& z!r~D-w-$M~jDiB3^(HbI@-ft+LD021H4HtcF9VoR*Qrm{S7OSMvke_Pa=PZ`ly+l; zBJgYWZo!#=cSR%X2@{}Or!vEhS6BFX3w!UT4z~jTjz-Bu;rw9-#7Wt1L{yx z6Lz>#=eW(PC8kc&nu%%FNQO%EbJoq+mEy|oy!%H$HE8Wrn@9yL7(@ z{pLR?l|V~f7D2jlSw!eod+H-G^(n)g(>}^uxgAafka3o(qr`M0cJ>}t;!2%_DkKN+ z7JdCV%2e)E!qOflDeVzcye_V^eIfP}jPwDq3+%M}Z`^O%#?Z8TpHzog`_$!h0zo~* z)IL$_xze8P_W9$WTU;sb2NW>1Y?jH2+sPO#?LH~HJ&7cK)fupui7V}%4{lv-lF}G* z=k0Z+j&g2lm*hg3M$Xi320Bw8LyK0k3p=!VyZt#lWC45vn*E%Zwy$=k{sWzN+1E=R z&tYc{RZow%ag@InAy>QB2gYIX$OC3C{kv;Qz~V{vBf7%Y6MH<5KmINUP-}(EOM|t6V!x6x`IIXXQ-{RVdG-7kQ&l;* z$jo{9HjDWvs5J+Ym}RHa+IW)c0aKmcI#xUD_8?2Who%--NpXIPbT^ z>7<L8}H%j3M1irpt;DX{R$L_IJb4F3h}esU@N*tTOBoI?f&a>?Mveq?YN*faBE$e4i{ zPa^y^f+OevYUM!gp_XB|i431PG&W@ZV5~oBz>FuHs!YW!RL!QC!DJw&6^w?Pfs`u2 zUUmn-mKkP?n7Q!on^%@m_C&rs4!shU|TXQ1ujVDl7@xJ1T6_f7e{D?Y|%&%TG@Vf!w<8?!`n938);a^B2i$0vu5zPx)!_<}HH=M;OB z#r5f54)5s^^LMoG{`JDIJTta_^1&-FpGdVY6`ZSc4v(%aI5~apBUAj-X6!!qU1#;y z73Fo~*8ibs@1vpj&dhpz_pT9x9{+CSrauMuH$8mh$D02-{_E!1yAS2xIAc@$yxHr1 zm~(343o-Nd*Y3@`>)#L5?LL3u3Y)7)3N2tJjauxFW=-pHnzY#Yvx+_h6{VX8Z~U&wDc>> z=iXkt=8n!Go!=h0;I{_09vr-WT#~#qZDIJ^149jK7c9BkfA5+f9y@kt(K}0f4s`GO zcgWx=`QoWzrt^o7UT;48Vdcx8Evp(lC-0g$($W=ho)?A!>AOq@d|)>cp#^4nVNua) zgJC&G+N0sZ)&RK#L<~`X>%pVdXuyM0o7CTVP-!%**An1L{jL%B6Qd!YbMh8kbx@(> z#*T?{s5KID+-4Y}{)v z#-q#+T+n+|{A(g+>YETerlf??2$@fFmNBGNhb++{D|N`jI^<~`@@I}*O6wEDt*wPY z{p1>M*Qx%gL+}YoO03SKbjTzfQm;b-I%K5|c}|DCr9<}XkYhUJe|5-}tm?EO%p9*n zY&vAF4oT_|e14J=GoRNXALx+Jb;wyAG7u*;PpohpM=m2~I@{q%kR!P=GK(YqWn>XY z1^~kREaga!jC66N4@FviA-qSTsV_w=t~z{pp$T`1J_Hba%%KTa1VxJR*%K44CW^=^ zT<=;0*F8l_@NohY?i+nbq3X-#KtPO!!B_~X=jvfgE~U4?c(s<-nR1BwyJ;Sj8Vz(s zgEjZ`Lr*HIm$-^@G_i1xWhyYp@ChRy>LaC8|it0zMq8v>u>^&vcm%}G*?k~q0#*Yxn z(Zm{}iS^shN|q_ANnAxanpi_Mu|ApdQQiPKRwGwYjwaTXnppq&^4=mvwTP=IM-vO5 zyp{1vF1UYAjvVVguA&@GtYNYWJ8a;Ie{5A$PjD6GXkrbQRbY^Uk8dsLBgcA)t0+ek zYlN)ASXb`;Y@?#u&Q+A7iG^pl(SSLo5A)Bh>nq3lD_2pDCf3!!Rpxy6hmC$k^$k~1 z4)uBt5L}U%F45d?;6u34z$X)VyWgI$a>h--r4I=?S{1%>FdBFN7&%&% znX05%)v)!KEvFRKY7QeutGbS= zq@G%P;N52x)$?419IeViRk#u{ErYvPMb*Pq$kD0_05KY*mOOa$#Cb*aJy#(|s~SU9 zIAbvtHoh=UQ4OTGR_ry9R&_majRsy!);%5mLQz>cj2x|MELGudhH2-u^KVg9KCVKJ zR&@g)MuXHFubtTVs-o)RD&%NY&)gVcv&@sDd1)lsfOj#f3Es&Eg)wEK>CeTwQ@Jjx&;N2@9X#Av`( zk7?bt5B*6|xw#5CS`|J=7!9~{V)`U^O-fPyoU4$dRTTlEwCjE6dDT38gR79ERTWbe zu2xLuALc_Nq&_^tRmjn*N&r!680>fxwnIr};R^^kT2(1kNqgPFsP#=n)xcHA(W=U* zO6tQk{r`GcQKh*GIa(FoWhnFTRMF`_D5`B-g&eJFq9#`I+0m+%a*C^vqgCO3kaFKL z**5h~CDx62y95b2TGeDglvVln##P;lYA#nHN2{7bRd~06>BtuUi;Aj)tB|8rO$Eeg z;KNCt_>FmkqFTpQ$hm}gTf&KCTQC3@G=U%0H~eXU84dUqUz^?oANZch8-{P-i8gPm zufrP%w)o)13US-r^)qkvdaMq+x4}8jPQ2c56kf=9+Y*6L)XN@Lyixdk9*wj?VW>6c z^?H5&c)}ZsHhb}v4M$t>Wmr(Uh{l2u$%dCw0m*I)1{X9=4GT_WKf1) z)g|mDroXp7l8Z8GE#v$RCR-)a@L+R7r6ml+XmnH&E%Fxkf)-0Cc0HZHgyvpsI=(|D z{B^McSdx*&p-8}@p5_+%zfQFfr}0I>8PXLmr1M%=P0qbY;YFp`mWxVhp<1dmSglc^ z>iVl%&sv(%Nm8HaJB!ivIQLE;m3alIUE#(5_5=G?11w+Pf}l`QTv74=?QeoGMVLZ> zQzdwdN*r#{TIH#(7Ah=N)k#6Z%c`rKHPxQFT8hJ`1G%K6uEyi2cZ;;3MS&~rPJ6Y- z>7e)m8836YTrQ{R^a%LXL53$)J1RZZR<{73At167qsJhtkr|aXL9F)F+Z^@vLKS;= zUQvz{tfGwmn^{d^`$5Z1Fq;*wMhSOVSK+Bv~x7%&CIeA6t_mYZo{&}UMoNaed{YrK1tA#p` zU97gcoPzw_MdtFJRf4#LYKOJPRaGzb1`i^Cm64?xVH`r8+iry+fqv(oYbwf>rmzuI z;?xLshr8D0bbFvvRo`)B_qv*S1edGEQR{SM)Qs(R{4DV@D&2y+#$8`8LSxvR;JqM!0FtC_nZ4~2Y_96sS_fT6IGZk}%oN%Lr_E}&IviEX zPpm4zR^=2uHrPs}uU8f2`1wlbYNETwWrN7DHsPZd6vKM`Kd8o?*#H0l literal 0 HcmV?d00001 diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/command.bat b/lib/c-api/tests/wasmer-c-api-test-runner/command.bat new file mode 100644 index 00000000000..bc40c1ebad5 --- /dev/null +++ b/lib/c-api/tests/wasmer-c-api-test-runner/command.bat @@ -0,0 +1 @@ +"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" -nologo -MD -O1 -Brepro -W4 "C:\\Users\\felix\\Development\\wasmer\\lib\\c-api\\tests\\wasmer-c-api-test-runner/../wasm-c-api/example/callback.c" /I "C:/Users/felix/Development/wasmer/package/include" /link /LIBPATH:"C:/Users/felix/Development/wasmer/package/lib" "C:/Users/felix/Development/wasmer/package/lib/wasmer.dll.lib" /OUT:"C:\\Users\\felix\\Development\\wasmer\\lib\\c-api\\tests\\wasmer-c-api-test-runner/../wasm-c-api/example/callback.exe" \ No newline at end of file diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 24b6bbf89a6..7071e6417ce 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -2,49 +2,160 @@ pub struct Config { pub wasmer_dir: String, pub root_dir: String, + // linux + mac pub cflags: String, pub ldflags: String, pub ldlibs: String, + // windows msvc + pub msvc_cflags: String, + pub msvc_ldflags: String, + pub msvc_ldlibs: String, + } -#[cfg(test)] -fn get_config() -> Config { - Config { - cflags: std::env::var("CFLAGS").unwrap(), - wasmer_dir: std::env::var("WASMER_DIR").unwrap(), - root_dir: std::env::var("ROOT_DIR").unwrap(), - ldflags: std::env::var("LDFLAGS").unwrap(), - ldlibs: std::env::var("LDLIBS").unwrap(), +impl Config { + pub fn get() -> Config { + Config { + wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), + root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), + + cflags: std::env::var("CFLAGS").unwrap_or_default(), + ldflags: std::env::var("LDFLAGS").unwrap_or_default(), + ldlibs: std::env::var("LDLIBS").unwrap_or_default(), + + msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), + msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), + msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), + } } } -/* -CAPI_BASE_TESTS = \ - wasm-c-api/example/callback wasm-c-api/example/global wasm-c-api/example/hello \ - wasm-c-api/example/memory wasm-c-api/example/reflect wasm-c-api/example/serialize \ - wasm-c-api/example/start wasm-c-api/example/trap wasm-c-api/example/multi +const CAPI_BASE_TESTS: &[&str] = &[ + "wasm-c-api/example/callback", + "wasm-c-api/example/memory", + "wasm-c-api/example/start", -CAPI_BASE_TESTS_NOT_WORKING = \ - wasm-c-api/example/finalize wasm-c-api/example/hostref wasm-c-api/example/threads \ - wasm-c-api/example/table + "wasm-c-api/example/global", + "wasm-c-api/example/reflect", + "wasm-c-api/example/trap", -ALL = $(CAPI_BASE_TESTS) -*/ + "wasm-c-api/example/hello", + "wasm-c-api/example/serialize", + "wasm-c-api/example/multi", +]; + + +const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ + "wasm-c-api/example/finalize", + "wasm-c-api/example/hostref", + "wasm-c-api/example/threads", + "wasm-c-api/example/table", +]; // Runs all the tests that are working in the /c directory #[test] fn test_ok() { - // let compiler = "cc" CFLAGS LDFLAGS LDLIBS - // for example in root_dir.join("").c { compiler.compile(...) } - - // target command on linux / mac: - - // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ - // -IC:/Users/felix/Development/wasmer/package/include - // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib - // wasm-c-api/example/callback.c - // -LC:/Users/felix/Development/wasmer/package/lib - // -lwasmer -o wasm-c-api/example/callback - - println!("config: {:#?}", get_config()); -} \ No newline at end of file + + let config = Config::get(); + println!("config: {:#?}", config); + + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + + let host = target_lexicon::HOST.to_string(); + let target = &host; + + #[cfg(target_os = "windows")] + for test in CAPI_BASE_TESTS.iter() { + + let mut build = cc::Build::new(); + let mut build = build + .cargo_metadata(false) + .warnings(true) + .static_crt(true) + .extra_warnings(true) + .warnings_into_errors(false) + .debug(config.ldflags.contains("-g")) + .host(&host) + .target(target) + .opt_level(1); + + let compiler = build.try_get_compiler().unwrap(); + let mut command = compiler.to_command(); + + command.arg(&format!("{manifest_dir}/../{test}.c")); + if !config.msvc_cflags.is_empty() { + command.arg(config.msvc_cflags.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg("/I"); + command.arg(&format!("{}/include", config.wasmer_dir)); + } + command.arg("/link"); + if !config.msvc_ldlibs.is_empty() { + command.arg(config.msvc_ldlibs.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + } + command.arg(&format!("/OUT:{manifest_dir}/../{test}.exe")); + + println!("command: {command:#?}"); + // compile + let output = command.output().expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + let output = command.output().expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ + // -IC:/Users/felix/Development/wasmer/package/include + // + // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib + // + // wasm-c-api/example/callback.c + // + // -LC:/Users/felix/Development/wasmer/package/lib -lwasmer + // + // -o wasm-c-api/example/callback + + } + + #[cfg(not(target_os = "windows"))] + for test in CAPI_BASE_TESTS.iter() { + + let mut command = std::process::Command::new("cc"); + + command.arg(config.cflags.clone()); + command.arg(config.ldflags.clone()); + command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(config.ldlibs.clone()); + command.arg("-o"); + command.arg(&format!("{manifest_dir}/../{test}")); + + // compile + let output = command.output().expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + let output = command.output().expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + } + } \ No newline at end of file From fd390f616099c61498939cad640f7853743fd1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 14 Sep 2022 15:55:41 +0200 Subject: [PATCH 05/68] Fix first Makefile completely on Windows --- .../wasmer-c-api-test-runner/callback.obj | Bin 13002 -> 0 bytes .../tests/wasmer-c-api-test-runner/src/lib.rs | 49 ++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) delete mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/callback.obj diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/callback.obj b/lib/c-api/tests/wasmer-c-api-test-runner/callback.obj deleted file mode 100644 index 2ca6322be44a244c54df34d6751f39bf2a7ae541..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13002 zcma)C3wTpiw%#!jNHJdNH>-_uw z*V^xW9t3_qjcguM{^QPJgd8F)6$au#f1*9eFUbTjT>Ydg{x>(D6b6FL$pw}MsboDE zcV+Mdl3!UE5BL&3iA6|0nAhbh*Jueu5DF8)j)bK(B9-KTQ3||ioNItXd6!&-X9N62;C#z@ri<`iHxe?mKOs8@0s)c(e!az=2l(nigdBq(ratiNjfWjH z=5j)ozz-9+@0B+l@W+93;3s%4;GG6e#T8&cx|qKwq3kx`oaH=hc5n5=A)7at5I_7d z$^G1+9XBj)9)Y0yS*;O+eM{B`)m#xm~wl|D6|G^;HbZ)<7^hC>}qwqScO9F4UGBZ;QPzP8q2yeS-NZt{=!#X?Pq zU|XV%!{aG59-;B^WF!Jazb_na_W2hTMw{;-Q_0PPNHZb($Q5K1N#8}}zwVGf9&L-Z zB+O%H-e9heB|@#CrJ=|Ib5*o8777RBsGN4DT{T?RiB5xbf!Ibv7X zk}q~8ELY7DJHIJ%rVcq%=fu=0G4=IPeDIcPvIt@-Y!Ss& z!r~D-w-$M~jDiB3^(HbI@-ft+LD021H4HtcF9VoR*Qrm{S7OSMvke_Pa=PZ`ly+l; zBJgYWZo!#=cSR%X2@{}Or!vEhS6BFX3w!UT4z~jTjz-Bu;rw9-#7Wt1L{yx z6Lz>#=eW(PC8kc&nu%%FNQO%EbJoq+mEy|oy!%H$HE8Wrn@9yL7(@ z{pLR?l|V~f7D2jlSw!eod+H-G^(n)g(>}^uxgAafka3o(qr`M0cJ>}t;!2%_DkKN+ z7JdCV%2e)E!qOflDeVzcye_V^eIfP}jPwDq3+%M}Z`^O%#?Z8TpHzog`_$!h0zo~* z)IL$_xze8P_W9$WTU;sb2NW>1Y?jH2+sPO#?LH~HJ&7cK)fupui7V}%4{lv-lF}G* z=k0Z+j&g2lm*hg3M$Xi320Bw8LyK0k3p=!VyZt#lWC45vn*E%Zwy$=k{sWzN+1E=R z&tYc{RZow%ag@InAy>QB2gYIX$OC3C{kv;Qz~V{vBf7%Y6MH<5KmINUP-}(EOM|t6V!x6x`IIXXQ-{RVdG-7kQ&l;* z$jo{9HjDWvs5J+Ym}RHa+IW)c0aKmcI#xUD_8?2Who%--NpXIPbT^ z>7<L8}H%j3M1irpt;DX{R$L_IJb4F3h}esU@N*tTOBoI?f&a>?Mveq?YN*faBE$e4i{ zPa^y^f+OevYUM!gp_XB|i431PG&W@ZV5~oBz>FuHs!YW!RL!QC!DJw&6^w?Pfs`u2 zUUmn-mKkP?n7Q!on^%@m_C&rs4!shU|TXQ1ujVDl7@xJ1T6_f7e{D?Y|%&%TG@Vf!w<8?!`n938);a^B2i$0vu5zPx)!_<}HH=M;OB z#r5f54)5s^^LMoG{`JDIJTta_^1&-FpGdVY6`ZSc4v(%aI5~apBUAj-X6!!qU1#;y z73Fo~*8ibs@1vpj&dhpz_pT9x9{+CSrauMuH$8mh$D02-{_E!1yAS2xIAc@$yxHr1 zm~(343o-Nd*Y3@`>)#L5?LL3u3Y)7)3N2tJjauxFW=-pHnzY#Yvx+_h6{VX8Z~U&wDc>> z=iXkt=8n!Go!=h0;I{_09vr-WT#~#qZDIJ^149jK7c9BkfA5+f9y@kt(K}0f4s`GO zcgWx=`QoWzrt^o7UT;48Vdcx8Evp(lC-0g$($W=ho)?A!>AOq@d|)>cp#^4nVNua) zgJC&G+N0sZ)&RK#L<~`X>%pVdXuyM0o7CTVP-!%**An1L{jL%B6Qd!YbMh8kbx@(> z#*T?{s5KID+-4Y}{)v z#-q#+T+n+|{A(g+>YETerlf??2$@fFmNBGNhb++{D|N`jI^<~`@@I}*O6wEDt*wPY z{p1>M*Qx%gL+}YoO03SKbjTzfQm;b-I%K5|c}|DCr9<}XkYhUJe|5-}tm?EO%p9*n zY&vAF4oT_|e14J=GoRNXALx+Jb;wyAG7u*;PpohpM=m2~I@{q%kR!P=GK(YqWn>XY z1^~kREaga!jC66N4@FviA-qSTsV_w=t~z{pp$T`1J_Hba%%KTa1VxJR*%K44CW^=^ zT<=;0*F8l_@NohY?i+nbq3X-#KtPO!!B_~X=jvfgE~U4?c(s<-nR1BwyJ;Sj8Vz(s zgEjZ`Lr*HIm$-^@G_i1xWhyYp@ChRy>LaC8|it0zMq8v>u>^&vcm%}G*?k~q0#*Yxn z(Zm{}iS^shN|q_ANnAxanpi_Mu|ApdQQiPKRwGwYjwaTXnppq&^4=mvwTP=IM-vO5 zyp{1vF1UYAjvVVguA&@GtYNYWJ8a;Ie{5A$PjD6GXkrbQRbY^Uk8dsLBgcA)t0+ek zYlN)ASXb`;Y@?#u&Q+A7iG^pl(SSLo5A)Bh>nq3lD_2pDCf3!!Rpxy6hmC$k^$k~1 z4)uBt5L}U%F45d?;6u34z$X)VyWgI$a>h--r4I=?S{1%>FdBFN7&%&% znX05%)v)!KEvFRKY7QeutGbS= zq@G%P;N52x)$?419IeViRk#u{ErYvPMb*Pq$kD0_05KY*mOOa$#Cb*aJy#(|s~SU9 zIAbvtHoh=UQ4OTGR_ry9R&_majRsy!);%5mLQz>cj2x|MELGudhH2-u^KVg9KCVKJ zR&@g)MuXHFubtTVs-o)RD&%NY&)gVcv&@sDd1)lsfOj#f3Es&Eg)wEK>CeTwQ@Jjx&;N2@9X#Av`( zk7?bt5B*6|xw#5CS`|J=7!9~{V)`U^O-fPyoU4$dRTTlEwCjE6dDT38gR79ERTWbe zu2xLuALc_Nq&_^tRmjn*N&r!680>fxwnIr};R^^kT2(1kNqgPFsP#=n)xcHA(W=U* zO6tQk{r`GcQKh*GIa(FoWhnFTRMF`_D5`B-g&eJFq9#`I+0m+%a*C^vqgCO3kaFKL z**5h~CDx62y95b2TGeDglvVln##P;lYA#nHN2{7bRd~06>BtuUi;Aj)tB|8rO$Eeg z;KNCt_>FmkqFTpQ$hm}gTf&KCTQC3@G=U%0H~eXU84dUqUz^?oANZch8-{P-i8gPm zufrP%w)o)13US-r^)qkvdaMq+x4}8jPQ2c56kf=9+Y*6L)XN@Lyixdk9*wj?VW>6c z^?H5&c)}ZsHhb}v4M$t>Wmr(Uh{l2u$%dCw0m*I)1{X9=4GT_WKf1) z)g|mDroXp7l8Z8GE#v$RCR-)a@L+R7r6ml+XmnH&E%Fxkf)-0Cc0HZHgyvpsI=(|D z{B^McSdx*&p-8}@p5_+%zfQFfr}0I>8PXLmr1M%=P0qbY;YFp`mWxVhp<1dmSglc^ z>iVl%&sv(%Nm8HaJB!ivIQLE;m3alIUE#(5_5=G?11w+Pf}l`QTv74=?QeoGMVLZ> zQzdwdN*r#{TIH#(7Ah=N)k#6Z%c`rKHPxQFT8hJ`1G%K6uEyi2cZ;;3MS&~rPJ6Y- z>7e)m8836YTrQ{R^a%LXL53$)J1RZZR<{73At167qsJhtkr|aXL9F)F+Z^@vLKS;= zUQvz{tfGwmn^{d^`$5Z1Fq;*wMhSOVSK+Bv~x7%&CIeA6t_mYZo{&}UMoNaed{YrK1tA#p` zU97gcoPzw_MdtFJRf4#LYKOJPRaGzb1`i^Cm64?xVH`r8+iry+fqv(oYbwf>rmzuI z;?xLshr8D0bbFvvRo`)B_qv*S1edGEQR{SM)Qs(R{4DV@D&2y+#$8`8LSxvR;JqM!0FtC_nZ4~2Y_96sS_fT6IGZk}%oN%Lr_E}&IviEX zPpm4zR^=2uHrPs}uU8f2`1wlbYNETwWrN7DHsPZd6vKM`Kd8o?*#H0l diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 7071e6417ce..b1bab4deb06 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -96,9 +96,31 @@ fn test_ok() { command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - command.arg(&format!("/OUT:{manifest_dir}/../{test}.exe")); + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); + + let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); + + // run vcvars + let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); + let mut vcvars = std::process::Command::new("cmd"); + vcvars.arg("/C"); + vcvars.arg(vcvars_bat_path); + println!("running {vcvars:?}"); + + // cmd /C vcvars64.bat + let output = vcvars.output() + .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); + + if !output.status.success() { + println!(""); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to invoke vcvars64.bat {test}"); + } + + println!("compiling {test}: {command:?}"); - println!("command: {command:#?}"); // compile let output = command.output().expect(&format!("failed to compile {command:#?}")); if !output.status.success() { @@ -107,13 +129,20 @@ fn test_ok() { panic!("failed to compile {test}"); } + let path = std::env::var("PATH").unwrap_or_default(); + let newpath = format!("{wasmer_dll_dir};{path}"); + // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + command.env("PATH", newpath.clone()); + command.current_dir(exe_dir.clone()); + println!("executing {test}: {command:?}"); + println!("setting current dir = {exe_dir}"); let output = command.output().expect(&format!("failed to run {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); + panic!("failed to execute {test}"); } // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ @@ -158,4 +187,18 @@ fn test_ok() { panic!("failed to compile {test}"); } } + } + + #[cfg(test)] + fn find_vcvars64(compiler: &cc::Tool) -> Option { + + if !compiler.is_like_msvc() { + return None; + } + + let path = compiler.path(); + let path = format!("{}", path.display()); + let split = path.split("VC").nth(0)?; + + Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat")) } \ No newline at end of file From 7441fade9cdcdfb6828b672855d810f18dd2bc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 14 Sep 2022 22:31:19 +0200 Subject: [PATCH 06/68] Final fixes for make test-capi on windows-msvc - .wasm files should always be opened in "rb" mode - open_memstream doesn't exist on Windows, use tempfile() instead - remove .obj and .exe files when the test finish --- Cargo.lock | 8 + Cargo.toml | 1 + lib/c-api/examples/Makefile | 54 ++-- lib/c-api/examples/early-exit.c | 2 +- lib/c-api/examples/wasi.c | 27 +- lib/c-api/tests/Makefile | 2 +- .../wasmer-c-api-test-runner/command.bat | 1 - .../tests/wasmer-c-api-test-runner/src/lib.rs | 270 ++++++++++-------- 8 files changed, 196 insertions(+), 169 deletions(-) delete mode 100644 lib/c-api/tests/wasmer-c-api-test-runner/command.bat diff --git a/Cargo.lock b/Cargo.lock index cc3119b45da..90ca7c28a5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3054,6 +3054,14 @@ dependencies = [ "wasmer-compiler-singlepass", ] +[[package]] +name = "wasmer-capi-examples-runner" +version = "0.1.0" +dependencies = [ + "cc", + "target-lexicon 0.11.2", +] + [[package]] name = "wasmer-cli" version = "3.0.0-beta" diff --git a/Cargo.toml b/Cargo.toml index 06ecf49d77f..bed30b2181a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ members = [ "lib/wasi-experimental-io-devices", "lib/wasi-local-networking", "lib/c-api/tests/wasmer-c-api-test-runner", + "lib/c-api/examples/wasmer-capi-examples-runner", "lib/types", "tests/wasi-wast", "tests/lib/wast", diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 884619acaf1..192df90fb15 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -4,14 +4,26 @@ $(info Using provided WASMER_DIR=$(WASMER_DIR)) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +MSVC_CFLAGS:="" +MSVC_LDFLAGS:="" +MSVC_LDLIBS:="" + ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) - CFLAGS = -g -I$(ROOT_DIR)/../tests -I$(WASMER_DIR)/include + CFLAGS = -g -I$(ROOT_DIR)/ -I$(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L$(WASMER_DIR)/lib -lwasmer + + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(WASMER_DIR)/include + MSVC_LDFLAGS:= "" + MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I$(ROOT_DIR)/../tests -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) + CFLAGS = -g -I$(ROOT_DIR)/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) + + MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + MSVC_LDFLAGS:= "" + MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config --libs) wasmer.dll.lib endif $(info * CFLAGS: $(CFLAGS)) @@ -20,44 +32,10 @@ $(info * LDLIBS: $(LDLIBS)) ALL = deprecated-header early-exit instance imports-exports exports-function exports-global memory memory2 features wasi -.SILENT: deprecated-header deprecated-header.o -deprecated-header: deprecated-header.o - -.SILENT: early-exit early-exit.o -early-exit: early-exit.o - -.SILENT: instance instance.o -instance: instance.o - -.SILENT: imports-exports imports-exports.o -imports-exports: imports-exports.o - -.SILENT: exports-function exports-function.o -exports-function: exports-function.o - -.SILENT: exports-global exports-global.o -exports-global: exports-global.o - -.SILENT: memory memory.o -memory: memory.o - -.SILENT: memory2 memory2.o -memory2: memory2.o - -.SILENT: features features.o -features: features.o - -.SILENT: wasi wasi.o -wasi: wasi.o - -.PHONY: all -all: $(ALL) - .PHONY: run .SILENT: run -run: $(ALL) - set -o errexit; \ - $(foreach example,$?,echo Running \"$(example)\" example; ./$(example); echo;) +run: + WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture .SILENT: clean .PHONY: clean diff --git a/lib/c-api/examples/early-exit.c b/lib/c-api/examples/early-exit.c index d2410ca8baf..6c4bb08156e 100644 --- a/lib/c-api/examples/early-exit.c +++ b/lib/c-api/examples/early-exit.c @@ -45,7 +45,7 @@ int main(int argc, const char *argv[]) { // Load binary. printf("Loading binary...\n"); - FILE *file = fopen("assets/call_trap.wasm", "r"); + FILE *file = fopen("assets/call_trap.wasm", "rb"); if (!file) { printf("> Error loading module!\n"); return 1; diff --git a/lib/c-api/examples/wasi.c b/lib/c-api/examples/wasi.c index 529268e8591..7771560aa05 100644 --- a/lib/c-api/examples/wasi.c +++ b/lib/c-api/examples/wasi.c @@ -38,7 +38,7 @@ int main(int argc, const char* argv[]) { // Load binary. printf("Loading binary...\n"); - FILE* file = fopen("assets/qjs.wasm", "r"); + FILE* file = fopen("assets/qjs.wasm", "rb"); if (!file) { printf("> Error loading module!\n"); return 1; @@ -49,7 +49,7 @@ int main(int argc, const char* argv[]) { wasm_byte_vec_t binary; wasm_byte_vec_new_uninitialized(&binary, file_size); if (fread(binary.data, file_size, 1, file) != 1) { - printf("> Error loading module!\n"); + printf("> Error initializing module!\n"); return 1; } fclose(file); @@ -137,12 +137,12 @@ int main(int argc, const char* argv[]) { } printf("Call completed\n"); - { - FILE *memory_stream; - char* stdout; - size_t stdout_size = 0; + if(true) { - memory_stream = open_memstream(&stdout, &stdout_size); + // NOTE: previously, this used open_memstream, + // which is not cross-platform + FILE *memory_stream = NULL; + memory_stream = tmpfile(); // stdio.h if (NULL == memory_stream) { printf("> Error creating a memory stream.\n"); @@ -161,15 +161,20 @@ int main(int argc, const char* argv[]) { } if (data_read_size > 0) { - stdout_size += data_read_size; fwrite(buffer, sizeof(char), data_read_size, memory_stream); } } while (BUF_SIZE == data_read_size); + // print memory_stream + rewind(memory_stream); + fputs("WASI Stdout: ", stdout); + char buffer2[256]; + while (!feof(memory_stream)) { + if (fgets(buffer2, 256, memory_stream) == NULL) break; + fputs(buffer2, stdout); + } + fputs("\n", stdout); fclose(memory_stream); - - printf("WASI Stdout: `%.*s`\n", (int) stdout_size, stdout); - free(stdout); } diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 91ba07f6e39..9c02b82c8f7 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -35,7 +35,7 @@ $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) test: - cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture + WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/command.bat b/lib/c-api/tests/wasmer-c-api-test-runner/command.bat deleted file mode 100644 index bc40c1ebad5..00000000000 --- a/lib/c-api/tests/wasmer-c-api-test-runner/command.bat +++ /dev/null @@ -1 +0,0 @@ -"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" -nologo -MD -O1 -Brepro -W4 "C:\\Users\\felix\\Development\\wasmer\\lib\\c-api\\tests\\wasmer-c-api-test-runner/../wasm-c-api/example/callback.c" /I "C:/Users/felix/Development/wasmer/package/include" /link /LIBPATH:"C:/Users/felix/Development/wasmer/package/lib" "C:/Users/felix/Development/wasmer/package/lib/wasmer.dll.lib" /OUT:"C:\\Users\\felix\\Development\\wasmer\\lib\\c-api\\tests\\wasmer-c-api-test-runner/../wasm-c-api/example/callback.exe" \ No newline at end of file diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index b1bab4deb06..86b3c1cdc98 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -30,6 +30,36 @@ impl Config { } } + +#[derive(Default)] +pub struct RemoveTestsOnDrop { } + +impl Drop for RemoveTestsOnDrop { + fn drop(&mut self) { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + for entry in std::fs::read_dir(&manifest_dir).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let extension = path.extension().and_then(|s| s.to_str()); + if extension == Some("obj") || extension == Some("exe") { + println!("removing {}", path.display()); + let _ = std::fs::remove_file(&path); + } + } + if let Some(parent) = std::path::Path::new(&manifest_dir).parent() { + for entry in std::fs::read_dir(&parent).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let extension = path.extension().and_then(|s| s.to_str()); + if extension == Some("obj") || extension == Some("exe") { + println!("removing {}", path.display()); + let _ = std::fs::remove_file(&path); + } + } + } + } +} + const CAPI_BASE_TESTS: &[&str] = &[ "wasm-c-api/example/callback", "wasm-c-api/example/memory", @@ -56,136 +86,142 @@ const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ #[test] fn test_ok() { + let _drop = RemoveTestsOnDrop::default(); let config = Config::get(); println!("config: {:#?}", config); let manifest_dir = env!("CARGO_MANIFEST_DIR"); - let host = target_lexicon::HOST.to_string(); let target = &host; - #[cfg(target_os = "windows")] - for test in CAPI_BASE_TESTS.iter() { - - let mut build = cc::Build::new(); - let mut build = build - .cargo_metadata(false) - .warnings(true) - .static_crt(true) - .extra_warnings(true) - .warnings_into_errors(false) - .debug(config.ldflags.contains("-g")) - .host(&host) - .target(target) - .opt_level(1); - - let compiler = build.try_get_compiler().unwrap(); - let mut command = compiler.to_command(); - - command.arg(&format!("{manifest_dir}/../{test}.c")); - if !config.msvc_cflags.is_empty() { - command.arg(config.msvc_cflags.clone()); - } else if !config.wasmer_dir.is_empty() { - command.arg("/I"); - command.arg(&format!("{}/include", config.wasmer_dir)); - } - command.arg("/link"); - if !config.msvc_ldlibs.is_empty() { - command.arg(config.msvc_ldlibs.clone()); - } else if !config.wasmer_dir.is_empty() { - command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); - command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); - } - let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); - command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); - - let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); - - // run vcvars - let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); - let mut vcvars = std::process::Command::new("cmd"); - vcvars.arg("/C"); - vcvars.arg(vcvars_bat_path); - println!("running {vcvars:?}"); - - // cmd /C vcvars64.bat - let output = vcvars.output() - .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); - - if !output.status.success() { - println!(""); - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to invoke vcvars64.bat {test}"); - } - - println!("compiling {test}: {command:?}"); - - // compile - let output = command.output().expect(&format!("failed to compile {command:#?}")); - if !output.status.success() { - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); + if target.contains("msvc") { + for test in CAPI_BASE_TESTS.iter() { + + let mut build = cc::Build::new(); + let mut build = build + .cargo_metadata(false) + .warnings(true) + .static_crt(true) + .extra_warnings(true) + .warnings_into_errors(false) + .debug(config.ldflags.contains("-g")) + .host(&host) + .target(target) + .opt_level(1); + + let compiler = build.try_get_compiler().unwrap(); + let mut command = compiler.to_command(); + + command.arg(&format!("{manifest_dir}/../{test}.c")); + if !config.msvc_cflags.is_empty() { + command.arg(config.msvc_cflags.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg("/I"); + command.arg(&format!("{}/include", config.wasmer_dir)); + } + command.arg("/link"); + if !config.msvc_ldlibs.is_empty() { + command.arg(config.msvc_ldlibs.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + } + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); + + let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); + + // run vcvars + let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); + let mut vcvars = std::process::Command::new("cmd"); + vcvars.arg("/C"); + vcvars.arg(vcvars_bat_path); + println!("running {vcvars:?}"); + + // cmd /C vcvars64.bat + let output = vcvars.output() + .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); + + if !output.status.success() { + println!(""); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to invoke vcvars64.bat {test}"); + } + + println!("compiling {test}: {command:?}"); + + // compile + let output = command.output().expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + let path = std::env::var("PATH").unwrap_or_default(); + let newpath = format!("{wasmer_dll_dir};{path}"); + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + command.env("PATH", newpath.clone()); + command.current_dir(exe_dir.clone()); + println!("executing {test}: {command:?}"); + println!("setting current dir = {exe_dir}"); + let output = command.output().expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to execute {test}"); + } + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ + // -IC:/Users/felix/Development/wasmer/package/include + // + // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib + // + // wasm-c-api/example/callback.c + // + // -LC:/Users/felix/Development/wasmer/package/lib -lwasmer + // + // -o wasm-c-api/example/callback + } + } else { + for test in CAPI_BASE_TESTS.iter() { - let path = std::env::var("PATH").unwrap_or_default(); - let newpath = format!("{wasmer_dll_dir};{path}"); - - // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); - command.env("PATH", newpath.clone()); - command.current_dir(exe_dir.clone()); - println!("executing {test}: {command:?}"); - println!("setting current dir = {exe_dir}"); - let output = command.output().expect(&format!("failed to run {command:#?}")); - if !output.status.success() { - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to execute {test}"); + let mut command = std::process::Command::new("cc"); + + command.arg(config.cflags.clone()); + command.arg(config.ldflags.clone()); + command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(config.ldlibs.clone()); + command.arg("-o"); + command.arg(&format!("{manifest_dir}/../{test}")); + + // compile + let output = command.output().expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + let output = command.output().expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to execute {test}"); + } } - - // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ - // -IC:/Users/felix/Development/wasmer/package/include - // - // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib - // - // wasm-c-api/example/callback.c - // - // -LC:/Users/felix/Development/wasmer/package/lib -lwasmer - // - // -o wasm-c-api/example/callback - } - #[cfg(not(target_os = "windows"))] for test in CAPI_BASE_TESTS.iter() { - - let mut command = std::process::Command::new("cc"); - - command.arg(config.cflags.clone()); - command.arg(config.ldflags.clone()); - command.arg(&format!("{manifest_dir}/../{test}.c")); - command.arg(config.ldlibs.clone()); - command.arg("-o"); - command.arg(&format!("{manifest_dir}/../{test}")); - - // compile - let output = command.output().expect(&format!("failed to compile {command:#?}")); - if !output.status.success() { - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); - } - - // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); - let output = command.output().expect(&format!("failed to run {command:#?}")); - if !output.status.success() { - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); - } + let _ = std::fs::remove_file(&format!("{manifest_dir}/{test}.obj")); + let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}.exe")); + let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}")); } } From 4d1ebda1d2b2df1bea28cae6d291b4271e1fb358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 11:36:23 +0200 Subject: [PATCH 07/68] Undo accidental symlink removal --- lib/c-api/wasm.h | 728 +---------------------------------------------- 1 file changed, 1 insertion(+), 727 deletions(-) diff --git a/lib/c-api/wasm.h b/lib/c-api/wasm.h index 087319398da..14a5311999f 120000 --- a/lib/c-api/wasm.h +++ b/lib/c-api/wasm.h @@ -1,727 +1 @@ -// WebAssembly C API - -#ifndef WASM_H -#define WASM_H - -#include -#include -#include -#include -#include - -#ifndef WASM_API_EXTERN -#ifdef _WIN32 -#define WASM_API_EXTERN __declspec(dllimport) -#else -#define WASM_API_EXTERN -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/////////////////////////////////////////////////////////////////////////////// -// Auxiliaries - -// Machine types - -inline void assertions() { - static_assert(sizeof(float) == sizeof(uint32_t), "incompatible float type"); - static_assert(sizeof(double) == sizeof(uint64_t), "incompatible double type"); - static_assert(sizeof(intptr_t) == sizeof(uint32_t) || - sizeof(intptr_t) == sizeof(uint64_t), - "incompatible pointer type"); -} - -typedef char byte_t; -typedef float float32_t; -typedef double float64_t; - - -// Ownership - -#define own - -// The qualifier `own` is used to indicate ownership of data in this API. -// It is intended to be interpreted similar to a `const` qualifier: -// -// - `own wasm_xxx_t*` owns the pointed-to data -// - `own wasm_xxx_t` distributes to all fields of a struct or union `xxx` -// - `own wasm_xxx_vec_t` owns the vector as well as its elements(!) -// - an `own` function parameter passes ownership from caller to callee -// - an `own` function result passes ownership from callee to caller -// - an exception are `own` pointer parameters named `out`, which are copy-back -// output parameters passing back ownership from callee to caller -// -// Own data is created by `wasm_xxx_new` functions and some others. -// It must be released with the corresponding `wasm_xxx_delete` function. -// -// Deleting a reference does not necessarily delete the underlying object, -// it merely indicates that this owner no longer uses it. -// -// For vectors, `const wasm_xxx_vec_t` is used informally to indicate that -// neither the vector nor its elements should be modified. -// TODO: introduce proper `wasm_xxx_const_vec_t`? - - -#define WASM_DECLARE_OWN(name) \ - typedef struct wasm_##name##_t wasm_##name##_t; \ - \ - WASM_API_EXTERN void wasm_##name##_delete(own wasm_##name##_t*); - - -// Vectors - -#define WASM_DECLARE_VEC(name, ptr_or_none) \ - typedef struct wasm_##name##_vec_t { \ - size_t size; \ - wasm_##name##_t ptr_or_none* data; \ - } wasm_##name##_vec_t; \ - \ - WASM_API_EXTERN void wasm_##name##_vec_new_empty(own wasm_##name##_vec_t* out); \ - WASM_API_EXTERN void wasm_##name##_vec_new_uninitialized( \ - own wasm_##name##_vec_t* out, size_t); \ - WASM_API_EXTERN void wasm_##name##_vec_new( \ - own wasm_##name##_vec_t* out, \ - size_t, own wasm_##name##_t ptr_or_none const[]); \ - WASM_API_EXTERN void wasm_##name##_vec_copy( \ - own wasm_##name##_vec_t* out, const wasm_##name##_vec_t*); \ - WASM_API_EXTERN void wasm_##name##_vec_delete(own wasm_##name##_vec_t*); - - -// Byte vectors - -typedef byte_t wasm_byte_t; -WASM_DECLARE_VEC(byte, ) - -typedef wasm_byte_vec_t wasm_name_t; - -#define wasm_name wasm_byte_vec -#define wasm_name_new wasm_byte_vec_new -#define wasm_name_new_empty wasm_byte_vec_new_empty -#define wasm_name_new_new_uninitialized wasm_byte_vec_new_uninitialized -#define wasm_name_copy wasm_byte_vec_copy -#define wasm_name_delete wasm_byte_vec_delete - -static inline void wasm_name_new_from_string( - own wasm_name_t* out, own const char* s -) { - wasm_name_new(out, strlen(s), s); -} - -static inline void wasm_name_new_from_string_nt( - own wasm_name_t* out, own const char* s -) { - wasm_name_new(out, strlen(s) + 1, s); -} - - -/////////////////////////////////////////////////////////////////////////////// -// Runtime Environment - -// Configuration - -WASM_DECLARE_OWN(config) - -WASM_API_EXTERN own wasm_config_t* wasm_config_new(); - -// Embedders may provide custom functions for manipulating configs. - - -// Engine - -WASM_DECLARE_OWN(engine) - -// During testing, we use a custom implementation of wasm_engine_new -#if defined(TEST_WASM) || defined(TEST_WASMER) -wasm_engine_t* wasm_engine_new(); -#else -WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(); -#endif -WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); - - -// Store - -WASM_DECLARE_OWN(store) - -WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*); - -/////////////////////////////////////////////////////////////////////////////// -// Type Representations - -// Type attributes - -typedef uint8_t wasm_mutability_t; -enum wasm_mutability_enum { - WASM_CONST, - WASM_VAR, -}; - -typedef struct wasm_limits_t { - uint32_t min; - uint32_t max; -} wasm_limits_t; - -static const uint32_t wasm_limits_max_default = 0xffffffff; - - -// Generic - -#define WASM_DECLARE_TYPE(name) \ - WASM_DECLARE_OWN(name) \ - WASM_DECLARE_VEC(name, *) \ - \ - WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(wasm_##name##_t*); - - -// Value Types - -WASM_DECLARE_TYPE(valtype) - -typedef uint8_t wasm_valkind_t; -enum wasm_valkind_enum { - WASM_I32, - WASM_I64, - WASM_F32, - WASM_F64, - WASM_ANYREF = 128, - WASM_FUNCREF, -}; - -WASM_API_EXTERN own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t); - -WASM_API_EXTERN wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*); - -static inline bool wasm_valkind_is_num(wasm_valkind_t k) { - return k < WASM_ANYREF; -} -static inline bool wasm_valkind_is_ref(wasm_valkind_t k) { - return k >= WASM_ANYREF; -} - -static inline bool wasm_valtype_is_num(const wasm_valtype_t* t) { - return wasm_valkind_is_num(wasm_valtype_kind(t)); -} -static inline bool wasm_valtype_is_ref(const wasm_valtype_t* t) { - return wasm_valkind_is_ref(wasm_valtype_kind(t)); -} - - -// Function Types - -WASM_DECLARE_TYPE(functype) - -WASM_API_EXTERN own wasm_functype_t* wasm_functype_new( - own wasm_valtype_vec_t* params, own wasm_valtype_vec_t* results); - -WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t*); -WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t*); - - -// Global Types - -WASM_DECLARE_TYPE(globaltype) - -WASM_API_EXTERN own wasm_globaltype_t* wasm_globaltype_new( - own wasm_valtype_t*, wasm_mutability_t); - -WASM_API_EXTERN const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t*); -WASM_API_EXTERN wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t*); - - -// Table Types - -WASM_DECLARE_TYPE(tabletype) - -WASM_API_EXTERN own wasm_tabletype_t* wasm_tabletype_new( - own wasm_valtype_t*, const wasm_limits_t*); - -WASM_API_EXTERN const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t*); -WASM_API_EXTERN const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t*); - - -// Memory Types - -WASM_DECLARE_TYPE(memorytype) - -WASM_API_EXTERN own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*); - -WASM_API_EXTERN const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t*); - - -// Extern Types - -WASM_DECLARE_TYPE(externtype) - -typedef uint8_t wasm_externkind_t; -enum wasm_externkind_enum { - WASM_EXTERN_FUNC, - WASM_EXTERN_GLOBAL, - WASM_EXTERN_TABLE, - WASM_EXTERN_MEMORY, -}; - -WASM_API_EXTERN wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*); - -WASM_API_EXTERN wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t*); -WASM_API_EXTERN wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t*); -WASM_API_EXTERN wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t*); -WASM_API_EXTERN wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t*); - -WASM_API_EXTERN wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*); -WASM_API_EXTERN wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t*); -WASM_API_EXTERN wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t*); -WASM_API_EXTERN wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t*); - -WASM_API_EXTERN const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t*); -WASM_API_EXTERN const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t*); -WASM_API_EXTERN const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t*); -WASM_API_EXTERN const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t*); - -WASM_API_EXTERN const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t*); -WASM_API_EXTERN const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t*); -WASM_API_EXTERN const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t*); -WASM_API_EXTERN const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t*); - - -// Import Types - -WASM_DECLARE_TYPE(importtype) - -WASM_API_EXTERN own wasm_importtype_t* wasm_importtype_new( - own wasm_name_t* module, own wasm_name_t* name, own wasm_externtype_t*); - -WASM_API_EXTERN const wasm_name_t* wasm_importtype_module(const wasm_importtype_t*); -WASM_API_EXTERN const wasm_name_t* wasm_importtype_name(const wasm_importtype_t*); -WASM_API_EXTERN const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t*); - - -// Export Types - -WASM_DECLARE_TYPE(exporttype) - -WASM_API_EXTERN own wasm_exporttype_t* wasm_exporttype_new( - own wasm_name_t*, own wasm_externtype_t*); - -WASM_API_EXTERN const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t*); -WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t*); - - -/////////////////////////////////////////////////////////////////////////////// -// Runtime Objects - -// Values - -struct wasm_ref_t; - -typedef struct wasm_val_t { - wasm_valkind_t kind; - union { - int32_t i32; - int64_t i64; - float32_t f32; - float64_t f64; - struct wasm_ref_t* ref; - } of; -} wasm_val_t; - -WASM_API_EXTERN void wasm_val_delete(own wasm_val_t* v); -WASM_API_EXTERN void wasm_val_copy(own wasm_val_t* out, const wasm_val_t*); - -WASM_DECLARE_VEC(val, ) - - -// References - -#define WASM_DECLARE_REF_BASE(name) \ - WASM_DECLARE_OWN(name) \ - \ - WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_copy(const wasm_##name##_t*); \ - WASM_API_EXTERN bool wasm_##name##_same(const wasm_##name##_t*, const wasm_##name##_t*); \ - \ - WASM_API_EXTERN void* wasm_##name##_get_host_info(const wasm_##name##_t*); \ - WASM_API_EXTERN void wasm_##name##_set_host_info(wasm_##name##_t*, void*); \ - WASM_API_EXTERN void wasm_##name##_set_host_info_with_finalizer( \ - wasm_##name##_t*, void*, void (*)(void*)); - -#define WASM_DECLARE_REF(name) \ - WASM_DECLARE_REF_BASE(name) \ - \ - WASM_API_EXTERN wasm_ref_t* wasm_##name##_as_ref(wasm_##name##_t*); \ - WASM_API_EXTERN wasm_##name##_t* wasm_ref_as_##name(wasm_ref_t*); \ - WASM_API_EXTERN const wasm_ref_t* wasm_##name##_as_ref_const(const wasm_##name##_t*); \ - WASM_API_EXTERN const wasm_##name##_t* wasm_ref_as_##name##_const(const wasm_ref_t*); - -#define WASM_DECLARE_SHARABLE_REF(name) \ - WASM_DECLARE_REF(name) \ - WASM_DECLARE_OWN(shared_##name) \ - \ - WASM_API_EXTERN own wasm_shared_##name##_t* wasm_##name##_share(const wasm_##name##_t*); \ - WASM_API_EXTERN own wasm_##name##_t* wasm_##name##_obtain(wasm_store_t*, const wasm_shared_##name##_t*); - - -WASM_DECLARE_REF_BASE(ref) - - -// Frames - -WASM_DECLARE_OWN(frame) -WASM_DECLARE_VEC(frame, *) -WASM_API_EXTERN own wasm_frame_t* wasm_frame_copy(const wasm_frame_t*); - -WASM_API_EXTERN struct wasm_instance_t* wasm_frame_instance(const wasm_frame_t*); -WASM_API_EXTERN uint32_t wasm_frame_func_index(const wasm_frame_t*); -WASM_API_EXTERN size_t wasm_frame_func_offset(const wasm_frame_t*); -WASM_API_EXTERN size_t wasm_frame_module_offset(const wasm_frame_t*); - - -// Traps - -typedef wasm_name_t wasm_message_t; // null terminated - -WASM_DECLARE_REF(trap) - -WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*); - -WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out); -WASM_API_EXTERN own wasm_frame_t* wasm_trap_origin(const wasm_trap_t*); -WASM_API_EXTERN void wasm_trap_trace(const wasm_trap_t*, own wasm_frame_vec_t* out); - - -// Foreign Objects - -WASM_DECLARE_REF(foreign) - -WASM_API_EXTERN own wasm_foreign_t* wasm_foreign_new(wasm_store_t*); - - -// Modules - -WASM_DECLARE_SHARABLE_REF(module) - -WASM_API_EXTERN own wasm_module_t* wasm_module_new( - wasm_store_t*, const wasm_byte_vec_t* binary); - -WASM_API_EXTERN bool wasm_module_validate(wasm_store_t*, const wasm_byte_vec_t* binary); - -WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out); -WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out); - -WASM_API_EXTERN void wasm_module_serialize(const wasm_module_t*, own wasm_byte_vec_t* out); -WASM_API_EXTERN own wasm_module_t* wasm_module_deserialize(wasm_store_t*, const wasm_byte_vec_t*); - - -// Function Instances - -WASM_DECLARE_REF(func) - -typedef own wasm_trap_t* (*wasm_func_callback_t)( - const wasm_val_vec_t* args, own wasm_val_vec_t* results); -typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)( - void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results); - -WASM_API_EXTERN own wasm_func_t* wasm_func_new( - wasm_store_t*, const wasm_functype_t*, wasm_func_callback_t); -WASM_API_EXTERN own wasm_func_t* wasm_func_new_with_env( - wasm_store_t*, const wasm_functype_t* type, wasm_func_callback_with_env_t, - void* env, void (*finalizer)(void*)); - -WASM_API_EXTERN own wasm_functype_t* wasm_func_type(const wasm_func_t*); -WASM_API_EXTERN size_t wasm_func_param_arity(const wasm_func_t*); -WASM_API_EXTERN size_t wasm_func_result_arity(const wasm_func_t*); - -WASM_API_EXTERN own wasm_trap_t* wasm_func_call( - const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results); - - -// Global Instances - -WASM_DECLARE_REF(global) - -WASM_API_EXTERN own wasm_global_t* wasm_global_new( - wasm_store_t*, const wasm_globaltype_t*, const wasm_val_t*); - -WASM_API_EXTERN own wasm_globaltype_t* wasm_global_type(const wasm_global_t*); - -WASM_API_EXTERN void wasm_global_get(const wasm_global_t*, own wasm_val_t* out); -WASM_API_EXTERN void wasm_global_set(wasm_global_t*, const wasm_val_t*); - - -// Table Instances - -WASM_DECLARE_REF(table) - -typedef uint32_t wasm_table_size_t; - -WASM_API_EXTERN own wasm_table_t* wasm_table_new( - wasm_store_t*, const wasm_tabletype_t*, wasm_ref_t* init); - -WASM_API_EXTERN own wasm_tabletype_t* wasm_table_type(const wasm_table_t*); - -WASM_API_EXTERN own wasm_ref_t* wasm_table_get(const wasm_table_t*, wasm_table_size_t index); -WASM_API_EXTERN bool wasm_table_set(wasm_table_t*, wasm_table_size_t index, wasm_ref_t*); - -WASM_API_EXTERN wasm_table_size_t wasm_table_size(const wasm_table_t*); -WASM_API_EXTERN bool wasm_table_grow(wasm_table_t*, wasm_table_size_t delta, wasm_ref_t* init); - - -// Memory Instances - -WASM_DECLARE_REF(memory) - -typedef uint32_t wasm_memory_pages_t; - -static const size_t MEMORY_PAGE_SIZE = 0x10000; - -WASM_API_EXTERN own wasm_memory_t* wasm_memory_new(wasm_store_t*, const wasm_memorytype_t*); - -WASM_API_EXTERN own wasm_memorytype_t* wasm_memory_type(const wasm_memory_t*); - -WASM_API_EXTERN byte_t* wasm_memory_data(wasm_memory_t*); -WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*); - -WASM_API_EXTERN wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*); -WASM_API_EXTERN bool wasm_memory_grow(wasm_memory_t*, wasm_memory_pages_t delta); - - -// Externals - -WASM_DECLARE_REF(extern) -WASM_DECLARE_VEC(extern, *) - -WASM_API_EXTERN wasm_externkind_t wasm_extern_kind(const wasm_extern_t*); -WASM_API_EXTERN own wasm_externtype_t* wasm_extern_type(const wasm_extern_t*); - -WASM_API_EXTERN wasm_extern_t* wasm_func_as_extern(wasm_func_t*); -WASM_API_EXTERN wasm_extern_t* wasm_global_as_extern(wasm_global_t*); -WASM_API_EXTERN wasm_extern_t* wasm_table_as_extern(wasm_table_t*); -WASM_API_EXTERN wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*); - -WASM_API_EXTERN wasm_func_t* wasm_extern_as_func(wasm_extern_t*); -WASM_API_EXTERN wasm_global_t* wasm_extern_as_global(wasm_extern_t*); -WASM_API_EXTERN wasm_table_t* wasm_extern_as_table(wasm_extern_t*); -WASM_API_EXTERN wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*); - -WASM_API_EXTERN const wasm_extern_t* wasm_func_as_extern_const(const wasm_func_t*); -WASM_API_EXTERN const wasm_extern_t* wasm_global_as_extern_const(const wasm_global_t*); -WASM_API_EXTERN const wasm_extern_t* wasm_table_as_extern_const(const wasm_table_t*); -WASM_API_EXTERN const wasm_extern_t* wasm_memory_as_extern_const(const wasm_memory_t*); - -WASM_API_EXTERN const wasm_func_t* wasm_extern_as_func_const(const wasm_extern_t*); -WASM_API_EXTERN const wasm_global_t* wasm_extern_as_global_const(const wasm_extern_t*); -WASM_API_EXTERN const wasm_table_t* wasm_extern_as_table_const(const wasm_extern_t*); -WASM_API_EXTERN const wasm_memory_t* wasm_extern_as_memory_const(const wasm_extern_t*); - - -// Module Instances - -WASM_DECLARE_REF(instance) - -WASM_API_EXTERN own wasm_instance_t* wasm_instance_new( - wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports, - own wasm_trap_t** -); - -WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out); - - -/////////////////////////////////////////////////////////////////////////////// -// Convenience - -// Vectors - -#define WASM_EMPTY_VEC {0, NULL} -#define WASM_ARRAY_VEC(array) {sizeof(array)/sizeof(*(array)), array} - - -// Value Type construction short-hands - -static inline own wasm_valtype_t* wasm_valtype_new_i32() { - return wasm_valtype_new(WASM_I32); -} -static inline own wasm_valtype_t* wasm_valtype_new_i64() { - return wasm_valtype_new(WASM_I64); -} -static inline own wasm_valtype_t* wasm_valtype_new_f32() { - return wasm_valtype_new(WASM_F32); -} -static inline own wasm_valtype_t* wasm_valtype_new_f64() { - return wasm_valtype_new(WASM_F64); -} - -static inline own wasm_valtype_t* wasm_valtype_new_anyref() { - return wasm_valtype_new(WASM_ANYREF); -} -static inline own wasm_valtype_t* wasm_valtype_new_funcref() { - return wasm_valtype_new(WASM_FUNCREF); -} - - -// Function Types construction short-hands - -static inline own wasm_functype_t* wasm_functype_new_0_0() { - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new_empty(¶ms); - wasm_valtype_vec_new_empty(&results); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_1_0( - own wasm_valtype_t* p -) { - wasm_valtype_t* ps[1] = {p}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 1, ps); - wasm_valtype_vec_new_empty(&results); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_2_0( - own wasm_valtype_t* p1, own wasm_valtype_t* p2 -) { - wasm_valtype_t* ps[2] = {p1, p2}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 2, ps); - wasm_valtype_vec_new_empty(&results); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_3_0( - own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3 -) { - wasm_valtype_t* ps[3] = {p1, p2, p3}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 3, ps); - wasm_valtype_vec_new_empty(&results); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_0_1( - own wasm_valtype_t* r -) { - wasm_valtype_t* rs[1] = {r}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new_empty(¶ms); - wasm_valtype_vec_new(&results, 1, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_1_1( - own wasm_valtype_t* p, own wasm_valtype_t* r -) { - wasm_valtype_t* ps[1] = {p}; - wasm_valtype_t* rs[1] = {r}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 1, ps); - wasm_valtype_vec_new(&results, 1, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_2_1( - own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* r -) { - wasm_valtype_t* ps[2] = {p1, p2}; - wasm_valtype_t* rs[1] = {r}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 2, ps); - wasm_valtype_vec_new(&results, 1, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_3_1( - own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, - own wasm_valtype_t* r -) { - wasm_valtype_t* ps[3] = {p1, p2, p3}; - wasm_valtype_t* rs[1] = {r}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 3, ps); - wasm_valtype_vec_new(&results, 1, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_0_2( - own wasm_valtype_t* r1, own wasm_valtype_t* r2 -) { - wasm_valtype_t* rs[2] = {r1, r2}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new_empty(¶ms); - wasm_valtype_vec_new(&results, 2, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_1_2( - own wasm_valtype_t* p, own wasm_valtype_t* r1, own wasm_valtype_t* r2 -) { - wasm_valtype_t* ps[1] = {p}; - wasm_valtype_t* rs[2] = {r1, r2}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 1, ps); - wasm_valtype_vec_new(&results, 2, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_2_2( - own wasm_valtype_t* p1, own wasm_valtype_t* p2, - own wasm_valtype_t* r1, own wasm_valtype_t* r2 -) { - wasm_valtype_t* ps[2] = {p1, p2}; - wasm_valtype_t* rs[2] = {r1, r2}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 2, ps); - wasm_valtype_vec_new(&results, 2, rs); - return wasm_functype_new(¶ms, &results); -} - -static inline own wasm_functype_t* wasm_functype_new_3_2( - own wasm_valtype_t* p1, own wasm_valtype_t* p2, own wasm_valtype_t* p3, - own wasm_valtype_t* r1, own wasm_valtype_t* r2 -) { - wasm_valtype_t* ps[3] = {p1, p2, p3}; - wasm_valtype_t* rs[2] = {r1, r2}; - wasm_valtype_vec_t params, results; - wasm_valtype_vec_new(¶ms, 3, ps); - wasm_valtype_vec_new(&results, 2, rs); - return wasm_functype_new(¶ms, &results); -} - - -// Value construction short-hands - -static inline void wasm_val_init_ptr(own wasm_val_t* out, void* p) { -#if UINTPTR_MAX == UINT32_MAX - out->kind = WASM_I32; - out->of.i32 = (intptr_t)p; -#elif UINTPTR_MAX == UINT64_MAX - out->kind = WASM_I64; - out->of.i64 = (intptr_t)p; -#endif -} - -static inline void* wasm_val_ptr(const wasm_val_t* val) { -#if UINTPTR_MAX == UINT32_MAX - return (void*)(intptr_t)val->of.i32; -#elif UINTPTR_MAX == UINT64_MAX - return (void*)(intptr_t)val->of.i64; -#endif -} - -#define WASM_I32_VAL(i) {.kind = WASM_I32, .of = {.i32 = i}} -#define WASM_I64_VAL(i) {.kind = WASM_I64, .of = {.i64 = i}} -#define WASM_F32_VAL(z) {.kind = WASM_F32, .of = {.f32 = z}} -#define WASM_F64_VAL(z) {.kind = WASM_F64, .of = {.f64 = z}} -#define WASM_REF_VAL(r) {.kind = WASM_ANYREF, .of = {.ref = r}} -#define WASM_INIT_VAL {.kind = WASM_ANYREF, .of = {.ref = NULL}} - - -/////////////////////////////////////////////////////////////////////////////// - -#undef own - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // #ifdef WASM_H +tests/wasm-c-api/include/wasm.h \ No newline at end of file From 94baa50bbfb4a5ccbc088e28f5c3dc55646179c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 11:38:13 +0200 Subject: [PATCH 08/68] cargo fmt --- .../tests/wasmer-c-api-test-runner/src/lib.rs | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 86b3c1cdc98..c54bcd267ed 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -10,7 +10,6 @@ pub struct Config { pub msvc_cflags: String, pub msvc_ldflags: String, pub msvc_ldlibs: String, - } impl Config { @@ -30,13 +29,12 @@ impl Config { } } - #[derive(Default)] -pub struct RemoveTestsOnDrop { } +pub struct RemoveTestsOnDrop {} -impl Drop for RemoveTestsOnDrop { +impl Drop for RemoveTestsOnDrop { fn drop(&mut self) { - let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let manifest_dir = env!("CARGO_MANIFEST_DIR"); for entry in std::fs::read_dir(&manifest_dir).unwrap() { let entry = entry.unwrap(); let path = entry.path(); @@ -64,17 +62,14 @@ const CAPI_BASE_TESTS: &[&str] = &[ "wasm-c-api/example/callback", "wasm-c-api/example/memory", "wasm-c-api/example/start", - "wasm-c-api/example/global", "wasm-c-api/example/reflect", "wasm-c-api/example/trap", - "wasm-c-api/example/hello", "wasm-c-api/example/serialize", "wasm-c-api/example/multi", ]; - const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ "wasm-c-api/example/finalize", "wasm-c-api/example/hostref", @@ -85,7 +80,6 @@ const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ // Runs all the tests that are working in the /c directory #[test] fn test_ok() { - let _drop = RemoveTestsOnDrop::default(); let config = Config::get(); println!("config: {:#?}", config); @@ -96,7 +90,6 @@ fn test_ok() { if target.contains("msvc") { for test in CAPI_BASE_TESTS.iter() { - let mut build = cc::Build::new(); let mut build = build .cargo_metadata(false) @@ -108,10 +101,10 @@ fn test_ok() { .host(&host) .target(target) .opt_level(1); - + let compiler = build.try_get_compiler().unwrap(); let mut command = compiler.to_command(); - + command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.msvc_cflags.is_empty() { command.arg(config.msvc_cflags.clone()); @@ -128,88 +121,95 @@ fn test_ok() { } let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); - + let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); - + // run vcvars let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); let mut vcvars = std::process::Command::new("cmd"); vcvars.arg("/C"); vcvars.arg(vcvars_bat_path); println!("running {vcvars:?}"); - + // cmd /C vcvars64.bat - let output = vcvars.output() - .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); - + let output = vcvars + .output() + .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); + if !output.status.success() { println!(""); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); panic!("failed to invoke vcvars64.bat {test}"); } - + println!("compiling {test}: {command:?}"); - + // compile - let output = command.output().expect(&format!("failed to compile {command:#?}")); + let output = command + .output() + .expect(&format!("failed to compile {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); panic!("failed to compile {test}"); } - + let path = std::env::var("PATH").unwrap_or_default(); let newpath = format!("{wasmer_dll_dir};{path}"); - + // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); println!("executing {test}: {command:?}"); println!("setting current dir = {exe_dir}"); - let output = command.output().expect(&format!("failed to run {command:#?}")); + let output = command + .output() + .expect(&format!("failed to run {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); panic!("failed to execute {test}"); } - - // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ - // -IC:/Users/felix/Development/wasmer/package/include + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/tests/ + // -IC:/Users/felix/Development/wasmer/package/include + // + // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib // - // -Wl,-rpath,C:/Users/felix/Development/wasmer/package/lib + // wasm-c-api/example/callback.c // - // wasm-c-api/example/callback.c + // -LC:/Users/felix/Development/wasmer/package/lib -lwasmer // - // -LC:/Users/felix/Development/wasmer/package/lib -lwasmer - // // -o wasm-c-api/example/callback - } } else { for test in CAPI_BASE_TESTS.iter() { - let mut command = std::process::Command::new("cc"); - + command.arg(config.cflags.clone()); command.arg(config.ldflags.clone()); command.arg(&format!("{manifest_dir}/../{test}.c")); command.arg(config.ldlibs.clone()); command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); - + // compile - let output = command.output().expect(&format!("failed to compile {command:#?}")); + let output = command + .output() + .expect(&format!("failed to compile {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); panic!("failed to compile {test}"); } - + // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); - let output = command.output().expect(&format!("failed to run {command:#?}")); + let output = command + .output() + .expect(&format!("failed to run {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); @@ -223,18 +223,17 @@ fn test_ok() { let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}.exe")); let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}")); } - } +} - #[cfg(test)] - fn find_vcvars64(compiler: &cc::Tool) -> Option { - +#[cfg(test)] +fn find_vcvars64(compiler: &cc::Tool) -> Option { if !compiler.is_like_msvc() { return None; } - + let path = compiler.path(); let path = format!("{}", path.display()); let split = path.split("VC").nth(0)?; Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat")) - } \ No newline at end of file +} From ada5810b25cd92ea6d7ed26d58d1b9382a4b3ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 11:47:20 +0200 Subject: [PATCH 09/68] Fix various compilation errors on windows --- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 8 +++++--- tests/integration/cli/src/assets.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index c54bcd267ed..ab55946b93a 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -58,7 +58,8 @@ impl Drop for RemoveTestsOnDrop { } } -const CAPI_BASE_TESTS: &[&str] = &[ +#[cfg(test)] +pub const CAPI_BASE_TESTS: &[&str] = &[ "wasm-c-api/example/callback", "wasm-c-api/example/memory", "wasm-c-api/example/start", @@ -70,7 +71,8 @@ const CAPI_BASE_TESTS: &[&str] = &[ "wasm-c-api/example/multi", ]; -const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ +#[allow(unused_variables, dead_code)] +pub const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[ "wasm-c-api/example/finalize", "wasm-c-api/example/hostref", "wasm-c-api/example/threads", @@ -137,7 +139,7 @@ fn test_ok() { .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); if !output.status.success() { - println!(""); + println!(); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); panic!("failed to invoke vcvars64.bat {test}"); diff --git a/tests/integration/cli/src/assets.rs b/tests/integration/cli/src/assets.rs index 6f7b9a24b14..15220ebbbdc 100644 --- a/tests/integration/cli/src/assets.rs +++ b/tests/integration/cli/src/assets.rs @@ -36,7 +36,7 @@ pub const WASMER_TARGET_PATH2: &str = concat!( pub const LIBWASMER_FILENAME: &str = "libwasmer.a"; #[cfg(windows)] -pub const LIBWASMER_PATH: &str = "wasmer.lib"; +pub const LIBWASMER_FILENAME: &str = "wasmer.lib"; /// Get the path to the `libwasmer.a` static library. pub fn get_libwasmer_path() -> PathBuf { From 7e0a3b5cd6e62488e8a70b60ed2434641786032e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 11:59:07 +0200 Subject: [PATCH 10/68] Migrate from inline-c to wasmer-inline-c --- Cargo.lock | 38 ++++++++++--------- lib/c-api/Cargo.toml | 2 +- lib/c-api/build.rs | 4 +- lib/c-api/src/error.rs | 2 +- lib/c-api/src/wasm_c_api/engine.rs | 12 +++--- lib/c-api/src/wasm_c_api/externals/global.rs | 2 +- lib/c-api/src/wasm_c_api/externals/mod.rs | 2 +- lib/c-api/src/wasm_c_api/instance.rs | 4 +- lib/c-api/src/wasm_c_api/macros.rs | 6 +-- lib/c-api/src/wasm_c_api/mod.rs | 14 +++---- lib/c-api/src/wasm_c_api/module.rs | 10 ++--- lib/c-api/src/wasm_c_api/trap.rs | 4 +- lib/c-api/src/wasm_c_api/unstable/engine.rs | 8 ++-- lib/c-api/src/wasm_c_api/unstable/features.rs | 2 +- .../unstable/middlewares/metering.rs | 4 +- lib/c-api/src/wasm_c_api/unstable/module.rs | 4 +- .../src/wasm_c_api/unstable/target_lexicon.rs | 8 ++-- lib/c-api/src/wasm_c_api/value.rs | 2 +- lib/c-api/src/wasm_c_api/version.rs | 4 +- lib/c-api/src/wasm_c_api/wasi/mod.rs | 2 +- lib/c-api/src/wasm_c_api/wat.rs | 2 +- 21 files changed, 70 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90ca7c28a5f..3cd75789ff5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,24 +1232,11 @@ dependencies = [ "syn", ] -[[package]] -name = "inline-c" -version = "0.1.0" -dependencies = [ - "assert_cmd", - "cc", - "inline-c-macro", - "lazy_static", - "predicates", - "regex", - "rustc_version 0.3.3", - "target-lexicon 0.11.2", - "tempfile", -] - [[package]] name = "inline-c-macro" -version = "0.1.6" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f5621ec7adacda881d7c2826c064f5c29c72fd44333f97df61b458a583ae15" dependencies = [ "proc-macro2", "quote", @@ -3015,7 +3002,6 @@ dependencies = [ "cfg-if 1.0.0", "enumset", "field-offset", - "inline-c", "lazy_static", "libc", "paste", @@ -3027,6 +3013,7 @@ dependencies = [ "wasmer-compiler-llvm", "wasmer-compiler-singlepass", "wasmer-emscripten", + "wasmer-inline-c", "wasmer-middlewares", "wasmer-types", "wasmer-wasi", @@ -3230,6 +3217,23 @@ dependencies = [ "wasmer-types", ] +[[package]] +name = "wasmer-inline-c" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c5002da7f51d03c06452231ba2a4f4d84dae7f282dd3145aba01d260545210" +dependencies = [ + "assert_cmd", + "cc", + "inline-c-macro", + "lazy_static", + "predicates", + "regex", + "rustc_version 0.3.3", + "target-lexicon 0.11.2", + "tempfile", +] + [[package]] name = "wasmer-integration-tests-cli" version = "3.0.0-beta" diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 740c716ec46..4ebdd632bd2 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -41,7 +41,7 @@ paste = "1.0" [dev-dependencies] field-offset = "0.3.3" -inline-c = { path = "../../../wasmer-inline-c-rs" } +wasmer-inline-c = "0.1.0" [features] default = [ diff --git a/lib/c-api/build.rs b/lib/c-api/build.rs index 8fb05bc97ed..98400014c00 100644 --- a/lib/c-api/build.rs +++ b/lib/c-api/build.rs @@ -1,7 +1,7 @@ //! This build script aims at: //! //! * generating the C header files for the C API, -//! * setting `inline-c` up. +//! * setting `wasmer-inline-c` up. use cbindgen::{Builder, Language}; use std::{ @@ -83,7 +83,7 @@ fn main() { build_cdylib_link_arg(); } -/// Check whether we should build the C API headers or set `inline-c` up. +/// Check whether we should build the C API headers or set `wasmer-inline-c` up. fn running_self() -> bool { env::var("DOCS_RS").is_err() && env::var("_CBINDGEN_IS_RUNNING").is_err() diff --git a/lib/c-api/src/error.rs b/lib/c-api/src/error.rs index f47caec1b92..adb988440ed 100644 --- a/lib/c-api/src/error.rs +++ b/lib/c-api/src/error.rs @@ -10,7 +10,7 @@ //! # Example //! //! ```rust -//! # use inline_c::assert_c; +//! # use wasmer_inline_c::assert_c; //! # fn main() { //! # (assert_c! { //! # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 505109f9bbc..53ad02ba03d 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -89,7 +89,7 @@ pub struct wasm_config_t { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -128,7 +128,7 @@ pub extern "C" fn wasm_config_new() -> Box { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -157,7 +157,7 @@ pub extern "C" fn wasm_config_delete(_config: Option>) {} /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -211,7 +211,7 @@ pub extern "C" fn wasm_config_set_compiler( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -315,7 +315,7 @@ cfg_if! { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -440,7 +440,7 @@ pub extern "C" fn wasm_engine_new_with_config( #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_engine_new() { diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index b6f8a4f74f5..d79bd333851 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -97,7 +97,7 @@ pub unsafe extern "C" fn wasm_global_type( #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_set_host_global_immutable() { diff --git a/lib/c-api/src/wasm_c_api/externals/mod.rs b/lib/c-api/src/wasm_c_api/externals/mod.rs index 9fe5eca1d4a..687af235901 100644 --- a/lib/c-api/src/wasm_c_api/externals/mod.rs +++ b/lib/c-api/src/wasm_c_api/externals/mod.rs @@ -132,7 +132,7 @@ pub extern "C" fn wasm_extern_as_table(r#extern: Option<&wasm_extern_t>) -> Opti #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_extern_copy() { diff --git a/lib/c-api/src/wasm_c_api/instance.rs b/lib/c-api/src/wasm_c_api/instance.rs index c32b44fbe93..9fff1e0ac6d 100644 --- a/lib/c-api/src/wasm_c_api/instance.rs +++ b/lib/c-api/src/wasm_c_api/instance.rs @@ -106,7 +106,7 @@ pub unsafe extern "C" fn wasm_instance_delete(_instance: Option>) /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -113,7 +113,7 @@ pub unsafe extern "C" fn wasm_module_validate( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -236,7 +236,7 @@ pub unsafe extern "C" fn wasm_module_exports( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -387,7 +387,7 @@ pub unsafe extern "C" fn wasm_module_imports( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -480,7 +480,7 @@ pub unsafe extern "C" fn wasm_module_serialize(module: &wasm_module_t, out: &mut #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_module_validate() { diff --git a/lib/c-api/src/wasm_c_api/trap.rs b/lib/c-api/src/wasm_c_api/trap.rs index af21b00efb1..14d8d7c7431 100644 --- a/lib/c-api/src/wasm_c_api/trap.rs +++ b/lib/c-api/src/wasm_c_api/trap.rs @@ -70,7 +70,7 @@ pub unsafe extern "C" fn wasm_trap_delete(_trap: Option>) {} /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -144,7 +144,7 @@ pub unsafe extern "C" fn wasm_trap_trace( #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_trap_message_null_terminated() { diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index 43f12facbc0..c114df0ec8c 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -14,7 +14,7 @@ use super::target_lexicon::wasmer_target_t; /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -58,7 +58,7 @@ pub extern "C" fn wasm_config_set_target(config: &mut wasm_config_t, target: Box /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -105,7 +105,7 @@ pub extern "C" fn wasm_config_set_features( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -166,7 +166,7 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; use std::env::{remove_var, set_var}; #[test] diff --git a/lib/c-api/src/wasm_c_api/unstable/features.rs b/lib/c-api/src/wasm_c_api/unstable/features.rs index 51aee70c52a..349e69f704b 100644 --- a/lib/c-api/src/wasm_c_api/unstable/features.rs +++ b/lib/c-api/src/wasm_c_api/unstable/features.rs @@ -5,7 +5,7 @@ //! # Example //! //! ```rust -//! # use inline_c::assert_c; +//! # use wasmer_inline_c::assert_c; //! # fn main() { //! # (assert_c! { //! # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs index f46301e672f..41958eafd5b 100644 --- a/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs +++ b/lib/c-api/src/wasm_c_api/unstable/middlewares/metering.rs @@ -8,7 +8,7 @@ //! # Example //! //! ```rust -//! # use inline_c::assert_c; +//! # use wasmer_inline_c::assert_c; //! # fn main() { //! # (assert_c! { //! # #include "tests/wasmer.h" @@ -234,7 +234,7 @@ pub unsafe extern "C" fn wasmer_metering_points_are_exhausted( /// points aren't updated by the WebAssembly module execution /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/unstable/module.rs b/lib/c-api/src/wasm_c_api/unstable/module.rs index b53e0b14608..ed2e9b9c984 100644 --- a/lib/c-api/src/wasm_c_api/unstable/module.rs +++ b/lib/c-api/src/wasm_c_api/unstable/module.rs @@ -12,7 +12,7 @@ use std::str; /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -79,7 +79,7 @@ pub unsafe extern "C" fn wasmer_module_name( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs b/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs index 541b7a87498..cb875d5f477 100644 --- a/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs +++ b/lib/c-api/src/wasm_c_api/unstable/target_lexicon.rs @@ -6,7 +6,7 @@ //! # Example //! //! ```rust -//! # use inline_c::assert_c; +//! # use wasmer_inline_c::assert_c; //! # fn main() { //! # (assert_c! { //! # #include "tests/wasmer.h" @@ -108,7 +108,7 @@ pub extern "C" fn wasmer_target_delete(_target: Option>) {} /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -161,7 +161,7 @@ pub unsafe extern "C" fn wasmer_triple_new( /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -225,7 +225,7 @@ pub extern "C" fn wasmer_triple_delete(_triple: Option>) {} /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/value.rs b/lib/c-api/src/wasm_c_api/value.rs index 130bb9782dd..737975fa881 100644 --- a/lib/c-api/src/wasm_c_api/value.rs +++ b/lib/c-api/src/wasm_c_api/value.rs @@ -42,7 +42,7 @@ pub union wasm_val_inner { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/version.rs b/lib/c-api/src/wasm_c_api/version.rs index 3d2130e8eb6..337ad738b56 100644 --- a/lib/c-api/src/wasm_c_api/version.rs +++ b/lib/c-api/src/wasm_c_api/version.rs @@ -40,7 +40,7 @@ pub unsafe extern "C" fn wasmer_version() -> *const c_char { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" @@ -98,7 +98,7 @@ pub unsafe extern "C" fn wasmer_version_patch() -> u8 { /// # Example /// /// ```rust -/// # use inline_c::assert_c; +/// # use wasmer_inline_c::assert_c; /// # fn main() { /// # (assert_c! { /// # #include "tests/wasmer.h" diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 4501b83f44f..6332db76025 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -403,7 +403,7 @@ pub unsafe extern "C" fn wasi_get_start_function( #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_wasi_get_wasi_version_snapshot0() { diff --git a/lib/c-api/src/wasm_c_api/wat.rs b/lib/c-api/src/wasm_c_api/wat.rs index fe985409882..14c6c71215e 100644 --- a/lib/c-api/src/wasm_c_api/wat.rs +++ b/lib/c-api/src/wasm_c_api/wat.rs @@ -26,7 +26,7 @@ pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t, out: &mut wasm_byte_vec #[cfg(test)] mod tests { - use inline_c::assert_c; + use wasmer_inline_c::assert_c; #[test] fn test_wat2wasm() { From 837f3ec0fe184b0508263f190701040171e38f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 12:03:43 +0200 Subject: [PATCH 11/68] Add wasmer-capi-example-runner --- lib/c-api/examples/.gitignore | 3 +- .../wasmer-capi-examples-runner/Cargo.toml | 9 + .../wasmer-capi-examples-runner/src/lib.rs | 223 ++++++++++++++++++ 3 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml create mode 100644 lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs diff --git a/lib/c-api/examples/.gitignore b/lib/c-api/examples/.gitignore index 259f7fb0864..d97fb8d9b31 100644 --- a/lib/c-api/examples/.gitignore +++ b/lib/c-api/examples/.gitignore @@ -1,6 +1,7 @@ -* + *.o +*.exe # Unignore files ending with `.c` (i.e. `wasm-c-api-wasi.c`) !*.c diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml new file mode 100644 index 00000000000..f84d124923c --- /dev/null +++ b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "wasmer-capi-examples-runner" +version = "0.1.0" +edition = "2021" +license = "MIT" + +[dependencies] +cc = "1.0" +target-lexicon = "0.11" \ No newline at end of file diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs new file mode 100644 index 00000000000..0fd1434c559 --- /dev/null +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -0,0 +1,223 @@ +#[derive(Default)] +pub struct RemoveTestsOnDrop {} + +impl Drop for RemoveTestsOnDrop { + fn drop(&mut self) { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + for entry in std::fs::read_dir(&manifest_dir).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let extension = path.extension().and_then(|s| s.to_str()); + if extension == Some("obj") || extension == Some("exe") { + println!("removing {}", path.display()); + let _ = std::fs::remove_file(&path); + } + } + if let Some(parent) = std::path::Path::new(&manifest_dir).parent() { + for entry in std::fs::read_dir(&parent).unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let extension = path.extension().and_then(|s| s.to_str()); + if extension == Some("obj") || extension == Some("exe") { + println!("removing {}", path.display()); + let _ = std::fs::remove_file(&path); + } + } + } + } +} + +#[derive(Debug)] +pub struct Config { + pub wasmer_dir: String, + pub root_dir: String, + // linux + mac + pub cflags: String, + pub ldflags: String, + pub ldlibs: String, + // windows msvc + pub msvc_cflags: String, + pub msvc_ldflags: String, + pub msvc_ldlibs: String, +} + +impl Config { + pub fn get() -> Config { + Config { + wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), + root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), + + cflags: std::env::var("CFLAGS").unwrap_or_default(), + ldflags: std::env::var("LDFLAGS").unwrap_or_default(), + ldlibs: std::env::var("LDLIBS").unwrap_or_default(), + + msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), + msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), + msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), + } + } +} + +#[cfg(test)] +pub const TESTS: &[&str] = &[ + "deprecated-header", + "early-exit", + "instance", + "imports-exports", + "exports-function", + "exports-global", + "memory", + "memory2", + "features", + "wasi", +]; + +#[test] +fn test_run() { + let _drop = RemoveTestsOnDrop::default(); + let config = Config::get(); + println!("config: {:#?}", config); + + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let host = target_lexicon::HOST.to_string(); + let target = &host; + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests + // -IC:/Users/felix/Development/wasmer/package/include + // -c -o deprecated-header.o deprecated-header.c + + if target.contains("msvc") { + for test in TESTS.iter() { + let mut build = cc::Build::new(); + let mut build = build + .cargo_metadata(false) + .warnings(true) + .static_crt(true) + .extra_warnings(true) + .warnings_into_errors(false) + .debug(config.ldflags.contains("-g")) + .host(&host) + .target(target) + .opt_level(1); + + let compiler = build.try_get_compiler().unwrap(); + let mut command = compiler.to_command(); + + command.arg(&format!("{manifest_dir}/../{test}.c")); + if !config.msvc_cflags.is_empty() { + command.arg(config.msvc_cflags.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg("/I"); + command.arg(&format!("{}/include", config.wasmer_dir)); + } + command.arg("/link"); + if !config.msvc_ldlibs.is_empty() { + command.arg(config.msvc_ldlibs.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + } + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); + + let exe_dir = match std::path::Path::new(&manifest_dir).parent() { + Some(parent) => format!("{}", parent.display()), + None => format!("{manifest_dir}"), + }; + + // run vcvars + let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); + let mut vcvars = std::process::Command::new("cmd"); + vcvars.arg("/C"); + vcvars.arg(vcvars_bat_path); + println!("running {vcvars:?}"); + + // cmd /C vcvars64.bat + let output = vcvars + .output() + .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); + + if !output.status.success() { + println!(); + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to invoke vcvars64.bat {test}"); + } + + println!("compiling {test}: {command:?}"); + + // compile + let output = command + .output() + .expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + let path = std::env::var("PATH").unwrap_or_default(); + let newpath = format!("{wasmer_dll_dir};{path}"); + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + command.env("PATH", newpath.clone()); + command.current_dir(exe_dir.clone()); + println!("executing {test}: {command:?}"); + println!("setting current dir = {exe_dir}"); + let output = command + .output() + .expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to execute {test}"); + } + } + } else { + for test in TESTS.iter() { + let mut command = std::process::Command::new("cc"); + + command.arg(config.cflags.clone()); + command.arg(config.ldflags.clone()); + command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(config.ldlibs.clone()); + command.arg("-o"); + command.arg(&format!("{manifest_dir}/../{test}")); + + // compile + let output = command + .output() + .expect(&format!("failed to compile {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}"); + } + + // execute + let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + let output = command + .output() + .expect(&format!("failed to run {command:#?}")); + if !output.status.success() { + println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to execute {test}"); + } + } + } +} + +#[cfg(test)] +fn find_vcvars64(compiler: &cc::Tool) -> Option { + if !compiler.is_like_msvc() { + return None; + } + + let path = compiler.path(); + let path = format!("{}", path.display()); + let split = path.split("VC").nth(0)?; + + Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat")) +} From 66bfb88d8374be4ffdbfae3257bfc30c6bde0c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 12:06:06 +0200 Subject: [PATCH 12/68] cargo fmt --- lib/c-api/src/wasm_c_api/unstable/engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index c114df0ec8c..b9c9cf08963 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -166,8 +166,8 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { #[cfg(test)] mod tests { - use wasmer_inline_c::assert_c; use std::env::{remove_var, set_var}; + use wasmer_inline_c::assert_c; #[test] fn test_wasmer_is_headless() { From c59ca2c3e5a43ebc29f8f5f831d8f551fa8735f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:10:30 +0200 Subject: [PATCH 13/68] Add symlink resolving to testing crates --- Cargo.lock | 2 + .../wasmer-capi-examples-runner/Cargo.toml | 3 +- .../wasmer-capi-examples-runner/src/lib.rs | 83 ++++++++++++++++++- .../tests/wasmer-c-api-test-runner/Cargo.toml | 3 +- .../tests/wasmer-c-api-test-runner/src/lib.rs | 83 ++++++++++++++++++- 5 files changed, 170 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3cd75789ff5..e5fc3ce810c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3024,6 +3024,7 @@ name = "wasmer-c-api-test-runner" version = "0.1.0" dependencies = [ "cc", + "regex", "target-lexicon 0.11.2", ] @@ -3046,6 +3047,7 @@ name = "wasmer-capi-examples-runner" version = "0.1.0" dependencies = [ "cc", + "regex", "target-lexicon 0.11.2", ] diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml index f84d124923c..1f2bf1caed1 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml +++ b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml @@ -6,4 +6,5 @@ license = "MIT" [dependencies] cc = "1.0" -target-lexicon = "0.11" \ No newline at end of file +target-lexicon = "0.11" +regex = "1.6" diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 0fd1434c559..f588d596162 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -1,3 +1,9 @@ +#[cfg(test)] +use std::error::Error; + +#[cfg(test)] +static INCLUDE_REGEX: &str = "#include \"(.*)\""; + #[derive(Default)] pub struct RemoveTestsOnDrop {} @@ -43,7 +49,7 @@ pub struct Config { impl Config { pub fn get() -> Config { - Config { + let mut config = Config { wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), @@ -54,7 +60,22 @@ impl Config { msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), + }; + + if config.wasmer_dir.is_empty() { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + if let Some(s) = manifest_dir.split("wasmer").next() { + config.wasmer_dir = s.to_string() + "wasmer/package"; + } } + if config.root_dir.is_empty() { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + if let Some(s) = manifest_dir.split("wasmer/lib/c-api/examples").next() { + config.wasmer_dir = s.to_string() + "wasmer/lib/c-api/examples"; + } + } + + config } } @@ -109,6 +130,10 @@ fn test_run() { } else if !config.wasmer_dir.is_empty() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); + let mut log = String::new(); + fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) + .expect(&format!("failed to fix symlinks: {log}")); + println!("{log}"); } command.arg("/link"); if !config.msvc_ldlibs.is_empty() { @@ -209,6 +234,62 @@ fn test_run() { } } +#[cfg(test)] +fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { + log.push_str(&format!("include paths: {include_paths:?}")); + for i in include_paths { + let i = i.replacen("-I", "", 1); + let mut paths_headers = Vec::new(); + for entry in std::fs::read_dir(&i)? { + let entry = entry?; + let path = entry.path(); + let path_display = format!("{}", path.display()); + if path_display.ends_with("h") { + paths_headers.push(path_display); + } + } + fixup_symlinks_inner(&paths_headers, log)?; + } + + Ok(()) +} + +#[cfg(test)] +fn fixup_symlinks_inner( + include_paths: &[String], + log: &mut String, +) -> Result<(), Box> { + log.push_str(&format!("fixup symlinks: {include_paths:#?}")); + let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); + for path in include_paths.iter() { + let file = std::fs::read_to_string(&path)?; + let lines_3 = file.lines().take(3).collect::>(); + log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); + + let parent = std::path::Path::new(&path).parent().unwrap(); + if let Ok(symlink) = std::fs::read_to_string(parent.clone().join(&file)) { + log.push_str(&format!("symlinking {path:?}\n")); + std::fs::write(&path, symlink)?; + } + + // follow #include directives and recurse + let filepaths = regex + .captures_iter(&file) + .map(|c| c[1].to_string()) + .collect::>(); + log.push_str(&format!("regex captures: ({path:?}): {:#?}\n", filepaths)); + let joined_filepaths = filepaths + .iter() + .filter_map(|s| { + let path = parent.clone().join(s); + Some(format!("{}", path.display())) + }) + .collect::>(); + fixup_symlinks_inner(&joined_filepaths, log)?; + } + Ok(()) +} + #[cfg(test)] fn find_vcvars64(compiler: &cc::Tool) -> Option { if !compiler.is_like_msvc() { diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml index 6d63f720412..790a872d41a 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml +++ b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] cc = "1.0" -target-lexicon = "0.11" \ No newline at end of file +target-lexicon = "0.11" +regex = "1.6" diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index ab55946b93a..dab19afd95f 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -1,3 +1,10 @@ +#[cfg(test)] +use std::error::Error; + +#[cfg(test)] +static INCLUDE_REGEX: &str = "#include \"(.*)\""; + + #[derive(Debug)] pub struct Config { pub wasmer_dir: String, @@ -14,7 +21,7 @@ pub struct Config { impl Config { pub fn get() -> Config { - Config { + let mut config = Config { wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), @@ -25,7 +32,21 @@ impl Config { msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), + }; + + if config.wasmer_dir.is_empty() { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + if let Some(s) = manifest_dir.split("wasmer").next() { + config.wasmer_dir = s.to_string() + "wasmer/package"; + } + } + if config.root_dir.is_empty() { + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + if let Some(s) = manifest_dir.split("wasmer/lib/c-api/tests").next() { + config.wasmer_dir = s.to_string() + "wasmer/lib/c-api/tests"; + } } + config } } @@ -113,6 +134,10 @@ fn test_ok() { } else if !config.wasmer_dir.is_empty() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); + let mut log = String::new(); + fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) + .expect(&format!("failed to fix symlinks: {log}")); + println!("{log}"); } command.arg("/link"); if !config.msvc_ldlibs.is_empty() { @@ -227,6 +252,62 @@ fn test_ok() { } } +#[cfg(test)] +fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { + log.push_str(&format!("include paths: {include_paths:?}")); + for i in include_paths { + let i = i.replacen("-I", "", 1); + let mut paths_headers = Vec::new(); + for entry in std::fs::read_dir(&i)? { + let entry = entry?; + let path = entry.path(); + let path_display = format!("{}", path.display()); + if path_display.ends_with("h") { + paths_headers.push(path_display); + } + } + fixup_symlinks_inner(&paths_headers, log)?; + } + + Ok(()) +} + +#[cfg(test)] +fn fixup_symlinks_inner( + include_paths: &[String], + log: &mut String, +) -> Result<(), Box> { + log.push_str(&format!("fixup symlinks: {include_paths:#?}")); + let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); + for path in include_paths.iter() { + let file = std::fs::read_to_string(&path)?; + let lines_3 = file.lines().take(3).collect::>(); + log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); + + let parent = std::path::Path::new(&path).parent().unwrap(); + if let Ok(symlink) = std::fs::read_to_string(parent.clone().join(&file)) { + log.push_str(&format!("symlinking {path:?}\n")); + std::fs::write(&path, symlink)?; + } + + // follow #include directives and recurse + let filepaths = regex + .captures_iter(&file) + .map(|c| c[1].to_string()) + .collect::>(); + log.push_str(&format!("regex captures: ({path:?}): {:#?}\n", filepaths)); + let joined_filepaths = filepaths + .iter() + .filter_map(|s| { + let path = parent.clone().join(s); + Some(format!("{}", path.display())) + }) + .collect::>(); + fixup_symlinks_inner(&joined_filepaths, log)?; + } + Ok(()) +} + #[cfg(test)] fn find_vcvars64(compiler: &cc::Tool) -> Option { if !compiler.is_like_msvc() { From 97e5ffe264c5aa259d559cc6134db106c8b75890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:16:06 +0200 Subject: [PATCH 14/68] cargo fmt --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 7 ++----- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index f588d596162..bd769ad19ec 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -132,7 +132,7 @@ fn test_run() { command.arg(&format!("{}/include", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) - .expect(&format!("failed to fix symlinks: {log}")); + .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } command.arg("/link"); @@ -255,10 +255,7 @@ fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box< } #[cfg(test)] -fn fixup_symlinks_inner( - include_paths: &[String], - log: &mut String, -) -> Result<(), Box> { +fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<(), Box> { log.push_str(&format!("fixup symlinks: {include_paths:#?}")); let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); for path in include_paths.iter() { diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index dab19afd95f..298ee368fa3 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -4,7 +4,6 @@ use std::error::Error; #[cfg(test)] static INCLUDE_REGEX: &str = "#include \"(.*)\""; - #[derive(Debug)] pub struct Config { pub wasmer_dir: String, @@ -136,7 +135,7 @@ fn test_ok() { command.arg(&format!("{}/include", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) - .expect(&format!("failed to fix symlinks: {log}")); + .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } command.arg("/link"); @@ -273,10 +272,7 @@ fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box< } #[cfg(test)] -fn fixup_symlinks_inner( - include_paths: &[String], - log: &mut String, -) -> Result<(), Box> { +fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<(), Box> { log.push_str(&format!("fixup symlinks: {include_paths:#?}")); let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); for path in include_paths.iter() { From 7e851ffcbbd65846c0ee67873b18b85c1d6c23be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:33:55 +0200 Subject: [PATCH 15/68] Add "best try" fix to find wasmer binary in tests --- tests/integration/cli/src/assets.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/cli/src/assets.rs b/tests/integration/cli/src/assets.rs index 15220ebbbdc..48c2d93fc9b 100644 --- a/tests/integration/cli/src/assets.rs +++ b/tests/integration/cli/src/assets.rs @@ -63,6 +63,14 @@ pub fn get_wasmer_path() -> PathBuf { ret = PathBuf::from(format!("{}wasmer", WASMER_TARGET_PATH2)); } if !ret.exists() { + if let Some(s) = env!("CARGO_MANIFEST_DIR").split("wasmer").next() { + #[cfg(target_os = "windows")] { + return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer.exe")).to_path_buf(); + } + #[cfg(not(target_os = "windows"))] { + return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer")).to_path_buf(); + } + } panic!("Could not find wasmer executable path! {:?}", ret); } ret From 29b8ed93eab1c7194914828b2a8c358591c28763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:40:18 +0200 Subject: [PATCH 16/68] cargo fmt --- tests/integration/cli/src/assets.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/integration/cli/src/assets.rs b/tests/integration/cli/src/assets.rs index 48c2d93fc9b..8fe5dbc79c3 100644 --- a/tests/integration/cli/src/assets.rs +++ b/tests/integration/cli/src/assets.rs @@ -64,11 +64,15 @@ pub fn get_wasmer_path() -> PathBuf { } if !ret.exists() { if let Some(s) = env!("CARGO_MANIFEST_DIR").split("wasmer").next() { - #[cfg(target_os = "windows")] { - return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer.exe")).to_path_buf(); + #[cfg(target_os = "windows")] + { + return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer.exe")) + .to_path_buf(); } - #[cfg(not(target_os = "windows"))] { - return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer")).to_path_buf(); + #[cfg(not(target_os = "windows"))] + { + return std::path::Path::new(&format!("{s}wasmer/target/release/wasmer")) + .to_path_buf(); } } panic!("Could not find wasmer executable path! {:?}", ret); From 4a7e3d0d9ba91a48ada9be1edbc3723c69348762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 13:55:34 +0200 Subject: [PATCH 17/68] Added proper resolving of WASMER_DIR --- lib/c-api/examples/.gitignore | 4 +++- .../wasmer-capi-examples-runner/src/lib.rs | 22 ++++++++++--------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 22 ++++++++++--------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/c-api/examples/.gitignore b/lib/c-api/examples/.gitignore index d97fb8d9b31..be618742b91 100644 --- a/lib/c-api/examples/.gitignore +++ b/lib/c-api/examples/.gitignore @@ -1,5 +1,5 @@ - +* *.o *.exe @@ -9,3 +9,5 @@ !Makefile !assets !assets/* +!wasmer-capi-examples-runner +!wasmer-capi-examples-runner/* diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index bd769ad19ec..21bdff795e2 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -14,7 +14,7 @@ impl Drop for RemoveTestsOnDrop { let entry = entry.unwrap(); let path = entry.path(); let extension = path.extension().and_then(|s| s.to_str()); - if extension == Some("obj") || extension == Some("exe") { + if extension == Some("obj") || extension == Some("exe") || extension == Some("o") { println!("removing {}", path.display()); let _ = std::fs::remove_file(&path); } @@ -24,7 +24,7 @@ impl Drop for RemoveTestsOnDrop { let entry = entry.unwrap(); let path = entry.path(); let extension = path.extension().and_then(|s| s.to_str()); - if extension == Some("obj") || extension == Some("exe") { + if extension == Some("obj") || extension == Some("exe") || extension == Some("o") { println!("removing {}", path.display()); let _ = std::fs::remove_file(&path); } @@ -62,17 +62,19 @@ impl Config { msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), }; + // resolve the path until the /wasmer root directory + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); + let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); + path2.pop(); + let wasmer_base_dir = path2.join("wasmer"); + if config.wasmer_dir.is_empty() { - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - if let Some(s) = manifest_dir.split("wasmer").next() { - config.wasmer_dir = s.to_string() + "wasmer/package"; - } + println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); + config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; } if config.root_dir.is_empty() { - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - if let Some(s) = manifest_dir.split("wasmer/lib/c-api/examples").next() { - config.wasmer_dir = s.to_string() + "wasmer/lib/c-api/examples"; - } + config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/examples"; } config diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 298ee368fa3..7e7c3f7d331 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -33,18 +33,20 @@ impl Config { msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), }; + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); + let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); + path2.pop(); + let wasmer_base_dir = path2.join("wasmer"); + if config.wasmer_dir.is_empty() { - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - if let Some(s) = manifest_dir.split("wasmer").next() { - config.wasmer_dir = s.to_string() + "wasmer/package"; - } + println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); + config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; } if config.root_dir.is_empty() { - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - if let Some(s) = manifest_dir.split("wasmer/lib/c-api/tests").next() { - config.wasmer_dir = s.to_string() + "wasmer/lib/c-api/tests"; - } + config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/examples"; } + config } } @@ -59,7 +61,7 @@ impl Drop for RemoveTestsOnDrop { let entry = entry.unwrap(); let path = entry.path(); let extension = path.extension().and_then(|s| s.to_str()); - if extension == Some("obj") || extension == Some("exe") { + if extension == Some("obj") || extension == Some("exe") || extension == Some("o") { println!("removing {}", path.display()); let _ = std::fs::remove_file(&path); } @@ -69,7 +71,7 @@ impl Drop for RemoveTestsOnDrop { let entry = entry.unwrap(); let path = entry.path(); let extension = path.extension().and_then(|s| s.to_str()); - if extension == Some("obj") || extension == Some("exe") { + if extension == Some("obj") || extension == Some("exe") || extension == Some("o") { println!("removing {}", path.display()); let _ = std::fs::remove_file(&path); } From 4f9b9a82cd7cb4cfc635d145cd2932c647b383a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 14:05:37 +0200 Subject: [PATCH 18/68] Fix include paths on linux CC --- .../wasmer-capi-examples-runner/src/lib.rs | 14 ++++++++++++-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 21bdff795e2..efbf14d48f1 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -205,10 +205,20 @@ fn test_run() { for test in TESTS.iter() { let mut command = std::process::Command::new("cc"); - command.arg(config.cflags.clone()); + if !config.cflags.is_empty() { + command.arg(config.cflags.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg("-I"); + command.arg(&format!("{}/include", config.wasmer_dir)); + } command.arg(config.ldflags.clone()); command.arg(&format!("{manifest_dir}/../{test}.c")); - command.arg(config.ldlibs.clone()); + if !config.ldlibs.is_empty() { + command.arg(config.ldlibs.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg(&format!("-L{}/lib", config.wasmer_dir)); + command.arg(&format!("-lwasmer")); + } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 7e7c3f7d331..ecf93bb6a5d 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -216,10 +216,20 @@ fn test_ok() { for test in CAPI_BASE_TESTS.iter() { let mut command = std::process::Command::new("cc"); - command.arg(config.cflags.clone()); + if !config.cflags.is_empty() { + command.arg(config.cflags.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg("-I"); + command.arg(&format!("{}/include", config.wasmer_dir)); + } command.arg(config.ldflags.clone()); command.arg(&format!("{manifest_dir}/../{test}.c")); - command.arg(config.ldlibs.clone()); + if !config.ldlibs.is_empty() { + command.arg(config.ldlibs.clone()); + } else if !config.wasmer_dir.is_empty() { + command.arg(&format!("-L{}/lib", config.wasmer_dir)); + command.arg(&format!("-lwasmer")); + } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); From 219d0c02785a2ec2b713954ef0b2785252af1709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 14:46:41 +0200 Subject: [PATCH 19/68] Use gcc instead of cc, fix wasmer/lib/c-api in wasmer_base_dir string --- .../wasmer-capi-examples-runner/src/lib.rs | 14 ++++++++++++-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 13 +++++++++++-- lib/cli/src/commands/create_exe.rs | 15 +++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index efbf14d48f1..22e1e28be03 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -67,7 +67,11 @@ impl Config { let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); path2.pop(); - let wasmer_base_dir = path2.join("wasmer"); + let mut wasmer_base_dir = path2.join("wasmer"); + + if wasmer_base_dir.contains("wasmer/lib/c-api") { + wasmer_base_dir = wasmer_base_dir.split("wasmer/lib/c-api").next().unwrap().to_string(); + } if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); @@ -203,7 +207,13 @@ fn test_run() { } } else { for test in TESTS.iter() { - let mut command = std::process::Command::new("cc"); + + let compiler_cmd = match std::process::Command::new("cc").output() { + Ok(_) => "cc", + Err(_) => "gcc", + }; + + let mut command = std::process::Command::new(compiler_cmd); if !config.cflags.is_empty() { command.arg(config.cflags.clone()); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index ecf93bb6a5d..818b6fd3934 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -37,7 +37,11 @@ impl Config { let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); path2.pop(); - let wasmer_base_dir = path2.join("wasmer"); + let mut wasmer_base_dir = path2.join("wasmer"); + + if wasmer_base_dir.contains("wasmer/lib/c-api") { + wasmer_base_dir = wasmer_base_dir.split("wasmer/lib/c-api").next().unwrap().to_string(); + } if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); @@ -214,7 +218,12 @@ fn test_ok() { } } else { for test in CAPI_BASE_TESTS.iter() { - let mut command = std::process::Command::new("cc"); + + let compiler_cmd = match std::process::Command::new("cc").output() { + Ok(_) => "cc", + Err(_) => "gcc", + }; + let mut command = std::process::Command::new(compiler_cmd); if !config.cflags.is_empty() { command.arg(config.cflags.clone()); diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 9756b9102fd..1274982ce45 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -480,9 +480,14 @@ impl CreateExe { include_dir.pop(); include_dir.push("include"); + let compiler_cmd = match std::process::Command::new("cc").output() { + Ok(_) => "cc", + Err(_) => "gcc", + }; + let mut cmd = Command::new(zig_binary_path); let mut cmd_mut: &mut Command = cmd - .arg("cc") + .arg(compiler_cmd) .arg("-w") .arg("-fgnu-inline-asm") .arg("-fsanitize=undefined") @@ -549,7 +554,13 @@ impl CreateExe { /* Compile main function */ let compilation = { - Command::new("cc") + + let compiler_cmd = match Command::new("cc").output() { + Ok(_) => "cc", + Err(_) => "gcc", + }; + + Command::new(compiler_cmd) .arg("-c") .arg(&c_src_path) .arg(if linkcode.optimization_flag.is_empty() { From c7fcd2464a0a846dc6232c71cfd477e43a3885a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 14:48:19 +0200 Subject: [PATCH 20/68] Update dependencies --- Cargo.lock | 122 ++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5fc3ce810c..5ad67a83b23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -57,15 +57,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.63" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "arbitrary" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8931eb436ab9bf1980c6cb2b9d1ba5390cd6793b2c6e2d2ea8147da3570c2a2e" +checksum = "f44124848854b941eafdb34f05b3bcf59472f643c7e151eba7c2b69daa469ed5" dependencies = [ "derive_arbitrary", ] @@ -194,9 +194,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] @@ -279,7 +279,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ - "clap 3.2.20", + "clap 3.2.21", "heck", "indexmap", "log", @@ -364,9 +364,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.20" +version = "3.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" +checksum = "1ed5341b2301a26ab80be5cbdced622e80ed808483c52e45e3310a877d3b37d7" dependencies = [ "atty", "bitflags", @@ -759,9 +759,9 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d749b611838b7e92cba33b8552187059f2dc32f91d4d66bdc4fe5da9526b4e07" +checksum = "226ad66541d865d7a7173ad6a9e691c33fdb910ac723f4bc734b3e5294a1f931" dependencies = [ "proc-macro2", "quote", @@ -1177,9 +1177,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.47" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" +checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1264,9 +1264,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "d8bf247779e67a9082a4790b45e71ac7cfd1321331a5c856a74a9faebdab78d0" dependencies = [ "either", ] @@ -1294,9 +1294,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -1457,9 +1457,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -1570,9 +1570,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "oorandom" @@ -1649,9 +1649,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "pest" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0560d531d1febc25a3c9398a62a71256c0178f2e3443baedd9ad4bb8c9deb4" +checksum = "cb779fcf4bb850fbbb0edc96ff6cf34fd90c4b1a112ce042653280d9a7364048" dependencies = [ "thiserror", "ucd-trie", @@ -1671,9 +1671,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "plotters" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716b4eeb6c4a1d3ecc956f75b43ec2e8e8ba80026413e70a3f41fd3313d3492b" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" dependencies = [ "num-traits", "plotters-backend", @@ -2081,7 +2081,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.13", + "semver 1.0.14", ] [[package]] @@ -2203,9 +2203,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "semver-parser" @@ -2545,18 +2545,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" dependencies = [ "proc-macro2", "quote", @@ -2735,9 +2735,9 @@ dependencies = [ [[package]] name = "ucd-trie" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicase" @@ -2750,15 +2750,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "unix_mode" @@ -2830,9 +2830,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -2840,9 +2840,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -2855,9 +2855,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2867,9 +2867,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2877,9 +2877,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -2890,15 +2890,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wasm-bindgen-test" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513df541345bb9fcc07417775f3d51bbb677daf307d8035c0afafd87dc2e6599" +checksum = "09d2fff962180c3fadf677438054b1db62bee4aa32af26a45388af07d1287e1d" dependencies = [ "console_error_panic_hook", "js-sys", @@ -2910,9 +2910,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6150d36a03e90a3cf6c12650be10626a9902d70c5270fd47d7a47e5389a10d56" +checksum = "4683da3dfc016f704c9f82cf401520c4f1cb3ee440f7f52b3d6ac29506a49ca7" dependencies = [ "proc-macro2", "quote", @@ -3059,7 +3059,7 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", - "clap 3.2.20", + "clap 3.2.21", "colored 2.0.0", "dirs", "distance", @@ -3120,7 +3120,7 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", - "clap 3.2.20", + "clap 3.2.21", "colored 2.0.0", "distance", "fern", @@ -3167,7 +3167,7 @@ dependencies = [ "rayon", "regex", "rustc_version 0.4.0", - "semver 1.0.13", + "semver 1.0.14", "smallvec", "target-lexicon 0.12.4", "wasmer-compiler", @@ -3579,9 +3579,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", From abfb861072f1e7238d5d373ed0734cdca9b42f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 14:48:58 +0200 Subject: [PATCH 21/68] cargo fmt --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 7 +++++-- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 22e1e28be03..0b8423bd2b8 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -70,7 +70,11 @@ impl Config { let mut wasmer_base_dir = path2.join("wasmer"); if wasmer_base_dir.contains("wasmer/lib/c-api") { - wasmer_base_dir = wasmer_base_dir.split("wasmer/lib/c-api").next().unwrap().to_string(); + wasmer_base_dir = wasmer_base_dir + .split("wasmer/lib/c-api") + .next() + .unwrap() + .to_string(); } if config.wasmer_dir.is_empty() { @@ -207,7 +211,6 @@ fn test_run() { } } else { for test in TESTS.iter() { - let compiler_cmd = match std::process::Command::new("cc").output() { Ok(_) => "cc", Err(_) => "gcc", diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 818b6fd3934..fe9a0abd4cf 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -40,7 +40,11 @@ impl Config { let mut wasmer_base_dir = path2.join("wasmer"); if wasmer_base_dir.contains("wasmer/lib/c-api") { - wasmer_base_dir = wasmer_base_dir.split("wasmer/lib/c-api").next().unwrap().to_string(); + wasmer_base_dir = wasmer_base_dir + .split("wasmer/lib/c-api") + .next() + .unwrap() + .to_string(); } if config.wasmer_dir.is_empty() { @@ -218,7 +222,6 @@ fn test_ok() { } } else { for test in CAPI_BASE_TESTS.iter() { - let compiler_cmd = match std::process::Command::new("cc").output() { Ok(_) => "cc", Err(_) => "gcc", From 58294b8d468c58d0073cb2bcf7b26c6f28d39337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 15:06:39 +0200 Subject: [PATCH 22/68] cargo fmt --- lib/cli/src/commands/create_exe.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 1274982ce45..a3b51f0836a 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -554,7 +554,6 @@ impl CreateExe { /* Compile main function */ let compilation = { - let compiler_cmd = match Command::new("cc").output() { Ok(_) => "cc", Err(_) => "gcc", From d267966db3c9e9b6538594257c0b7649f273ebff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 15:42:34 +0200 Subject: [PATCH 23/68] Add better debugging to wasmer-capi runner --- .../wasmer-capi-examples-runner/src/lib.rs | 40 ++++++++++------ .../tests/wasmer-c-api-test-runner/src/lib.rs | 46 ++++++++++++------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 0b8423bd2b8..9faf5846497 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -64,18 +64,7 @@ impl Config { // resolve the path until the /wasmer root directory let manifest_dir = env!("CARGO_MANIFEST_DIR"); - let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); - let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); - path2.pop(); - let mut wasmer_base_dir = path2.join("wasmer"); - - if wasmer_base_dir.contains("wasmer/lib/c-api") { - wasmer_base_dir = wasmer_base_dir - .split("wasmer/lib/c-api") - .next() - .unwrap() - .to_string(); - } + let wasmer_base_dir = find_wasmer_base_dir(); if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); @@ -89,6 +78,29 @@ impl Config { } } +fn find_wasmer_base_dir() -> String { + let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); + let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); + path2.pop(); + let mut wasmer_base_dir = path2.join("wasmer"); + + if wasmer_base_dir.contains("wasmer/lib/c-api") { + wasmer_base_dir = wasmer_base_dir + .split("wasmer/lib/c-api") + .next() + .unwrap() + .to_string(); + } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { + wasmer_base_dir = wasmer_base_dir + .split("wasmer\\lib\\c-api") + .next() + .unwrap() + .to_string(); + } + + wasmer_base_dir +} + #[cfg(test)] pub const TESTS: &[&str] = &[ "deprecated-header", @@ -241,8 +253,8 @@ fn test_run() { .expect(&format!("failed to compile {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}: {command:#?}"); } // execute diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index fe9a0abd4cf..7ec8e0ea060 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -33,32 +33,44 @@ impl Config { msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), }; + let wasmer_base_dir = find_wasmer_base_dir(); let manifest_dir = env!("CARGO_MANIFEST_DIR"); - let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); - let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); - path2.pop(); - let mut wasmer_base_dir = path2.join("wasmer"); - - if wasmer_base_dir.contains("wasmer/lib/c-api") { - wasmer_base_dir = wasmer_base_dir - .split("wasmer/lib/c-api") - .next() - .unwrap() - .to_string(); - } if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; } if config.root_dir.is_empty() { - config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/examples"; + config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/tests"; } config } } +fn find_wasmer_base_dir() -> String { + let wasmer_base_dir = env!("CARGO_MANIFEST_DIR"); + let mut path2 = wasmer_base_dir.split("wasmer").collect::>(); + path2.pop(); + let mut wasmer_base_dir = path2.join("wasmer"); + + if wasmer_base_dir.contains("wasmer/lib/c-api") { + wasmer_base_dir = wasmer_base_dir + .split("wasmer/lib/c-api") + .next() + .unwrap() + .to_string(); + } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { + wasmer_base_dir = wasmer_base_dir + .split("wasmer\\lib\\c-api") + .next() + .unwrap() + .to_string(); + } + + wasmer_base_dir +} + #[derive(Default)] pub struct RemoveTestsOnDrop {} @@ -251,8 +263,8 @@ fn test_ok() { .expect(&format!("failed to compile {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to compile {test}"); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to compile {test}: {command:#?}"); } // execute @@ -262,8 +274,8 @@ fn test_ok() { .expect(&format!("failed to run {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to execute {test}"); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + panic!("failed to execute {test}: {command:#?}"); } } } From d70f03ae27cdb61faaf5d456e3c889dd11d0fa6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 17:16:20 +0200 Subject: [PATCH 24/68] Run "make package" in test code if the include dirs don't exist --- .../wasmer-capi-examples-runner/src/lib.rs | 18 ++++++++++++++++++ .../tests/wasmer-c-api-test-runner/src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 9faf5846497..f473f67536c 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -69,6 +69,24 @@ impl Config { if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; + if !std::path::Path::new(&config.wasmer_dir).exists() { + + if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")).exists() { + println!("running make build-capi..."); + // run make build-capi + let mut cmd = std::process::Command::new("make"); + cmd.arg("build-capi"); + cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + let _ = cmd.output(); + } + + println!("running make package..."); + // run make package + let mut cmd = std::process::Command::new("make"); + cmd.arg("package"); + cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + let _ = cmd.output(); + } } if config.root_dir.is_empty() { config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/examples"; diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 7ec8e0ea060..e8cd308ad10 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -39,6 +39,24 @@ impl Config { if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; + if !std::path::Path::new(&config.wasmer_dir).exists() { + + if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")).exists() { + println!("running make build-capi..."); + // run make build-capi + let mut cmd = std::process::Command::new("make"); + cmd.arg("build-capi"); + cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + let _ = cmd.output(); + } + + println!("running make package..."); + // run make package + let mut cmd = std::process::Command::new("make"); + cmd.arg("package"); + cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + let _ = cmd.output(); + } } if config.root_dir.is_empty() { config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/tests"; From 04089220798a82e1a73671ce1f61f81e96779b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 17:17:29 +0200 Subject: [PATCH 25/68] cargo fmt --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 5 +++-- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index f473f67536c..1df456df1cb 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -70,8 +70,9 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - - if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")).exists() { + if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")) + .exists() + { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index e8cd308ad10..b015683b941 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -40,8 +40,9 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - - if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")).exists() { + if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")) + .exists() + { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); From 18006009aa18ff8fe45552a4393dc78e2c537b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 18:23:25 +0200 Subject: [PATCH 26/68] Add more debugging to failing "make package" command --- .../wasmer-capi-examples-runner/src/lib.rs | 20 +++++++++++++++++-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 1df456df1cb..33a117b4a2b 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -78,7 +78,8 @@ impl Config { let mut cmd = std::process::Command::new("make"); cmd.arg("build-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); - let _ = cmd.output(); + let result = cmd.output(); + println!("make build-capi: {result:#?}"); } println!("running make package..."); @@ -86,7 +87,22 @@ impl Config { let mut cmd = std::process::Command::new("make"); cmd.arg("package"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); - let _ = cmd.output(); + let result = cmd.output(); + println!("make package: {result:#?}"); + + println!("list {}", config.wasmer_dir); + match std::fs::read_dir(&config.wasmer_dir) { + Ok(o) => { + for entry in o { + let entry = entry.unwrap(); + let path = entry.path(); + println!(" {:?}", path.file_name()); + } + } + Err(e) => { + println!("error in reading config.wasmer_dir: {e}"); + } + }; } } if config.root_dir.is_empty() { diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index b015683b941..1f62ab2c457 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -48,7 +48,8 @@ impl Config { let mut cmd = std::process::Command::new("make"); cmd.arg("build-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); - let _ = cmd.output(); + let result = cmd.output(); + println!("make build-capi: {result:#?}"); } println!("running make package..."); @@ -56,7 +57,22 @@ impl Config { let mut cmd = std::process::Command::new("make"); cmd.arg("package"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); - let _ = cmd.output(); + let result = cmd.output(); + println!("make package: {result:#?}"); + + println!("list {}", config.wasmer_dir); + match std::fs::read_dir(&config.wasmer_dir) { + Ok(o) => { + for entry in o { + let entry = entry.unwrap(); + let path = entry.path(); + println!(" {:?}", path.file_name()); + } + } + Err(e) => { + println!("error in reading config.wasmer_dir: {e}"); + } + }; } } if config.root_dir.is_empty() { From ec58b61b665c2750c4ba073306918bf56ea82d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 18:48:48 +0200 Subject: [PATCH 27/68] Use "make package-capi" instead of "make package" --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 4 ++-- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 33a117b4a2b..559ac28ffcd 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -82,10 +82,10 @@ impl Config { println!("make build-capi: {result:#?}"); } - println!("running make package..."); + println!("running make package-capi..."); // run make package let mut cmd = std::process::Command::new("make"); - cmd.arg("package"); + cmd.arg("package-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); let result = cmd.output(); println!("make package: {result:#?}"); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 1f62ab2c457..226c741d7c6 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -53,9 +53,9 @@ impl Config { } println!("running make package..."); - // run make package + // run make package-capi let mut cmd = std::process::Command::new("make"); - cmd.arg("package"); + cmd.arg("package-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); let result = cmd.output(); println!("make package: {result:#?}"); From dd5a5cc8071ee9c05a9a712a953557901e5403a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 21:47:59 +0200 Subject: [PATCH 28/68] Debug /include directory and don't emit empty ldflags --- .../wasmer-capi-examples-runner/src/lib.rs | 4 +++- .../tests/wasmer-c-api-test-runner/src/lib.rs | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 559ac28ffcd..e80002cf61f 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -271,7 +271,9 @@ fn test_run() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); } - command.arg(config.ldflags.clone()); + if !config.ldflags.is_empty() { + command.arg(config.ldflags.clone()); + } command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.ldlibs.is_empty() { command.arg(config.ldlibs.clone()); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 226c741d7c6..0ed31bed978 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -73,6 +73,20 @@ impl Config { println!("error in reading config.wasmer_dir: {e}"); } }; + + println!("list {}/include", config.wasmer_dir); + match std::fs::read_dir(&config.wasmer_dir) { + Ok(o) => { + for entry in o { + let entry = entry.unwrap(); + let path = entry.path(); + println!(" {:?}", path.file_name()); + } + } + Err(e) => { + println!("error in reading config.wasmer_dir: {e}"); + } + }; } } if config.root_dir.is_empty() { @@ -281,7 +295,9 @@ fn test_ok() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); } - command.arg(config.ldflags.clone()); + if !config.ldflags.is_empty() { + command.arg(config.ldflags.clone()); + } command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.ldlibs.is_empty() { command.arg(config.ldlibs.clone()); From a68b8fb4b7e9d3530d579d56f0682edb928ab909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 22:47:51 +0200 Subject: [PATCH 29/68] Set working dir on both windows and linux --- .../wasmer-capi-examples-runner/src/lib.rs | 19 ++++++++++--------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 15 ++++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index e80002cf61f..05808e7d5a2 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -164,6 +164,14 @@ fn test_run() { // -IC:/Users/felix/Development/wasmer/package/include // -c -o deprecated-header.o deprecated-header.c + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + let path = std::env::var("PATH").unwrap_or_default(); + let newpath = format!("{wasmer_dll_dir};{path}"); + let exe_dir = match std::path::Path::new(&manifest_dir).parent() { + Some(parent) => format!("{}", parent.display()), + None => format!("{manifest_dir}"), + }; + if target.contains("msvc") { for test in TESTS.iter() { let mut build = cc::Build::new(); @@ -199,14 +207,8 @@ fn test_run() { command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); - let exe_dir = match std::path::Path::new(&manifest_dir).parent() { - Some(parent) => format!("{}", parent.display()), - None => format!("{manifest_dir}"), - }; - // run vcvars let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); let mut vcvars = std::process::Command::new("cmd"); @@ -238,9 +240,6 @@ fn test_run() { panic!("failed to compile {test}"); } - let path = std::env::var("PATH").unwrap_or_default(); - let newpath = format!("{wasmer_dll_dir};{path}"); - // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); command.env("PATH", newpath.clone()); @@ -296,6 +295,8 @@ fn test_run() { // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + command.env("PATH", newpath.clone()); + command.current_dir(exe_dir.clone()); let output = command .output() .expect(&format!("failed to run {command:#?}")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 0ed31bed978..c11a4e9200c 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -75,7 +75,7 @@ impl Config { }; println!("list {}/include", config.wasmer_dir); - match std::fs::read_dir(&config.wasmer_dir) { + match std::fs::read_dir(&format!("{}/include", config.wasmer_dir)) { Ok(o) => { for entry in o { let entry = entry.unwrap(); @@ -181,6 +181,11 @@ fn test_ok() { let host = target_lexicon::HOST.to_string(); let target = &host; + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); + let path = std::env::var("PATH").unwrap_or_default(); + let newpath = format!("{wasmer_dll_dir};{path}"); + if target.contains("msvc") { for test in CAPI_BASE_TESTS.iter() { let mut build = cc::Build::new(); @@ -216,11 +221,8 @@ fn test_ok() { command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); - let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); - // run vcvars let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); let mut vcvars = std::process::Command::new("cmd"); @@ -252,9 +254,6 @@ fn test_ok() { panic!("failed to compile {test}"); } - let path = std::env::var("PATH").unwrap_or_default(); - let newpath = format!("{wasmer_dll_dir};{path}"); - // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); command.env("PATH", newpath.clone()); @@ -320,6 +319,8 @@ fn test_ok() { // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); + command.env("PATH", newpath.clone()); + command.current_dir(exe_dir.clone()); let output = command .output() .expect(&format!("failed to run {command:#?}")); From 1895dd21bbd3d29227765daae94eccd2c692445e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 15 Sep 2022 23:59:03 +0200 Subject: [PATCH 30/68] Fix problem with wasmer-inline-c dependency --- Cargo.lock | 35 ++++++++++++++++++-- lib/c-api/Cargo.toml | 7 +++- lib/c-api/src/wasm_c_api/engine.rs | 3 ++ lib/c-api/src/wasm_c_api/externals/global.rs | 3 ++ lib/c-api/src/wasm_c_api/externals/mod.rs | 3 ++ lib/c-api/src/wasm_c_api/instance.rs | 3 ++ lib/c-api/src/wasm_c_api/module.rs | 3 ++ lib/c-api/src/wasm_c_api/trap.rs | 3 ++ lib/c-api/src/wasm_c_api/unstable/engine.rs | 3 ++ lib/c-api/src/wasm_c_api/wasi/mod.rs | 3 ++ lib/c-api/src/wasm_c_api/wat.rs | 3 ++ 11 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ad67a83b23..d7c378c1c41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,6 +1232,23 @@ dependencies = [ "syn", ] +[[package]] +name = "inline-c" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340dd3d6102fa919bd20987024a6d84954c36ec691ac1efea37742ee983c8dd5" +dependencies = [ + "assert_cmd", + "cc", + "inline-c-macro", + "lazy_static", + "predicates", + "regex", + "rustc_version 0.3.3", + "target-lexicon 0.11.2", + "tempfile", +] + [[package]] name = "inline-c-macro" version = "0.1.5" @@ -3002,6 +3019,7 @@ dependencies = [ "cfg-if 1.0.0", "enumset", "field-offset", + "inline-c", "lazy_static", "libc", "paste", @@ -3221,19 +3239,30 @@ dependencies = [ [[package]] name = "wasmer-inline-c" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c5002da7f51d03c06452231ba2a4f4d84dae7f282dd3145aba01d260545210" +checksum = "e2405c99de49dc05338e5ed2eb397fe70b7128340d960507d0ba716f7d29a91a" dependencies = [ "assert_cmd", "cc", - "inline-c-macro", "lazy_static", "predicates", "regex", "rustc_version 0.3.3", "target-lexicon 0.11.2", "tempfile", + "wasmer-inline-c-macro", +] + +[[package]] +name = "wasmer-inline-c-macro" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058581df4116836c51906e346d6f49ad1b1de0129243fba6b1e1d3c206cd36d1" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version 0.3.3", ] [[package]] diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index 4ebdd632bd2..ac6b2728364 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -41,7 +41,12 @@ paste = "1.0" [dev-dependencies] field-offset = "0.3.3" -wasmer-inline-c = "0.1.0" + +[target.'cfg(target_os = "windows")'.dev-dependencies] +wasmer-inline-c = "0.1.1" + +[target.'cfg(not(target_os = "windows"))'.dev-dependencies] +inline-c = "0.1.7" [features] default = [ diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 53ad02ba03d..623f605649b 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -440,7 +440,10 @@ pub extern "C" fn wasm_engine_new_with_config( #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_engine_new() { diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index d79bd333851..a706d7029b1 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -97,7 +97,10 @@ pub unsafe extern "C" fn wasm_global_type( #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_set_host_global_immutable() { diff --git a/lib/c-api/src/wasm_c_api/externals/mod.rs b/lib/c-api/src/wasm_c_api/externals/mod.rs index 687af235901..51e6fd2d83c 100644 --- a/lib/c-api/src/wasm_c_api/externals/mod.rs +++ b/lib/c-api/src/wasm_c_api/externals/mod.rs @@ -132,7 +132,10 @@ pub extern "C" fn wasm_extern_as_table(r#extern: Option<&wasm_extern_t>) -> Opti #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_extern_copy() { diff --git a/lib/c-api/src/wasm_c_api/instance.rs b/lib/c-api/src/wasm_c_api/instance.rs index 9fff1e0ac6d..6ac151fc823 100644 --- a/lib/c-api/src/wasm_c_api/instance.rs +++ b/lib/c-api/src/wasm_c_api/instance.rs @@ -207,7 +207,10 @@ pub unsafe extern "C" fn wasm_instance_exports( #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_instance_new() { diff --git a/lib/c-api/src/wasm_c_api/module.rs b/lib/c-api/src/wasm_c_api/module.rs index e6f833b61ff..db04b0fff82 100644 --- a/lib/c-api/src/wasm_c_api/module.rs +++ b/lib/c-api/src/wasm_c_api/module.rs @@ -480,7 +480,10 @@ pub unsafe extern "C" fn wasm_module_serialize(module: &wasm_module_t, out: &mut #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_module_validate() { diff --git a/lib/c-api/src/wasm_c_api/trap.rs b/lib/c-api/src/wasm_c_api/trap.rs index 14d8d7c7431..bbe79266dae 100644 --- a/lib/c-api/src/wasm_c_api/trap.rs +++ b/lib/c-api/src/wasm_c_api/trap.rs @@ -144,7 +144,10 @@ pub unsafe extern "C" fn wasm_trap_trace( #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_trap_message_null_terminated() { diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index b9c9cf08963..36e7a80130e 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -167,7 +167,10 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { #[cfg(test)] mod tests { use std::env::{remove_var, set_var}; + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_wasmer_is_headless() { diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 6332db76025..429e573da70 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -403,7 +403,10 @@ pub unsafe extern "C" fn wasi_get_start_function( #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_wasi_get_wasi_version_snapshot0() { diff --git a/lib/c-api/src/wasm_c_api/wat.rs b/lib/c-api/src/wasm_c_api/wat.rs index 14c6c71215e..373118d27a6 100644 --- a/lib/c-api/src/wasm_c_api/wat.rs +++ b/lib/c-api/src/wasm_c_api/wat.rs @@ -26,7 +26,10 @@ pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t, out: &mut wasm_byte_vec #[cfg(test)] mod tests { + #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; #[test] fn test_wat2wasm() { From 7eb4d0fc7c566eb7798dc518d0ea3dc9e5492d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 00:03:13 +0200 Subject: [PATCH 31/68] cargo fmt --- lib/c-api/src/wasm_c_api/engine.rs | 4 ++-- lib/c-api/src/wasm_c_api/externals/global.rs | 4 ++-- lib/c-api/src/wasm_c_api/externals/mod.rs | 4 ++-- lib/c-api/src/wasm_c_api/instance.rs | 4 ++-- lib/c-api/src/wasm_c_api/module.rs | 4 ++-- lib/c-api/src/wasm_c_api/trap.rs | 4 ++-- lib/c-api/src/wasm_c_api/unstable/engine.rs | 4 ++-- lib/c-api/src/wasm_c_api/wasi/mod.rs | 4 ++-- lib/c-api/src/wasm_c_api/wat.rs | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 623f605649b..67a3c730196 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -440,10 +440,10 @@ pub extern "C" fn wasm_engine_new_with_config( #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_engine_new() { diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index a706d7029b1..0c911cf3943 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -97,10 +97,10 @@ pub unsafe extern "C" fn wasm_global_type( #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_set_host_global_immutable() { diff --git a/lib/c-api/src/wasm_c_api/externals/mod.rs b/lib/c-api/src/wasm_c_api/externals/mod.rs index 51e6fd2d83c..fdd2a419569 100644 --- a/lib/c-api/src/wasm_c_api/externals/mod.rs +++ b/lib/c-api/src/wasm_c_api/externals/mod.rs @@ -132,10 +132,10 @@ pub extern "C" fn wasm_extern_as_table(r#extern: Option<&wasm_extern_t>) -> Opti #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_extern_copy() { diff --git a/lib/c-api/src/wasm_c_api/instance.rs b/lib/c-api/src/wasm_c_api/instance.rs index 6ac151fc823..863c736c0f6 100644 --- a/lib/c-api/src/wasm_c_api/instance.rs +++ b/lib/c-api/src/wasm_c_api/instance.rs @@ -207,10 +207,10 @@ pub unsafe extern "C" fn wasm_instance_exports( #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_instance_new() { diff --git a/lib/c-api/src/wasm_c_api/module.rs b/lib/c-api/src/wasm_c_api/module.rs index db04b0fff82..480483962fb 100644 --- a/lib/c-api/src/wasm_c_api/module.rs +++ b/lib/c-api/src/wasm_c_api/module.rs @@ -480,10 +480,10 @@ pub unsafe extern "C" fn wasm_module_serialize(module: &wasm_module_t, out: &mut #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_module_validate() { diff --git a/lib/c-api/src/wasm_c_api/trap.rs b/lib/c-api/src/wasm_c_api/trap.rs index bbe79266dae..55ce4211ae1 100644 --- a/lib/c-api/src/wasm_c_api/trap.rs +++ b/lib/c-api/src/wasm_c_api/trap.rs @@ -144,10 +144,10 @@ pub unsafe extern "C" fn wasm_trap_trace( #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_trap_message_null_terminated() { diff --git a/lib/c-api/src/wasm_c_api/unstable/engine.rs b/lib/c-api/src/wasm_c_api/unstable/engine.rs index 36e7a80130e..fe3d53cb14e 100644 --- a/lib/c-api/src/wasm_c_api/unstable/engine.rs +++ b/lib/c-api/src/wasm_c_api/unstable/engine.rs @@ -166,11 +166,11 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool { #[cfg(test)] mod tests { + #[cfg(not(target_os = "windows"))] + use inline_c::assert_c; use std::env::{remove_var, set_var}; #[cfg(target_os = "windows")] use wasmer_inline_c::assert_c; - #[cfg(not(target_os = "windows"))] - use inline_c::assert_c; #[test] fn test_wasmer_is_headless() { diff --git a/lib/c-api/src/wasm_c_api/wasi/mod.rs b/lib/c-api/src/wasm_c_api/wasi/mod.rs index 429e573da70..6598ab2c608 100644 --- a/lib/c-api/src/wasm_c_api/wasi/mod.rs +++ b/lib/c-api/src/wasm_c_api/wasi/mod.rs @@ -403,10 +403,10 @@ pub unsafe extern "C" fn wasi_get_start_function( #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_wasi_get_wasi_version_snapshot0() { diff --git a/lib/c-api/src/wasm_c_api/wat.rs b/lib/c-api/src/wasm_c_api/wat.rs index 373118d27a6..4d0c3928c6e 100644 --- a/lib/c-api/src/wasm_c_api/wat.rs +++ b/lib/c-api/src/wasm_c_api/wat.rs @@ -26,10 +26,10 @@ pub unsafe extern "C" fn wat2wasm(wat: &wasm_byte_vec_t, out: &mut wasm_byte_vec #[cfg(test)] mod tests { - #[cfg(target_os = "windows")] - use wasmer_inline_c::assert_c; #[cfg(not(target_os = "windows"))] use inline_c::assert_c; + #[cfg(target_os = "windows")] + use wasmer_inline_c::assert_c; #[test] fn test_wat2wasm() { From a99a67314c4ddb1c4cf0ec4213dad87d643f7a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 11:46:41 +0200 Subject: [PATCH 32/68] Split CLI arguments with whitespace --- .../wasmer-capi-examples-runner/src/lib.rs | 49 +++++++++++++++++-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 49 +++++++++++++++++-- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 05808e7d5a2..69660573e0f 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -33,6 +33,42 @@ impl Drop for RemoveTestsOnDrop { } } +fn make_package() { + + let wasmer_root_dir = find_wasmer_base_dir(); + let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/lib")); + let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/include")); + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), + &format!("{wasmer_root_dir}/package/include/wasm.h") + ); + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), + &format!("{wasmer_root_dir}/package/include/wasmer.h") + ); + #[cfg(target_os = "windows")] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/wasmer.dll"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(target_os = "windows")] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(not(target_os = "windows"))] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/libwasmer.so"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(not(target_os = "windows"))] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), + &format!("{wasmer_root_dir}/package/lib") + ); + println!("copying done (make package)"); +} + #[derive(Debug)] pub struct Config { pub wasmer_dir: String, @@ -88,6 +124,7 @@ impl Config { cmd.arg("package-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); let result = cmd.output(); + make_package(); println!("make package: {result:#?}"); println!("list {}", config.wasmer_dir); @@ -265,17 +302,23 @@ fn test_run() { let mut command = std::process::Command::new(compiler_cmd); if !config.cflags.is_empty() { - command.arg(config.cflags.clone()); + for f in config.cflags.split_whitespace() { + command.arg(f); + } } else if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); } if !config.ldflags.is_empty() { - command.arg(config.ldflags.clone()); + for f in config.ldflags.split_whitespace() { + command.arg(f); + } } command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.ldlibs.is_empty() { - command.arg(config.ldlibs.clone()); + for f in config.ldlibs.split_whitespace() { + command.arg(f); + } } else if !config.wasmer_dir.is_empty() { command.arg(&format!("-L{}/lib", config.wasmer_dir)); command.arg(&format!("-lwasmer")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index c11a4e9200c..972376663ec 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -58,6 +58,7 @@ impl Config { cmd.arg("package-capi"); cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); let result = cmd.output(); + make_package(); println!("make package: {result:#?}"); println!("list {}", config.wasmer_dir); @@ -149,6 +150,42 @@ impl Drop for RemoveTestsOnDrop { } } +fn make_package() { + + let wasmer_root_dir = find_wasmer_base_dir(); + let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/lib")); + let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/include")); + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), + &format!("{wasmer_root_dir}/package/include/wasm.h") + ); + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), + &format!("{wasmer_root_dir}/package/include/wasmer.h") + ); + #[cfg(target_os = "windows")] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/wasmer.dll"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(target_os = "windows")] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(not(target_os = "windows"))] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/libwasmer.so"), + &format!("{wasmer_root_dir}/package/lib") + ); + #[cfg(not(target_os = "windows"))] + let _ = std::fs::copy( + &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), + &format!("{wasmer_root_dir}/package/lib") + ); + println!("copying done (make package)"); +} + #[cfg(test)] pub const CAPI_BASE_TESTS: &[&str] = &[ "wasm-c-api/example/callback", @@ -289,17 +326,23 @@ fn test_ok() { let mut command = std::process::Command::new(compiler_cmd); if !config.cflags.is_empty() { - command.arg(config.cflags.clone()); + for f in config.cflags.split_whitespace() { + command.arg(f); + } } else if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); } if !config.ldflags.is_empty() { - command.arg(config.ldflags.clone()); + for f in config.ldflags.split_whitespace() { + command.arg(f); + } } command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.ldlibs.is_empty() { - command.arg(config.ldlibs.clone()); + for f in config.ldlibs.split_whitespace() { + command.arg(f); + } } else if !config.wasmer_dir.is_empty() { command.arg(&format!("-L{}/lib", config.wasmer_dir)); command.arg(&format!("-lwasmer")); From e4d3194f1833aad55a8f2759d94948c4138611ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 12:03:16 +0200 Subject: [PATCH 33/68] cargo fmt --- .../wasmer-capi-examples-runner/src/lib.rs | 25 +++++++++---------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 25 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 69660573e0f..ee74e724e4c 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -34,37 +34,36 @@ impl Drop for RemoveTestsOnDrop { } fn make_package() { - let wasmer_root_dir = find_wasmer_base_dir(); let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/lib")); let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/include")); let _ = std::fs::copy( - &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), - &format!("{wasmer_root_dir}/package/include/wasm.h") + &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), + &format!("{wasmer_root_dir}/package/include/wasm.h"), ); let _ = std::fs::copy( - &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), - &format!("{wasmer_root_dir}/package/include/wasmer.h") + &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), + &format!("{wasmer_root_dir}/package/include/wasmer.h"), ); #[cfg(target_os = "windows")] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/wasmer.dll"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/wasmer.dll"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(target_os = "windows")] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(not(target_os = "windows"))] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/libwasmer.so"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/libwasmer.so"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(not(target_os = "windows"))] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), + &format!("{wasmer_root_dir}/package/lib"), ); println!("copying done (make package)"); } diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 972376663ec..1366ebf38f3 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -151,37 +151,36 @@ impl Drop for RemoveTestsOnDrop { } fn make_package() { - let wasmer_root_dir = find_wasmer_base_dir(); let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/lib")); let _ = std::fs::create_dir_all(&format!("{wasmer_root_dir}/package/include")); let _ = std::fs::copy( - &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), - &format!("{wasmer_root_dir}/package/include/wasm.h") + &format!("{wasmer_root_dir}/lib/c-api/tests/wasm.h"), + &format!("{wasmer_root_dir}/package/include/wasm.h"), ); let _ = std::fs::copy( - &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), - &format!("{wasmer_root_dir}/package/include/wasmer.h") + &format!("{wasmer_root_dir}/lib/c-api/tests/wasmer.h"), + &format!("{wasmer_root_dir}/package/include/wasmer.h"), ); #[cfg(target_os = "windows")] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/wasmer.dll"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/wasmer.dll"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(target_os = "windows")] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/wasmer.dll.lib"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(not(target_os = "windows"))] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/libwasmer.so"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/libwasmer.so"), + &format!("{wasmer_root_dir}/package/lib"), ); #[cfg(not(target_os = "windows"))] let _ = std::fs::copy( - &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), - &format!("{wasmer_root_dir}/package/lib") + &format!("{wasmer_root_dir}/target/release/libwasmer.lib"), + &format!("{wasmer_root_dir}/package/lib"), ); println!("copying done (make package)"); } From ff52789f7212822ff8e381c99c05f6a2714b786b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 12:24:47 +0200 Subject: [PATCH 34/68] Fix issue with wasmer dir not set correctly --- .../wasmer-capi-examples-runner/src/lib.rs | 14 +++++++------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index ee74e724e4c..4fa00a87970 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -103,16 +103,16 @@ impl Config { if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); - config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; + config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")) + if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")) .exists() { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); cmd.arg("build-capi"); - cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + cmd.current_dir(wasmer_base_dir.clone()); let result = cmd.output(); println!("make build-capi: {result:#?}"); } @@ -121,7 +121,7 @@ impl Config { // run make package let mut cmd = std::process::Command::new("make"); cmd.arg("package-capi"); - cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + cmd.current_dir(wasmer_base_dir.clone()); let result = cmd.output(); make_package(); println!("make package: {result:#?}"); @@ -142,7 +142,7 @@ impl Config { } } if config.root_dir.is_empty() { - config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/examples"; + config.root_dir = wasmer_base_dir + "/lib/c-api/examples"; } config @@ -160,13 +160,13 @@ fn find_wasmer_base_dir() -> String { .split("wasmer/lib/c-api") .next() .unwrap() - .to_string(); + .to_string() + "wasmer"; } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { wasmer_base_dir = wasmer_base_dir .split("wasmer\\lib\\c-api") .next() .unwrap() - .to_string(); + .to_string() + "wasmer"; } wasmer_base_dir diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 1366ebf38f3..1b12f16d007 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -38,16 +38,16 @@ impl Config { if config.wasmer_dir.is_empty() { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); - config.wasmer_dir = wasmer_base_dir.clone() + "wasmer/package"; + config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}wasmer/target/release")) + if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")) .exists() { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); cmd.arg("build-capi"); - cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + cmd.current_dir(wasmer_base_dir.clone()); let result = cmd.output(); println!("make build-capi: {result:#?}"); } @@ -56,7 +56,7 @@ impl Config { // run make package-capi let mut cmd = std::process::Command::new("make"); cmd.arg("package-capi"); - cmd.current_dir(wasmer_base_dir.clone() + "wasmer"); + cmd.current_dir(wasmer_base_dir.clone()); let result = cmd.output(); make_package(); println!("make package: {result:#?}"); @@ -91,7 +91,7 @@ impl Config { } } if config.root_dir.is_empty() { - config.root_dir = wasmer_base_dir + "wasmer/lib/c-api/tests"; + config.root_dir = wasmer_base_dir + "/lib/c-api/tests"; } config @@ -109,13 +109,13 @@ fn find_wasmer_base_dir() -> String { .split("wasmer/lib/c-api") .next() .unwrap() - .to_string(); + .to_string() + "wasmer"; } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { wasmer_base_dir = wasmer_base_dir .split("wasmer\\lib\\c-api") .next() .unwrap() - .to_string(); + .to_string() + "wasmer"; } wasmer_base_dir From dd1c7478ef0973e20e5c945ea4871f30cf291a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 13:13:19 +0200 Subject: [PATCH 35/68] Add root_dir to include paths --- .../examples/wasmer-capi-examples-runner/src/lib.rs | 12 +++++++----- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 4fa00a87970..cf7cea24d64 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -105,9 +105,7 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")) - .exists() - { + if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")).exists() { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); @@ -160,13 +158,15 @@ fn find_wasmer_base_dir() -> String { .split("wasmer/lib/c-api") .next() .unwrap() - .to_string() + "wasmer"; + .to_string() + + "wasmer"; } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { wasmer_base_dir = wasmer_base_dir .split("wasmer\\lib\\c-api") .next() .unwrap() - .to_string() + "wasmer"; + .to_string() + + "wasmer"; } wasmer_base_dir @@ -307,6 +307,8 @@ fn test_run() { } else if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg("-I"); + command.arg(&config.root_dir); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 1b12f16d007..fc1a5b43445 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -40,9 +40,7 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")) - .exists() - { + if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")).exists() { println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); @@ -109,13 +107,15 @@ fn find_wasmer_base_dir() -> String { .split("wasmer/lib/c-api") .next() .unwrap() - .to_string() + "wasmer"; + .to_string() + + "wasmer"; } else if wasmer_base_dir.contains("wasmer\\lib\\c-api") { wasmer_base_dir = wasmer_base_dir .split("wasmer\\lib\\c-api") .next() .unwrap() - .to_string() + "wasmer"; + .to_string() + + "wasmer"; } wasmer_base_dir @@ -331,6 +331,8 @@ fn test_ok() { } else if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg("-I"); + command.arg(&config.root_dir); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { From 582ce847e5a88997d8c39474ddbeb6e8e955c255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 15:34:47 +0200 Subject: [PATCH 36/68] Try to fix windows build again --- .../wasmer-capi-examples-runner/src/lib.rs | 18 ++++++++++++++---- .../tests/wasmer-c-api-test-runner/src/lib.rs | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index cf7cea24d64..70db298b217 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -232,8 +232,11 @@ fn test_run() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); let mut log = String::new(); - fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) - .expect(&format!("failed to fix symlinks: {log}")); + fixup_symlinks(&[ + format!("{}/include", config.wasmer_dir), + format!("{}", config.root_dir), + ], &mut log) + .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } command.arg("/link"); @@ -359,7 +362,11 @@ fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box< for i in include_paths { let i = i.replacen("-I", "", 1); let mut paths_headers = Vec::new(); - for entry in std::fs::read_dir(&i)? { + let readdir = match std::fs::read_dir(&i) { + Ok(o) => o, + Err(_) => continue, + }; + for entry in readdir { let entry = entry?; let path = entry.path(); let path_display = format!("{}", path.display()); @@ -378,7 +385,10 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() log.push_str(&format!("fixup symlinks: {include_paths:#?}")); let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); for path in include_paths.iter() { - let file = std::fs::read_to_string(&path)?; + let file = match std::fs::read_to_string(&path) { + Ok(o) => o, + _ => continue, + }; let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index fc1a5b43445..b597d71c60a 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -246,8 +246,11 @@ fn test_ok() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); let mut log = String::new(); - fixup_symlinks(&[format!("{}/include", config.wasmer_dir)], &mut log) - .expect(&format!("failed to fix symlinks: {log}")); + fixup_symlinks(&[ + format!("{}/include", config.wasmer_dir), + format!("{}", config.root_dir), + ], &mut log) + .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } command.arg("/link"); @@ -389,7 +392,11 @@ fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box< for i in include_paths { let i = i.replacen("-I", "", 1); let mut paths_headers = Vec::new(); - for entry in std::fs::read_dir(&i)? { + let readdir = match std::fs::read_dir(&i) { + Ok(o) => o, + Err(_) => continue, + }; + for entry in readdir { let entry = entry?; let path = entry.path(); let path_display = format!("{}", path.display()); @@ -408,7 +415,10 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() log.push_str(&format!("fixup symlinks: {include_paths:#?}")); let regex = regex::Regex::new(INCLUDE_REGEX).unwrap(); for path in include_paths.iter() { - let file = std::fs::read_to_string(&path)?; + let file = match std::fs::read_to_string(&path) { + Ok(o) => o, + _ => continue, + }; let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); From 740d78d9b1942db1e49146c7764b87ac27312ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 17:40:46 +0200 Subject: [PATCH 37/68] Add tmate to github CI --- .github/workflows/build.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8411bd32a32..3ee988b000d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,6 +87,10 @@ jobs: TARGET: ${{ matrix.target }} steps: - uses: actions/checkout@v3 + - uses: actions/checkout@v2 + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | @@ -268,6 +272,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 - uses: dtolnay/rust-toolchain@stable with: toolchain: 1.61 From dd7e9b2107fe004e7717d8d808d01cf5760986db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 17:42:16 +0200 Subject: [PATCH 38/68] Add wasmer root dir as include directory --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 2 ++ lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 70db298b217..9201e9bb056 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -231,6 +231,8 @@ fn test_run() { } else if !config.wasmer_dir.is_empty() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg("/I"); + command.arg(&format!("{}", config.root_dir)); let mut log = String::new(); fixup_symlinks(&[ format!("{}/include", config.wasmer_dir), diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index b597d71c60a..cab361d0ea8 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -245,6 +245,8 @@ fn test_ok() { } else if !config.wasmer_dir.is_empty() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg("/I"); + command.arg(&format!("{}/include", config.root_dir)); let mut log = String::new(); fixup_symlinks(&[ format!("{}/include", config.wasmer_dir), From 906d9338cccc57ca0fe939703e4652b4887ccce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 17:49:05 +0200 Subject: [PATCH 39/68] List directory if cc fails --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 7 +++++++ lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 9201e9bb056..3ba80f4008b 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -352,6 +352,13 @@ fn test_run() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + println!("listing {manifest_dir}/../{test}:"); + if let Ok(r) = std::fs::read_dir(&format!("{manifest_dir}/../")) { + for entry in r { + let entry = entry.unwrap(); + println!(" {entry:?}"); + } + } panic!("failed to execute {test}"); } } diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index cab361d0ea8..2a7069c9121 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -376,6 +376,13 @@ fn test_ok() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + println!("listing {manifest_dir}/../{test}:"); + if let Ok(r) = std::fs::read_dir(&format!("{manifest_dir}/../")) { + for entry in r { + let entry = entry.unwrap(); + println!(" {entry:?}"); + } + } panic!("failed to execute {test}: {command:#?}"); } } From 2ed90eabf654e69479fb5d8bda72684ad075a199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 16 Sep 2022 20:22:30 +0200 Subject: [PATCH 40/68] Add tmate properly and change include path order --- .github/workflows/build.yml | 3 --- .github/workflows/test-sys.yaml | 2 ++ lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ee988b000d..82b6320115d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,9 +88,6 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/checkout@v2 - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 3afacb5b53f..ddb35f6a69f 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -97,6 +97,8 @@ jobs: SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }} steps: - uses: actions/checkout@v3 + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 2a7069c9121..3f17c3d00b9 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -244,9 +244,9 @@ fn test_ok() { command.arg(config.msvc_cflags.clone()); } else if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg(&format!("{}", config.root_dir)); command.arg("/I"); - command.arg(&format!("{}/include", config.root_dir)); + command.arg(&format!("{}/include", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks(&[ format!("{}/include", config.wasmer_dir), @@ -334,10 +334,10 @@ fn test_ok() { command.arg(f); } } else if !config.wasmer_dir.is_empty() { - command.arg("-I"); - command.arg(&format!("{}/include", config.wasmer_dir)); command.arg("-I"); command.arg(&config.root_dir); + command.arg("-I"); + command.arg(&format!("{}/include", config.wasmer_dir)); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { From 399510190c1a46251824f490fd208c73771d79d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Sun, 18 Sep 2022 23:44:26 +0200 Subject: [PATCH 41/68] Trigger CI again --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 3ba80f4008b..6fca2b7ce4a 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -359,7 +359,7 @@ fn test_run() { println!(" {entry:?}"); } } - panic!("failed to execute {test}"); + panic!("failed to execute {test} executable"); } } } From 78c24a512e73b53b4fe0354b895ca6a2d3978c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 08:13:11 +0200 Subject: [PATCH 42/68] Remove tmate (session times out) --- .github/workflows/build.yml | 3 --- .github/workflows/test-sys.yaml | 2 -- 2 files changed, 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 82b6320115d..42b171fe5fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -270,9 +270,6 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/checkout@v2 - - name: Setup tmate session - if: ${{ failure() }} - uses: mxschmitt/action-tmate@v3 - uses: dtolnay/rust-toolchain@stable with: toolchain: 1.61 diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index ddb35f6a69f..3afacb5b53f 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -97,8 +97,6 @@ jobs: SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }} steps: - uses: actions/checkout@v3 - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | From 6b5c0e93cb77774c050e86da21451866e5756ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 08:16:42 +0200 Subject: [PATCH 43/68] Use upterm instead of tmate --- .github/workflows/test-sys.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 3afacb5b53f..fe17d0ac449 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -97,6 +97,8 @@ jobs: SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }} steps: - uses: actions/checkout@v3 + - name: Setup upterm session + uses: lhotari/action-upterm@v1 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | From 121003659573be427d742fc2ac87dc52a1fee79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 09:56:21 +0200 Subject: [PATCH 44/68] Remove upterm (times out on CI) --- .github/workflows/test-sys.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index fe17d0ac449..3afacb5b53f 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -97,8 +97,6 @@ jobs: SCCACHE_AZURE_CONNECTION_STRING: ${{ secrets.SCCACHE_AZURE_CONNECTION_STRING }} steps: - uses: actions/checkout@v3 - - name: Setup upterm session - uses: lhotari/action-upterm@v1 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | From 6b800783a2d6db966abdcff750eb6d50efae8920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 10:19:28 +0200 Subject: [PATCH 45/68] Try debugging directory file paths with exa on failure --- lib/c-api/examples/Makefile | 5 +++-- lib/c-api/tests/Makefile | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 192df90fb15..2802e37e350 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -3,6 +3,7 @@ WASMER_DIR:=$(realpath $(WASMER_DIR)) $(info Using provided WASMER_DIR=$(WASMER_DIR)) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +ROOT_DIR_PARENT:=$(shell dirname $(ROOT_DIR)) MSVC_CFLAGS:="" MSVC_LDFLAGS:="" @@ -34,8 +35,8 @@ ALL = deprecated-header early-exit instance imports-exports exports-function exp .PHONY: run .SILENT: run -run: - WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture +run: + cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 1 .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 9c02b82c8f7..2787906c60e 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -3,6 +3,7 @@ WASMER_DIR:=$(realpath $(WASMER_DIR)) $(info Using provided WASMER_DIR=$(WASMER_DIR)) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) +ROOT_DIR_PARENT:=$(shell dirname $(ROOT_DIR)) MSVC_CFLAGS:="" MSVC_LDFLAGS:="" @@ -35,7 +36,7 @@ $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) test: - WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture + cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 1 .SILENT: clean .PHONY: clean From 463575b4c465806571f279ef8cc58f48872f97cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 13:40:11 +0200 Subject: [PATCH 46/68] Invoke exa via Rust since it doesn't seem to be working with Makefiles --- .../wasmer-capi-examples-runner/src/lib.rs | 34 +++++++++++++++ .../tests/wasmer-c-api-test-runner/src/lib.rs | 41 +++++++++++++++---- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 6fca2b7ce4a..f9d6d2967dd 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -271,6 +271,8 @@ fn test_run() { println!("compiling {test}: {command:?}"); + print_wasmer_root_to_stdout(&config); + // compile let output = command .output() @@ -278,6 +280,7 @@ fn test_run() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}"); } @@ -293,6 +296,7 @@ fn test_run() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to execute {test}"); } } @@ -365,6 +369,36 @@ fn test_run() { } } +#[cfg(test)] +fn print_wasmer_root_to_stdout(config: &Config) { + println!("print_wasmer_root_to_stdout"); + + let mut cmd = std::process::Command::new("cargo"); + cmd.arg("install"); + cmd.arg("exa"); + let _ = cmd.output().unwrap(); + + println!("exa installed, listing wasmer dir"); + + let mut cmd = std::process::Command::new("exa"); + cmd.arg("--tree"); + cmd.arg(&config.wasmer_dir); + let o = cmd.output().unwrap(); + println!("{}", String::from_utf8_lossy(&o.stdout)); + println!("{}", String::from_utf8_lossy(&o.stderr)); + + println!("exa installed, listing root dir"); + + let mut cmd = std::process::Command::new("exa"); + cmd.arg("--tree"); + cmd.arg(&config.root_dir); + let o = cmd.output().unwrap(); + println!("{}", String::from_utf8_lossy(&o.stdout)); + println!("{}", String::from_utf8_lossy(&o.stderr)); + + println!("printed"); +} + #[cfg(test)] fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { log.push_str(&format!("include paths: {include_paths:?}")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 3f17c3d00b9..2742a95b2d4 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -356,6 +356,8 @@ fn test_ok() { command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); + print_wasmer_root_to_stdout(&config); + // compile let output = command .output() @@ -363,6 +365,7 @@ fn test_ok() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}: {command:#?}"); } @@ -376,13 +379,7 @@ fn test_ok() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); - println!("listing {manifest_dir}/../{test}:"); - if let Ok(r) = std::fs::read_dir(&format!("{manifest_dir}/../")) { - for entry in r { - let entry = entry.unwrap(); - println!(" {entry:?}"); - } - } + print_wasmer_root_to_stdout(&config); panic!("failed to execute {test}: {command:#?}"); } } @@ -395,6 +392,36 @@ fn test_ok() { } } +#[cfg(test)] +fn print_wasmer_root_to_stdout(config: &Config) { + println!("print_wasmer_root_to_stdout"); + + let mut cmd = std::process::Command::new("cargo"); + cmd.arg("install"); + cmd.arg("exa"); + let _ = cmd.output().unwrap(); + + println!("exa installed, listing wasmer dir"); + + let mut cmd = std::process::Command::new("exa"); + cmd.arg("--tree"); + cmd.arg(&config.wasmer_dir); + let o = cmd.output().unwrap(); + println!("{}", String::from_utf8_lossy(&o.stdout)); + println!("{}", String::from_utf8_lossy(&o.stderr)); + + println!("exa installed, listing root dir"); + + let mut cmd = std::process::Command::new("exa"); + cmd.arg("--tree"); + cmd.arg(&config.root_dir); + let o = cmd.output().unwrap(); + println!("{}", String::from_utf8_lossy(&o.stdout)); + println!("{}", String::from_utf8_lossy(&o.stderr)); + + println!("printed"); +} + #[cfg(test)] fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { log.push_str(&format!("include paths: {include_paths:?}")); From 64e45ce1dd7ce621ced0e5ccddb636a87959ec2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 14:31:54 +0200 Subject: [PATCH 47/68] Debug file system paths without exa --- Cargo.lock | 2 + .../wasmer-capi-examples-runner/Cargo.toml | 1 + .../wasmer-capi-examples-runner/src/lib.rs | 46 +++++++------------ .../tests/wasmer-c-api-test-runner/Cargo.toml | 1 + .../tests/wasmer-c-api-test-runner/src/lib.rs | 40 ++++++++-------- 5 files changed, 39 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7c378c1c41..ac52e11755a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3044,6 +3044,7 @@ dependencies = [ "cc", "regex", "target-lexicon 0.11.2", + "walkdir", ] [[package]] @@ -3067,6 +3068,7 @@ dependencies = [ "cc", "regex", "target-lexicon 0.11.2", + "walkdir", ] [[package]] diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml index 1f2bf1caed1..67425ff2eff 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml +++ b/lib/c-api/examples/wasmer-capi-examples-runner/Cargo.toml @@ -8,3 +8,4 @@ license = "MIT" cc = "1.0" target-lexicon = "0.11" regex = "1.6" +walkdir = "2.3.2" \ No newline at end of file diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index f9d6d2967dd..a5e4beba262 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -343,6 +343,7 @@ fn test_run() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}: {command:#?}"); } @@ -356,13 +357,7 @@ fn test_run() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); - println!("listing {manifest_dir}/../{test}:"); - if let Ok(r) = std::fs::read_dir(&format!("{manifest_dir}/../")) { - for entry in r { - let entry = entry.unwrap(); - println!(" {entry:?}"); - } - } + print_wasmer_root_to_stdout(&config); panic!("failed to execute {test} executable"); } } @@ -373,28 +368,21 @@ fn test_run() { fn print_wasmer_root_to_stdout(config: &Config) { println!("print_wasmer_root_to_stdout"); - let mut cmd = std::process::Command::new("cargo"); - cmd.arg("install"); - cmd.arg("exa"); - let _ = cmd.output().unwrap(); - - println!("exa installed, listing wasmer dir"); - - let mut cmd = std::process::Command::new("exa"); - cmd.arg("--tree"); - cmd.arg(&config.wasmer_dir); - let o = cmd.output().unwrap(); - println!("{}", String::from_utf8_lossy(&o.stdout)); - println!("{}", String::from_utf8_lossy(&o.stderr)); - - println!("exa installed, listing root dir"); - - let mut cmd = std::process::Command::new("exa"); - cmd.arg("--tree"); - cmd.arg(&config.root_dir); - let o = cmd.output().unwrap(); - println!("{}", String::from_utf8_lossy(&o.stdout)); - println!("{}", String::from_utf8_lossy(&o.stderr)); + use walkdir::WalkDir; + + for entry in WalkDir::new(&config.wasmer_dir) + .into_iter() + .filter_map(Result::ok) { + let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); + println!("{f_name}"); + } + + for entry in WalkDir::new(&config.root_dir) + .into_iter() + .filter_map(Result::ok) { + let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); + println!("{f_name}"); + } println!("printed"); } diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml index 790a872d41a..e5ab4eb22df 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml +++ b/lib/c-api/tests/wasmer-c-api-test-runner/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" cc = "1.0" target-lexicon = "0.11" regex = "1.6" +walkdir = "2.3.2" \ No newline at end of file diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 2742a95b2d4..506cd6bfb17 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -280,6 +280,7 @@ fn test_ok() { println!(); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to invoke vcvars64.bat {test}"); } @@ -292,6 +293,7 @@ fn test_ok() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}"); } @@ -307,6 +309,7 @@ fn test_ok() { if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + print_wasmer_root_to_stdout(&config); panic!("failed to execute {test}"); } @@ -396,28 +399,21 @@ fn test_ok() { fn print_wasmer_root_to_stdout(config: &Config) { println!("print_wasmer_root_to_stdout"); - let mut cmd = std::process::Command::new("cargo"); - cmd.arg("install"); - cmd.arg("exa"); - let _ = cmd.output().unwrap(); - - println!("exa installed, listing wasmer dir"); - - let mut cmd = std::process::Command::new("exa"); - cmd.arg("--tree"); - cmd.arg(&config.wasmer_dir); - let o = cmd.output().unwrap(); - println!("{}", String::from_utf8_lossy(&o.stdout)); - println!("{}", String::from_utf8_lossy(&o.stderr)); - - println!("exa installed, listing root dir"); - - let mut cmd = std::process::Command::new("exa"); - cmd.arg("--tree"); - cmd.arg(&config.root_dir); - let o = cmd.output().unwrap(); - println!("{}", String::from_utf8_lossy(&o.stdout)); - println!("{}", String::from_utf8_lossy(&o.stderr)); + use walkdir::WalkDir; + + for entry in WalkDir::new(&config.wasmer_dir) + .into_iter() + .filter_map(Result::ok) { + let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); + println!("{f_name}"); + } + + for entry in WalkDir::new(&config.root_dir) + .into_iter() + .filter_map(Result::ok) { + let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); + println!("{f_name}"); + } println!("printed"); } From d7bb0ae982990c766a4d921facef946a670fe065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 15:57:33 +0200 Subject: [PATCH 48/68] Try to fix wrong include path on Windows MSVC --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 4 ++++ lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index a5e4beba262..dcc3ff0ea38 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -420,6 +420,10 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() Ok(o) => o, _ => continue, }; + // VERY hacky. + if file.contains("#include \"../wasmer.h\"") { + std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; + } let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 506cd6bfb17..99c9dbc3487 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -451,6 +451,10 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() Ok(o) => o, _ => continue, }; + // VERY hacky. + if file.contains("#include \"../wasmer.h\"") { + std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; + } let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); From f8a28e2653eea36d84fd7ecebdff7d583a95e677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 15:59:14 +0200 Subject: [PATCH 49/68] Debug panicking command on Linux --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 2 ++ lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index dcc3ff0ea38..72a1250060f 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -336,6 +336,7 @@ fn test_run() { command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); + println!("compile: {command:#?}"); // compile let output = command .output() @@ -351,6 +352,7 @@ fn test_run() { let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); + println!("execute: {command:#?}"); let output = command .output() .expect(&format!("failed to run {command:#?}")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 99c9dbc3487..bd84ec26a8d 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -361,6 +361,7 @@ fn test_ok() { print_wasmer_root_to_stdout(&config); + println!("compile: {command:#?}"); // compile let output = command .output() @@ -376,6 +377,7 @@ fn test_ok() { let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); + println!("execute: {command:#?}"); let output = command .output() .expect(&format!("failed to run {command:#?}")); @@ -454,7 +456,7 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() // VERY hacky. if file.contains("#include \"../wasmer.h\"") { std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; - } + }fixup_symlinks_i let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); From 40ed77cf690106546fa8c101b0b64175f9943718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 16:28:18 +0200 Subject: [PATCH 50/68] Fix typo --- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index bd84ec26a8d..80b616cac8e 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -456,7 +456,7 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() // VERY hacky. if file.contains("#include \"../wasmer.h\"") { std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; - }fixup_symlinks_i + } let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); From 186706402e0703d0300f0bf8ba02ad3c43a3fb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 16:34:04 +0200 Subject: [PATCH 51/68] Temporarily remove "make" step from CI --- .github/workflows/test-sys.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 3afacb5b53f..c98840f3cc9 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -199,14 +199,6 @@ jobs: '${{ runner.tool_cache }}/cargo-sccache/bin/sccache' -s echo 'RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache' >> $GITHUB_ENV shell: bash - - name: Test - if: matrix.run_test && matrix.os != 'windows-2019' - run: | - make - env: - TARGET: ${{ matrix.target }} - TARGET_DIR: target/${{ matrix.target }}/release - CARGO_TARGET: --target ${{ matrix.target }} - name: Test if: matrix.run_test && matrix.os != 'windows-2019' run: | From b8ec4a526e40dd4a0d68bcd1ff50bfdd30ec86c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 19 Sep 2022 17:40:58 +0200 Subject: [PATCH 52/68] Remove duplicate checkout --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 42b171fe5fe..f05afc0a324 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -268,7 +268,6 @@ jobs: name: Linux aarch64 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@stable with: From 048202b68b92472ba18d7da2be9a1f2cf0151e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 09:48:56 +0200 Subject: [PATCH 53/68] Fix LD_PRELOAD on Linux, exit with 0 instead of 1 --- lib/c-api/examples/Makefile | 2 +- .../wasmer-capi-examples-runner/src/lib.rs | 38 +++++++++++-------- lib/c-api/tests/Makefile | 6 +-- .../tests/wasmer-c-api-test-runner/src/lib.rs | 9 ++--- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 2802e37e350..70b7302be8f 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -36,7 +36,7 @@ ALL = deprecated-header early-exit instance imports-exports exports-function exp .PHONY: run .SILENT: run run: - cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 1 + cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 0 .SILENT: clean .PHONY: clean diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 72a1250060f..3b03394b80b 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -195,12 +195,9 @@ fn test_run() { let manifest_dir = env!("CARGO_MANIFEST_DIR"); let host = target_lexicon::HOST.to_string(); let target = &host; - - // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests - // -IC:/Users/felix/Development/wasmer/package/include - // -c -o deprecated-header.o deprecated-header.c - + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir); let path = std::env::var("PATH").unwrap_or_default(); let newpath = format!("{wasmer_dll_dir};{path}"); let exe_dir = match std::path::Path::new(&manifest_dir).parent() { @@ -269,14 +266,15 @@ fn test_run() { panic!("failed to invoke vcvars64.bat {test}"); } - println!("compiling {test}: {command:?}"); + println!("compiling WINDOWS {test}: {command:?}"); print_wasmer_root_to_stdout(&config); // compile let output = command .output() - .expect(&format!("failed to compile {command:#?}")); + .map_err(|e| format!("failed to compile {command:#?}: {e}")) + .unwrap(); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); @@ -335,12 +333,26 @@ fn test_run() { } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); - - println!("compile: {command:#?}"); + + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests + // -IC:/Users/felix/Development/wasmer/package/include + // -c -o deprecated-header.o deprecated-header.c + + /* + cc -I /home/runner/work/wasmer/wasmer/lib/c-api/tests + -I" "/home/runner/work/wasmer/wasmer/package/include" + "/home/runner/work/wasmer/wasmer/lib/c-api/tests/wasmer-c-api-test-runner/../wasm-c-api/example/callback.c" + "-L/home/runner/work/wasmer/wasmer/package/lib" + "-lwasmer" + "-o" "/home/runner/work/wasmer/wasmer/lib/c-api/tests/wasmer-c-api-test-runner/../wasm-c-api/example/callback" + */ + + println!("compiling LINUX {command:#?}"); // compile let output = command .output() - .expect(&format!("failed to compile {command:#?}")); + .map_err(|e| format!("failed to compile {command:#?}: {e}")) + .unwrap(); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); @@ -350,7 +362,7 @@ fn test_run() { // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); - command.env("PATH", newpath.clone()); + command.env("LD_PRELOAD", libwasmer_so_path.clone()); command.current_dir(exe_dir.clone()); println!("execute: {command:#?}"); let output = command @@ -422,10 +434,6 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() Ok(o) => o, _ => continue, }; - // VERY hacky. - if file.contains("#include \"../wasmer.h\"") { - std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; - } let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 2787906c60e..9b34d92e7bc 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -10,7 +10,7 @@ MSVC_LDFLAGS:="" MSVC_LDLIBS:="" ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) - CFLAGS = -g -I$(ROOT_DIR)/ -I$(WASMER_DIR)/include + CFLAGS = -g -I$(ROOT_DIR) -I$(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L$(WASMER_DIR)/lib -lwasmer @@ -18,7 +18,7 @@ ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) MSVC_LDFLAGS:= "" MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I$(ROOT_DIR)/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) + CFLAGS = -g -I$(ROOT_DIR)/wasm-c-api/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) @@ -36,7 +36,7 @@ $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) test: - cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 1 + cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 0 .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 80b616cac8e..a214be6755b 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -218,6 +218,7 @@ fn test_ok() { let target = &host; let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); + let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir); let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); let path = std::env::var("PATH").unwrap_or_default(); let newpath = format!("{wasmer_dll_dir};{path}"); @@ -338,7 +339,7 @@ fn test_ok() { } } else if !config.wasmer_dir.is_empty() { command.arg("-I"); - command.arg(&config.root_dir); + command.arg(&format!("{}/wasm-c-api", config.root_dir)); command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); } @@ -375,7 +376,7 @@ fn test_ok() { // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}")); - command.env("PATH", newpath.clone()); + command.env("LD_PRELOAD", libwasmer_so_path.clone()); command.current_dir(exe_dir.clone()); println!("execute: {command:#?}"); let output = command @@ -453,10 +454,6 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() Ok(o) => o, _ => continue, }; - // VERY hacky. - if file.contains("#include \"../wasmer.h\"") { - std::fs::write(&path, file.replace("#include \"../wasmer.h\"", "#include \"wasmer.h\""))?; - } let lines_3 = file.lines().take(3).collect::>(); log.push_str(&format!("first 3 lines of {path:?}: {:#?}\n", lines_3)); From 4f5699216e303d5313ca07cf1d952cfa5dff253b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 10:25:22 +0200 Subject: [PATCH 54/68] Fixed -L and -I options to contain a space --- lib/c-api/examples/Makefile | 6 +++--- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 3 ++- lib/c-api/tests/Makefile | 6 +++--- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 70b7302be8f..325b29fff2e 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -10,15 +10,15 @@ MSVC_LDFLAGS:="" MSVC_LDLIBS:="" ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) - CFLAGS = -g -I$(ROOT_DIR)/ -I$(WASMER_DIR)/include + CFLAGS = -g -I $(ROOT_DIR)/ -I $(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib - LDLIBS = -L$(WASMER_DIR)/lib -lwasmer + LDLIBS = -L $(WASMER_DIR)/lib -lwasmer MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(WASMER_DIR)/include MSVC_LDFLAGS:= "" MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I$(ROOT_DIR)/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) + CFLAGS = -g -I $(ROOT_DIR)/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 3b03394b80b..d7ea8bf200b 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -328,7 +328,8 @@ fn test_run() { command.arg(f); } } else if !config.wasmer_dir.is_empty() { - command.arg(&format!("-L{}/lib", config.wasmer_dir)); + command.arg("-L"); + command.arg(&format!("{}/lib", config.wasmer_dir)); command.arg(&format!("-lwasmer")); } command.arg("-o"); diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 9b34d92e7bc..daa476ee35c 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -10,15 +10,15 @@ MSVC_LDFLAGS:="" MSVC_LDLIBS:="" ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) - CFLAGS = -g -I$(ROOT_DIR) -I$(WASMER_DIR)/include + CFLAGS = -g -I $(ROOT_DIR) -I $(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib - LDLIBS = -L$(WASMER_DIR)/lib -lwasmer + LDLIBS = -L $(WASMER_DIR)/lib -lwasmer MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(WASMER_DIR)/include MSVC_LDFLAGS:= "" MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I$(ROOT_DIR)/wasm-c-api/ -I$(shell $(WASMER_DIR)/bin/wasmer config --includedir) + CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index a214be6755b..9035b9e4e16 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -354,7 +354,8 @@ fn test_ok() { command.arg(f); } } else if !config.wasmer_dir.is_empty() { - command.arg(&format!("-L{}/lib", config.wasmer_dir)); + command.arg("-L"); + command.arg(&format!("{}/lib", config.wasmer_dir)); command.arg(&format!("-lwasmer")); } command.arg("-o"); From 9a3f8526523cbc1f9ce06fbbc951c79bebdd7f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 10:59:12 +0200 Subject: [PATCH 55/68] Use trailing slashes for include and link dirs --- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 9035b9e4e16..4225fce2c5e 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -339,9 +339,9 @@ fn test_ok() { } } else if !config.wasmer_dir.is_empty() { command.arg("-I"); - command.arg(&format!("{}/wasm-c-api", config.root_dir)); + command.arg(&format!("{}/wasm-c-api/", config.root_dir)); command.arg("-I"); - command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg(&format!("{}/include/", config.wasmer_dir)); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { @@ -355,7 +355,7 @@ fn test_ok() { } } else if !config.wasmer_dir.is_empty() { command.arg("-L"); - command.arg(&format!("{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("-lwasmer")); } command.arg("-o"); From 114e8177e6561ab4a822ebb5815b841bb0c74c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 13:25:09 +0200 Subject: [PATCH 56/68] Try fixing wrong include paths on Windows --- lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs | 2 +- lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index d7ea8bf200b..6aaa4907552 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -329,7 +329,7 @@ fn test_run() { } } else if !config.wasmer_dir.is_empty() { command.arg("-L"); - command.arg(&format!("{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("-lwasmer")); } command.arg("-o"); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 4225fce2c5e..4fa9ecdcf66 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -245,13 +245,13 @@ fn test_ok() { command.arg(config.msvc_cflags.clone()); } else if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}", config.root_dir)); + command.arg(&format!("{}/wasm-c-api/", config.root_dir)); command.arg("/I"); - command.arg(&format!("{}/include", config.wasmer_dir)); + command.arg(&format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks(&[ - format!("{}/include", config.wasmer_dir), - format!("{}", config.root_dir), + format!("{}/include/", config.wasmer_dir), + format!("{}/wasm-c-api/", config.root_dir), ], &mut log) .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); From e7b41f87f2d3b740a41122f014d747b0f089804e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 17:07:44 +0200 Subject: [PATCH 57/68] Fix Windows build in VM: --- Makefile | 2 +- lib/c-api/examples/Makefile | 2 +- lib/c-api/tests/Makefile | 2 +- .../tests/wasmer-c-api-test-runner/src/lib.rs | 64 +++++++++++-------- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index e0ba8828a55..557ea873a19 100644 --- a/Makefile +++ b/Makefile @@ -602,7 +602,7 @@ package-capi: mkdir -p "package/lib" cp lib/c-api/wasmer.h* package/include cp lib/c-api/wasmer_wasm.h* package/include - cp lib/c-api/wasm.h* package/include + cp lib/c-api/tests/wasm-c-api/include/wasm.h* package/include cp lib/c-api/README.md package/include/README.md if [ -f $(TARGET_DIR)/wasmer.dll ]; then \ diff --git a/lib/c-api/examples/Makefile b/lib/c-api/examples/Makefile index 325b29fff2e..9bea95c12fc 100644 --- a/lib/c-api/examples/Makefile +++ b/lib/c-api/examples/Makefile @@ -36,7 +36,7 @@ ALL = deprecated-header early-exit instance imports-exports exports-function exp .PHONY: run .SILENT: run run: - cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 0 + WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-capi-examples-runner/Cargo.toml" -- --nocapture 2>&1 .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index daa476ee35c..4a4fc272238 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -36,7 +36,7 @@ $(info * LDFLAGS: $(LDFLAGS)) $(info * LDLIBS: $(LDLIBS)) test: - cargo install exa && WASMER_DIR="$(WASMER_DIR)" ROOT_DIR="$(ROOT_DIR)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LDLIBS="$(LDLIBS)" cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture 2>&1 || exa --tree $(WASMER_DIR) && exa --tree $(ROOT_DIR_PARENT) && exit 0 + cargo test --manifest-path="./wasmer-c-api-test-runner/Cargo.toml" -- --nocapture 2>&1 .SILENT: clean .PHONY: clean diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 4fa9ecdcf66..06c010031c3 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -221,7 +221,7 @@ fn test_ok() { let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir); let exe_dir = format!("{manifest_dir}/../wasm-c-api/example"); let path = std::env::var("PATH").unwrap_or_default(); - let newpath = format!("{wasmer_dll_dir};{path}"); + let newpath = format!("{};{path}", format!("{wasmer_dll_dir}").replace("/", "\\")); if target.contains("msvc") { for test in CAPI_BASE_TESTS.iter() { @@ -238,32 +238,8 @@ fn test_ok() { .opt_level(1); let compiler = build.try_get_compiler().unwrap(); - let mut command = compiler.to_command(); - command.arg(&format!("{manifest_dir}/../{test}.c")); - if !config.msvc_cflags.is_empty() { - command.arg(config.msvc_cflags.clone()); - } else if !config.wasmer_dir.is_empty() { - command.arg("/I"); - command.arg(&format!("{}/wasm-c-api/", config.root_dir)); - command.arg("/I"); - command.arg(&format!("{}/include/", config.wasmer_dir)); - let mut log = String::new(); - fixup_symlinks(&[ - format!("{}/include/", config.wasmer_dir), - format!("{}/wasm-c-api/", config.root_dir), - ], &mut log) - .expect(&format!("failed to fix symlinks: {log}")); - println!("{log}"); - } - command.arg("/link"); - if !config.msvc_ldlibs.is_empty() { - command.arg(config.msvc_ldlibs.clone()); - } else if !config.wasmer_dir.is_empty() { - command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); - command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); - } - command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); + println!("compiler {:#?}", compiler); // run vcvars let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); @@ -285,6 +261,30 @@ fn test_ok() { panic!("failed to invoke vcvars64.bat {test}"); } + let mut command = compiler.to_command(); + + command.arg(&format!("{manifest_dir}/../{test}.c")); + if !config.wasmer_dir.is_empty() { + command.arg("/I"); + command.arg(&format!("{}/wasm-c-api/", config.root_dir)); + command.arg("/I"); + command.arg(&format!("{}/include/", config.wasmer_dir)); + let mut log = String::new(); + fixup_symlinks(&[ + format!("{}/include/", config.wasmer_dir), + format!("{}/wasm-c-api/", config.root_dir), + format!("{}", config.root_dir), + ], &mut log) + .expect(&format!("failed to fix symlinks: {log}")); + println!("{log}"); + } + command.arg("/link"); + if !config.wasmer_dir.is_empty() { + command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); + command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); + } + command.arg(&format!("/OUT:{manifest_dir}/../{test}.exe")); + println!("compiling {test}: {command:?}"); // compile @@ -293,13 +293,19 @@ fn test_ok() { .expect(&format!("failed to compile {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + println!("output: {:#?}", output); print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}"); } + if std::path::Path::new(&format!("{manifest_dir}/../{test}.exe")).exists() { + println!("exe does not exist"); + } + // execute let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + println!("newpath: {}", newpath.clone()); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); println!("executing {test}: {command:?}"); @@ -309,7 +315,8 @@ fn test_ok() { .expect(&format!("failed to run {command:#?}")); if !output.status.success() { println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + println!("output: {:#?}", output); print_wasmer_root_to_stdout(&config); panic!("failed to execute {test}"); } @@ -427,6 +434,7 @@ fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box< log.push_str(&format!("include paths: {include_paths:?}")); for i in include_paths { let i = i.replacen("-I", "", 1); + let i = i.replacen("/I", "", 1); let mut paths_headers = Vec::new(); let readdir = match std::fs::read_dir(&i) { Ok(o) => o, From aea817fb47354e00f41b802a1f62307a869ce4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 22 Sep 2022 18:21:28 +0200 Subject: [PATCH 58/68] Manually force copying wasm.h when testing --- .../wasmer-capi-examples-runner/src/lib.rs | 52 +++++++++++++------ .../tests/wasmer-c-api-test-runner/src/lib.rs | 43 +++++++++++---- 2 files changed, 70 insertions(+), 25 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 6aaa4907552..a78a68042c3 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -195,7 +195,7 @@ fn test_run() { let manifest_dir = env!("CARGO_MANIFEST_DIR"); let host = target_lexicon::HOST.to_string(); let target = &host; - + let wasmer_dll_dir = format!("{}/lib", config.wasmer_dir); let libwasmer_so_path = format!("{}/lib/libwasmer.so", config.wasmer_dir); let path = std::env::var("PATH").unwrap_or_default(); @@ -231,10 +231,14 @@ fn test_run() { command.arg("/I"); command.arg(&format!("{}", config.root_dir)); let mut log = String::new(); - fixup_symlinks(&[ - format!("{}/include", config.wasmer_dir), - format!("{}", config.root_dir), - ], &mut log) + fixup_symlinks( + &[ + format!("{}/include", config.wasmer_dir), + format!("{}", config.root_dir), + ], + &mut log, + &config.root_dir, + ) .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } @@ -316,6 +320,16 @@ fn test_run() { command.arg(&format!("{}/include", config.wasmer_dir)); command.arg("-I"); command.arg(&config.root_dir); + let mut log = String::new(); + fixup_symlinks( + &[ + format!("{}/include", config.wasmer_dir), + format!("{}", config.root_dir), + ], + &mut log, + &config.root_dir, + ) + .expect(&format!("failed to fix symlinks: {log}")); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { @@ -334,17 +348,17 @@ fn test_run() { } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); - + // cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests // -IC:/Users/felix/Development/wasmer/package/include // -c -o deprecated-header.o deprecated-header.c /* cc -I /home/runner/work/wasmer/wasmer/lib/c-api/tests - -I" "/home/runner/work/wasmer/wasmer/package/include" - "/home/runner/work/wasmer/wasmer/lib/c-api/tests/wasmer-c-api-test-runner/../wasm-c-api/example/callback.c" - "-L/home/runner/work/wasmer/wasmer/package/lib" - "-lwasmer" + -I" "/home/runner/work/wasmer/wasmer/package/include" + "/home/runner/work/wasmer/wasmer/lib/c-api/tests/wasmer-c-api-test-runner/../wasm-c-api/example/callback.c" + "-L/home/runner/work/wasmer/wasmer/package/lib" + "-lwasmer" "-o" "/home/runner/work/wasmer/wasmer/lib/c-api/tests/wasmer-c-api-test-runner/../wasm-c-api/example/callback" */ @@ -386,15 +400,17 @@ fn print_wasmer_root_to_stdout(config: &Config) { use walkdir::WalkDir; for entry in WalkDir::new(&config.wasmer_dir) - .into_iter() - .filter_map(Result::ok) { + .into_iter() + .filter_map(Result::ok) + { let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); println!("{f_name}"); } for entry in WalkDir::new(&config.root_dir) - .into_iter() - .filter_map(Result::ok) { + .into_iter() + .filter_map(Result::ok) + { let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); println!("{f_name}"); } @@ -403,7 +419,13 @@ fn print_wasmer_root_to_stdout(config: &Config) { } #[cfg(test)] -fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { +fn fixup_symlinks(include_paths: &[String], log: &mut String, root_dir: &str) -> Result<(), Box> { + + let source = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm-c-api").join("include").join("wasm.h"); + let target = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm.h"); + println!("copying {} -> {}", source.display(), target.display()); + let _ = std::fs::copy(source, target); + log.push_str(&format!("include paths: {include_paths:?}")); for i in include_paths { let i = i.replacen("-I", "", 1); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 06c010031c3..f58350d66d6 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -270,11 +270,15 @@ fn test_ok() { command.arg("/I"); command.arg(&format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); - fixup_symlinks(&[ - format!("{}/include/", config.wasmer_dir), - format!("{}/wasm-c-api/", config.root_dir), - format!("{}", config.root_dir), - ], &mut log) + fixup_symlinks( + &[ + format!("{}/include/", config.wasmer_dir), + format!("{}/wasm-c-api/", config.root_dir), + format!("{}", config.root_dir), + ], + &mut log, + &config.root_dir, + ) .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } @@ -349,6 +353,17 @@ fn test_ok() { command.arg(&format!("{}/wasm-c-api/", config.root_dir)); command.arg("-I"); command.arg(&format!("{}/include/", config.wasmer_dir)); + let mut log = String::new(); + fixup_symlinks( + &[ + format!("{}/include/", config.wasmer_dir), + format!("{}/wasm-c-api/", config.root_dir), + format!("{}", config.root_dir), + ], + &mut log, + &config.root_dir, + ) + .expect(&format!("failed to fix symlinks: {log}")); } if !config.ldflags.is_empty() { for f in config.ldflags.split_whitespace() { @@ -413,15 +428,17 @@ fn print_wasmer_root_to_stdout(config: &Config) { use walkdir::WalkDir; for entry in WalkDir::new(&config.wasmer_dir) - .into_iter() - .filter_map(Result::ok) { + .into_iter() + .filter_map(Result::ok) + { let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); println!("{f_name}"); } for entry in WalkDir::new(&config.root_dir) - .into_iter() - .filter_map(Result::ok) { + .into_iter() + .filter_map(Result::ok) + { let f_name = String::from(entry.path().canonicalize().unwrap().to_string_lossy()); println!("{f_name}"); } @@ -430,7 +447,13 @@ fn print_wasmer_root_to_stdout(config: &Config) { } #[cfg(test)] -fn fixup_symlinks(include_paths: &[String], log: &mut String) -> Result<(), Box> { +fn fixup_symlinks(include_paths: &[String], log: &mut String, root_dir: &str) -> Result<(), Box> { + + let source = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm-c-api").join("include").join("wasm.h"); + let target = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm.h"); + println!("copying {} -> {}", source.display(), target.display()); + let _ = std::fs::copy(source, target); + log.push_str(&format!("include paths: {include_paths:?}")); for i in include_paths { let i = i.replacen("-I", "", 1); From dc54c608d0881e5206ce935c2241d4c091046ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 14:22:48 +0200 Subject: [PATCH 59/68] Add /include directory to c-api/tests --- lib/c-api/tests/Makefile | 14 +----- .../tests/wasmer-c-api-test-runner/src/lib.rs | 43 +++---------------- lib/wasi-types-generated/wit-bindgen | 1 + 3 files changed, 9 insertions(+), 49 deletions(-) create mode 160000 lib/wasi-types-generated/wit-bindgen diff --git a/lib/c-api/tests/Makefile b/lib/c-api/tests/Makefile index 4a4fc272238..05c01037923 100644 --- a/lib/c-api/tests/Makefile +++ b/lib/c-api/tests/Makefile @@ -5,26 +5,14 @@ $(info Using provided WASMER_DIR=$(WASMER_DIR)) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR_PARENT:=$(shell dirname $(ROOT_DIR)) -MSVC_CFLAGS:="" -MSVC_LDFLAGS:="" -MSVC_LDLIBS:="" - ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer)) CFLAGS = -g -I $(ROOT_DIR) -I $(WASMER_DIR)/include LDFLAGS = -Wl,-rpath,$(WASMER_DIR)/lib LDLIBS = -L $(WASMER_DIR)/lib -lwasmer - - MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(WASMER_DIR)/include - MSVC_LDFLAGS:= "" - MSVC_LDLIBS:= /LIBPATH:$(WASMER_DIR)/lib wasmer.dll.lib else - CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) + CFLAGS = -g -I $(ROOT_DIR)/wasm-c-api/include/ -I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir) LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs) - - MSVC_CFLAGS:= /DEBUG /I $(ROOT_DIR)/ /I $(shell $(WASMER_DIR)/bin/wasmer config --includedir) - MSVC_LDFLAGS:= "" - MSVC_LDLIBS:= /LIBPATH:$(shell $(WASMER_DIR)/bin/wasmer config --libs) wasmer.dll.lib endif diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index f58350d66d6..8c11a3e3053 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -8,14 +8,6 @@ static INCLUDE_REGEX: &str = "#include \"(.*)\""; pub struct Config { pub wasmer_dir: String, pub root_dir: String, - // linux + mac - pub cflags: String, - pub ldflags: String, - pub ldlibs: String, - // windows msvc - pub msvc_cflags: String, - pub msvc_ldflags: String, - pub msvc_ldlibs: String, } impl Config { @@ -23,14 +15,6 @@ impl Config { let mut config = Config { wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), - - cflags: std::env::var("CFLAGS").unwrap_or_default(), - ldflags: std::env::var("LDFLAGS").unwrap_or_default(), - ldlibs: std::env::var("LDLIBS").unwrap_or_default(), - - msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), - msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), - msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), }; let wasmer_base_dir = find_wasmer_base_dir(); @@ -232,7 +216,7 @@ fn test_ok() { .static_crt(true) .extra_warnings(true) .warnings_into_errors(false) - .debug(config.ldflags.contains("-g")) + .debug(true) .host(&host) .target(target) .opt_level(1); @@ -266,14 +250,14 @@ fn test_ok() { command.arg(&format!("{manifest_dir}/../{test}.c")); if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}/wasm-c-api/", config.root_dir)); + command.arg(&format!("{}/wasm-c-api/include/", config.root_dir)); command.arg("/I"); command.arg(&format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ format!("{}/include/", config.wasmer_dir), - format!("{}/wasm-c-api/", config.root_dir), + format!("{}/wasm-c-api/include/", config.root_dir), format!("{}", config.root_dir), ], &mut log, @@ -344,20 +328,16 @@ fn test_ok() { }; let mut command = std::process::Command::new(compiler_cmd); - if !config.cflags.is_empty() { - for f in config.cflags.split_whitespace() { - command.arg(f); - } - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg("-I"); - command.arg(&format!("{}/wasm-c-api/", config.root_dir)); + command.arg(&format!("{}/wasm-c-api/include/", config.root_dir)); command.arg("-I"); command.arg(&format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ format!("{}/include/", config.wasmer_dir), - format!("{}/wasm-c-api/", config.root_dir), + format!("{}/wasm-c-api/include/", config.root_dir), format!("{}", config.root_dir), ], &mut log, @@ -365,17 +345,8 @@ fn test_ok() { ) .expect(&format!("failed to fix symlinks: {log}")); } - if !config.ldflags.is_empty() { - for f in config.ldflags.split_whitespace() { - command.arg(f); - } - } command.arg(&format!("{manifest_dir}/../{test}.c")); - if !config.ldlibs.is_empty() { - for f in config.ldlibs.split_whitespace() { - command.arg(f); - } - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg("-L"); command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("-lwasmer")); diff --git a/lib/wasi-types-generated/wit-bindgen b/lib/wasi-types-generated/wit-bindgen new file mode 160000 index 00000000000..095d295be63 --- /dev/null +++ b/lib/wasi-types-generated/wit-bindgen @@ -0,0 +1 @@ +Subproject commit 095d295be6392259924e48488af188d3ed3e4102 From 9f32fcffb868801bdf33429cfcec483982ca2555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 14:50:17 +0200 Subject: [PATCH 60/68] Add -Wl,rpath argument for macos --- .../wasmer-capi-examples-runner/src/lib.rs | 44 +++---------------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index a78a68042c3..fa831ccc237 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -72,14 +72,6 @@ fn make_package() { pub struct Config { pub wasmer_dir: String, pub root_dir: String, - // linux + mac - pub cflags: String, - pub ldflags: String, - pub ldlibs: String, - // windows msvc - pub msvc_cflags: String, - pub msvc_ldflags: String, - pub msvc_ldlibs: String, } impl Config { @@ -87,14 +79,6 @@ impl Config { let mut config = Config { wasmer_dir: std::env::var("WASMER_DIR").unwrap_or_default(), root_dir: std::env::var("ROOT_DIR").unwrap_or_default(), - - cflags: std::env::var("CFLAGS").unwrap_or_default(), - ldflags: std::env::var("LDFLAGS").unwrap_or_default(), - ldlibs: std::env::var("LDLIBS").unwrap_or_default(), - - msvc_cflags: std::env::var("MSVC_CFLAGS").unwrap_or_default(), - msvc_ldflags: std::env::var("MSVC_LDFLAGS").unwrap_or_default(), - msvc_ldlibs: std::env::var("MSVC_LDLIBS").unwrap_or_default(), }; // resolve the path until the /wasmer root directory @@ -214,7 +198,7 @@ fn test_run() { .static_crt(true) .extra_warnings(true) .warnings_into_errors(false) - .debug(config.ldflags.contains("-g")) + .debug(true) .host(&host) .target(target) .opt_level(1); @@ -223,9 +207,7 @@ fn test_run() { let mut command = compiler.to_command(); command.arg(&format!("{manifest_dir}/../{test}.c")); - if !config.msvc_cflags.is_empty() { - command.arg(config.msvc_cflags.clone()); - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg("/I"); command.arg(&format!("{}/include", config.wasmer_dir)); command.arg("/I"); @@ -243,9 +225,7 @@ fn test_run() { println!("{log}"); } command.arg("/link"); - if !config.msvc_ldlibs.is_empty() { - command.arg(config.msvc_ldlibs.clone()); - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } @@ -311,11 +291,7 @@ fn test_run() { let mut command = std::process::Command::new(compiler_cmd); - if !config.cflags.is_empty() { - for f in config.cflags.split_whitespace() { - command.arg(f); - } - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); command.arg("-I"); @@ -331,20 +307,12 @@ fn test_run() { ) .expect(&format!("failed to fix symlinks: {log}")); } - if !config.ldflags.is_empty() { - for f in config.ldflags.split_whitespace() { - command.arg(f); - } - } command.arg(&format!("{manifest_dir}/../{test}.c")); - if !config.ldlibs.is_empty() { - for f in config.ldlibs.split_whitespace() { - command.arg(f); - } - } else if !config.wasmer_dir.is_empty() { + if !config.wasmer_dir.is_empty() { command.arg("-L"); command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("-lwasmer")); + command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 8c11a3e3053..3fa36164f98 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -350,6 +350,7 @@ fn test_ok() { command.arg("-L"); command.arg(&format!("{}/lib/", config.wasmer_dir)); command.arg(&format!("-lwasmer")); + command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir)); } command.arg("-o"); command.arg(&format!("{manifest_dir}/../{test}")); From a1557b58506b03cbac3afe86648701fe965ce396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 15:05:42 +0200 Subject: [PATCH 61/68] Re-add previous "make test" step to GitHub CI --- .github/workflows/build.yml | 1 - .github/workflows/test-sys.yaml | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f05afc0a324..8411bd32a32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,6 @@ jobs: TARGET: ${{ matrix.target }} steps: - uses: actions/checkout@v3 - - uses: actions/checkout@v2 - name: Set up libstdc++ on Linux if: matrix.build == 'linux-x64' run: | diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index c98840f3cc9..3afacb5b53f 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -199,6 +199,14 @@ jobs: '${{ runner.tool_cache }}/cargo-sccache/bin/sccache' -s echo 'RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache' >> $GITHUB_ENV shell: bash + - name: Test + if: matrix.run_test && matrix.os != 'windows-2019' + run: | + make + env: + TARGET: ${{ matrix.target }} + TARGET_DIR: target/${{ matrix.target }}/release + CARGO_TARGET: --target ${{ matrix.target }} - name: Test if: matrix.run_test && matrix.os != 'windows-2019' run: | From f91f9ae79bdcaf54274138812d81bc741edbd9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 15:06:15 +0200 Subject: [PATCH 62/68] cargo fmt --- .../wasmer-capi-examples-runner/src/lib.rs | 21 +++++++++++++++---- .../tests/wasmer-c-api-test-runner/src/lib.rs | 21 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index fa831ccc237..61a30a75607 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -387,10 +387,23 @@ fn print_wasmer_root_to_stdout(config: &Config) { } #[cfg(test)] -fn fixup_symlinks(include_paths: &[String], log: &mut String, root_dir: &str) -> Result<(), Box> { - - let source = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm-c-api").join("include").join("wasm.h"); - let target = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm.h"); +fn fixup_symlinks( + include_paths: &[String], + log: &mut String, + root_dir: &str, +) -> Result<(), Box> { + let source = std::path::Path::new(root_dir) + .join("lib") + .join("c-api") + .join("tests") + .join("wasm-c-api") + .join("include") + .join("wasm.h"); + let target = std::path::Path::new(root_dir) + .join("lib") + .join("c-api") + .join("tests") + .join("wasm.h"); println!("copying {} -> {}", source.display(), target.display()); let _ = std::fs::copy(source, target); diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 3fa36164f98..54d45969ec8 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -419,10 +419,23 @@ fn print_wasmer_root_to_stdout(config: &Config) { } #[cfg(test)] -fn fixup_symlinks(include_paths: &[String], log: &mut String, root_dir: &str) -> Result<(), Box> { - - let source = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm-c-api").join("include").join("wasm.h"); - let target = std::path::Path::new(root_dir).join("lib").join("c-api").join("tests").join("wasm.h"); +fn fixup_symlinks( + include_paths: &[String], + log: &mut String, + root_dir: &str, +) -> Result<(), Box> { + let source = std::path::Path::new(root_dir) + .join("lib") + .join("c-api") + .join("tests") + .join("wasm-c-api") + .join("include") + .join("wasm.h"); + let target = std::path::Path::new(root_dir) + .join("lib") + .join("c-api") + .join("tests") + .join("wasm.h"); println!("copying {} -> {}", source.display(), target.display()); let _ = std::fs::copy(source, target); From d0f432221bbeb1fe5dc9cdbcb33e2c735590249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 15:51:24 +0200 Subject: [PATCH 63/68] Always run make build-capi --- .../wasmer-capi-examples-runner/src/lib.rs | 16 +++++++--------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 17 ++++++++--------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 61a30a75607..a867fd472a5 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -89,15 +89,13 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")).exists() { - println!("running make build-capi..."); - // run make build-capi - let mut cmd = std::process::Command::new("make"); - cmd.arg("build-capi"); - cmd.current_dir(wasmer_base_dir.clone()); - let result = cmd.output(); - println!("make build-capi: {result:#?}"); - } + println!("running make build-capi..."); + // run make build-capi + let mut cmd = std::process::Command::new("make"); + cmd.arg("build-capi"); + cmd.current_dir(wasmer_base_dir.clone()); + let result = cmd.output(); + println!("make build-capi: {result:#?}"); println!("running make package-capi..."); // run make package diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 54d45969ec8..9bfb468071b 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -24,15 +24,14 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - if !std::path::Path::new(&format!("{wasmer_base_dir}/target/release")).exists() { - println!("running make build-capi..."); - // run make build-capi - let mut cmd = std::process::Command::new("make"); - cmd.arg("build-capi"); - cmd.current_dir(wasmer_base_dir.clone()); - let result = cmd.output(); - println!("make build-capi: {result:#?}"); - } + + println!("running make build-capi..."); + // run make build-capi + let mut cmd = std::process::Command::new("make"); + cmd.arg("build-capi"); + cmd.current_dir(wasmer_base_dir.clone()); + let result = cmd.output(); + println!("make build-capi: {result:#?}"); println!("running make package..."); // run make package-capi From 8e8c97bb63127f49ad6edada1e846c5839209a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 23 Sep 2022 19:16:03 +0200 Subject: [PATCH 64/68] WIndows: generate executables (segfaulting) --- .../wasmer-capi-examples-runner/.gitignore | 4 + .../wasmer-capi-examples-runner/src/lib.rs | 90 +++++++++++-------- 2 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 lib/c-api/examples/wasmer-capi-examples-runner/.gitignore diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/.gitignore b/lib/c-api/examples/wasmer-capi-examples-runner/.gitignore new file mode 100644 index 00000000000..1b04d33b6ab --- /dev/null +++ b/lib/c-api/examples/wasmer-capi-examples-runner/.gitignore @@ -0,0 +1,4 @@ +*.bat +*.ilk +*.pdb +*.exe \ No newline at end of file diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index a867fd472a5..97ee79a4769 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -9,6 +9,7 @@ pub struct RemoveTestsOnDrop {} impl Drop for RemoveTestsOnDrop { fn drop(&mut self) { + return; let manifest_dir = env!("CARGO_MANIFEST_DIR"); for entry in std::fs::read_dir(&manifest_dir).unwrap() { let entry = entry.unwrap(); @@ -187,8 +188,14 @@ fn test_run() { None => format!("{manifest_dir}"), }; - if target.contains("msvc") { - for test in TESTS.iter() { + for test in TESTS.iter() { + + let mut manifest_dir_parent = std::path::Path::new(&manifest_dir); + let mut manifest_dir_parent = manifest_dir_parent.parent().unwrap(); + let c_file_path = manifest_dir_parent.join(&format!("{test}.c")); + + if target.contains("msvc") { + let mut build = cc::Build::new(); let mut build = build .cargo_metadata(false) @@ -204,12 +211,10 @@ fn test_run() { let compiler = build.try_get_compiler().unwrap(); let mut command = compiler.to_command(); - command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(&format!("{}", c_file_path.display())); if !config.wasmer_dir.is_empty() { command.arg("/I"); - command.arg(&format!("{}/include", config.wasmer_dir)); - command.arg("/I"); - command.arg(&format!("{}", config.root_dir)); + command.arg(&format!("{}/include/", config.wasmer_dir)); let mut log = String::new(); fixup_symlinks( &[ @@ -222,38 +227,46 @@ fn test_run() { .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } + + let exe_outpath = manifest_dir_parent.join(&format!("{test}.exe")); + let exe_outpath = format!("{}", exe_outpath.display()); + println!("compiling exe to {exe_outpath}"); + + command.arg(&format!("/Fo:{}/", manifest_dir_parent.display())); command.arg("/link"); if !config.wasmer_dir.is_empty() { command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir)); command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir)); } - command.arg(&format!("/OUT:\"{manifest_dir}/../{test}.exe\"")); - - // run vcvars - let vcvars_bat_path = find_vcvars64(&compiler).expect("no vcvars64.bat"); - let mut vcvars = std::process::Command::new("cmd"); - vcvars.arg("/C"); - vcvars.arg(vcvars_bat_path); - println!("running {vcvars:?}"); + command.arg(&format!("/OUT:{exe_outpath}")); - // cmd /C vcvars64.bat - let output = vcvars - .output() - .expect("could not invoke vcvars64.bat at {vcvars_bat_path}"); - - if !output.status.success() { - println!(); - println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); - panic!("failed to invoke vcvars64.bat {test}"); - } + // read vcvars into file, append command, then execute the bat println!("compiling WINDOWS {test}: {command:?}"); + let vcvars_bat_path = find_vcvarsall(&compiler).expect("no vcvarsall.bat"); + let vcvars_bat_path_parent = std::path::Path::new(&vcvars_bat_path).parent().unwrap(); + let vcvars_modified_output = vcvars_bat_path_parent.join("compile-windows.bat"); + let vcvars_bat_file = std::fs::read_to_string(&vcvars_bat_path).unwrap(); + let batch_formatted = format!("{}\\", vcvars_bat_path_parent.display()); + let vcvars_bat_file = vcvars_bat_file + .replace("%~dp0", &batch_formatted.replace("\\", "\\\\")) + .replace("\"%1\"", "\"x64\""); + let vcvars_modified = format!("{vcvars_bat_file}\r\n{command:?}"); + let path = std::path::Path::new(&manifest_dir).join("compile-windows.bat"); + println!("outputting batch to {}", path.display()); + std::fs::write(&path, vcvars_modified).unwrap(); + print_wasmer_root_to_stdout(&config); + let mut vcvars = std::process::Command::new("cmd"); + vcvars.arg("/C"); + vcvars.arg(&path); + vcvars.arg("x64"); + vcvars.current_dir(&vcvars_bat_path_parent); + // compile - let output = command + let output = vcvars .output() .map_err(|e| format!("failed to compile {command:#?}: {e}")) .unwrap(); @@ -263,9 +276,15 @@ fn test_run() { print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}"); } - + + if !std::path::Path::new(&exe_outpath).exists() { + panic!("error: {exe_outpath} does not exist"); + } + if !std::path::Path::new(&wasmer_dll_dir).join("wasmer.dll").exists() { + panic!("error: {wasmer_dll_dir} has no wasmer.dll"); + } // execute - let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe")); + let mut command = std::process::Command::new(&exe_outpath); command.env("PATH", newpath.clone()); command.current_dir(exe_dir.clone()); println!("executing {test}: {command:?}"); @@ -274,14 +293,13 @@ fn test_run() { .output() .expect(&format!("failed to run {command:#?}")); if !output.status.success() { + println!("{output:#?}"); println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); - println!("stdout: {}", String::from_utf8_lossy(&output.stderr)); + println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); print_wasmer_root_to_stdout(&config); panic!("failed to execute {test}"); } - } - } else { - for test in TESTS.iter() { + } else { let compiler_cmd = match std::process::Command::new("cc").output() { Ok(_) => "cc", Err(_) => "gcc", @@ -292,8 +310,6 @@ fn test_run() { if !config.wasmer_dir.is_empty() { command.arg("-I"); command.arg(&format!("{}/include", config.wasmer_dir)); - command.arg("-I"); - command.arg(&config.root_dir); let mut log = String::new(); fixup_symlinks( &[ @@ -305,7 +321,7 @@ fn test_run() { ) .expect(&format!("failed to fix symlinks: {log}")); } - command.arg(&format!("{manifest_dir}/../{test}.c")); + command.arg(&c_file_path); if !config.wasmer_dir.is_empty() { command.arg("-L"); command.arg(&format!("{}/lib/", config.wasmer_dir)); @@ -464,7 +480,7 @@ fn fixup_symlinks_inner(include_paths: &[String], log: &mut String) -> Result<() } #[cfg(test)] -fn find_vcvars64(compiler: &cc::Tool) -> Option { +fn find_vcvarsall(compiler: &cc::Tool) -> Option { if !compiler.is_like_msvc() { return None; } @@ -473,5 +489,5 @@ fn find_vcvars64(compiler: &cc::Tool) -> Option { let path = format!("{}", path.display()); let split = path.split("VC").nth(0)?; - Some(format!("{split}VC\\Auxiliary\\Build\\vcvars64.bat")) + Some(format!("{split}VC\\Auxiliary\\Build\\vcvarsall.bat")) } From e0e3aff4e4c053a591455bfefb6df65873ee5633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 07:48:55 +0200 Subject: [PATCH 65/68] Add make build-capi and make package-capi before CI test step --- .github/workflows/test-sys.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 3afacb5b53f..ab60fd437fb 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -210,7 +210,7 @@ jobs: - name: Test if: matrix.run_test && matrix.os != 'windows-2019' run: | - make test + make build-capi && make package && export WASMER_DIR=`pwd`/package && make test env: TARGET: ${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }}/release @@ -236,7 +236,7 @@ jobs: - name: Test if: matrix.run_test && matrix.os == 'windows-2019' run: | - make test + make build-capi && make package && export WASMER_DIR=`pwd`/package && make test - name: Test C API if: matrix.run_test_capi && matrix.os == 'windows-2019' run: | From 35d41e75cf00cdf96e541ad29642f557193e6d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 10:22:06 +0200 Subject: [PATCH 66/68] Use "make package-capi" instead of "make package" --- .github/workflows/test-sys.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index ab60fd437fb..88aaea31e0d 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -210,7 +210,7 @@ jobs: - name: Test if: matrix.run_test && matrix.os != 'windows-2019' run: | - make build-capi && make package && export WASMER_DIR=`pwd`/package && make test + make build-capi && make package-capi && export WASMER_DIR=`pwd`/package && make test env: TARGET: ${{ matrix.target }} TARGET_DIR: target/${{ matrix.target }}/release @@ -236,7 +236,7 @@ jobs: - name: Test if: matrix.run_test && matrix.os == 'windows-2019' run: | - make build-capi && make package && export WASMER_DIR=`pwd`/package && make test + make build-capi && make package-capi && export WASMER_DIR=`pwd`/package && make test - name: Test C API if: matrix.run_test_capi && matrix.os == 'windows-2019' run: | From 449a77fb6b09b2a9a98ea535301c1856a5380f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 10:22:56 +0200 Subject: [PATCH 67/68] cargo fmt --- .../wasmer-capi-examples-runner/src/lib.rs | 15 ++++++++------- .../tests/wasmer-c-api-test-runner/src/lib.rs | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs index 97ee79a4769..77030cc63b5 100644 --- a/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs +++ b/lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs @@ -189,13 +189,11 @@ fn test_run() { }; for test in TESTS.iter() { - let mut manifest_dir_parent = std::path::Path::new(&manifest_dir); let mut manifest_dir_parent = manifest_dir_parent.parent().unwrap(); let c_file_path = manifest_dir_parent.join(&format!("{test}.c")); - - if target.contains("msvc") { + if target.contains("msvc") { let mut build = cc::Build::new(); let mut build = build .cargo_metadata(false) @@ -227,7 +225,7 @@ fn test_run() { .expect(&format!("failed to fix symlinks: {log}")); println!("{log}"); } - + let exe_outpath = manifest_dir_parent.join(&format!("{test}.exe")); let exe_outpath = format!("{}", exe_outpath.display()); println!("compiling exe to {exe_outpath}"); @@ -251,7 +249,7 @@ fn test_run() { let batch_formatted = format!("{}\\", vcvars_bat_path_parent.display()); let vcvars_bat_file = vcvars_bat_file .replace("%~dp0", &batch_formatted.replace("\\", "\\\\")) - .replace("\"%1\"", "\"x64\""); + .replace("\"%1\"", "\"x64\""); let vcvars_modified = format!("{vcvars_bat_file}\r\n{command:?}"); let path = std::path::Path::new(&manifest_dir).join("compile-windows.bat"); println!("outputting batch to {}", path.display()); @@ -276,11 +274,14 @@ fn test_run() { print_wasmer_root_to_stdout(&config); panic!("failed to compile {test}"); } - + if !std::path::Path::new(&exe_outpath).exists() { panic!("error: {exe_outpath} does not exist"); } - if !std::path::Path::new(&wasmer_dll_dir).join("wasmer.dll").exists() { + if !std::path::Path::new(&wasmer_dll_dir) + .join("wasmer.dll") + .exists() + { panic!("error: {wasmer_dll_dir} has no wasmer.dll"); } // execute diff --git a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs index 9bfb468071b..60b2d300845 100644 --- a/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs +++ b/lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs @@ -24,7 +24,6 @@ impl Config { println!("manifest dir = {manifest_dir}, wasmer root dir = {wasmer_base_dir}"); config.wasmer_dir = wasmer_base_dir.clone() + "/package"; if !std::path::Path::new(&config.wasmer_dir).exists() { - println!("running make build-capi..."); // run make build-capi let mut cmd = std::process::Command::new("make"); From bb9b349dfef0b8ce0561937961deab424cb55b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 26 Sep 2022 10:52:24 +0200 Subject: [PATCH 68/68] Use bash shell on Windows CI --- .github/workflows/test-sys.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-sys.yaml b/.github/workflows/test-sys.yaml index 88aaea31e0d..6e7402fbc54 100644 --- a/.github/workflows/test-sys.yaml +++ b/.github/workflows/test-sys.yaml @@ -235,12 +235,14 @@ jobs: CARGO_TARGET: --target ${{ matrix.target }} - name: Test if: matrix.run_test && matrix.os == 'windows-2019' + shell: bash run: | make build-capi && make package-capi && export WASMER_DIR=`pwd`/package && make test - name: Test C API if: matrix.run_test_capi && matrix.os == 'windows-2019' + shell: bash run: | - make test-capi + export WASMER_DIR=`pwd`/package && make test-capi - name: Build Doc if: matrix.run_build_docs run: |