Skip to content

Commit cd330c2

Browse files
simongdaviesCopilotCopilot
authored
feat: add binary type support for host functions (#40)
* feat: add binary type support for host functions Adds Uint8Array/Buffer support for host function arguments and returns. Architecture: - New hyperlight-js-common crate: shared wire-format constants, binary sidecar encode/decode, FnReturn enum, DecodeError type - Guest extracts Uint8Array from QuickJS VM into binary sidecar - Host dispatches via register() (typed serde) or register_js() (JS bridge) - NAPI layer creates native Node.js Buffers via C API (no base64) - Tagged return format (0x00=JSON, 0x01=binary) for return path Key changes: - Single CallHostJsFunction entry point (removed legacy JSON-only path) - Native Buffer marshalling in NAPI (JsArg/JsReturn types) - Depth limits on all recursive JSON tree traversals (MAX_JSON_DEPTH=64) - Trailing data rejection in sidecar decoder - Typed register() rejects binary args with clear error message - Comprehensive test coverage (Rust unit + integration + JS vitest) - Updated README with Binary Data section and wire protocol docs - Updated CI publish order for new common crate Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Update src/js-host-api/src/lib.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * fix: address PR review comments - Fix napi_create_string_utf8 length parameter cast (isize usize) - Fix formatted error string using concat!() to avoid embedded whitespace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f0e1ad7 commit cd330c2

20 files changed

Lines changed: 2793 additions & 172 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["src/hyperlight-js", "src/js-host-api", "src/hyperlight-js-runtime"]
3+
members = ["src/hyperlight-js", "src/js-host-api", "src/hyperlight-js-runtime", "src/hyperlight-js-common"]
44

55
[workspace.package]
66
version = "0.3.0"
@@ -13,9 +13,12 @@ readme = "README.md"
1313
[workspace.dependencies]
1414
hyperlight-guest-bin = { version = "0.16.0", features = ["libc"] }
1515
hyperlight-host = { version = "0.16.0", default-features = false }
16+
hyperlight-common = { version = "0.16.0", default-features = false }
17+
hyperlight-guest = { version = "0.16.0" }
1618

1719
hyperlight-js = { version = "0.3.0", path = "src/hyperlight-js" }
1820
hyperlight-js-runtime = { version = "0.3.0", path = "src/hyperlight-js-runtime" }
21+
hyperlight-js-common = { version = "0.3.0", path = "src/hyperlight-js-common" }
1922

2023
[profile.dev]
2124
panic = "abort"

docs/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ When this job is done, a new [GitHub release](https://github.com/hyperlight-dev/
5151

5252
This release contains the benchmark results and the source code for the release along with automatically generated release notes.
5353

54-
In addition the hyperlight-js crates will be published to crates.io. You can verify this by going to the [hyperlight-js page on crates.io](https://crates.io/crates/hyperlight-js) and checking that the new version is listed.
54+
In addition, the hyperlight-js crates will be published to crates.io in dependency order (`hyperlight-js-common``hyperlight-js-runtime``hyperlight-js`). You can verify this by going to the [hyperlight-js page on crates.io](https://crates.io/crates/hyperlight-js) and checking that the new version is listed.
5555

5656
The npm packages (`@hyperlight-dev/js-host-api` and platform-specific binaries) are also published automatically as part of this workflow. Publishing uses [npm trusted publishing (OIDC)](https://docs.npmjs.com/trusted-publishers) — no `NPM_TOKEN` secret is needed for the `CreateRelease` workflow. Provenance attestations are generated automatically.
5757

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "hyperlight-js-common"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
readme.workspace = true
9+
description = """
10+
Shared constants and binary framing utilities for hyperlight-js.
11+
12+
This crate is `no_std`-compatible (with `alloc`) so it can be used by both
13+
the host-side `hyperlight-js` crate and the guest-side `hyperlight-js-runtime`
14+
crate (which compiles for `x86_64-hyperlight-none`).
15+
"""
16+
17+
[dependencies]
18+
# no_std + alloc only — no std, no serde, no anyhow

0 commit comments

Comments
 (0)