Skip to content

Commit

Permalink
Final fixes for make test-capi on windows-msvc
Browse files Browse the repository at this point in the history
- .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
  • Loading branch information
fschutt committed Sep 14, 2022
1 parent fd390f6 commit 7441fad
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 169 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 16 additions & 38 deletions lib/c-api/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/examples/early-exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 16 additions & 11 deletions lib/c-api/examples/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/c-api/tests/wasmer-c-api-test-runner/command.bat

This file was deleted.

Loading

0 comments on commit 7441fad

Please sign in to comment.