Skip to content

[wasm2c] Add the very beginning of a wasm2c implementation and test harness - #8763

Merged
tlively merged 34 commits into
WebAssembly:mainfrom
lexi-nadia:main
Jul 30, 2026
Merged

[wasm2c] Add the very beginning of a wasm2c implementation and test harness#8763
tlively merged 34 commits into
WebAssembly:mainfrom
lexi-nadia:main

Conversation

@lexi-nadia

@lexi-nadia lexi-nadia commented May 22, 2026

Copy link
Copy Markdown
Collaborator

This change adds an extremely bare-bones wasm2c implementation and test harness.

Most of the code here is imported directly from WABT, particularly the boilerplate code and tests. The only substantive new code is in src/tools/wasm2c/* and scripts/test/wasm2c.py.

I tried to prune this down to be as minimal as possible while still providing a useful checkpoint, but I'm not sure I succeeded. Please feel free to offer suggestions if you see more ways to shrink this down.

Comment thread src/tools/wasm2c/prebuilt/wasm2c_atomicops_source_declarations.cpp
Comment thread src/templates/wasm2c.declarations.c Outdated
Comment thread src/tools/wasm2c/templates/wasm2c.declarations.c
Comment thread src/tools/CMakeLists.txt
Comment thread src/tools/wasm2c.cpp Outdated
Comment thread src/tools/wasm2c/examples/fac/fac.c Outdated
Comment thread third_party/picosha2
Comment thread wasm2c/benchmarks/dhrystone/src/dhry.h Outdated
Comment thread wasm2c/benchmarks/dhrystone/dhrystone.wasm Outdated
Comment thread src/tools/wasm2c/README.md
@lexi-nadia

Copy link
Copy Markdown
Collaborator Author

Okay, I uploaded a new draft that incorporates all your feedback. PTAL. Thanks!

@tlively tlively left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % final comment!

Comment thread src/tools/wasm2c/wasm2c-builder.cpp
Comment thread test/spec/minimal.wast Outdated
@tlively

tlively commented Jun 23, 2026

Copy link
Copy Markdown
Member

@kripken, any final comments here?

@tlively
tlively marked this pull request as ready for review June 23, 2026 16:38
@tlively
tlively requested a review from a team as a code owner June 23, 2026 16:38
@tlively
tlively requested review from kripken and removed request for a team June 23, 2026 16:38

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concerns from me for landing.

(I didn't review the code in detail - let me know if you also want that.)

@tlively

tlively commented Jun 24, 2026

Copy link
Copy Markdown
Member

Looks like the test needs to be updated before this can land.

@lexi-nadia

Copy link
Copy Markdown
Collaborator Author

Looks like the test needs to be updated before this can land.

It took me a while, but they're finally passing. :)

@tlively
tlively merged commit a979100 into WebAssembly:main Jul 30, 2026
16 checks passed
Comment thread .gitignore
# files related to building in-tree
CMakeFiles
*.cmake
!src/tools/wasm2c/gen-wasm2c-templates.cmake

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This this file was not actually added in this PR it seem to include this here.

BTW, the *.cmake line above seems odd.. does the in-tree build really make files with the .cmake extension?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this file, and the generation step, in favor of just checking in the "prebuilt" files. I forgot to remove this from .gitignore, though. :( I'll remove it in my next PR (or I can send a one-line PR to remove it, if you'd prefer?).

Comment thread CMakeLists.txt
add_compile_flag("-Wnon-virtual-dtor")
add_compile_flag("-Wsuggest-override")
add_compile_flag("-Wnon-virtual-dtor" "CXX_ONLY")
add_compile_flag("-Wsuggest-override" "CXX_ONLY")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would hope these are not needed, and we don't try to use the same compile flags for building binaryen itself as the generated C source code. i.e. those two sets of flags should probably not be related.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These flags aren't used for building the generated C source code, but they are used for building the wasm-rt C runtime library. I added this because I couldn't find any other way to get the clang-tidy pass to treat this as C code rather than C++ code (the file extension notwithstanding).

If you have a better idea, I'm happy to change this!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. i'm kind of tempted to say that the wasm-rt C runtime library should also be built with the same flags that the generated code (i.e. not these flags), but whatever works best I guess

Comment thread scripts/test/wasm2c.py
@sbc100

sbc100 commented Jul 31, 2026

Copy link
Copy Markdown
Member

This change seems to be breaking the emscripten-releases roller:

https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8674789067983951889/+/u/Build_Binaryen/stdout

FAILED: [code=1] lib/libwasm-rt.dylib 
: && /Volumes/Work/s/w/ir/cache/builder/v8/third_party/llvm-build/Release+Asserts/bin/clang --sysroot=/Volumes/Work/s/w/ir/cache/builder/emscripten-releases/build/binaryen-out/xcode_sdk -no-canonical-prefixes --target=x86_64-apple-darwin -fno-omit-frame-pointer -fPIC -fcolor-diagnostics -DBUILD_LLVM_DWARF -Wall -Werror -Wextra -Wno-unused-parameter -Wno-dangling-pointer -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -Wswitch -Wimplicit-fallthrough -Wctad-maybe-unsupported -Wno-deprecated-declarations -O3 -DNDEBUG -UNDEBUG -arch x86_64 -isysroot /Volumes/Work/s/w/ir/cache/builder/emscripten-releases/build/binaryen-out/xcode_sdk -mmacosx-version-min=11 -dynamiclib -Wl,-headerpad_max_install_names -L/Volumes/Work/s/w/ir/cache/builder/emscripten-releases/build/temp/libcxx-install/lib -stdlib=libc++ -o lib/libwasm-rt.dylib -install_name @rpath/libwasm-rt.dylib src/tools/wasm2c/CMakeFiles/wasm-rt.dir/wasm-rt/wasm-rt-exceptions-impl.c.o src/tools/wasm2c/CMakeFiles/wasm-rt.dir/wasm-rt/wasm-rt-impl.c.o src/tools/wasm2c/CMakeFiles/wasm-rt.dir/wasm-rt/wasm-rt-mem-impl.c.o   && :
clang: error: argument unused during compilation: '-stdlib=libc++' [-Werror,-Wunused-command-line-argument]

@sbc100

sbc100 commented Jul 31, 2026

Copy link
Copy Markdown
Member

It looks like emscripten-releases is injecting -stdlib=libc++ by setting -DCMAKE_EXE_LINKER_FLAGS which unfortunately is global to all programs, but when this new library is built using clang (not clang++) that argument is ignored.

I wonder, could libwasm-rt always be a static library? That would avoid this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants