Browse Source
- Added the `bindgen-ctru-sys` to be able to use `ParseCallbacks` when generating the bindings. - Updated `doxygen-rs` to 0.4, which has a faster engine and more extensible internal (even though there are some regressions). - Removes the `docstring-to-rustdoc` package because it is no longer needed.pull/110/head
TechiePi
2 years ago
6 changed files with 3486 additions and 8339 deletions
@ -1,7 +1,8 @@
@@ -1,7 +1,8 @@
|
||||
[package] |
||||
name = "docstring-to-rustdoc" |
||||
name = "bindgen-ctru-sys" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
[dependencies] |
||||
doxygen-rs = "0.3.1" |
||||
bindgen = "0.64" |
||||
doxygen-rs = "0.4" |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
use bindgen::callbacks::ParseCallbacks; |
||||
use bindgen::{Builder, RustTarget}; |
||||
use std::path::PathBuf; |
||||
|
||||
#[derive(Debug)] |
||||
struct CustomCallbacks; |
||||
|
||||
impl ParseCallbacks for CustomCallbacks { |
||||
fn process_comment(&self, comment: &str) -> Option<String> { |
||||
Some(doxygen_rs::transform(comment)) |
||||
} |
||||
} |
||||
|
||||
fn main() { |
||||
let devkitpro = std::env::var("DEVKITPRO").expect("DEVKITPRO not set in environment"); |
||||
let devkitarm = std::env::var("DEVKITARM").expect("DEVKITARM not set in environment"); |
||||
|
||||
let include_path = PathBuf::from_iter([devkitpro.as_str(), "libctru", "include"]); |
||||
let header = include_path.join("3ds.h"); |
||||
|
||||
let sysroot = PathBuf::from(devkitarm).join("arm-none-eabi"); |
||||
let system_include = sysroot.join("include"); |
||||
|
||||
let bindings = Builder::default() |
||||
.header(header.to_str().unwrap()) |
||||
.rust_target(RustTarget::Nightly) |
||||
.use_core() |
||||
.trust_clang_mangling(false) |
||||
.must_use_type("Result") |
||||
.layout_tests(false) |
||||
.ctypes_prefix("::libc") |
||||
.prepend_enum_name(false) |
||||
.blocklist_type("u(8|16|32|64)") |
||||
.blocklist_type("__builtin_va_list") |
||||
.blocklist_type("__va_list") |
||||
.opaque_type("MiiData") |
||||
.derive_default(true) |
||||
.clang_args([ |
||||
"--target=arm-none-eabi", |
||||
"--sysroot", |
||||
sysroot.to_str().unwrap(), |
||||
"-isystem", |
||||
system_include.to_str().unwrap(), |
||||
"-I", |
||||
include_path.to_str().unwrap(), |
||||
"-mfloat-abi=hard", |
||||
"-march=armv6k", |
||||
"-mtune=mpcore", |
||||
"-mfpu=vfp", |
||||
"-DARM11 ", |
||||
"-D_3DS ", |
||||
"-D__3DS__ ", |
||||
]) |
||||
.parse_callbacks(Box::new(CustomCallbacks)) |
||||
.generate() |
||||
.expect("unable to generate bindings"); |
||||
|
||||
bindings |
||||
.write(Box::new(std::io::stdout())) |
||||
.expect("failed to write bindings"); |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
//! This script transforms _some_ Boxygen comments to Rustdoc format
|
||||
//!
|
||||
//! # Usage
|
||||
//!
|
||||
//! `cargo run --package docstring-to-rustdoc -- [location of the bindings.rs]`
|
||||
//! Example: `cargo run --package docstring-to-rustdoc -- src/bindings.rs`
|
||||
//!
|
||||
//! # Transformations
|
||||
//!
|
||||
//! Check [doxygen-rs docs](https://techie-pi.github.io/doxygen-rs/doxygen_rs/)
|
||||
|
||||
use std::path::Path; |
||||
use std::{env, fs, io}; |
||||
|
||||
fn main() -> io::Result<()> { |
||||
let args: Vec<String> = env::args().collect(); |
||||
|
||||
let bindings_path = Path::new(args.get(1).expect("bindings.rs not provided in the args")); |
||||
let bindings = fs::read_to_string(bindings_path)?; |
||||
|
||||
let parsed = doxygen_rs::transform_bindgen(bindings.as_str()); |
||||
|
||||
let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old"; |
||||
|
||||
// If something fails, the original bindings are available at ``bindings.rs.old``
|
||||
fs::rename(bindings_path, &old_bindings_path)?; |
||||
fs::write(bindings_path, parsed)?; |
||||
fs::remove_file(&old_bindings_path)?; |
||||
|
||||
Ok(()) |
||||
} |
Loading…
Reference in new issue