add WASI Preview 2 bindings (#460)

* add WASI Preview 2 bindings

This adds C bindings generated from the `wasi:cli/imports@0.2.0-rc-2023-12-05`
world, plus a makefile target to regenerate them from the WIT source files.

We'll use these bindings to call Preview 2 host functions when building for the
`wasm32-wasi-preview2` target.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* update to pre-release of `wit-bindgen` 0.17.0

This includes https://github.com/bytecodealliance/wit-bindgen/pull/804 (fix
broken indentation in generated code) and
https://github.com/bytecodealliance/wit-bindgen/pull/805 (support overriding
world name and adding a suffix to the component type custom section).

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* test all targets; update preview2 expected output files

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* build for `wasm32-wasi-threads` before testing it

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* move generated bindings per review feedback

Since these files aren't part of cloudlibc, no reason to put them under the
cloudlibc directory.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* move preview2.h to wasi directory

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
This commit is contained in:
Joel Dice 2024-01-11 12:53:15 -07:00 committed by GitHub
parent 03b228e46b
commit 47b9db6d15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 7502 additions and 25 deletions

View File

@ -88,6 +88,14 @@ jobs:
make -j4
WASI_SNAPSHOT=preview2 make -j4
- name: Build libc + threads
# Only build the thread-capable wasi-libc in the latest supported Clang
# version; the earliest version does not have all necessary builtins
# (e.g., `__builtin_wasm_memory_atomic_notify`).
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 THREAD_MODEL=posix
- name: Test
shell: bash
# For Clang linking to work correctly, we need to place Clang's runtime
@ -99,23 +107,17 @@ jobs:
export WASI_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasi/)
mkdir -p $WASI_DIR
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASI_DIR
make test
TARGET_TRIPLE=wasm32-wasi make test
rm -r build
WASI_SNAPSHOT=preview2 make test
TARGET_TRIPLE=wasm32-wasi-preview2 make test
rm -r build
TARGET_TRIPLE=wasm32-wasi-threads make test
# The older version of Clang does not provide the expected symbol for the
# test entrypoints: `undefined symbol: __main_argc_argv`.
# The older (<15.0.7) version of wasm-ld does not provide `__heap_end`,
# which is required by our malloc implementation.
if: matrix.os == 'ubuntu-latest' && matrix.clang_version != '10.0.0'
- name: Build libc + threads
# Only build the thread-capable wasi-libc in the latest supported Clang
# version; the earliest version does not have all necessary builtins
# (e.g., `__builtin_wasm_memory_atomic_notify`).
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 THREAD_MODEL=posix
- uses: actions/upload-artifact@v1
with:
# Upload the sysroot folder. Give it a name according to the OS it was built for.

View File

@ -23,6 +23,17 @@ MALLOC_IMPL ?= dlmalloc
BUILD_LIBC_TOP_HALF ?= yes
# The directory where we will store intermediate artifacts.
OBJDIR ?= build/$(TARGET_TRIPLE)
# The directory where we store files and tools for generating WASI Preview 2 bindings
BINDING_WORK_DIR ?= build/bindings
# URL from which to retrieve the WIT files used to generate the WASI Preview 2 bindings
WASI_CLI_URL ?= https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0-rc-2023-12-05.tar.gz
# URL from which to retrieve the `wit-bindgen` command used to generate the WASI
# Preview 2 bindings.
#
# TODO: Switch to bytecodealliance/wit-bindgen 0.17.0 once it's released (which
# will include https://github.com/bytecodealliance/wit-bindgen/pull/804 and
# https://github.com/bytecodealliance/wit-bindgen/pull/805, which we rely on)
WIT_BINDGEN_URL ?= https://github.com/dicej/wit-bindgen/releases/download/wit-bindgen-cli-0.17.0-dicej-pre0/wit-bindgen-v0.17.0-dicej-pre0-x86_64-linux.tar.gz
# When the length is no larger than this threshold, we consider the
# overhead of bulk memory opcodes to outweigh the performance benefit,
@ -37,7 +48,7 @@ BULK_MEMORY_THRESHOLD ?= 32
# Set the default WASI target triple.
TARGET_TRIPLE = wasm32-wasi
# Threaded version necessitates a different traget, as objects from different
# Threaded version necessitates a different target, as objects from different
# targets can't be mixed together while linking.
ifeq ($(THREAD_MODEL), posix)
TARGET_TRIPLE = wasm32-wasi-threads
@ -68,6 +79,16 @@ LIBC_BOTTOM_HALF_ALL_SOURCES = \
$(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \
$(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c))
ifeq ($(WASI_SNAPSHOT), preview1)
# Omit source files not relevant to WASI Preview 1. As we introduce files
# supporting `wasi-sockets` for `wasm32-wasi-preview2`, we'll add those files to
# this list.
LIBC_BOTTOM_HALF_OMIT_SOURCES := $(LIBC_BOTTOM_HALF_SOURCES)/preview2.c
LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES))
# Omit preview2.h from include-all.c test.
INCLUDE_ALL_CLAUSES := -not -name preview2.h
endif
# FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak
# references to a function defined in `chdir.c` only work if `chdir.c` is at the
# end of the archive, but once that LLD review lands and propagates into LLVM
@ -741,7 +762,7 @@ check-symbols: startup_files libc
# Generate a test file that includes all public C header files.
#
cd "$(SYSROOT_INC)" && \
for header in $$(find . -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h |grep -v /bits/ |grep -v /c++/); do \
for header in $$(find . -type f -not -name mman.h -not -name signal.h -not -name times.h -not -name resource.h $(INCLUDE_ALL_CLAUSES) |grep -v /bits/ |grep -v /c++/); do \
echo '#include <'$$header'>' | sed 's/\.\///' ; \
done |LC_ALL=C sort >$(SYSROOT_SHARE)/include-all.c ; \
cd - >/dev/null
@ -816,8 +837,65 @@ install: finish
mkdir -p "$(INSTALL_DIR)"
cp -r "$(SYSROOT)/lib" "$(SYSROOT)/share" "$(SYSROOT)/include" "$(INSTALL_DIR)"
$(BINDING_WORK_DIR)/wasi-cli:
mkdir -p "$(BINDING_WORK_DIR)"
cd "$(BINDING_WORK_DIR)" && \
curl -L "$(WASI_CLI_URL)" -o wasi-cli.tar.gz && \
tar xf wasi-cli.tar.gz && \
mv wasi-cli-* wasi-cli
$(BINDING_WORK_DIR)/wit-bindgen:
mkdir -p "$(BINDING_WORK_DIR)"
cd "$(BINDING_WORK_DIR)" && \
curl -L "$(WIT_BINDGEN_URL)" -o wit-bindgen.tar.gz && \
tar xf wit-bindgen.tar.gz && \
mv wit-bindgen-* wit-bindgen
bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
cd "$(BINDING_WORK_DIR)" && \
./wit-bindgen/wit-bindgen c \
--rename-world preview2 \
--type-section-suffix __wasi_libc \
--world wasi:cli/imports@0.2.0-rc-2023-12-05 \
--rename wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10=monotonic_clock \
--rename wasi:clocks/wall-clock@0.2.0-rc-2023-11-10=wall_clock \
--rename wasi:filesystem/preopens@0.2.0-rc-2023-11-10=filesystem_preopens \
--rename wasi:filesystem/types@0.2.0-rc-2023-11-10=filesystem \
--rename wasi:io/error@0.2.0-rc-2023-11-10=io_error \
--rename wasi:io/poll@0.2.0-rc-2023-11-10=poll \
--rename wasi:io/streams@0.2.0-rc-2023-11-10=streams \
--rename wasi:random/insecure-seed@0.2.0-rc-2023-11-10=random_insecure_seed \
--rename wasi:random/insecure@0.2.0-rc-2023-11-10=random_insecure \
--rename wasi:random/random@0.2.0-rc-2023-11-10=random \
--rename wasi:sockets/instance-network@0.2.0-rc-2023-11-10=instance_network \
--rename wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10=ip_name_lookup \
--rename wasi:sockets/network@0.2.0-rc-2023-11-10=network \
--rename wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10=tcp_create_socket \
--rename wasi:sockets/tcp@0.2.0-rc-2023-11-10=tcp \
--rename wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10=udp_create_socket \
--rename wasi:sockets/udp@0.2.0-rc-2023-11-10=udp \
--rename wasi:cli/environment@0.2.0-rc-2023-12-05=environment \
--rename wasi:cli/exit@0.2.0-rc-2023-12-05=exit \
--rename wasi:cli/stdin@0.2.0-rc-2023-12-05=stdin \
--rename wasi:cli/stdout@0.2.0-rc-2023-12-05=stdout \
--rename wasi:cli/stderr@0.2.0-rc-2023-12-05=stderr \
--rename wasi:cli/terminal-input@0.2.0-rc-2023-12-05=terminal_input \
--rename wasi:cli/terminal-output@0.2.0-rc-2023-12-05=terminal_output \
--rename wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05=terminal_stdin \
--rename wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05=terminal_stdout \
--rename wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05=terminal_stderr \
./wasi-cli/wit && \
mv preview2.h ../../libc-bottom-half/headers/public/wasi/ && \
mv preview2_component_type.o ../../libc-bottom-half/sources && \
sed 's_#include "preview2.h"_#include "wasi/preview2.h"_' \
< preview2.c \
> ../../libc-bottom-half/sources/preview2.c && \
rm preview2.c
clean:
$(RM) -r "$(BINDING_WORK_DIR)"
$(RM) -r "$(OBJDIR)"
$(RM) -r "$(SYSROOT)"
.PHONY: default startup_files libc libc_so finish install include_dirs clean check-symbols
.PHONY: default startup_files libc libc_so finish install include_dirs clean check-symbols bindings

View File

@ -19,6 +19,7 @@ __c_locale
__clock
__clock_gettime
__clock_nanosleep
__component_type_object_force_link_preview2_public_use_in_this_compilation_unit
__cos
__cosdf
__cosl
@ -403,6 +404,7 @@ btowc
bzero
c16rtomb
c32rtomb
cabi_realloc
cabs
cabsf
cabsl
@ -517,6 +519,9 @@ duplocale
ecvt
encrypt
environ
environment_get_arguments
environment_get_environment
environment_initial_cwd
erand48
erf
erfc
@ -526,6 +531,8 @@ erff
erfl
errno
exit
exit_exit
exit_result_void_void_free
exp
exp10
exp10f
@ -586,6 +593,63 @@ fgetws
fgetws_unlocked
fileno
fileno_unlocked
filesystem_borrow_descriptor
filesystem_borrow_directory_entry_stream
filesystem_descriptor_drop_borrow
filesystem_descriptor_drop_own
filesystem_descriptor_stat_free
filesystem_directory_entry_free
filesystem_directory_entry_stream_drop_borrow
filesystem_directory_entry_stream_drop_own
filesystem_filesystem_error_code
filesystem_method_descriptor_advise
filesystem_method_descriptor_append_via_stream
filesystem_method_descriptor_create_directory_at
filesystem_method_descriptor_get_flags
filesystem_method_descriptor_get_type
filesystem_method_descriptor_is_same_object
filesystem_method_descriptor_link_at
filesystem_method_descriptor_metadata_hash
filesystem_method_descriptor_metadata_hash_at
filesystem_method_descriptor_open_at
filesystem_method_descriptor_read
filesystem_method_descriptor_read_directory
filesystem_method_descriptor_read_via_stream
filesystem_method_descriptor_readlink_at
filesystem_method_descriptor_remove_directory_at
filesystem_method_descriptor_rename_at
filesystem_method_descriptor_set_size
filesystem_method_descriptor_set_times
filesystem_method_descriptor_set_times_at
filesystem_method_descriptor_stat
filesystem_method_descriptor_stat_at
filesystem_method_descriptor_symlink_at
filesystem_method_descriptor_sync
filesystem_method_descriptor_sync_data
filesystem_method_descriptor_unlink_file_at
filesystem_method_descriptor_write
filesystem_method_descriptor_write_via_stream
filesystem_method_directory_entry_stream_read_directory_entry
filesystem_new_timestamp_free
filesystem_option_datetime_free
filesystem_option_directory_entry_free
filesystem_option_error_code_free
filesystem_preopens_get_directories
filesystem_preopens_list_tuple2_own_descriptor_string_free
filesystem_preopens_tuple2_own_descriptor_string_free
filesystem_result_descriptor_flags_error_code_free
filesystem_result_descriptor_stat_error_code_free
filesystem_result_descriptor_type_error_code_free
filesystem_result_filesize_error_code_free
filesystem_result_metadata_hash_value_error_code_free
filesystem_result_option_directory_entry_error_code_free
filesystem_result_own_descriptor_error_code_free
filesystem_result_own_directory_entry_stream_error_code_free
filesystem_result_own_input_stream_error_code_free
filesystem_result_own_output_stream_error_code_free
filesystem_result_string_error_code_free
filesystem_result_tuple2_list_u8_bool_error_code_free
filesystem_result_void_error_code_free
finite
finitef
floor
@ -715,7 +779,22 @@ inet_ntop
inet_pton
initstate
insque
instance_network_instance_network
io_error_borrow_error
io_error_error_drop_borrow
io_error_error_drop_own
io_error_method_error_to_debug_string
ioctl
ip_name_lookup_borrow_resolve_address_stream
ip_name_lookup_ip_address_free
ip_name_lookup_method_resolve_address_stream_resolve_next_address
ip_name_lookup_method_resolve_address_stream_subscribe
ip_name_lookup_option_ip_address_free
ip_name_lookup_resolve_address_stream_drop_borrow
ip_name_lookup_resolve_address_stream_drop_own
ip_name_lookup_resolve_addresses
ip_name_lookup_result_option_ip_address_error_code_free
ip_name_lookup_result_own_resolve_address_stream_error_code_free
iprintf
isalnum
isalnum_l
@ -856,6 +935,10 @@ mmap
modf
modff
modfl
monotonic_clock_now
monotonic_clock_resolution
monotonic_clock_subscribe_duration
monotonic_clock_subscribe_instant
mrand48
munmap
nan
@ -865,6 +948,11 @@ nanosleep
nearbyint
nearbyintf
nearbyintl
network_borrow_network
network_ip_address_free
network_ip_socket_address_free
network_network_drop_borrow
network_network_drop_own
newlocale
nextafter
nextafterf
@ -893,6 +981,13 @@ optreset
pathconf
perror
poll
poll_borrow_pollable
poll_list_borrow_pollable_free
poll_method_pollable_block
poll_method_pollable_ready
poll_poll
poll_pollable_drop_borrow
poll_pollable_drop_own
posix_close
posix_fadvise
posix_fallocate
@ -905,6 +1000,15 @@ powf
powl
pread
preadv
preview2_list_string_free
preview2_list_tuple2_string_string_free
preview2_list_u32_free
preview2_list_u8_free
preview2_option_string_free
preview2_string_dup
preview2_string_free
preview2_string_set
preview2_tuple2_string_string_free
printf
program_invocation_name
program_invocation_short_name
@ -930,6 +1034,11 @@ raise
rand
rand_r
random
random_get_random_bytes
random_get_random_u64
random_insecure_get_insecure_random_bytes
random_insecure_get_insecure_random_u64
random_insecure_seed_insecure_seed
read
readdir
readlink
@ -1013,8 +1122,11 @@ srandom
sscanf
stat
stderr
stderr_get_stderr
stdin
stdin_get_stdin
stdout
stdout_get_stdout
stpcpy
stpncpy
strcasecmp
@ -1029,6 +1141,31 @@ strcoll_l
strcpy
strcspn
strdup
streams_borrow_input_stream
streams_borrow_output_stream
streams_input_stream_drop_borrow
streams_input_stream_drop_own
streams_method_input_stream_blocking_read
streams_method_input_stream_blocking_skip
streams_method_input_stream_read
streams_method_input_stream_skip
streams_method_input_stream_subscribe
streams_method_output_stream_blocking_flush
streams_method_output_stream_blocking_splice
streams_method_output_stream_blocking_write_and_flush
streams_method_output_stream_blocking_write_zeroes_and_flush
streams_method_output_stream_check_write
streams_method_output_stream_flush
streams_method_output_stream_splice
streams_method_output_stream_subscribe
streams_method_output_stream_write
streams_method_output_stream_write_zeroes
streams_output_stream_drop_borrow
streams_output_stream_drop_own
streams_result_list_u8_stream_error_free
streams_result_u64_stream_error_free
streams_result_void_stream_error_free
streams_stream_error_free
strerror
strerror_l
strerror_r
@ -1082,9 +1219,66 @@ tanh
tanhf
tanhl
tanl
tcp_borrow_tcp_socket
tcp_create_socket_create_tcp_socket
tcp_create_socket_result_own_tcp_socket_error_code_free
tcp_ip_socket_address_free
tcp_method_tcp_socket_accept
tcp_method_tcp_socket_address_family
tcp_method_tcp_socket_finish_bind
tcp_method_tcp_socket_finish_connect
tcp_method_tcp_socket_finish_listen
tcp_method_tcp_socket_hop_limit
tcp_method_tcp_socket_ipv6_only
tcp_method_tcp_socket_is_listening
tcp_method_tcp_socket_keep_alive_count
tcp_method_tcp_socket_keep_alive_enabled
tcp_method_tcp_socket_keep_alive_idle_time
tcp_method_tcp_socket_keep_alive_interval
tcp_method_tcp_socket_local_address
tcp_method_tcp_socket_receive_buffer_size
tcp_method_tcp_socket_remote_address
tcp_method_tcp_socket_send_buffer_size
tcp_method_tcp_socket_set_hop_limit
tcp_method_tcp_socket_set_ipv6_only
tcp_method_tcp_socket_set_keep_alive_count
tcp_method_tcp_socket_set_keep_alive_enabled
tcp_method_tcp_socket_set_keep_alive_idle_time
tcp_method_tcp_socket_set_keep_alive_interval
tcp_method_tcp_socket_set_listen_backlog_size
tcp_method_tcp_socket_set_receive_buffer_size
tcp_method_tcp_socket_set_send_buffer_size
tcp_method_tcp_socket_shutdown
tcp_method_tcp_socket_start_bind
tcp_method_tcp_socket_start_connect
tcp_method_tcp_socket_start_listen
tcp_method_tcp_socket_subscribe
tcp_result_bool_error_code_free
tcp_result_duration_error_code_free
tcp_result_ip_socket_address_error_code_free
tcp_result_tuple2_own_input_stream_own_output_stream_error_code_free
tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_free
tcp_result_u32_error_code_free
tcp_result_u64_error_code_free
tcp_result_u8_error_code_free
tcp_result_void_error_code_free
tcp_tcp_socket_drop_borrow
tcp_tcp_socket_drop_own
tdelete
tdestroy
telldir
terminal_input_borrow_terminal_input
terminal_input_terminal_input_drop_borrow
terminal_input_terminal_input_drop_own
terminal_output_borrow_terminal_output
terminal_output_terminal_output_drop_borrow
terminal_output_terminal_output_drop_own
terminal_stderr_get_terminal_stderr
terminal_stderr_option_own_terminal_output_free
terminal_stdin_get_terminal_stdin
terminal_stdin_option_own_terminal_input_free
terminal_stdout_get_terminal_stdout
terminal_stdout_option_own_terminal_output_free
tfind
tgamma
tgammaf
@ -1111,6 +1305,50 @@ truncf
truncl
tsearch
twalk
udp_borrow_incoming_datagram_stream
udp_borrow_outgoing_datagram_stream
udp_borrow_udp_socket
udp_create_socket_create_udp_socket
udp_create_socket_result_own_udp_socket_error_code_free
udp_incoming_datagram_free
udp_incoming_datagram_stream_drop_borrow
udp_incoming_datagram_stream_drop_own
udp_ip_socket_address_free
udp_list_incoming_datagram_free
udp_list_outgoing_datagram_free
udp_method_incoming_datagram_stream_receive
udp_method_incoming_datagram_stream_subscribe
udp_method_outgoing_datagram_stream_check_send
udp_method_outgoing_datagram_stream_send
udp_method_outgoing_datagram_stream_subscribe
udp_method_udp_socket_address_family
udp_method_udp_socket_finish_bind
udp_method_udp_socket_ipv6_only
udp_method_udp_socket_local_address
udp_method_udp_socket_receive_buffer_size
udp_method_udp_socket_remote_address
udp_method_udp_socket_send_buffer_size
udp_method_udp_socket_set_ipv6_only
udp_method_udp_socket_set_receive_buffer_size
udp_method_udp_socket_set_send_buffer_size
udp_method_udp_socket_set_unicast_hop_limit
udp_method_udp_socket_start_bind
udp_method_udp_socket_stream
udp_method_udp_socket_subscribe
udp_method_udp_socket_unicast_hop_limit
udp_option_ip_socket_address_free
udp_outgoing_datagram_free
udp_outgoing_datagram_stream_drop_borrow
udp_outgoing_datagram_stream_drop_own
udp_result_bool_error_code_free
udp_result_ip_socket_address_error_code_free
udp_result_list_incoming_datagram_error_code_free
udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_free
udp_result_u64_error_code_free
udp_result_u8_error_code_free
udp_result_void_error_code_free
udp_udp_socket_drop_borrow
udp_udp_socket_drop_own
uname
ungetc
ungetwc
@ -1139,6 +1377,8 @@ vswprintf
vswscanf
vwprintf
vwscanf
wall_clock_now
wall_clock_resolution
wcpcpy
wcpncpy
wcrtomb

View File

@ -167,5 +167,6 @@
#include <wasi/libc-find-relpath.h>
#include <wasi/libc-nocwd.h>
#include <wasi/libc.h>
#include <wasi/preview2.h>
#include <wchar.h>
#include <wctype.h>

View File

@ -335,6 +335,71 @@
#define FIFOTYPE '6'
#define FILENAME_MAX 4096
#define FILESIZEBITS 64
#define FILESYSTEM_ADVICE_DONT_NEED 4
#define FILESYSTEM_ADVICE_NORMAL 0
#define FILESYSTEM_ADVICE_NO_REUSE 5
#define FILESYSTEM_ADVICE_RANDOM 2
#define FILESYSTEM_ADVICE_SEQUENTIAL 1
#define FILESYSTEM_ADVICE_WILL_NEED 3
#define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3)
#define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2)
#define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5)
#define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0)
#define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4)
#define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1)
#define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1
#define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2
#define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3
#define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4
#define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6
#define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7
#define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5
#define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0
#define FILESYSTEM_ERROR_CODE_ACCESS 0
#define FILESYSTEM_ERROR_CODE_ALREADY 2
#define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3
#define FILESYSTEM_ERROR_CODE_BUSY 4
#define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36
#define FILESYSTEM_ERROR_CODE_DEADLOCK 5
#define FILESYSTEM_ERROR_CODE_EXIST 7
#define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8
#define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9
#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22
#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23
#define FILESYSTEM_ERROR_CODE_INTERRUPTED 11
#define FILESYSTEM_ERROR_CODE_INVALID 12
#define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34
#define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10
#define FILESYSTEM_ERROR_CODE_IO 13
#define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14
#define FILESYSTEM_ERROR_CODE_LOOP 15
#define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17
#define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18
#define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24
#define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25
#define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31
#define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26
#define FILESYSTEM_ERROR_CODE_NO_DEVICE 19
#define FILESYSTEM_ERROR_CODE_NO_ENTRY 20
#define FILESYSTEM_ERROR_CODE_NO_LOCK 21
#define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29
#define FILESYSTEM_ERROR_CODE_NO_TTY 28
#define FILESYSTEM_ERROR_CODE_OVERFLOW 30
#define FILESYSTEM_ERROR_CODE_PIPE 32
#define FILESYSTEM_ERROR_CODE_QUOTA 6
#define FILESYSTEM_ERROR_CODE_READ_ONLY 33
#define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35
#define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16
#define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27
#define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1
#define FILESYSTEM_NEW_TIMESTAMP_NOW 1
#define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0
#define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2
#define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0)
#define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1)
#define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2)
#define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3)
#define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0)
#define FIONBIO 2
#define FIONREAD 1
#define FLOATBITS (sizeof(float) * 8)
@ -1140,6 +1205,33 @@
#define ND_REDIRECT 137
#define ND_ROUTER_ADVERT 134
#define ND_ROUTER_SOLICIT 133
#define NETWORK_ERROR_CODE_ACCESS_DENIED 1
#define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12
#define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11
#define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6
#define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16
#define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14
#define NETWORK_ERROR_CODE_CONNECTION_RESET 15
#define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17
#define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3
#define NETWORK_ERROR_CODE_INVALID_STATE 9
#define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18
#define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10
#define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7
#define NETWORK_ERROR_CODE_NOT_SUPPORTED 2
#define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4
#define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20
#define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13
#define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19
#define NETWORK_ERROR_CODE_TIMEOUT 5
#define NETWORK_ERROR_CODE_UNKNOWN 0
#define NETWORK_ERROR_CODE_WOULD_BLOCK 8
#define NETWORK_IP_ADDRESS_FAMILY_IPV4 0
#define NETWORK_IP_ADDRESS_FAMILY_IPV6 1
#define NETWORK_IP_ADDRESS_IPV4 0
#define NETWORK_IP_ADDRESS_IPV6 1
#define NETWORK_IP_SOCKET_ADDRESS_IPV4 0
#define NETWORK_IP_SOCKET_ADDRESS_IPV6 1
#define NEW_ENV_VALUE 1
#define NEW_ENV_VAR 0
#define NGROUPS 32
@ -1634,6 +1726,8 @@
#define STDERR_FILENO 2
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STREAMS_STREAM_ERROR_CLOSED 1
#define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0
#define STRU_F 1
#define STRU_P 3
#define STRU_R 2
@ -1754,6 +1848,9 @@
#define TCP_REPAIR_WINDOW 29
#define TCP_SAVED_SYN 28
#define TCP_SAVE_SYN 27
#define TCP_SHUTDOWN_TYPE_BOTH 2
#define TCP_SHUTDOWN_TYPE_RECEIVE 0
#define TCP_SHUTDOWN_TYPE_SEND 1
#define TCP_SYNCNT 7
#define TCP_SYN_RECV 3
#define TCP_SYN_SENT 2
@ -2018,7 +2115,7 @@
#define _Complex_I (0.0f+1.0fi)
#define _DIRENT_H
#define _DIRENT_HAVE_D_TYPE
#define _DLFCN_H
#define _DLFCN_H
#define _ENDIAN_H
#define _ERRNO_H
#define _ERR_H
@ -2363,6 +2460,7 @@
#define __BIGGEST_ALIGNMENT__ 16
#define __BIG_ENDIAN 4321
#define __BIND 19950621
#define __BINDINGS_PREVIEW2_H
#define __BYTE_ORDER __BYTE_ORDER__
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __CHAR16_TYPE__ unsigned short

View File

@ -1,4 +1,5 @@
__addtf3
__component_type_object_force_link_preview2
__divtf3
__eqtf2
__extenddftf2
@ -66,3 +67,143 @@ __trunctfdf2
__trunctfsf2
__unordtf2
__wasm_call_ctors
__wasm_import_environment_get_arguments
__wasm_import_environment_get_environment
__wasm_import_environment_initial_cwd
__wasm_import_exit_exit
__wasm_import_filesystem_descriptor_drop
__wasm_import_filesystem_directory_entry_stream_drop
__wasm_import_filesystem_filesystem_error_code
__wasm_import_filesystem_method_descriptor_advise
__wasm_import_filesystem_method_descriptor_append_via_stream
__wasm_import_filesystem_method_descriptor_create_directory_at
__wasm_import_filesystem_method_descriptor_get_flags
__wasm_import_filesystem_method_descriptor_get_type
__wasm_import_filesystem_method_descriptor_is_same_object
__wasm_import_filesystem_method_descriptor_link_at
__wasm_import_filesystem_method_descriptor_metadata_hash
__wasm_import_filesystem_method_descriptor_metadata_hash_at
__wasm_import_filesystem_method_descriptor_open_at
__wasm_import_filesystem_method_descriptor_read
__wasm_import_filesystem_method_descriptor_read_directory
__wasm_import_filesystem_method_descriptor_read_via_stream
__wasm_import_filesystem_method_descriptor_readlink_at
__wasm_import_filesystem_method_descriptor_remove_directory_at
__wasm_import_filesystem_method_descriptor_rename_at
__wasm_import_filesystem_method_descriptor_set_size
__wasm_import_filesystem_method_descriptor_set_times
__wasm_import_filesystem_method_descriptor_set_times_at
__wasm_import_filesystem_method_descriptor_stat
__wasm_import_filesystem_method_descriptor_stat_at
__wasm_import_filesystem_method_descriptor_symlink_at
__wasm_import_filesystem_method_descriptor_sync
__wasm_import_filesystem_method_descriptor_sync_data
__wasm_import_filesystem_method_descriptor_unlink_file_at
__wasm_import_filesystem_method_descriptor_write
__wasm_import_filesystem_method_descriptor_write_via_stream
__wasm_import_filesystem_method_directory_entry_stream_read_directory_entry
__wasm_import_filesystem_preopens_get_directories
__wasm_import_instance_network_instance_network
__wasm_import_io_error_error_drop
__wasm_import_io_error_method_error_to_debug_string
__wasm_import_ip_name_lookup_method_resolve_address_stream_resolve_next_address
__wasm_import_ip_name_lookup_method_resolve_address_stream_subscribe
__wasm_import_ip_name_lookup_resolve_address_stream_drop
__wasm_import_ip_name_lookup_resolve_addresses
__wasm_import_monotonic_clock_now
__wasm_import_monotonic_clock_resolution
__wasm_import_monotonic_clock_subscribe_duration
__wasm_import_monotonic_clock_subscribe_instant
__wasm_import_network_network_drop
__wasm_import_poll_method_pollable_block
__wasm_import_poll_method_pollable_ready
__wasm_import_poll_poll
__wasm_import_poll_pollable_drop
__wasm_import_random_get_random_bytes
__wasm_import_random_get_random_u64
__wasm_import_random_insecure_get_insecure_random_bytes
__wasm_import_random_insecure_get_insecure_random_u64
__wasm_import_random_insecure_seed_insecure_seed
__wasm_import_stderr_get_stderr
__wasm_import_stdin_get_stdin
__wasm_import_stdout_get_stdout
__wasm_import_streams_input_stream_drop
__wasm_import_streams_method_input_stream_blocking_read
__wasm_import_streams_method_input_stream_blocking_skip
__wasm_import_streams_method_input_stream_read
__wasm_import_streams_method_input_stream_skip
__wasm_import_streams_method_input_stream_subscribe
__wasm_import_streams_method_output_stream_blocking_flush
__wasm_import_streams_method_output_stream_blocking_splice
__wasm_import_streams_method_output_stream_blocking_write_and_flush
__wasm_import_streams_method_output_stream_blocking_write_zeroes_and_flush
__wasm_import_streams_method_output_stream_check_write
__wasm_import_streams_method_output_stream_flush
__wasm_import_streams_method_output_stream_splice
__wasm_import_streams_method_output_stream_subscribe
__wasm_import_streams_method_output_stream_write
__wasm_import_streams_method_output_stream_write_zeroes
__wasm_import_streams_output_stream_drop
__wasm_import_tcp_create_socket_create_tcp_socket
__wasm_import_tcp_method_tcp_socket_accept
__wasm_import_tcp_method_tcp_socket_address_family
__wasm_import_tcp_method_tcp_socket_finish_bind
__wasm_import_tcp_method_tcp_socket_finish_connect
__wasm_import_tcp_method_tcp_socket_finish_listen
__wasm_import_tcp_method_tcp_socket_hop_limit
__wasm_import_tcp_method_tcp_socket_ipv6_only
__wasm_import_tcp_method_tcp_socket_is_listening
__wasm_import_tcp_method_tcp_socket_keep_alive_count
__wasm_import_tcp_method_tcp_socket_keep_alive_enabled
__wasm_import_tcp_method_tcp_socket_keep_alive_idle_time
__wasm_import_tcp_method_tcp_socket_keep_alive_interval
__wasm_import_tcp_method_tcp_socket_local_address
__wasm_import_tcp_method_tcp_socket_receive_buffer_size
__wasm_import_tcp_method_tcp_socket_remote_address
__wasm_import_tcp_method_tcp_socket_send_buffer_size
__wasm_import_tcp_method_tcp_socket_set_hop_limit
__wasm_import_tcp_method_tcp_socket_set_ipv6_only
__wasm_import_tcp_method_tcp_socket_set_keep_alive_count
__wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled
__wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time
__wasm_import_tcp_method_tcp_socket_set_keep_alive_interval
__wasm_import_tcp_method_tcp_socket_set_listen_backlog_size
__wasm_import_tcp_method_tcp_socket_set_receive_buffer_size
__wasm_import_tcp_method_tcp_socket_set_send_buffer_size
__wasm_import_tcp_method_tcp_socket_shutdown
__wasm_import_tcp_method_tcp_socket_start_bind
__wasm_import_tcp_method_tcp_socket_start_connect
__wasm_import_tcp_method_tcp_socket_start_listen
__wasm_import_tcp_method_tcp_socket_subscribe
__wasm_import_tcp_tcp_socket_drop
__wasm_import_terminal_input_terminal_input_drop
__wasm_import_terminal_output_terminal_output_drop
__wasm_import_terminal_stderr_get_terminal_stderr
__wasm_import_terminal_stdin_get_terminal_stdin
__wasm_import_terminal_stdout_get_terminal_stdout
__wasm_import_udp_create_socket_create_udp_socket
__wasm_import_udp_incoming_datagram_stream_drop
__wasm_import_udp_method_incoming_datagram_stream_receive
__wasm_import_udp_method_incoming_datagram_stream_subscribe
__wasm_import_udp_method_outgoing_datagram_stream_check_send
__wasm_import_udp_method_outgoing_datagram_stream_send
__wasm_import_udp_method_outgoing_datagram_stream_subscribe
__wasm_import_udp_method_udp_socket_address_family
__wasm_import_udp_method_udp_socket_finish_bind
__wasm_import_udp_method_udp_socket_ipv6_only
__wasm_import_udp_method_udp_socket_local_address
__wasm_import_udp_method_udp_socket_receive_buffer_size
__wasm_import_udp_method_udp_socket_remote_address
__wasm_import_udp_method_udp_socket_send_buffer_size
__wasm_import_udp_method_udp_socket_set_ipv6_only
__wasm_import_udp_method_udp_socket_set_receive_buffer_size
__wasm_import_udp_method_udp_socket_set_send_buffer_size
__wasm_import_udp_method_udp_socket_set_unicast_hop_limit
__wasm_import_udp_method_udp_socket_start_bind
__wasm_import_udp_method_udp_socket_stream
__wasm_import_udp_method_udp_socket_subscribe
__wasm_import_udp_method_udp_socket_unicast_hop_limit
__wasm_import_udp_outgoing_datagram_stream_drop
__wasm_import_udp_udp_socket_drop
__wasm_import_wall_clock_now
__wasm_import_wall_clock_resolution

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -16,8 +16,7 @@ test: run
OBJDIR ?= $(CURDIR)/build
DOWNDIR ?= $(CURDIR)/download
# preview1 or preview2
WASI_SNAPSHOT ?= preview1
TARGET_TRIPLE ?= wasm32-wasi
##### DOWNLOAD #################################################################
@ -25,7 +24,8 @@ LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test
LIBC_TEST = $(DOWNDIR)/libc-test
LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz
LIBRT = $(DOWNDIR)/lib/wasi/libclang_rt.builtins-wasm32.a
WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v16.0.0/wasmtime-v16.0.0-x86_64-linux.tar.xz
# TODO: Switch to Wasmtime 17 once it's released, which will include https://github.com/bytecodealliance/wasmtime/pull/7750
WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz
WASMTIME = $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime
WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.54/wasm-tools-1.0.54-x86_64-linux.tar.gz
WASM_TOOLS = $(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL) .tar.gz)/wasm-tools
@ -33,7 +33,7 @@ ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v1
ADAPTER = $(DOWNDIR)/wasi_snapshot_preview1.command.wasm
TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME)
ifeq ($(WASI_SNAPSHOT), preview2)
ifeq ($(TARGET_TRIPLE), wasm32-wasi-preview2)
TO_DOWNLOAD += $(ADAPTER) $(WASM_TOOLS)
endif
@ -129,11 +129,6 @@ WASM_OBJS += $(INFRA_WASM_OBJS)
DIRS := $(patsubst $(OBJDIR)/%/,%,$(sort $(dir $(WASM_OBJS))))
OBJDIRS := $(DIRS:%=$(OBJDIR)/%)
TARGET_TRIPLE = wasm32-wasi
ifeq ($(WASI_SNAPSHOT), preview2)
TARGET_TRIPLE = wasm32-wasi-preview2
endif
# Allow $(CC) to be set from the command line; ?= doesn't work for CC because
# make has a default value for it.
ifeq ($(origin CC), default)
@ -143,6 +138,9 @@ LDFLAGS ?=
CFLAGS ?= --target=$(TARGET_TRIPLE) --sysroot=../sysroot
# Always include the `libc-test` infrastructure headers.
CFLAGS += -I$(LIBC_TEST)/src/common
ifeq ($(TARGET_TRIPLE), wasm32-wasi-threads)
CFLAGS += -pthread
endif
# 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.
@ -154,7 +152,7 @@ build: download $(WASMS)
$(WASMS): | $(OBJDIRS)
$(OBJDIR)/%.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
ifeq ($(WASI_SNAPSHOT), preview2)
ifeq ($(TARGET_TRIPLE), wasm32-wasi-preview2)
$(WASM_TOOLS) component new --adapt $(ADAPTER) $@ -o $@
endif
@ -171,7 +169,7 @@ clean::
##### RUN ######################################################################
ENGINE ?= $(WASMTIME) run
ifeq ($(WASI_SNAPSHOT), preview2)
ifeq ($(TARGET_TRIPLE), wasm32-wasi-preview2)
ENGINE += --wasm component-model
endif
ERRS:=$(WASMS:%.wasm=%.wasm.err)