Skip to content

Commit 6036a9f

Browse files
authored
Add a wasm32-wasip3 target (#700)
Almost all functions are stubbed out to return errors. This is all done in preparation for eventually filling out these functions, but the goal of this commit is to lay down the scaffolding of the target rather than actually implement anything. CI jobs are added to build and test this target. Most tests are expected to fail, but all tests are still run as usual. Once tests are passing they'll be updated in `CMakeLists.txt` to flag the test as expected to pass instead of expected to fail. This is a very large PR line-wise, but all the major changes with large chunks of code are generated code and are expected to be easy to review. The actual changes here in the source are primarily: * Adding `#elif defined(__wasip3__)` cases * Sometimes using the WASIp2 definitions of functions for WASIp3 * Shuffling naming in the network utilities to support both WASIp2 and WASIp3 which have the same types, just renamed. * Generated bindings for WASIp3 are now vendored like WASIp2 bindings. * Wasmtime is updated for testing to be able to run generated WASIp3 binaries.
1 parent 637bdc9 commit 6036a9f

File tree

113 files changed

+13334
-2741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+13334
-2741
lines changed

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22
# them differing depending on the line-ending style of the host they
33
# were checked out on.
44
* text eol=lf
5+
6+
# All of the `expected/**/*.txt` files are auto-generated via the
7+
# `update-symbols` target, so flag them as such.
8+
expected linguist-generated
9+
10+
# Flag some wit-bindgen-generated files checked into the repo as generated
11+
__generated_wasip2.h linguist-generated
12+
__generated_wasip3.h linguist-generated
13+
libc-bottom-half/sources/wasip2.c linguist-generated
14+
libc-bottom-half/sources/wasip3.c linguist-generated

.github/workflows/main.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ jobs:
125125
test: true
126126
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip1-threads
127127

128+
- name: Test wasm32-wasip3
129+
os: ubuntu-24.04
130+
clang_version: 19
131+
test: true
132+
upload: wasm32-wasip3
133+
args: -DTARGET_TRIPLE=wasm32-wasip3
134+
135+
- name: Test wasm32-wasip3 (debug)
136+
os: ubuntu-24.04
137+
clang_version: 19
138+
test: true
139+
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip3
140+
128141
- name: Test emmalloc
129142
os: ubuntu-24.04
130143
clang_version: 19

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ elseif(TARGET_TRIPLE MATCHES "-wasip1$")
6666
elseif(TARGET_TRIPLE MATCHES "-wasip2$")
6767
set(WASI p2)
6868
set(SHARED ON)
69+
elseif(TARGET_TRIPLE MATCHES "-wasip3$")
70+
set(WASI p3)
71+
set(SHARED ON)
6972
else()
7073
message(FATAL_ERROR "Unknown WASI target triple: ${TARGET_TRIPLE}")
7174
endif()
@@ -132,6 +135,8 @@ if(WASI STREQUAL "p1")
132135
set(__wasip1__ ON)
133136
elseif(WASI STREQUAL "p2")
134137
set(__wasip2__ ON)
138+
elseif(WASI STREQUAL "p3")
139+
set(__wasip3__ ON)
135140
else()
136141
message(FATAL_ERROR "Unknown WASI version: ${WASI}")
137142
endif()
@@ -318,6 +323,8 @@ endif()
318323
# here since I can't figure out anything else that works for now.
319324
if (WASI STREQUAL "p2")
320325
set(libc_extra_objects libc-bottom-half/sources/wasip2_component_type.o)
326+
elseif (WASI STREQUAL "p3")
327+
set(libc_extra_objects libc-bottom-half/sources/wasip3_component_type.o)
321328
endif()
322329

323330
add_library(c SHARED EXCLUDE_FROM_ALL

cmake/bindings.cmake

Lines changed: 100 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,63 +31,124 @@ if (NOT WIT_BINDGEN_EXECUTABLE)
3131
ExternalProject_Get_Property(wit-bindgen SOURCE_DIR)
3232
set(wit_bindgen "${SOURCE_DIR}/wit-bindgen")
3333
else()
34+
add_custom_target(wit-bindgen)
3435
set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE})
3536
endif()
3637

3738
include(ExternalProject)
39+
set(p2 0.2.0)
3840
ExternalProject_Add(
39-
wasi-wits
40-
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz
41+
wasip2-wits
42+
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p2}.tar.gz
4143
CONFIGURE_COMMAND ""
4244
BUILD_COMMAND ""
4345
INSTALL_COMMAND ""
4446
EXCLUDE_FROM_ALL TRUE
4547
)
46-
ExternalProject_Get_Property(wasi-wits SOURCE_DIR)
47-
set(wit_dir ${SOURCE_DIR}/wit)
48+
ExternalProject_Get_Property(wasip2-wits SOURCE_DIR)
49+
set(wasip2_wit_dir ${SOURCE_DIR}/wit)
4850
set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half")
4951

5052
add_custom_target(
51-
bindings
53+
bindings-p2
5254
COMMAND
5355
${wit_bindgen} c
5456
--autodrop-borrows yes
5557
--rename-world wasip2
5658
--type-section-suffix __wasi_libc
57-
--world wasi:cli/imports@0.2.0
58-
--rename wasi:clocks/monotonic-clock@0.2.0=monotonic_clock
59-
--rename wasi:clocks/wall-clock@0.2.0=wall_clock
60-
--rename wasi:filesystem/preopens@0.2.0=filesystem_preopens
61-
--rename wasi:filesystem/types@0.2.0=filesystem
62-
--rename wasi:io/error@0.2.0=io_error
63-
--rename wasi:io/poll@0.2.0=poll
64-
--rename wasi:io/streams@0.2.0=streams
65-
--rename wasi:random/insecure-seed@0.2.0=random_insecure_seed
66-
--rename wasi:random/insecure@0.2.0=random_insecure
67-
--rename wasi:random/random@0.2.0=random
68-
--rename wasi:sockets/instance-network@0.2.0=instance_network
69-
--rename wasi:sockets/ip-name-lookup@0.2.0=ip_name_lookup
70-
--rename wasi:sockets/network@0.2.0=network
71-
--rename wasi:sockets/tcp-create-socket@0.2.0=tcp_create_socket
72-
--rename wasi:sockets/tcp@0.2.0=tcp
73-
--rename wasi:sockets/udp-create-socket@0.2.0=udp_create_socket
74-
--rename wasi:sockets/udp@0.2.0=udp
75-
--rename wasi:cli/environment@0.2.0=environment
76-
--rename wasi:cli/exit@0.2.0=exit
77-
--rename wasi:cli/stdin@0.2.0=stdin
78-
--rename wasi:cli/stdout@0.2.0=stdout
79-
--rename wasi:cli/stderr@0.2.0=stderr
80-
--rename wasi:cli/terminal-input@0.2.0=terminal_input
81-
--rename wasi:cli/terminal-output@0.2.0=terminal_output
82-
--rename wasi:cli/terminal-stdin@0.2.0=terminal_stdin
83-
--rename wasi:cli/terminal-stdout@0.2.0=terminal_stdout
84-
--rename wasi:cli/terminal-stderr@0.2.0=terminal_stderr
85-
${wit_dir}
86-
COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/
59+
--world wasi:cli/imports@${p2}
60+
--rename wasi:clocks/monotonic-clock@${p2}=monotonic_clock
61+
--rename wasi:clocks/wall-clock@${p2}=wall_clock
62+
--rename wasi:filesystem/preopens@${p2}=filesystem_preopens
63+
--rename wasi:filesystem/types@${p2}=filesystem
64+
--rename wasi:io/error@${p2}=io_error
65+
--rename wasi:io/poll@${p2}=poll
66+
--rename wasi:io/streams@${p2}=streams
67+
--rename wasi:random/insecure-seed@${p2}=random_insecure_seed
68+
--rename wasi:random/insecure@${p2}=random_insecure
69+
--rename wasi:random/random@${p2}=random
70+
--rename wasi:sockets/instance-network@${p2}=instance_network
71+
--rename wasi:sockets/ip-name-lookup@${p2}=ip_name_lookup
72+
--rename wasi:sockets/network@${p2}=network
73+
--rename wasi:sockets/tcp-create-socket@${p2}=tcp_create_socket
74+
--rename wasi:sockets/tcp@${p2}=tcp
75+
--rename wasi:sockets/udp-create-socket@${p2}=udp_create_socket
76+
--rename wasi:sockets/udp@${p2}=udp
77+
--rename wasi:cli/environment@${p2}=environment
78+
--rename wasi:cli/exit@${p2}=exit
79+
--rename wasi:cli/stdin@${p2}=stdin
80+
--rename wasi:cli/stdout@${p2}=stdout
81+
--rename wasi:cli/stderr@${p2}=stderr
82+
--rename wasi:cli/terminal-input@${p2}=terminal_input
83+
--rename wasi:cli/terminal-output@${p2}=terminal_output
84+
--rename wasi:cli/terminal-stdin@${p2}=terminal_stdin
85+
--rename wasi:cli/terminal-stdout@${p2}=terminal_stdout
86+
--rename wasi:cli/terminal-stderr@${p2}=terminal_stderr
87+
${wasip2_wit_dir}
88+
COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/__generated_wasip2.h
8789
COMMAND cmake -E copy wasip2_component_type.o ${bottom_half}/sources
8890
COMMAND cmake -E copy wasip2.c ${bottom_half}/sources
89-
COMMAND sed -i "'s_#include .wasip2\.h._#include \"wasi/wasip2.h\"_'" ${bottom_half}/sources/wasip2.c
90-
COMMAND sed -i "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/wasip2.h
91-
COMMAND sed -i "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasip2.c
92-
DEPENDS wit-bindgen wasi-wits
91+
DEPENDS wit-bindgen wasip2-wits
9392
)
93+
94+
set(p3 0.3.0-rc-2025-09-16)
95+
ExternalProject_Add(
96+
wasip3-wits
97+
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p3}.tar.gz
98+
CONFIGURE_COMMAND ""
99+
BUILD_COMMAND ""
100+
INSTALL_COMMAND ""
101+
EXCLUDE_FROM_ALL TRUE
102+
)
103+
ExternalProject_Get_Property(wasip3-wits SOURCE_DIR)
104+
set(wasip3_wit_dir ${SOURCE_DIR}/wit-0.3.0-draft)
105+
106+
add_custom_target(
107+
bindings-p3
108+
COMMAND
109+
${wit_bindgen} c
110+
--autodrop-borrows yes
111+
--rename-world wasip3
112+
--type-section-suffix __wasi_libc
113+
--world wasi:cli/imports@${p3}
114+
--rename wasi:clocks/monotonic-clock@${p3}=monotonic_clock
115+
--rename wasi:clocks/wall-clock@${p3}=wall_clock
116+
--rename wasi:filesystem/preopens@${p3}=filesystem_preopens
117+
--rename wasi:filesystem/types@${p3}=filesystem
118+
--rename wasi:random/insecure-seed@${p3}=random_insecure_seed
119+
--rename wasi:random/insecure@${p3}=random_insecure
120+
--rename wasi:random/random@${p3}=random
121+
--rename wasi:sockets/types@${p3}=sockets
122+
--rename wasi:sockets/ip-name-lookup@${p3}=ip_name_lookup
123+
--rename wasi:cli/environment@${p3}=environment
124+
--rename wasi:cli/exit@${p3}=exit
125+
--rename wasi:cli/stdin@${p3}=stdin
126+
--rename wasi:cli/stdout@${p3}=stdout
127+
--rename wasi:cli/stderr@${p3}=stderr
128+
--rename wasi:cli/terminal-input@${p3}=terminal_input
129+
--rename wasi:cli/terminal-output@${p3}=terminal_output
130+
--rename wasi:cli/terminal-stdin@${p3}=terminal_stdin
131+
--rename wasi:cli/terminal-stdout@${p3}=terminal_stdout
132+
--rename wasi:cli/terminal-stderr@${p3}=terminal_stderr
133+
${wasip3_wit_dir}
134+
COMMAND cmake -E copy wasip3.h ${bottom_half}/headers/public/wasi/__generated_wasip3.h
135+
COMMAND cmake -E copy wasip3_component_type.o ${bottom_half}/sources
136+
COMMAND cmake -E copy wasip3.c ${bottom_half}/sources
137+
DEPENDS wit-bindgen wasip3-wits
138+
)
139+
140+
add_custom_target(bindings DEPENDS bindings-p2 bindings-p3)
141+
142+
function(wit_bindgen_edit p)
143+
add_custom_target(
144+
bindings-${p}-edit
145+
COMMAND sed -i "" "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c
146+
COMMAND sed -i "" "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h
147+
COMMAND sed -i "" "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c
148+
DEPENDS bindings-${p}
149+
)
150+
add_dependencies(bindings bindings-${p}-edit)
151+
endfunction()
152+
153+
wit_bindgen_edit(p2)
154+
wit_bindgen_edit(p3)

cmake/check-symbols.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ elseif(WASI STREQUAL "p1")
2828
set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip1")
2929
elseif(WASI STREQUAL "p2")
3030
set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip2")
31+
elseif(WASI STREQUAL "p3")
32+
set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip3")
3133
else()
3234
message(FATAL_ERROR "Unknown WASI version: ${WASI}")
3335
endif()

cmake/clang-format.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ add_custom_target(format-check)
2020
set(formatted_sources)
2121

2222
function(clang_format_file file)
23-
if (file MATCHES "wasip2\..$") # Skip auto-generated files
23+
if (file MATCHES "__generated" OR
24+
file MATCHES "wasip.\.c$") # Skip auto-generated files
2425
return()
2526
endif()
2627
cmake_path(ABSOLUTE_PATH file BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE src)

cmake/wasm-component-ld.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if (NOT WASM_COMPONENT_LD_EXECUTABLE)
1414
)
1515
ExternalProject_Get_Property(wasm-component-ld SOURCE_DIR)
1616
set(WASM_COMPONENT_LD_EXECUTABLE "${SOURCE_DIR}/wasm-component-ld")
17-
add_link_options(-fuse-ld=${WASM_COMPONENT_LD_EXECUTABLE})
1817
add_dependencies(sysroot_inc wasm-component-ld)
1918
endif()
19+
20+
add_link_options(-fuse-ld=${WASM_COMPONENT_LD_EXECUTABLE})

expected/wasm32-wasip1-threads/include-all.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,7 @@
173173
#include <wasi/libc.h>
174174
#include <wasi/version.h>
175175
#include <wasi/wasip1.h>
176+
#include <wasi/wasip2.h>
177+
#include <wasi/wasip3.h>
176178
#include <wchar.h>
177179
#include <wctype.h>

expected/wasm32-wasip1-threads/predefined-macros.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,6 +3093,8 @@
30933093
#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1))
30943094
#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
30953095
#define __WASI_VERSION_H
3096+
#define __WASI_WASIP2_H
3097+
#define __WASI_WASIP3_H
30963098
#define __WASI_WHENCE_CUR (UINT8_C(1))
30973099
#define __WASI_WHENCE_END (UINT8_C(2))
30983100
#define __WASI_WHENCE_SET (UINT8_C(0))

expected/wasm32-wasip1/include-all.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,7 @@
173173
#include <wasi/libc.h>
174174
#include <wasi/version.h>
175175
#include <wasi/wasip1.h>
176+
#include <wasi/wasip2.h>
177+
#include <wasi/wasip3.h>
176178
#include <wchar.h>
177179
#include <wctype.h>

0 commit comments

Comments
 (0)