Skip to content

Commit 3c852a2

Browse files
committed
analysis: Introduce Vulkan XML parser
1 parent 145eeca commit 3c852a2

File tree

6 files changed

+848
-4
lines changed

6 files changed

+848
-4
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: Install Vulkan loader
4343
run: sudo apt-get install libvulkan-dev
4444
- uses: actions/checkout@v4
45+
- name: Checkout submodule
46+
# Manually update submodules with --checkout because they are configured with update=none and will be skipped otherwise
47+
run: git submodule update --recursive --init --force --checkout
4548
- name: Test all targets
4649
run: cargo test --workspace --all-targets
4750
- name: Test docs

analysis/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ version = "2.0.0"
44
edition = "2021"
55

66
[dependencies]
7+
roxmltree = "0.19"
8+
tracing = "0.1"

analysis/src/lib.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1-
use std::path::Path;
1+
mod xml;
22

3-
pub struct Analysis {}
3+
use std::{fs, path::Path};
4+
use tracing::{debug, error_span};
5+
6+
#[derive(Debug)]
7+
pub struct Analysis {
8+
pub vk: Library,
9+
pub video: Library,
10+
}
411

512
impl Analysis {
6-
pub fn new(_vulkan_headers_path: impl AsRef<Path>) -> Analysis {
7-
Analysis {}
13+
pub fn new(vulkan_headers_path: impl AsRef<Path>) -> Analysis {
14+
let vulkan_headers_path = vulkan_headers_path.as_ref();
15+
Analysis {
16+
vk: Library::new(vulkan_headers_path.join("registry/vk.xml")),
17+
video: Library::new(vulkan_headers_path.join("registry/video.xml")),
18+
}
19+
}
20+
}
21+
22+
#[derive(Debug)]
23+
pub struct Library {
24+
_xml: xml::Registry,
25+
}
26+
27+
impl Library {
28+
fn new(xml_path: impl AsRef<Path>) -> Library {
29+
let xml = error_span!("xml", path = %xml_path.as_ref().display()).in_scope(|| {
30+
// We leak the input string here for convenience, to avoid explicit lifetimes.
31+
let xml_input = Box::leak(fs::read_to_string(xml_path).unwrap().into_boxed_str());
32+
debug!("parsing xml");
33+
xml::Registry::parse(xml_input, "vulkan")
34+
});
35+
36+
Library { _xml: xml }
837
}
938
}

0 commit comments

Comments
 (0)