Browse Source

Add docstring to rustdoc conversion

Right now, only basic things are changed (remove ``@`` annotations, trim spaces, etc.).
In the future, changes will be made (mostly to _truly_ transform ``@param``to rustdoc conventions.

Right now, the documentation is mostly decent, and definitely understandable
pull/64/head
TechiePi 2 years ago
parent
commit
d4db25cd63
  1. 2
      ctru-sys/bindgen.sh
  2. 50
      ctru-sys/src/bin/docstring-to-rustdoc.rs
  3. 12690
      ctru-sys/src/bindings.rs

2
ctru-sys/bindgen.sh

@ -28,3 +28,5 @@ bindgen "$DEVKITPRO/libctru/include/3ds.h" \ @@ -28,3 +28,5 @@ bindgen "$DEVKITPRO/libctru/include/3ds.h" \
-DARM11 \
-D__3DS__ \
> src/bindings.rs
cargo run --bin docstring-to-rustdoc -- src/bindings.rs

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

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
use std::{env, fs, io};
use std::path::Path;
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| {
// End-lines of bindings.rs are CRLF
v + "\r\n"
})
.collect::<String>();
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(())
}

12690
ctru-sys/src/bindings.rs

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