Skip to content

Commit

Permalink
feat: process doxygen comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Jan 2, 2025
1 parent 9b309a5 commit 2282614
Show file tree
Hide file tree
Showing 4 changed files with 817 additions and 653 deletions.
73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build = "src/build.rs"
description = "Rust bindings to the System Informer's (formerly known as Process Hacker) `phnt` native Windows headers"

[features]
regenerate = ["dep:regex", "dep:bindgen", "dep:chrono"]
regenerate = ["dep:regex", "dep:bindgen", "dep:chrono", "dep:doxygen-rs"]

[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
Expand All @@ -22,6 +22,7 @@ rustc-args = ["--cfg", "docsrs"]
regex = { version = "1.11.1", optional = true }
bindgen = { version = "0.71.1", optional = true }
chrono = { version = "0.4.39", optional = true }
doxygen-rs = { version = "0.4.2", optional = true }

[dependencies.windows-sys]
version = "0.59.0"
Expand Down
32 changes: 29 additions & 3 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use regen::main;
#[cfg_attr(docsrs, doc(cfg(not(feature = "regenerate"))))]
#[cfg(not(feature = "regenerate"))]
fn main() {
println!("Using vendored bindings, build script skipped.");
println!("Using vsendored bindings, build script skipped.");
}

#[cfg_attr(docsrs, doc(cfg(feature = "regenerate")))]
Expand All @@ -41,7 +41,33 @@ mod regen {
use std::env;
use std::path::PathBuf;

pub struct BindgenConfig {
use bindgen::callbacks::ParseCallbacks;

#[derive(Debug)]
struct ProcessComments;

impl ParseCallbacks for ProcessComments {
fn process_comment(&self, comment: &str) -> Option<String> {
match std::panic::catch_unwind(|| doxygen_rs::transform(comment)) {
Ok(res) => Some(res),
Err(err) => {
println!(
"cargo:warning=Problem processing comment: {}",
if let Some(msg) = err.downcast_ref::<String>() {
msg
} else if let Some(msg) = err.downcast_ref::<&str>() {
msg
} else {
"Unknown panic type"
}
);
None
}
}
}
}

struct BindgenConfig {
pub blocklist_types: Vec<String>,
pub raw_lines: Vec<String>,
}
Expand Down Expand Up @@ -132,7 +158,7 @@ mod regen {
.type_alias("NTSTATUS")
.opaque_type("std::.*")
.ctypes_prefix("cty")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.parse_callbacks(Box::new(ProcessComments))
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: true,
})
Expand Down
Loading

0 comments on commit 2282614

Please sign in to comment.