Browse Source

Make documentation on ``bindings.rs`` more _rustdoc-ly_

This adds a "_bin-dependency_" on ``ctru-sys`` to doxygen-rs, a project I've been roking on to improve Doxygen to Rustdoc conversion: https://github.com/Techie-Pi/doxygen-rs
pull/75/head
TechiePi 2 years ago
parent
commit
19990694d6
  1. 8
      ctru-sys/Cargo.toml
  2. 2
      ctru-sys/bindgen.sh
  3. 41
      ctru-sys/src/bin/docstring-to-rustdoc.rs
  4. 19347
      ctru-sys/src/bindings.rs

8
ctru-sys/Cargo.toml

@ -8,3 +8,11 @@ edition = "2021" @@ -8,3 +8,11 @@ edition = "2021"
[dependencies]
libc = { version = "0.2.121", default-features = false }
doxygen-rs = { git = "https://github.com/Techie-Pi/doxygen-rs.git", rev = "ef2300a4d6e7c6dc5a6061096d69bf054a9f7896", optional = true }
[features]
build-binary = ["doxygen-rs"]
[[bin]]
name = "docstring-to-rustdoc"
required-features = ["build-binary"]

2
ctru-sys/bindgen.sh

@ -29,4 +29,4 @@ bindgen "$DEVKITPRO/libctru/include/3ds.h" \ @@ -29,4 +29,4 @@ bindgen "$DEVKITPRO/libctru/include/3ds.h" \
-D__3DS__ \
> src/bindings.rs
cargo run --bin docstring-to-rustdoc -- src/bindings.rs
cargo run --bin docstring-to-rustdoc --features="build-binary" -- src/bindings.rs

41
ctru-sys/src/bin/docstring-to-rustdoc.rs

@ -7,17 +7,7 @@ @@ -7,17 +7,7 @@
//!
//! # Transformations
//!
//! The following are _completely_ removed, but _its contents are kept_:
//! * `@brief`
//! * `@ref`
//! * `@note`
//! * `@return`
//! * `@sa`
//! * `<`
//! * `[out]` and `[in]`
//!
//! The followings are _partially_ transformed to Rustdoc format:
//! * `@param`
//! Check [doxygen-rs docs](https://techie-pi.github.io/doxygen-rs/doxygen_rs/)
use std::path::Path;
use std::{env, fs, io};
@ -26,35 +16,8 @@ fn main() -> io::Result<()> { @@ -26,35 +16,8 @@ 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_string: String = fs::read_to_string(bindings_path)?;
let parsed = bindings_string
.lines()
.map(|v| {
// Only modify lines with the following structure: `` #[doc ... ] ``
if v.trim_start().starts_with("#[doc") && v.trim_end().ends_with(']') {
v.replace("@brief", "")
// Example: ``@param offset Offset of the RomFS...`` -> ``- offset Offset of the RomFS...``
// Will improve in the future
.replace("@param", "* ")
.replace("@ref", "")
.replace("@note", "")
.replace("@return", "")
.replace("@sa", "")
.replace("< ", "")
// Remove things like ``@param[out]``
.replace("[out]", "")
.replace("[in]", "")
// Trim start of the Rustdoc: ``...= " ...`` -> ``...= "...``
.replace("= \" ", "= \"")
// Double pass because _most_ annotations are at the start
.replace("= \" ", "= \"")
} else {
String::from(v)
}
})
.map(|v| v + "\n")
.collect::<String>();
let parsed = doxygen_rs::transform_bindgen(&bindings_path)?;
let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old";

19347
ctru-sys/src/bindings.rs

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save