Skip to content

Commit d551b06

Browse files
committed
Enabled comments in bindgen and added doxygen pre-processor
1 parent d1bed45 commit d551b06

File tree

4 files changed

+2495
-1
lines changed

4 files changed

+2495
-1
lines changed

Cargo.lock

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-util/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ proc-macro2 = { version = "1.0.76", default-features = false }
1919
toml = { version = "0.8.8", default-features = false, features = ["parse"] }
2020
bindgen = "0.69.4"
2121
quote = { version = "1.0.35", default-features = false }
22+
doxygen-rs = "0.4"
23+

build-util/src/bindgen.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{env, fs, io, path::Path, process};
22

3+
use bindgen::callbacks::ParseCallbacks;
34
use quote::ToTokens;
45
use syn::visit_mut::VisitMut;
56

@@ -79,6 +80,27 @@ pub fn generate(
7980
}
8081
}
8182

83+
#[derive(Debug)]
84+
struct Callbacks;
85+
86+
impl ParseCallbacks for Callbacks {
87+
fn process_comment(&self, comment: &str) -> Option<String> {
88+
let comment = comment.replace("@param[int]", "@param[in]");
89+
let comment = comment.replace("[inout]", "[in,out]");
90+
let comment = comment.replace("[in]\t", "[in] \t");
91+
let comment = comment.replace("[out]\t", "[out] \t");
92+
93+
let comment = doxygen_rs::transform(&comment);
94+
95+
let comment = comment.strip_prefix("!<").unwrap_or(&comment);
96+
let comment = comment.strip_prefix('!').unwrap_or(&comment);
97+
let comment = comment.strip_prefix('<').unwrap_or(&comment);
98+
let comment = comment.trim();
99+
100+
Some(comment.to_string())
101+
}
102+
}
103+
82104
fn generate_preprocessed_bindings(
83105
headers: &Path,
84106
vita_headers_include: &Path,
@@ -92,7 +114,8 @@ fn generate_preprocessed_bindings(
92114
.clang_args(&["-target", "armv7a-none-eabihf"])
93115
.use_core()
94116
.ctypes_prefix("crate::ctypes")
95-
.generate_comments(false)
117+
.generate_comments(true)
118+
.parse_callbacks(Box::new(Callbacks))
96119
.prepend_enum_name(false)
97120
.layout_tests(false)
98121
.formatter(bindgen::Formatter::None);

0 commit comments

Comments
 (0)