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

Update bindgen script and bindings #125

Merged
merged 13 commits into from
May 30, 2023
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["ctru-rs", "ctru-sys", "ctru-sys/docstring-to-rustdoc"]
members = ["ctru-rs", "ctru-sys", "ctru-sys/bindgen-ctru-sys"]
default-members = ["ctru-rs", "ctru-sys"]

[patch.'https://github.com/rust3ds/ctru-rs']
# Make sure all dependencies use the local ctru-sys package
Expand Down
2 changes: 1 addition & 1 deletion ctru-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = "ctru"

[dependencies]
cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "21.2" }
ctru-sys = { path = "../ctru-sys", version = "22.2" }
const-zero = "0.1.0"
shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" }
pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" }
Expand Down
2 changes: 1 addition & 1 deletion ctru-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ctru-sys"
version = "21.2.0+2.1.2-1"
version = "22.2.0+2.2.2-1"
authors = [ "Rust3DS Org", "Ronald Kinard <[email protected]>" ]
license = "Zlib"
links = "ctru"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions ctru-sys/bindgen-ctru-sys/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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__",
])
.parse_callbacks(Box::new(CustomCallbacks))
.generate()
.expect("unable to generate bindings");

bindings
.write(Box::new(std::io::stdout()))
.expect("failed to write bindings");
}
30 changes: 1 addition & 29 deletions ctru-sys/bindgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,7 @@ CTRU_SYS_VERSION="$(
)"

echo "Generating bindings.rs..."
bindgen "$DEVKITPRO/libctru/include/3ds.h" \
--rust-target nightly \
--use-core \
--distrust-clang-mangling \
--must-use-type 'Result' \
--no-layout-tests \
--ctypes-prefix "::libc" \
--no-prepend-enum-name \
--generate "functions,types,vars" \
--blocklist-type "u(8|16|32|64)" \
--blocklist-type "__builtin_va_list" \
--blocklist-type "__va_list" \
--opaque-type "MiiData" \
--with-derive-default \
-- \
--target=arm-none-eabi \
--sysroot="$DEVKITARM/arm-none-eabi" \
-isystem"$DEVKITARM/arm-none-eabi/include" \
-I"$DEVKITPRO/libctru/include" \
-mfloat-abi=hard \
-march=armv6k \
-mtune=mpcore \
-mfpu=vfp \
-DARM11 \
-D__3DS__ \
> src/bindings.rs

echo "Updating docstrings in bindings.rs..."
cargo run --quiet --package docstring-to-rustdoc -- src/bindings.rs
cargo run --package bindgen-ctru-sys > src/bindings.rs

echo "Formatting generated files..."
cargo fmt --all
Expand Down
31 changes: 0 additions & 31 deletions ctru-sys/docstring-to-rustdoc/src/main.rs

This file was deleted.

Loading