diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a4728690..814e34c00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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/checkout@v4.1.7 + with: + submodules: true + - run: make bindings + - run: git diff --exit-code diff --git a/Makefile b/Makefile index aec71cee3..0f5c53c15 100644 --- a/Makefile +++ b/Makefile @@ -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/monotonic-clock@0.2.0=monotonic_clock \ --rename wasi:clocks/wall-clock@0.2.0=wall_clock \ --rename wasi:filesystem/preopens@0.2.0=filesystem_preopens \ @@ -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: diff --git a/expected/wasm32-wasip2/defined-symbols.txt b/expected/wasm32-wasip2/defined-symbols.txt index 17d12a996..e41f16677 100644 --- a/expected/wasm32-wasip2/defined-symbols.txt +++ b/expected/wasm32-wasip2/defined-symbols.txt @@ -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 @@ -570,7 +569,6 @@ explicit_bzero expm1 expm1f expm1l -exports_wasi_cli_run_result_void_void_free exports_wasi_cli_run_run fabs fabsf diff --git a/libc-bottom-half/headers/public/wasi/wasip2.h b/libc-bottom-half/headers/public/wasi/wasip2.h index 2428f7e79..015686a8e 100644 --- a/libc-bottom-half/headers/public/wasi/wasip2.h +++ b/libc-bottom-half/headers/public/wasi/wasip2.h @@ -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/environment@0.2.0` // Get the POSIX-style environment variables. // @@ -1088,9 +1084,6 @@ extern bool environment_initial_cwd(wasip2_string_t *ret); // Imported Functions from `wasi:cli/exit@0.2.0` // 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/error@0.2.0` @@ -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/run@0.2.0` -bool exports_wasi_cli_run_run(void); - // Helper Functions void wasip2_tuple2_string_string_free(wasip2_tuple2_string_string_t *ptr); @@ -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); diff --git a/libc-bottom-half/sources/wasip2.c b/libc-bottom-half/sources/wasip2.c index cd8e2d28b..7b2ac2e4e 100644 --- a/libc-bottom-half/sources/wasip2.c +++ b/libc-bottom-half/sources/wasip2.c @@ -11,9 +11,6 @@ extern void __wasm_import_environment_get_arguments(int32_t); __attribute__((__import_module__("wasi:cli/environment@0.2.0"), __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/exit@0.2.0"), __import_name__("exit"))) _Noreturn extern void __wasm_import_exit_exit(int32_t); @@ -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); @@ -4328,19 +4320,6 @@ void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret) { }; } -__attribute__((__export_name__("wasi:cli/run@0.2.0#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(); diff --git a/libc-bottom-half/sources/wasip2_component_type.o b/libc-bottom-half/sources/wasip2_component_type.o index ec0b2468b..0548e3e97 100644 Binary files a/libc-bottom-half/sources/wasip2_component_type.o and b/libc-bottom-half/sources/wasip2_component_type.o differ diff --git a/test/Makefile b/test/Makefile index ee90d9954..64b070a51 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 $@ @@ -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 $@ @@ -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 @@ -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) @@ -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: @@ -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 diff --git a/test/scripts/add-flags.py b/test/scripts/add-flags.py index 643a922b2..f8716d710 100755 --- a/test/scripts/add-flags.py +++ b/test/scripts/add-flags.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Find additional compilation flags specified in test files. # diff --git a/test/scripts/filter.py b/test/scripts/filter.py index 6df117173..1eb312679 100755 --- a/test/scripts/filter.py +++ b/test/scripts/filter.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Filter out test files that do not match a configuration variable. # diff --git a/test/scripts/run-test.sh b/test/scripts/run-test.sh index ce408d989..88437c275 100755 --- a/test/scripts/run-test.sh +++ b/test/scripts/run-test.sh @@ -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