diff --git a/moli-protocol-cdp/Cargo.toml b/moli-protocol-cdp/Cargo.toml index 9ee5b4511f..3f96c942db 100644 --- a/moli-protocol-cdp/Cargo.toml +++ b/moli-protocol-cdp/Cargo.toml @@ -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 diff --git a/moli-protocol-cdp/build.rs b/moli-protocol-cdp/build.rs new file mode 100644 index 0000000000..dce3fb9602 --- /dev/null +++ b/moli-protocol-cdp/build.rs @@ -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"); +} diff --git a/moli-protocol-cdp/src/metadata.rs b/moli-protocol-cdp/src/metadata.rs index fa91c5684b..eb1d37aadc 100644 --- a/moli-protocol-cdp/src/metadata.rs +++ b/moli-protocol-cdp/src/metadata.rs @@ -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")); diff --git a/moli-protocol-cdp/tests/protocol_metadata.rs b/moli-protocol-cdp/tests/protocol_metadata.rs new file mode 100644 index 0000000000..16d96e08c2 --- /dev/null +++ b/moli-protocol-cdp/tests/protocol_metadata.rs @@ -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); +}