Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5498029
Big ugly WIP
bvisness Sep 30, 2026
522af17
time.h
bvisness Sep 30, 2026
cc8c7c3
Try to bind performance.now() in anticipation of monotonic clocks
bvisness Sep 30, 2026
518ba9a
Well, wit-bindgen is 1% happier
bvisness Oct 3, 2026
13fd474
Lots of time fixes + web-specific error reporting?
bvisness Oct 3, 2026
1031ca3
Don't include translate_error in webp2
bvisness Oct 3, 2026
a5661ed
Organize libc-bottom-half sources by category
bvisness Oct 3, 2026
4f5370f
Random implementation (disaster)
bvisness Oct 3, 2026
648d442
Always trap on exit
bvisness Oct 3, 2026
4027b90
Main ramblings
bvisness Oct 4, 2026
7f2fa0f
Empty environment for web
bvisness Oct 4, 2026
24fe702
Use many randomness hooray
bvisness Oct 4, 2026
1cecdc1
Actually build enough to get linker errors!!
bvisness Oct 4, 2026
7b6bc3a
Slog through many linker errors
bvisness Oct 4, 2026
e4e27cf
Exit 0!!!
bvisness Oct 4, 2026
6911219
Set -fvisibiliyt-hidden on webp2.c
bvisness Oct 5, 2026
8bdaabd
Hopefully fix CI errors
bvisness Oct 5, 2026
31dff18
Ensure trapping stubs for weakly aliased things we excluded
bvisness Oct 6, 2026
ef154ba
Exclude some headers and add some stubs
bvisness Oct 6, 2026
42ad0d9
Stub remaining header symbols
bvisness Oct 6, 2026
edfdcd5
Run update-symbols for webp2
bvisness Oct 6, 2026
92117be
Fix formatting, run more webp2 stuff in CI
bvisness Oct 6, 2026
ff9460e
Shrink initial __wasilibc_random allocation
bvisness Oct 6, 2026
dd3e50c
Properly stub sleep functions
bvisness Oct 6, 2026
89b9661
Remove unnecessary webp2 guards from sources that are no longer compiled
bvisness Oct 6, 2026
115eed7
Suppress unnecessary wasi headers
bvisness Oct 6, 2026
df8719f
Merge remote-tracking branch 'origin/main' into webp2
bvisness Oct 6, 2026
cabca69
Update expected files
bvisness Oct 6, 2026
28cbcb5
Better regex for a target triple
bvisness Oct 6, 2026
39664f1
Change what gets the external-id in WIT
bvisness Oct 7, 2026
96e1c0e
Fix formatting and expected symbols
bvisness Oct 7, 2026
6b78b5c
Support new WEB system name
bvisness Oct 8, 2026
2a623e6
Bump wasm-component-ld version for accessor support
bvisness Oct 8, 2026
2969570
Hook main into _initialize for webp2
bvisness Oct 8, 2026
4cb0ed1
Import web things from wasm:js/global interface
bvisness Oct 9, 2026
8825299
Use newer wasm-tools in tests
bvisness Oct 9, 2026
f6ef789
WIP stdio
bvisness Oct 9, 2026
13a3808
Move the console's external-id to the import
bvisness Oct 9, 2026
c9dd7b6
Fix stdio bugs
bvisness Oct 10, 2026
aa1ecfd
Only emit valid UTF-8 on stdout/stderr
bvisness Oct 11, 2026
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ expected linguist-generated
# Flag some wit-bindgen-generated files checked into the repo as generated
__generated_wasip2.h linguist-generated
__generated_wasip3.h linguist-generated
__generated_webp2.h linguist-generated
libc-bottom-half/sources/wasip2.c linguist-generated
libc-bottom-half/sources/wasip3.c linguist-generated
libc-bottom-half/sources/webp2.c linguist-generated
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ jobs:
test: true
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip3 -DENABLE_COOP_THREADS=ON

- name: Test wasm32-webp2
os: ubuntu-24.04
clang_version: 22
upload: wasm32-webp2
# TODO(webp2): Enable tests once there is a way to run them.
test: false
args: -DTARGET_TRIPLE=wasm32-webp2

- name: Test emmalloc
os: ubuntu-24.04
clang_version: 20
Expand Down Expand Up @@ -259,6 +267,8 @@ jobs:
- run: ninja -C build format-check
- run: cmake -S . -B build -DTARGET_TRIPLE=wasm32-wasip3
- run: ninja -C build format-check
- run: cmake -S . -B build -DTARGET_TRIPLE=wasm32-webp2
- run: ninja -C build format-check

rustfmt:
name: Rustfmt
Expand All @@ -279,6 +289,9 @@ jobs:
- uses: actions/checkout@v6
with:
submodules: true
# TODO(webp2): Switch back to a released wit-bindgen once one ships with
# getter/setter support (bytecodealliance/wit-bindgen#1726).
- run: cargo install wit-bindgen-cli --locked --git https://github.com/bytecodealliance/wit-bindgen --rev 7fb7a6a072a2c7d225fa183b93acfabdc36e744b
- run: CC=clang cmake -S . -B build -G Ninja
- run: ninja -C build bindings
- run: git diff --exit-code
Expand Down
34 changes: 27 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type to use" FORCE)
endif()

# Force a cross-compile to WASI at all times.
set(CMAKE_SYSTEM_NAME WASI)
set(TARGET_TRIPLE "wasm32-wasip1" CACHE STRING "WASI target to test")
set(CMAKE_C_COMPILER_TARGET ${TARGET_TRIPLE})

# Force a cross-compile to WASI or WEB at all times.
if(TARGET_TRIPLE MATCHES "-wasi")
set(CMAKE_SYSTEM_NAME WASI)
elseif(TARGET_TRIPLE MATCHES "-web")
set(CMAKE_SYSTEM_NAME WEB)
else()
message(FATAL_ERROR "Unknown target triple: ${TARGET_TRIPLE}")
endif()

# I'm not entirely sure why this is necessary on Windows. This may be a bug in
# CMake, I'm not sure. The problem is that, at least on CI, CMake detects that
Expand All @@ -26,9 +35,6 @@ if (CMAKE_HOST_WIN32)
set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
endif()

set(TARGET_TRIPLE "wasm32-wasip1" CACHE STRING "WASI target to test")
set(CMAKE_C_COMPILER_TARGET ${TARGET_TRIPLE})

# We're building libc, and the compiler being used may not have a wasm sysroot
# for libc, so skip this check. Otherwise the `project` call below attempts a
# link to see if the compiler is working and if that fails it doesn't mean it
Expand Down Expand Up @@ -79,8 +85,11 @@ elseif(TARGET_TRIPLE MATCHES "-wasip2$")
elseif(TARGET_TRIPLE MATCHES "-wasip3$")
set(WASI p3)
set(SHARED ON)
elseif(TARGET_TRIPLE MATCHES "-webp2$")
set(WEB p2)
set(SHARED ON)
else()
message(FATAL_ERROR "Unknown WASI target triple: ${TARGET_TRIPLE}")
message(FATAL_ERROR "Unknown target triple: ${TARGET_TRIPLE}")
endif()

if(BUILD_SHARED)
Expand Down Expand Up @@ -149,12 +158,15 @@ elseif(WASI STREQUAL "p2")
set(__wasip2__ ON)
elseif(WASI STREQUAL "p3")
set(__wasip3__ ON)
elseif(WEB STREQUAL "p2")
set(__webp2__ ON)
else()
message(FATAL_ERROR "Unknown WASI version: ${WASI}")
endif()

set(wasip2-version 0.2.12)
set(wasip3-version 0.3.0)
set(webp2-version 0.2.0)

# =============================================================================
# Detection of a libcall thread context for wasip3
Expand Down Expand Up @@ -204,6 +216,12 @@ add_link_options(
-resource-dir ${tmp_resource_dir}
)

if(__webp2__)
# TODO(webp2): Manually instruct clang to look at our new webp2 sysroot until
# it has been patched in wasi-sdk to know about "webp2" as an OS.
add_link_options(-B${SYSROOT_LIB} -L${SYSROOT_LIB})
endif()

# Expose the public headers to the implementation. We use `-isystem` for
# purpose for two reasons:
#
Expand Down Expand Up @@ -251,7 +269,7 @@ check_c_compiler_flag(-fdefer-ts HAVE_FDEFER_TS)
if(HAVE_FDEFER_TS)
add_compile_options(-fdefer-ts)
elseif(NOT WASI STREQUAL "p1")
message(FATAL_ERROR "wasip2/wasip3 require clang 22 or later for `-fdefer-ts`")
message(FATAL_ERROR "wasip2/wasip3/webp2 require clang 22 or later for `-fdefer-ts`")
endif()

# =============================================================================
Expand Down Expand Up @@ -372,6 +390,8 @@ if (WASI STREQUAL "p2")
set(libc_extra_objects libc-bottom-half/sources/wasip2_component_type.o)
elseif (WASI STREQUAL "p3")
set(libc_extra_objects libc-bottom-half/sources/wasip3_component_type.o)
elseif (WEB STREQUAL "p2")
set(libc_extra_objects libc-bottom-half/sources/webp2_component_type.o)
endif()

add_library(c SHARED EXCLUDE_FROM_ALL
Expand Down
1 change: 1 addition & 0 deletions cmake/Platform/WEB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(WEB 1)
39 changes: 28 additions & 11 deletions cmake/bindings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if(WIT_BINDGEN_EXECUTABLE)
OUTPUT_VARIABLE WIT_BINDGEN_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.60\\.0"))
message(WARNING "wit-bindgen version 0.60.0 is required, found: ${WIT_BINDGEN_VERSION}")
if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.62\\.0"))
message(WARNING "wit-bindgen version 0.62.0 is required, found: ${WIT_BINDGEN_VERSION}")
set(WIT_BINDGEN_EXECUTABLE "")
endif()
endif()
Expand All @@ -26,7 +26,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE)
ba_download(
wit-bindgen
"https://github.com/bytecodealliance/wit-bindgen"
"0.60.0"
"0.62.0"
)
ExternalProject_Get_Property(wit-bindgen SOURCE_DIR)
set(wit_bindgen "${SOURCE_DIR}/wit-bindgen")
Expand All @@ -38,7 +38,7 @@ endif()
set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half")

add_custom_target(
bindings-p2
bindings-wasip2
COMMAND
${wit_bindgen} c
--autodrop-borrows yes
Expand Down Expand Up @@ -80,7 +80,7 @@ add_custom_target(
)

add_custom_target(
bindings-p3
bindings-wasip3
COMMAND
${wit_bindgen} c
--autodrop-borrows yes
Expand Down Expand Up @@ -138,7 +138,23 @@ add_custom_target(
DEPENDS wit-bindgen wasip3-wits
)

add_custom_target(bindings DEPENDS bindings-p2 bindings-p3)
add_custom_target(
bindings-webp2
COMMAND
${wit_bindgen} c
--autodrop-borrows yes
--rename wasm:js/global=webp2
--rename wasm:js/console=webp2_console
--rename-world webp2
--type-section-suffix __wasi_libc
${CMAKE_SOURCE_DIR}/web/p2/wit
COMMAND cmake -E copy webp2.h ${bottom_half}/headers/public/wasi/__generated_webp2.h
COMMAND cmake -E copy webp2_component_type.o ${bottom_half}/sources
COMMAND cmake -E copy webp2.c ${bottom_half}/sources
DEPENDS wit-bindgen
)

add_custom_target(bindings DEPENDS bindings-wasip2 bindings-wasip3 bindings-webp2)

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(SED_INPLACE_ARGS -i '')
Expand All @@ -149,13 +165,14 @@ endif()
function(wit_bindgen_edit p)
add_custom_target(
bindings-${p}-edit
COMMAND sed ${SED_INPLACE_ARGS} "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c
COMMAND sed ${SED_INPLACE_ARGS} "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h
COMMAND sed ${SED_INPLACE_ARGS} "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c
COMMAND sed ${SED_INPLACE_ARGS} "'s_#include .${p}\.h._#include \"wasi/${p}.h\"_'" ${bottom_half}/sources/${p}.c
COMMAND sed ${SED_INPLACE_ARGS} "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_${p}.h
COMMAND sed ${SED_INPLACE_ARGS} "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/${p}.c
DEPENDS bindings-${p}
)
add_dependencies(bindings bindings-${p}-edit)
endfunction()

wit_bindgen_edit(p2)
wit_bindgen_edit(p3)
wit_bindgen_edit(wasip2)
wit_bindgen_edit(wasip3)
wit_bindgen_edit(webp2)
2 changes: 2 additions & 0 deletions cmake/check-symbols.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ elseif(WASI STREQUAL "p3")
else()
set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip3")
endif()
elseif(WEB STREQUAL "p2")
set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-webp2")
else()
message(FATAL_ERROR "Unknown WASI version: ${WASI}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/clang-format.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(formatted_sources)

function(clang_format_file file)
if (file MATCHES "__generated" OR
file MATCHES "wasip.\.c$" OR # Skip auto-generated files
file MATCHES "(wasip.|webp2)\.c$" OR # Skip auto-generated files
file MATCHES "\.(s|S)$") # Skip assembly files
return()
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/wasm-component-ld.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (NOT USE_WASM_COMPONENT_LD)
return()
endif()

set(WASM_COMPONENT_LD_REQUIRED_VERSION "0.5.30")
set(WASM_COMPONENT_LD_REQUIRED_VERSION "0.5.31")

find_program(WASM_COMPONENT_LD_EXECUTABLE NAMES wasm-component-ld)

Expand Down
2 changes: 1 addition & 1 deletion cmake/wasm-tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (NOT WASM_TOOLS_EXECUTABLE)
ba_download(
wasm-tools
"https://github.com/bytecodealliance/wasm-tools"
"1.257.0"
"1.261.0"
)
ExternalProject_Get_Property(wasm-tools SOURCE_DIR)
set(wasm_tools "${SOURCE_DIR}/wasm-tools")
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip1-threads/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ __wasilibc_pthread_self
__wasilibc_register_preopened_fd
__wasilibc_rename_newat
__wasilibc_rename_oldat
__wasilibc_report_error
__wasilibc_report_errorf
__wasilibc_reset_preopens
__wasilibc_rmdirat
__wasilibc_stat
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1-threads/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@
#include <wasi/wasip1.h>
#include <wasi/wasip2.h>
#include <wasi/wasip3.h>
#include <wasi/webp2.h>
#include <wchar.h>
#include <wctype.h>
3 changes: 2 additions & 1 deletion expected/wasm32-wasip1-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3061,7 +3061,8 @@
#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
#define __WASI_VERSION_H
#define __WASI_WASIP2_H
#define __WASI_WASIP3_H
#define __WASI_WASIP3_H
#define __WASI_WEBP2_H
#define __WASI_WHENCE_CUR (UINT8_C(1))
#define __WASI_WHENCE_END (UINT8_C(2))
#define __WASI_WHENCE_SET (UINT8_C(0))
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip1/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ __wasilibc_pthread_self
__wasilibc_register_preopened_fd
__wasilibc_rename_newat
__wasilibc_rename_oldat
__wasilibc_report_error
__wasilibc_report_errorf
__wasilibc_reset_preopens
__wasilibc_rmdirat
__wasilibc_stat
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,6 @@
#include <wasi/wasip1.h>
#include <wasi/wasip2.h>
#include <wasi/wasip3.h>
#include <wasi/webp2.h>
#include <wchar.h>
#include <wctype.h>
3 changes: 2 additions & 1 deletion expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,8 @@
#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
#define __WASI_VERSION_H
#define __WASI_WASIP2_H
#define __WASI_WASIP3_H
#define __WASI_WASIP3_H
#define __WASI_WEBP2_H
#define __WASI_WHENCE_CUR (UINT8_C(1))
#define __WASI_WHENCE_END (UINT8_C(2))
#define __WASI_WHENCE_SET (UINT8_C(0))
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ __wasilibc_random
__wasilibc_read
__wasilibc_rename_newat
__wasilibc_rename_oldat
__wasilibc_report_error
__wasilibc_report_errorf
__wasilibc_reset_preopens
__wasilibc_rmdirat
__wasilibc_setsockopt_timeout
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@
#include <wasi/wasip1.h>
#include <wasi/wasip2.h>
#include <wasi/wasip3.h>
#include <wasi/webp2.h>
#include <wchar.h>
#include <wctype.h>
3 changes: 2 additions & 1 deletion expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3061,7 +3061,8 @@
#define __USE_TIME_BITS64 1
#define __WASI_VERSION_H
#define __WASI_WASIP2_H
#define __WASI_WASIP3_H
#define __WASI_WASIP3_H
#define __WASI_WEBP2_H
#define __WCHAR_TYPE__ int
#define __WCHAR_WIDTH__ 32
#define __WINT_TYPE__ int
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip3-coop/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ __wasilibc_read
__wasilibc_read_poll
__wasilibc_rename_newat
__wasilibc_rename_oldat
__wasilibc_report_error
__wasilibc_report_errorf
__wasilibc_reset_preopens
__wasilibc_rmdirat
__wasilibc_setsockopt_timeout
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip3-coop/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@
#include <wasi/wasip1.h>
#include <wasi/wasip2.h>
#include <wasi/wasip3.h>
#include <wasi/webp2.h>
#include <wchar.h>
#include <wctype.h>
3 changes: 2 additions & 1 deletion expected/wasm32-wasip3-coop/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3068,7 +3068,8 @@
#define __USE_TIME_BITS64 1
#define __WASI_VERSION_H
#define __WASI_WASIP2_H
#define __WASI_WASIP3_H
#define __WASI_WASIP3_H
#define __WASI_WEBP2_H
#define __WCHAR_TYPE__ int
#define __WCHAR_WIDTH__ 32
#define __WINT_TYPE__ int
Expand Down
2 changes: 2 additions & 0 deletions expected/wasm32-wasip3/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ __wasilibc_read
__wasilibc_read_poll
__wasilibc_rename_newat
__wasilibc_rename_oldat
__wasilibc_report_error
__wasilibc_report_errorf
__wasilibc_reset_preopens
__wasilibc_rmdirat
__wasilibc_setsockopt_timeout
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip3/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@
#include <wasi/wasip1.h>
#include <wasi/wasip2.h>
#include <wasi/wasip3.h>
#include <wasi/webp2.h>
#include <wchar.h>
#include <wctype.h>
3 changes: 2 additions & 1 deletion expected/wasm32-wasip3/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,8 @@
#define __USE_TIME_BITS64 1
#define __WASI_VERSION_H
#define __WASI_WASIP2_H
#define __WASI_WASIP3_H
#define __WASI_WASIP3_H
#define __WASI_WEBP2_H
#define __WCHAR_TYPE__ int
#define __WCHAR_WIDTH__ 32
#define __WINT_TYPE__ int
Expand Down
Loading
Loading