Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled comments in bindgen and added doxygen pre-processor #30

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 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"
lazy-regex = "3.1.0"
40 changes: 39 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,42 @@ 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]");

// doxygen_rs doesn't handle tabs well
let comment = comment.replace('\t', " ");
// Fixes links to functions and types
let comment = comment.replace("@see ::", "@see crate::");

// Escape square brackets for non-links
let comment =
lazy_regex::regex_replace_all!("\\[([\\d]+)\\]", &comment, |_, num: &str| format!(
"\\[{num}\\]"
));
pheki marked this conversation as resolved.
Show resolved Hide resolved

// Without space these brackets are considered to be a link
let comment = comment.replace(
"[1,SCE_GXM_MAX_SCENES_PER_RENDERTARGET]",
"[1, SCE_GXM_MAX_SCENES_PER_RENDERTARGET]",
);

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 +129,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
Loading