mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-25 17:59:27 +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:
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user