refactor(java): dynamically match wasm-bindgen host functions by prefix#96
Merged
Conversation
…ix (#74) Instead of hardcoding 9 host function names with wasm-bindgen hash suffixes, WasmRuntime.java now inspects the WASM module's import section at startup and registers handlers by prefix pattern matching. This eliminates an entire class of CI failures from hash changes when Rust dependencies update. - Parse WasmModule.importSection() to discover all function imports - Match by stable prefixes (e.g., __wbg_getTime_*) instead of exact names - Update HOST_FUNCTIONS.md with all imports and dynamic matching examples Closes #74 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Motivation
wasm-bindgen generates function names with hash suffixes (e.g.,
__wbg_getTime_ad1e9878a735af08) that change whenever Rust dependencies or wasm-bindgen versions update. This has broken CI in multiple PRs (#64). By matching imports by prefix (__wbg_getTime_*) instead of exact name, the Java integration survives dependency changes without code updates.How it works
CompiledEvaluator.load()importSection().stream()to discover allFunctionImportsStoreTest plan
./mvnw test)wasm-objdumpCloses #74
🤖 Generated with Claude Code