perf(cdp): compact protocol metadata at build time

Parse the vendored schema with serde_json::Value and serialize compact JSON
in build.rs. Embed the generated bytes without request-time processing.
Verify the embedded protocol matches the complete vendored schema.

Validation on the unchanged final source tree: cargo fmt --all;
cargo clippy --workspace --all-targets --all-features -- -D warnings;
cargo nextest run --no-fail-fast (20,505 passed, 18 existing skips).
This commit is contained in:
ldm0
2026-10-21 23:16:23 +08:00
committed by Donough Liu
parent 6a7ea4e395
commit c5d91d50d0
4 changed files with 29 additions and 2 deletions
+3
View File
@@ -10,5 +10,8 @@ moli-time = { path = "../moli-time" }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
[build-dependencies]
serde_json = "1.0.145"
[lints]
workspace = true
+14
View File
@@ -0,0 +1,14 @@
use std::{env, fs, path::PathBuf};
const PROTOCOL_SOURCE: &str = "../vendor/v8-152.2.0/v8/include/js_protocol-1.3.json";
fn main() {
println!("cargo:rerun-if-changed={PROTOCOL_SOURCE}");
let source = fs::read(PROTOCOL_SOURCE).expect("read vendored CDP protocol metadata");
let protocol: serde_json::Value =
serde_json::from_slice(&source).expect("parse vendored CDP protocol metadata");
let compact = serde_json::to_vec(&protocol).expect("serialize compact CDP protocol metadata");
let destination = PathBuf::from(env::var_os("OUT_DIR").expect("Cargo build output directory"))
.join("cdp-protocol.json");
fs::write(destination, compact).expect("write compact CDP protocol metadata");
}
+1 -2
View File
@@ -1,2 +1 @@
pub const CDP_PROTOCOL_JSON: &str =
include_str!("../../vendor/v8-152.2.0/v8/include/js_protocol-1.3.json");
pub const CDP_PROTOCOL_JSON: &str = include_str!(concat!(env!("OUT_DIR"), "/cdp-protocol.json"));
@@ -0,0 +1,11 @@
use moli_protocol_cdp::CDP_PROTOCOL_JSON;
use serde_json::Value;
#[test]
fn embedded_protocol_preserves_the_complete_vendored_schema() {
let source = include_str!("../../vendor/v8-152.2.0/v8/include/js_protocol-1.3.json");
let original: Value = serde_json::from_str(source).expect("valid vendored CDP protocol");
let embedded: Value =
serde_json::from_str(CDP_PROTOCOL_JSON).expect("valid embedded CDP protocol");
assert_eq!(embedded, original);
}