Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,13 @@ jobs:
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
working-directory: tools/wasi-headers

bindings:
name: Ensure wit-bingen bindings are up-to-date
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
submodules: true
- run: make bindings
- run: git diff --exit-code
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
--autodrop-borrows yes \
--rename-world wasip2 \
--type-section-suffix __wasi_libc \
--world wasi:cli/command@0.2.0 \
--world wasi:cli/imports@0.2.0 \
--rename wasi:clocks/[email protected]=monotonic_clock \
--rename wasi:clocks/[email protected]=wall_clock \
--rename wasi:filesystem/[email protected]=filesystem_preopens \
Expand Down Expand Up @@ -1091,6 +1091,8 @@ bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
< wasip2.c \
> ../../libc-bottom-half/sources/wasip2.c && \
rm wasip2.c
sed -i 's/extern void exit_exit/_Noreturn extern void exit_exit/' libc-bottom-half/headers/public/wasi/wasip2.h
sed -i 's/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/' libc-bottom-half/sources/wasip2.c


clean:
Expand Down
2 changes: 0 additions & 2 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ __wasilibc_tell
__wasilibc_unlinkat
__wasilibc_utimens
__wasm_call_dtors
__wasm_export_exports_wasi_cli_run_run
__wcscoll_l
__wcsftime_l
__wcsxfrm_l
Expand Down Expand Up @@ -570,7 +569,6 @@ explicit_bzero
expm1
expm1f
expm1l
exports_wasi_cli_run_result_void_void_free
exports_wasi_cli_run_run
fabs
fabsf
Expand Down
12 changes: 0 additions & 12 deletions libc-bottom-half/headers/public/wasi/wasip2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,6 @@ typedef struct {
uint64_t f1;
} wasip2_tuple2_u64_u64_t;

typedef struct {
bool is_err;
} exports_wasi_cli_run_result_void_void_t;

// Imported Functions from `wasi:cli/[email protected]`
// Get the POSIX-style environment variables.
//
Expand All @@ -1088,9 +1084,6 @@ extern bool environment_initial_cwd(wasip2_string_t *ret);

// Imported Functions from `wasi:cli/[email protected]`
// Exit the current instance and any linked instances.
// NOTE: This file has been manually edited to add the _Noreturn
// annotation on exit_exit(). If the file is re-generated, this
// annotation will have to be re-added.
_Noreturn extern void exit_exit(exit_result_void_void_t *status);

// Imported Functions from `wasi:io/[email protected]`
Expand Down Expand Up @@ -2258,9 +2251,6 @@ extern uint64_t random_insecure_get_insecure_random_u64(void);
// protection.
extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret);

// Exported Functions from `wasi:cli/[email protected]`
bool exports_wasi_cli_run_run(void);

// Helper Functions

void wasip2_tuple2_string_string_free(wasip2_tuple2_string_string_t *ptr);
Expand Down Expand Up @@ -2479,8 +2469,6 @@ void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *p

void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr);

void exports_wasi_cli_run_result_void_void_free(exports_wasi_cli_run_result_void_void_t *ptr);

// Transfers ownership of `s` into the string `ret`
void wasip2_string_set(wasip2_string_t *ret, char*s);

Expand Down
21 changes: 0 additions & 21 deletions libc-bottom-half/sources/wasip2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ extern void __wasm_import_environment_get_arguments(int32_t);
__attribute__((__import_module__("wasi:cli/[email protected]"), __import_name__("initial-cwd")))
extern void __wasm_import_environment_initial_cwd(int32_t);

// NOTE: This file has been manually edited to add the _Noreturn
// annotation on __wasm_import_exit_exit(). If the file is re-generated, this
// annotation will have to be re-added.
__attribute__((__import_module__("wasi:cli/[email protected]"), __import_name__("exit")))
_Noreturn extern void __wasm_import_exit_exit(int32_t);

Expand Down Expand Up @@ -1013,11 +1010,6 @@ void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_resu
}
}

void exports_wasi_cli_run_result_void_void_free(exports_wasi_cli_run_result_void_void_t *ptr) {
if (!ptr->is_err) {
}
}

void wasip2_string_set(wasip2_string_t *ret, char*s) {
ret->ptr = (uint8_t*) s;
ret->len = strlen(s);
Expand Down Expand Up @@ -4328,19 +4320,6 @@ void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret) {
};
}

__attribute__((__export_name__("wasi:cli/[email protected]#run")))
int32_t __wasm_export_exports_wasi_cli_run_run(void) {
exports_wasi_cli_run_result_void_void_t ret;
ret.is_err = !exports_wasi_cli_run_run();
int32_t result;
if ((ret).is_err) {
result = 1;
} else {
result = 0;
}
return result;
}

extern void __component_type_object_force_link_wasip2(void);
void __component_type_object_force_link_wasip2_public_use_in_this_compilation_unit(void) {
__component_type_object_force_link_wasip2();
Expand Down
Binary file modified libc-bottom-half/sources/wasip2_component_type.o
Binary file not shown.
36 changes: 3 additions & 33 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ LIBC_TEST = $(DOWNDIR)/libc-test
ARCH := $(shell uname -m)
WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v38.0.2/wasmtime-v38.0.2-$(ARCH)-linux.tar.xz
WASMTIME = $(abspath $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime)
WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/v1.224.0/wasm-tools-1.224.0-$(ARCH)-linux.tar.gz
WASM_TOOLS = $(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL) .tar.gz)/wasm-tools

$(DOWNDIR):
@mkdir -p $@
Expand All @@ -60,15 +58,8 @@ $(WASMTIME): | $(DOWNDIR)
wget --no-clobber --directory-prefix=$(DOWNDIR) $(WASMTIME_URL)
tar --extract --file=$(DOWNDIR)/$(shell basename $(WASMTIME_URL)) --directory=$(DOWNDIR)/

$(WASM_TOOLS): | $(DOWNDIR)
wget --no-clobber --directory-prefix=$(DOWNDIR) $(WASM_TOOLS_URL)
tar --extract --file=$(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL)) --directory=$(DOWNDIR)/

# Target to download all necessary dependencies.
TO_DOWNLOAD = $(LIBC_TEST) $(WASMTIME)
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
TO_DOWNLOAD += $(WASM_TOOLS)
endif
DOWNLOADED := $(DOWNDIR)/downloaded.stamp
$(DOWNLOADED): $(TO_DOWNLOAD)
touch $@
Expand Down Expand Up @@ -109,11 +100,7 @@ ALL_TESTS := $(shell find $(SRCDIR) -name '*.c')
TESTS := $(shell TARGET_TRIPLE=$(TARGET_TRIPLE) scripts/filter.py $(ALL_TESTS))
WASM_OBJS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.wasm.o)
WASM_OBJS += $(INFRA_WASM_OBJS)
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.component.wasm)
else
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm)
endif
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.wasm)


# Setup the compiler. We allow $(CC) to be set from the command line; ?= doesn't
Expand Down Expand Up @@ -143,13 +130,6 @@ $(BUILTINS_STAMP):
make -C .. builtins
touch $@

# For wasip2, we want clang to generate a core module rather than a component,
# because `wasm-tools component new` is called subsequently and it expects
# a core module.
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
LDFLAGS += -Wl,--skip-wit-component
endif

# Build up all the `*.wasm.o` object files; these are the same regardless of
# whether we're building core modules or components.
$(WASM_OBJS): $(INFRA_HEADERS)
Expand All @@ -159,15 +139,10 @@ $(OBJDIR)/%.wasm.o: $(SRCDIR)/%.c $(DOWNLOADED) $(SYSROOT)

# Build up all the `*.wasm` files.
obj_to_c = $(patsubst $(OBJDIR)/%.wasm.o,$(SRCDIR)/%.c,$1)
$(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) | $(BUILTINS_STAMP)
$(OBJDIR)/%.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) | $(BUILTINS_STAMP)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(LDFLAGS) $(shell scripts/add-flags.py LDFLAGS $(call obj_to_c,$<)) $^ -o $@

# For wasip2, we include an additional step to wrap up the core module into
# a component.
$(OBJDIR)/%.component.wasm: $(OBJDIR)/%.core.wasm
$(WASM_TOOLS) component new $< -o $@

# Compile each selected test using Clang. Note that failures here are likely
# due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory.
# This location is system-dependent, but could be fixed by something like:
Expand All @@ -193,12 +168,7 @@ generate-stubs:
##### RUN ######################################################################

ENGINE ?= $(WASMTIME) run
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
ENGINE += --wasm component-model
OBJPAT := $(OBJDIR)/%.component.wasm
else
OBJPAT := $(OBJDIR)/%.core.wasm
endif
OBJPAT := $(OBJDIR)/%.wasm

# Each Wasm test is run every time, generating a folder containing a `cmd.sh`
# script and an `output.log` file (see `scripts/run-test.sh` for details). The
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/add-flags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Find additional compilation flags specified in test files.
#
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Filter out test files that do not match a configuration variable.
#
Expand Down
54 changes: 27 additions & 27 deletions test/scripts/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,63 +78,63 @@ run_sockets_test_multiple() {

testname=$(basename $WASM)
parent=$(dirname $WASM)
if [ $testname == "sockets-server.component.wasm" ]; then
if [ $testname == "sockets-server.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-multiple-server.component.wasm" ]; then
if [ $testname == "sockets-multiple-server.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-server-udp-blocking.component.wasm" ]; then
if [ $testname == "sockets-server-udp-blocking.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-client.component.wasm" ]; then
run_sockets_test $parent/"sockets-server.component.wasm"
if [ $testname == "sockets-client.wasm" ]; then
run_sockets_test $parent/"sockets-server.wasm"
exit $?
fi
if [ $testname == "sockets-client-udp-blocking.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-udp-blocking.component.wasm"
if [ $testname == "sockets-client-udp-blocking.wasm" ]; then
run_sockets_test $parent/"sockets-server-udp-blocking.wasm"
exit $?
fi
if [ $testname == "sockets-multiple-client.component.wasm" ]; then
run_sockets_test_multiple $parent/"sockets-multiple-server.component.wasm"
if [ $testname == "sockets-multiple-client.wasm" ]; then
run_sockets_test_multiple $parent/"sockets-multiple-server.wasm"
exit $?
fi
if [ $testname = "sockets-client-hangup-after-connect.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.component.wasm"
if [ $testname = "sockets-client-hangup-after-connect.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.wasm"
exit $?
fi
if [ $testname = "sockets-client-hangup-while-sending.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.component.wasm"
if [ $testname = "sockets-client-hangup-while-sending.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.wasm"
exit $?
fi
if [ $testname = "sockets-client-hangup-after-sending.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.component.wasm"
if [ $testname = "sockets-client-hangup-after-sending.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.wasm"
exit $?
fi
if [ $testname = "sockets-client-hangup-while-receiving.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.component.wasm"
if [ $testname = "sockets-client-hangup-while-receiving.wasm" ]; then
run_sockets_test $parent/"sockets-server-handle-hangups.wasm"
exit $?
fi
if [ $testname == "sockets-server-hangup-before-send.component.wasm" ]; then
if [ $testname == "sockets-server-hangup-before-send.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-server-hangup-during-send.component.wasm" ]; then
if [ $testname == "sockets-server-hangup-during-send.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-server-hangup-before-recv.component.wasm" ]; then
if [ $testname == "sockets-server-hangup-before-recv.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-server-hangup-during-recv.component.wasm" ]; then
if [ $testname == "sockets-server-hangup-during-recv.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-server-handle-hangups.component.wasm" ]; then
if [ $testname == "sockets-server-handle-hangups.wasm" ]; then
exit 0
fi
if [ $testname == "sockets-client-handle-hangups.component.wasm" ]; then
run_sockets_test $parent/"sockets-server-hangup-before-send.component.wasm"
run_sockets_test $parent/"sockets-server-hangup-during-send.component.wasm"
run_sockets_test $parent/"sockets-server-hangup-before-recv.component.wasm"
run_sockets_test $parent/"sockets-server-hangup-during-recv.component.wasm"
if [ $testname == "sockets-client-handle-hangups.wasm" ]; then
run_sockets_test $parent/"sockets-server-hangup-before-send.wasm"
run_sockets_test $parent/"sockets-server-hangup-during-send.wasm"
run_sockets_test $parent/"sockets-server-hangup-before-recv.wasm"
run_sockets_test $parent/"sockets-server-hangup-during-recv.wasm"
# Deliberately fall through so that we can run this test without a server
# (to test the behavior when connect() fails)
fi
Expand Down