From 37008b7fa16837d04c1658868646cad681cbe035 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 11 Feb 2026 18:04:07 -0800 Subject: Add BNTL utility plugin Allow users to easily create, diff, dump and validate type libraries Supports the following formats: - C header files (via core type parsers) - Binary files (collects exported and imported functions) - WinMD files (via `windows-metadata` crate) - Existing type library files (for easy fixups) - Apiset files (to resolve through forwarded windows dlls) Can be invoked as a regular plugin via UI commands or via CLI. Processing of type libraries inherently requires external linking, processing will automatically merge and deduplicate colliding type libraries so prefer to use inside a project or a directory and process all information (for a given platform) at once, rather than smaller invocations. --- plugins/bntl_utils/src/schema.rs | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 plugins/bntl_utils/src/schema.rs (limited to 'plugins/bntl_utils/src/schema.rs') diff --git a/plugins/bntl_utils/src/schema.rs b/plugins/bntl_utils/src/schema.rs new file mode 100644 index 00000000..2a9e6d50 --- /dev/null +++ b/plugins/bntl_utils/src/schema.rs @@ -0,0 +1,42 @@ +use serde::Deserialize; +use std::collections::{HashMap, HashSet}; +use std::fs::File; +use std::path::Path; + +#[derive(Deserialize, Debug)] +pub struct BntlSchema { + // The list of library names this library depends on + pub dependencies: Vec, + // Maps internal type IDs or names to their external sources + pub type_sources: Vec, +} + +impl BntlSchema { + pub fn from_file(file: &File) -> Self { + serde_json::from_reader(file).expect("JSON schema mismatch") + } + + pub fn from_path(path: &Path) -> Self { + Self::from_file(&File::open(path).expect("Failed to open schema file")) + } + + pub fn to_source_map(&self) -> HashMap> { + let mut dependencies_map: HashMap> = HashMap::new(); + for ts in &self.type_sources { + let full_name = ts.name.join("::"); + dependencies_map + .entry(ts.source.clone()) + .or_default() + .insert(full_name); + } + dependencies_map + } +} + +#[derive(Deserialize, Debug)] +pub struct TypeSource { + // The components of the name, e.g., ["std", "string"] + pub name: Vec, + // The name of the dependency library it comes from + pub source: String, +} -- cgit v1.3.1