Skip to content

Commit

Permalink
analysis: Introduce Vulkan XML parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Friz64 committed May 27, 2024
1 parent 145eeca commit 6831ac6
Show file tree
Hide file tree
Showing 6 changed files with 825 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Install Vulkan loader
run: sudo apt-get install libvulkan-dev
- uses: actions/checkout@v4
- name: Checkout submodule
# Manually update submodules with --checkout because they are configured with update=none and will be skipped otherwise
run: git submodule update --recursive --init --force --checkout
- name: Test all targets
run: cargo test --workspace --all-targets
- name: Test docs
Expand Down
2 changes: 2 additions & 0 deletions analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ version = "2.0.0"
edition = "2021"

[dependencies]
roxmltree = "0.20"
tracing = "0.1"
37 changes: 33 additions & 4 deletions analysis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
use std::path::Path;
mod xml;

pub struct Analysis {}
use std::{fs, path::Path};
use tracing::{debug, error_span};

#[derive(Debug)]
pub struct Analysis {
pub vk: Library,
pub video: Library,
}

impl Analysis {
pub fn new(_vulkan_headers_path: impl AsRef<Path>) -> Analysis {
Analysis {}
pub fn new(vulkan_headers_path: impl AsRef<Path>) -> Analysis {
let vulkan_headers_path = vulkan_headers_path.as_ref();
Analysis {
vk: Library::new(vulkan_headers_path.join("registry/vk.xml")),
video: Library::new(vulkan_headers_path.join("registry/video.xml")),
}
}
}

#[derive(Debug)]
pub struct Library {
_xml: xml::Registry,
}

impl Library {
fn new(xml_path: impl AsRef<Path>) -> Library {
let xml = error_span!("xml", path = %xml_path.as_ref().display()).in_scope(|| {
// We leak the input string here for convenience, to avoid explicit lifetimes.
let xml_input = Box::leak(fs::read_to_string(xml_path).unwrap().into_boxed_str());
debug!("parsing xml");
xml::Registry::parse(xml_input, "vulkan")
});

Library { _xml: xml }
}
}
Loading

0 comments on commit 6831ac6

Please sign in to comment.