Skip to content

Commit

Permalink
Enabled comments in bindgen and added doxygen pre-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh committed Mar 8, 2024
1 parent f6d0892 commit bd927da
Show file tree
Hide file tree
Showing 4 changed files with 2,510 additions and 1 deletion.
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.

2 changes: 2 additions & 0 deletions build-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ proc-macro2 = { version = "1.0.76", default-features = false }
toml = { version = "0.8.8", default-features = false, features = ["parse"] }
bindgen = "0.69.4"
quote = { version = "1.0.35", default-features = false }
doxygen-rs = "0.4"

25 changes: 24 additions & 1 deletion build-util/src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{env, fs, io, path::Path, process};

use bindgen::callbacks::ParseCallbacks;
use quote::ToTokens;
use syn::visit_mut::VisitMut;

Expand Down Expand Up @@ -79,6 +80,27 @@ pub fn generate(
}
}

#[derive(Debug)]
struct Callbacks;

impl ParseCallbacks for Callbacks {
fn process_comment(&self, comment: &str) -> Option<String> {
let comment = comment.replace("@param[int]", "@param[in]");
let comment = comment.replace("[inout]", "[in,out]");
let comment = comment.replace("[in]\t", "[in] \t");
let comment = comment.replace("[out]\t", "[out] \t");

let comment = doxygen_rs::transform(&comment);

let comment = comment.strip_prefix("!<").unwrap_or(&comment);
let comment = comment.strip_prefix('!').unwrap_or(&comment);
let comment = comment.strip_prefix('<').unwrap_or(&comment);
let comment = comment.trim();

Some(comment.to_string())
}
}

fn generate_preprocessed_bindings(
headers: &Path,
vita_headers_include: &Path,
Expand All @@ -92,7 +114,8 @@ fn generate_preprocessed_bindings(
.clang_args(&["-target", "armv7a-none-eabihf"])
.use_core()
.ctypes_prefix("crate::ctypes")
.generate_comments(false)
.generate_comments(true)
.parse_callbacks(Box::new(Callbacks))
.prepend_enum_name(false)
.layout_tests(false)
.formatter(bindgen::Formatter::None);
Expand Down
Loading

0 comments on commit bd927da

Please sign in to comment.