mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-24 09:19:25 +00:00
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
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -3054,6 +3054,14 @@ dependencies = [
|
|||||||
"wasmer-compiler-singlepass",
|
"wasmer-compiler-singlepass",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasmer-capi-examples-runner"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"target-lexicon 0.11.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmer-cli"
|
name = "wasmer-cli"
|
||||||
version = "3.0.0-beta"
|
version = "3.0.0-beta"
|
||||||
|
@ -47,6 +47,7 @@ members = [
|
|||||||
"lib/wasi-experimental-io-devices",
|
"lib/wasi-experimental-io-devices",
|
||||||
"lib/wasi-local-networking",
|
"lib/wasi-local-networking",
|
||||||
"lib/c-api/tests/wasmer-c-api-test-runner",
|
"lib/c-api/tests/wasmer-c-api-test-runner",
|
||||||
|
"lib/c-api/examples/wasmer-capi-examples-runner",
|
||||||
"lib/types",
|
"lib/types",
|
||||||
"tests/wasi-wast",
|
"tests/wasi-wast",
|
||||||
"tests/lib/wast",
|
"tests/lib/wast",
|
||||||
|
@ -4,14 +4,26 @@ $(info Using provided WASMER_DIR=$(WASMER_DIR))
|
|||||||
|
|
||||||
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
MSVC_CFLAGS:=""
|
||||||
|
MSVC_LDFLAGS:=""
|
||||||
|
MSVC_LDLIBS:=""
|
||||||
|
|
||||||
ifeq (,$(wildcard $(WASMER_DIR)/bin/wasmer))
|
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
|
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
|
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)
|
LDFLAGS = -Wl,-rpath,$(shell $(WASMER_DIR)/bin/wasmer config --libdir)
|
||||||
LDLIBS = $(shell $(WASMER_DIR)/bin/wasmer config --libs)
|
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
|
endif
|
||||||
|
|
||||||
$(info * CFLAGS: $(CFLAGS))
|
$(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
|
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
|
.PHONY: run
|
||||||
.SILENT: run
|
.SILENT: run
|
||||||
run: $(ALL)
|
run:
|
||||||
set -o errexit; \
|
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
|
||||||
$(foreach example,$?,echo Running \"$(example)\" example; ./$(example); echo;)
|
|
||||||
|
|
||||||
.SILENT: clean
|
.SILENT: clean
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
@ -45,7 +45,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
// Load binary.
|
// Load binary.
|
||||||
printf("Loading binary...\n");
|
printf("Loading binary...\n");
|
||||||
FILE *file = fopen("assets/call_trap.wasm", "r");
|
FILE *file = fopen("assets/call_trap.wasm", "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
printf("> Error loading module!\n");
|
printf("> Error loading module!\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
|
|
||||||
// Load binary.
|
// Load binary.
|
||||||
printf("Loading binary...\n");
|
printf("Loading binary...\n");
|
||||||
FILE* file = fopen("assets/qjs.wasm", "r");
|
FILE* file = fopen("assets/qjs.wasm", "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
printf("> Error loading module!\n");
|
printf("> Error loading module!\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -49,7 +49,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
wasm_byte_vec_t binary;
|
wasm_byte_vec_t binary;
|
||||||
wasm_byte_vec_new_uninitialized(&binary, file_size);
|
wasm_byte_vec_new_uninitialized(&binary, file_size);
|
||||||
if (fread(binary.data, file_size, 1, file) != 1) {
|
if (fread(binary.data, file_size, 1, file) != 1) {
|
||||||
printf("> Error loading module!\n");
|
printf("> Error initializing module!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -137,12 +137,12 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
printf("Call completed\n");
|
printf("Call completed\n");
|
||||||
|
|
||||||
{
|
if(true) {
|
||||||
FILE *memory_stream;
|
|
||||||
char* stdout;
|
|
||||||
size_t stdout_size = 0;
|
|
||||||
|
|
||||||
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) {
|
if (NULL == memory_stream) {
|
||||||
printf("> Error creating a memory stream.\n");
|
printf("> Error creating a memory stream.\n");
|
||||||
@ -161,15 +161,20 @@ int main(int argc, const char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data_read_size > 0) {
|
if (data_read_size > 0) {
|
||||||
stdout_size += data_read_size;
|
|
||||||
fwrite(buffer, sizeof(char), data_read_size, memory_stream);
|
fwrite(buffer, sizeof(char), data_read_size, memory_stream);
|
||||||
}
|
}
|
||||||
} while (BUF_SIZE == data_read_size);
|
} 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);
|
fclose(memory_stream);
|
||||||
|
|
||||||
printf("WASI Stdout: `%.*s`\n", (int) stdout_size, stdout);
|
|
||||||
free(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ $(info * LDFLAGS: $(LDFLAGS))
|
|||||||
$(info * LDLIBS: $(LDLIBS))
|
$(info * LDLIBS: $(LDLIBS))
|
||||||
|
|
||||||
test:
|
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
|
.SILENT: clean
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
@ -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"
|
|
@ -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] = &[
|
const CAPI_BASE_TESTS: &[&str] = &[
|
||||||
"wasm-c-api/example/callback",
|
"wasm-c-api/example/callback",
|
||||||
"wasm-c-api/example/memory",
|
"wasm-c-api/example/memory",
|
||||||
@ -56,15 +86,15 @@ const CAPI_BASE_TESTS_NOT_WORKING: &[&str] = &[
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_ok() {
|
fn test_ok() {
|
||||||
|
|
||||||
|
let _drop = RemoveTestsOnDrop::default();
|
||||||
let config = Config::get();
|
let config = Config::get();
|
||||||
println!("config: {:#?}", config);
|
println!("config: {:#?}", config);
|
||||||
|
|
||||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||||
|
|
||||||
let host = target_lexicon::HOST.to_string();
|
let host = target_lexicon::HOST.to_string();
|
||||||
let target = &host;
|
let target = &host;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
if target.contains("msvc") {
|
||||||
for test in CAPI_BASE_TESTS.iter() {
|
for test in CAPI_BASE_TESTS.iter() {
|
||||||
|
|
||||||
let mut build = cc::Build::new();
|
let mut build = cc::Build::new();
|
||||||
@ -157,8 +187,7 @@ fn test_ok() {
|
|||||||
// -o wasm-c-api/example/callback
|
// -o wasm-c-api/example/callback
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
for test in CAPI_BASE_TESTS.iter() {
|
for test in CAPI_BASE_TESTS.iter() {
|
||||||
|
|
||||||
let mut command = std::process::Command::new("cc");
|
let mut command = std::process::Command::new("cc");
|
||||||
@ -184,11 +213,18 @@ fn test_ok() {
|
|||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||||
println!("stdout: {}", String::from_utf8_lossy(&output.stderr));
|
println!("stdout: {}", String::from_utf8_lossy(&output.stderr));
|
||||||
panic!("failed to compile {test}");
|
panic!("failed to execute {test}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for test in CAPI_BASE_TESTS.iter() {
|
||||||
|
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}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn find_vcvars64(compiler: &cc::Tool) -> Option<String> {
|
fn find_vcvars64(compiler: &cc::Tool) -> Option<String> {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user