feat: add js-wasm bindings and formalise WASM runtime support#598
Open
niallnsec wants to merge 1 commit intoVirusTotal:mainfrom
Open
feat: add js-wasm bindings and formalise WASM runtime support#598niallnsec wants to merge 1 commit intoVirusTotal:mainfrom
niallnsec wants to merge 1 commit intoVirusTotal:mainfrom
Conversation
Signed-off-by: Niall Newman <nn@turacolabs.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.
First split PR for JS binding support, as requested here: #594 (comment)
This PR adds a browser-facing JavaScript package for
yara-xand the supporting library changes needed to run it onwasm32-unknown-unknown.The main library change is a refactor of the internal WASM runtime layer so that non-Wasm targets continue to use
wasmtime, while browser builds use a small compatibility shim over the hostWebAssemblyruntime. The browser-specific runtime code is isolated underlib/src/wasm/runtime/, which keeps the rest of the library largely unchanged and avoids spreading target-specific conditionals across the codebase.On top of that, this PR adds a new in-tree
js-wasmpackage. It exposes an object-based JavaScript API built aroundCompiler,Rules, andScanner, and is packaged using awasm-pack-based workflow with standardpkg/output plus a no-modules bundle indist/.A fair amount of work also went into testing. The package now has:
wasm-bindgen-testcoverage for the Rust-facing WASM APIWhile doing that work, I also fixed a browser-side issue in the
timemodule and tightened a few API behaviours injs-wasm, including proper handling of accumulated compiler errors and propagation of compiler warnings in scan results.The packaging flow was also tightened up to reduce output size:
vt-moduleis not included in the browser package feature setwasm-optis run as part of the package build.wasmbinary as the standard package instead of shipping a duplicate copyThis leaves
js-wasmas a browser-focused package with a cleaner runtime split, better test coverage, and a smaller final package size.One item to query, I am not sure if removing the
vtmodule was the right thing to do for the WASM browser build. The reason I removed it is that, as far as I can tell, the module is only used inside of VirusTotal's internal architecture and so is not something that normal users can take advantage of. Including the module adds an extra 1.5MB to the final build size, primarily due to the dependency on theplscrate.Its not ideal as it means that I am currently loading the main lib into the js-wasm crate as a crate local import since you can't disable default features in an imported crate when using a shared workspace. I didn't want to remove it from the default features list at the lib level as that seemed like a significant change and I am already not clear on whether the
vtmodule should be included in a browser focused build or not.