-
Notifications
You must be signed in to change notification settings - Fork 0
Add C FFI interface for WASM to support multiple languages #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
|
@copilot is this also building the wasm modules via github actions? |
The current CI workflow ( For the new C FFI interface, you would need to add additional build steps using: cargo build --target wasm32-unknown-unknown --release # for JS, Java/Chicory
cargo build --target wasm32-wasip1 --release # for Go, .NET, Python The artifacts would be in Would you like me to add these build steps to the CI workflow? |
|
@copilot yes please add them |
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
|
@copilot trigger the ci please |
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
|
@copilot currently we do not need the other builds except the ones we added. can you remove the other builds for wasm-bind and python. furthermore the build seems to be failing |
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
Simplified the CI workflow in d1a75a7. Removed wasm-bindgen/wasm-pack builds, Python builds (sdist, wheels), and NPM publishing. The CI now only runs Rust tests and builds the C FFI WASM modules for both targets ( |
|
@copilot ``` |
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
|
@copilot i think it would be best to use a packed pointer for |
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
Implemented in 37eff13. The API now uses a packed pointer approach - |
src/ffi/mod.rs- module declaration for FFIsrc/ffi/wasm.rs- C FFI interface with all required functionssrc/lib.rs- add ffi module, comment out wasm-bindgen codeCargo.toml- update features and make wasm-bindgen optionaldocs/WASM_FFI.md- complete documentationwasm32-unknown-unknowntargetwasm32-wasip1targetOriginal prompt
Context
The
json-logic-rscrate currently useswasm-bindgenwithJsValuetypes for WASM support, which limits it to JavaScript environments. We need to convert it to support WASM through a C-style FFI interface to allow multiple languages (Java/Chicory, JavaScript, Python, Go, .NET) to use the same WASM module.Current State
wasm-bindgenwithJsValuetypessrc/lib.rsunder#[cfg(feature = "wasm")](lines 20-57)pub fn apply(value: JsValue, data: JsValue) -> Result<JsValue, JsValue>pub fn apply(value: &Value, data: &Value) -> Result<Value, Error>insrc/lib.rs(lines 87-90)Requirements
1. Create C FFI Interface Module
Create a new file
src/ffi/wasm.rswith the following requirements:Memory Model:
Required Functions:
Additional Helper Functions:
Error Handling:
serde_json::from_strcrate::apply{"error": "error message here"}std::slice::from_raw_partsfor pointer → slice conversionSafety Considerations:
unsafeblocks appropriately with clear comments2. Update Module Structure
Create
src/ffi/mod.rs:Update
src/lib.rs:pub mod ffi;javascript_ifacemodule (lines 20-57)applyfunction unchanged (lines 87-90)3. Update Cargo.toml
Library configuration:
Features:
Dependencies:
wasm-bindgenoptional (keep it but mark as optional)4. Documentation
Create a new file
docs/WASM_FFI.mdwith:wasm32-unknown-unknownandwasm32-wasiAdd build commands:
5. Testing Recommendations
Add comments in the code suggesting test cases:
Expected Outcome
After implementation:
src/ffi/wasm.rs- Complete C FFI interface with all required functionssrc/ffi/mod.rs- Module declarationsrc/lib.rs- Updated with ffi module, wasm-bindgen code commented outCargo.toml- Updated features and optional dependenciesdocs/WASM_FFI.md- Complete documentationapplyfunction remains unchanged and continues to workImplementation Notes
std::sync::Mutex...This pull request was created as a result of the following prompt from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.