Skip to content
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}\\]"
));

// 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