mirror of
https://github.com/lexmount/moli.git
synced 2026-10-30 08:07:38 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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 +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);
|
||||
}
|
||||
Reference in New Issue
Block a user