Skip to content

Refactor JS runtime generation and improve WASM import handling#17

Merged
io-eric merged 2 commits into
mainfrom
linker-driven-feature-detection
Jun 15, 2026
Merged

Refactor JS runtime generation and improve WASM import handling#17
io-eric merged 2 commits into
mainfrom
linker-driven-feature-detection

Conversation

@io-eric

@io-eric io-eric commented Jun 15, 2026

Copy link
Copy Markdown
Owner

This pull request refactors and improves the WebCC build process and feature detection for JavaScript runtime generation. The key change is to use the actual linked WASM module's import table as the source of truth for which return-value commands are used, instead of scanning user code text. This makes feature detection more robust and accurate, and simplifies the interface between build steps. It also introduces a new wasm.cc module for parsing WASM imports, and updates the build pipeline and tests accordingly.

Build and Feature Detection Improvements:

  • The build process now links the WASM module earlier, using a constant set of required exports, and then reads the linked module's import table to determine which return-value commands are actually referenced by the user's code. This eliminates the need to guess feature usage from source code text. (build.ninja, src/cli/main.cc, [1] [2]
  • The JavaScript runtime generator (generate_js_runtime) now takes the set of WASM imports as input, using them to detect return-value commands, while void commands are still detected by scanning the source code (with comments and string literals stripped to avoid false positives). (src/cli/generators.cc, src/cli/generators.h, [1] [2] [3]

WASM Import Table Parsing:

  • Introduced a new wasm.cc module and wasm.h header that implement read_wasm_imports, a function to parse the WASM import section and extract the names of imported fields. This is now used to drive feature detection. (src/cli/wasm.cc, src/cli/wasm.h, [1] [2]
  • Updated the build system to compile and link the new wasm.cc source file. (build.ninja, build.ninjaR23-R25)

API and Codebase Simplification:

  • Removed the JsGenResult struct; the required exports are now a constant set returned by required_wasm_exports(). The JS generator interface is simplified to not return a value. (src/cli/generators.h, src/cli/generators.cc, [1] [2] [3]
  • Improved the logic for detecting void commands by stripping comments and string/char literals before scanning, reducing the risk of false positives. (src/cli/generators.cc, src/cli/generators.ccL682-R771)

Test and Tooling Updates:

  • Updated tests and JS syntax checker to require a successful WASM compile/link before JS generation, reflecting the new feature detection flow. (tests/js/check_js.mjs, [1]; tests/test_codegen.cc, [2] [3]

These changes make the build and feature detection process more robust, accurate, and maintainable by relying on the linker and actual WASM module content rather than source code heuristics.

io-eric added 2 commits June 15, 2026 02:00
- Removed the JsGenResult structure and replaced it with a function that returns a constant set of required WASM exports.
- Updated the generate_js_runtime function to accept a set of WASM imports instead of user code, allowing for more accurate feature detection based on the linked module.
- Introduced a new wasm.cc file to handle reading WASM imports and added a corresponding header file.
- Modified the main CLI logic to compile WASM first, then read the imports for generating the JS runtime.
- Updated tests to reflect changes in JS generation based on the new import handling.
@io-eric io-eric merged commit 1165866 into main Jun 15, 2026
1 check passed
@io-eric io-eric deleted the linker-driven-feature-detection branch June 15, 2026 00:33
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.

1 participant