Skip to content

Commit fe77770

Browse files
chore(deps): Bump napi-derive from 2.16.13 to 3.5.6 in /src/code-validator/guest (#133)
* chore(deps): Bump napi-derive in /src/code-validator/guest Bumps [napi-derive](https://github.com/napi-rs/napi-rs) from 2.16.13 to 3.5.6. - [Release notes](https://github.com/napi-rs/napi-rs/releases) - [Commits](https://github.com/napi-rs/napi-rs/compare/napi-derive@2.16.13...napi-derive-v3.5.6) --- updated-dependencies: - dependency-name: napi-derive dependency-version: 3.5.6 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump napi-derive to 3 in code-validator guest host Bump napi-derive together with napi to v3 (they are version-coupled); napi-build stays at v2 (no v3 exists). No Rust code changes are needed — the 3.x API used by the host crate is source-compatible. napi-derive 3 makes `napi build` emit JSDoc into the generated src/code-validator/guest/host/index.d.ts, which is not Prettier-formatted. That file is a build artifact (the hand-written canonical types live in src/code-validator/guest/index.d.ts), so it is now gitignored and prettierignored, matching how other generated *.d.ts files are handled. Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 7c30102 commit fe77770

6 files changed

Lines changed: 166 additions & 38 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ plugins/plugin-schema-types.js
5454
plugins/host-modules.d.ts
5555
output-hyperagent-*/
5656
scripts/bash-bundle/_tmp_bundle.js
57+
58+
# Generated NAPI bindings (emitted by `napi build`)
59+
src/code-validator/guest/host/index.d.ts
60+
src/code-validator/guest/host/index.js

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated NAPI binding type declarations (emitted by `napi build`).
2+
# napi-derive >= 3 writes JSDoc into this file, which is not Prettier-formatted.
3+
# The canonical, hand-written types live in src/code-validator/guest/index.d.ts.
4+
src/code-validator/guest/host/index.d.ts

src/code-validator/guest/Cargo.lock

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

src/code-validator/guest/host/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ crate-type = ["cdylib", "rlib"]
1717

1818
[dependencies]
1919
hyperlight-host = { workspace = true }
20-
napi = { version = "2", features = ["async", "napi6"] }
21-
napi-derive = "2"
20+
napi = { version = "3", features = ["async", "napi6"] }
21+
napi-derive = "3"
2222
sha2 = "0.11"
2323
hex = "0.4"
2424
base64 = "0.22"

src/code-validator/guest/host/build.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,40 @@ fn bundle_runtime() {
166166
let runtime_resource = build_runtime();
167167
let runtime_bytes = fs::read(&runtime_resource).expect("Failed to read runtime binary");
168168

169-
// Compute SHA256 hash
169+
assert!(
170+
!runtime_bytes.is_empty(),
171+
"analysis runtime binary is empty: {runtime_resource:?}"
172+
);
173+
174+
let out_dir = env::var_os("OUT_DIR").unwrap();
175+
176+
// Snapshot the runtime binary into this crate's OUT_DIR and embed THAT copy.
177+
//
178+
// The hash below is computed from `runtime_bytes`, while the embedded bytes
179+
// come from `include_bytes!` evaluated when this crate is compiled — two
180+
// reads at different times. The build path of `runtime_resource` lives in a
181+
// shared target directory that other cargo invocations (clippy, the napi
182+
// typedef pass, repeated `just build`/`just test` runs) can rebuild, and the
183+
// guest binary is not bit-for-bit reproducible. If that file changed between
184+
// hashing and the `include_bytes!` compile, the embedded bytes would no
185+
// longer match the stored hash and the runtime integrity check would fail.
186+
//
187+
// Writing a private snapshot into OUT_DIR — which nothing else ever touches —
188+
// and pointing `include_bytes!` at it guarantees the embedded bytes are
189+
// exactly the bytes we hashed, as a single atomic pair.
190+
let embedded_path = Path::new(&out_dir).join("analysis-runtime.bin");
191+
fs::write(&embedded_path, &runtime_bytes).expect("Failed to write runtime snapshot");
192+
193+
// Compute SHA256 hash of the same in-memory buffer we just embedded.
170194
use sha2::{Digest, Sha256};
171195
let mut hasher = Sha256::new();
172196
hasher.update(&runtime_bytes);
173197
let hash = hasher.finalize();
174198
let hash_hex = hex::encode(hash);
175199

176-
let out_dir = env::var_os("OUT_DIR").unwrap();
177200
let dest_path = Path::new(&out_dir).join("host_resource.rs");
178201
let contents = format!(
179-
r#"pub(crate) static ANALYSIS_RUNTIME: &[u8] = include_bytes!({runtime_resource:?});
202+
r#"pub(crate) static ANALYSIS_RUNTIME: &[u8] = include_bytes!({embedded_path:?});
180203
pub(crate) const ANALYSIS_RUNTIME_SHA256: &str = "{hash_hex}";"#
181204
);
182205

src/code-validator/guest/host/index.d.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)