Refactor JS runtime generation and improve WASM import handling#17
Merged
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ccmodule for parsing WASM imports, and updates the build pipeline and tests accordingly.Build and Feature Detection Improvements:
build.ninja,src/cli/main.cc, [1] [2]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:
wasm.ccmodule andwasm.hheader that implementread_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]wasm.ccsource file. (build.ninja, build.ninjaR23-R25)API and Codebase Simplification:
JsGenResultstruct; the required exports are now a constant set returned byrequired_wasm_exports(). The JS generator interface is simplified to not return a value. (src/cli/generators.h,src/cli/generators.cc, [1] [2] [3]src/cli/generators.cc, src/cli/generators.ccL682-R771)Test and Tooling Updates:
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.