Skip to content

Commit f629dda

Browse files
committed
Add a wasm32-wasip3 target
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 06bef3c commit f629dda

113 files changed

Lines changed: 13332 additions & 2740 deletions

File tree

Some content is hidden

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

.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
@@ -65,6 +65,9 @@ elseif(TARGET_TRIPLE MATCHES "-wasip1$")
6565
elseif(TARGET_TRIPLE MATCHES "-wasip2$")
6666
set(WASI p2)
6767
set(SHARED ON)
68+
elseif(TARGET_TRIPLE MATCHES "-wasip3$")
69+
set(WASI p3)
70+
set(SHARED ON)
6871
else()
6972
message(FATAL_ERROR "Unknown WASI target triple: ${TARGET_TRIPLE}")
7073
endif()
@@ -131,6 +134,8 @@ if(WASI STREQUAL "p1")
131134
set(__wasip1__ ON)
132135
elseif(WASI STREQUAL "p2")
133136
set(__wasip2__ ON)
137+
elseif(WASI STREQUAL "p3")
138+
set(__wasip3__ ON)
134139
else()
135140
message(FATAL_ERROR "Unknown WASI version: ${WASI}")
136141
endif()
@@ -317,6 +322,8 @@ endif()
317322
# here since I can't figure out anything else that works for now.
318323
if (WASI STREQUAL "p2")
319324
set(libc_extra_objects libc-bottom-half/sources/wasip2_component_type.o)
325+
elseif (WASI STREQUAL "p3")
326+
set(libc_extra_objects libc-bottom-half/sources/wasip3_component_type.o)
320327
endif()
321328

322329
add_library(c SHARED EXCLUDE_FROM_ALL

cmake/bindings.cmake

Lines changed: 99 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,119 @@ else()
3535
endif()
3636

3737
include(ExternalProject)
38+
set(p2 0.2.0)
3839
ExternalProject_Add(
39-
wasi-wits
40-
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz
40+
wasip2-wits
41+
URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p2}.tar.gz
4142
CONFIGURE_COMMAND ""
4243
BUILD_COMMAND ""
4344
INSTALL_COMMAND ""
4445
EXCLUDE_FROM_ALL TRUE
4546
)
46-
ExternalProject_Get_Property(wasi-wits SOURCE_DIR)
47-
set(wit_dir ${SOURCE_DIR}/wit)
47+
ExternalProject_Get_Property(wasip2-wits SOURCE_DIR)
48+
set(wasip2_wit_dir ${SOURCE_DIR}/wit)
4849
set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half")
4950

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