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

Further improve bindings.rs documentation #75

Merged
merged 8 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions ctru-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", version = "0.2.2", rev = "573f483ad63ab4662650961998d3ed093a703983", optional = true }
Techie-Pi marked this conversation as resolved.
Show resolved Hide resolved

[features]
build-binary = ["doxygen-rs"]

[[bin]]
name = "docstring-to-rustdoc"
required-features = ["build-binary"]
4 changes: 3 additions & 1 deletion ctru-sys/bindgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ 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

cargo fmt --all
46 changes: 5 additions & 41 deletions ctru-sys/src/bin/docstring-to-rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@
//!
//! # Usage
//!
//! `cargo run --bin docstring-to-rustdoc -- [location of the bindings.rs]`
//! Example: `cargo run --bin docstring-to-rustdoc -- src/bindings.rs`
//! `cargo run --bin docstring-to-rustdoc --features="build-binary" -- [location of the bindings.rs]`
//! Example: `cargo run --bin docstring-to-rustdoc --features="build-binary" -- src/bindings.rs`
//!
Techie-Pi marked this conversation as resolved.
Show resolved Hide resolved
//! # 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};
Expand All @@ -26,35 +16,9 @@ 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 bindings = 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.as_str());

let old_bindings_path = bindings_path.to_str().unwrap().to_owned() + ".old";

Expand Down