Skip to content

refactor(java): dynamically match wasm-bindgen host functions by prefix#96

Merged
aepfli merged 1 commit into
mainfrom
refactor/stable-host-functions
Feb 12, 2026
Merged

refactor(java): dynamically match wasm-bindgen host functions by prefix#96
aepfli merged 1 commit into
mainfrom
refactor/stable-host-functions

Conversation

@aepfli

@aepfli aepfli commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • WasmRuntime.java now inspects the WASM module's import section at startup and registers host function handlers by prefix pattern matching, instead of hardcoding 9 function names with wasm-bindgen hash suffixes
  • HOST_FUNCTIONS.md rewritten to document all 9 WASM imports across 3 modules, with dynamic matching examples for Java, Go, and JavaScript

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

  1. Load the WASM module via CompiledEvaluator.load()
  2. Iterate importSection().stream() to discover all FunctionImports
  3. Match each import by module + name prefix to the appropriate handler
  4. Register handlers dynamically in the Chicory Store

Test plan

  • All 30 Java tests pass (./mvnw test)
  • WASM binary imports verified via wasm-objdump
  • No Rust code changes required

Closes #74

🤖 Generated with Claude Code

…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>
@aepfli aepfli merged commit 6c531e5 into main Feb 12, 2026
15 checks passed
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.

refactor(java): eliminate wbindgen hash fragility in WasmRuntime.java

1 participant