Browse Source

Merge pull request #125 from rust3ds/update-sys

Update bindgen script and bindings
pull/133/head
Meziu 2 years ago committed by GitHub
parent
commit
54c6359ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/ci.yml
  2. 3
      Cargo.toml
  3. 2
      ctru-rs/Cargo.toml
  4. 2
      ctru-sys/Cargo.toml
  5. 8
      ctru-sys/bindgen-ctru-sys/Cargo.toml
  6. 62
      ctru-sys/bindgen-ctru-sys/src/main.rs
  7. 30
      ctru-sys/bindgen.sh
  8. 7
      ctru-sys/docstring-to-rustdoc/Cargo.toml
  9. 31
      ctru-sys/docstring-to-rustdoc/src/main.rs
  10. 10823
      ctru-sys/src/bindings.rs
  11. 5
      ctru-sys/src/lib.rs

2
.github/workflows/ci.yml

@ -47,7 +47,7 @@ jobs:
run: cargo fmt --all --verbose -- --check run: cargo fmt --all --verbose -- --check
- name: Cargo check - name: Cargo check
run: cargo 3ds clippy --color=always --workspace --verbose --all-targets run: cargo 3ds clippy --color=always --verbose --all-targets
# --deny=warnings would be nice, but can easily break CI for new clippy # --deny=warnings would be nice, but can easily break CI for new clippy
# lints getting added. I'd also like to use Github's "inline warnings" # lints getting added. I'd also like to use Github's "inline warnings"
# feature, but https://github.com/actions/runner/issues/2341 means we # feature, but https://github.com/actions/runner/issues/2341 means we

3
Cargo.toml

@ -1,5 +1,6 @@
[workspace] [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'] [patch.'https://github.com/rust3ds/ctru-rs']
# Make sure all dependencies use the local ctru-sys package # Make sure all dependencies use the local ctru-sys package

2
ctru-rs/Cargo.toml

@ -13,7 +13,7 @@ name = "ctru"
[dependencies] [dependencies]
cfg-if = "1.0" 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" const-zero = "0.1.0"
shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" } shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" }
pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" } pthread-3ds = { git = "https://github.com/rust3ds/pthread-3ds.git" }

2
ctru-sys/Cargo.toml

@ -1,6 +1,6 @@
[package] [package]
name = "ctru-sys" name = "ctru-sys"
version = "21.2.0+2.1.2-1" version = "22.2.0+2.2.2-1"
authors = [ "Rust3DS Org", "Ronald Kinard <furyhunter600@gmail.com>" ] authors = [ "Rust3DS Org", "Ronald Kinard <furyhunter600@gmail.com>" ]
license = "Zlib" license = "Zlib"
links = "ctru" links = "ctru"

8
ctru-sys/bindgen-ctru-sys/Cargo.toml

@ -0,0 +1,8 @@
[package]
name = "bindgen-ctru-sys"
version = "0.1.0"
edition = "2021"
[dependencies]
bindgen = "0.65.1"
doxygen-rs = "0.4.2"

62
ctru-sys/bindgen-ctru-sys/src/main.rs

@ -0,0 +1,62 @@
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 ctru_header = include_path.join("3ds.h");
let sysroot = PathBuf::from(devkitarm).join("arm-none-eabi");
let system_include = sysroot.join("include");
let errno_header = system_include.join("errno.h");
let bindings = Builder::default()
.header(ctru_header.to_str().unwrap())
.header(errno_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
ctru-sys/bindgen.sh

@ -21,35 +21,7 @@ CTRU_SYS_VERSION="$(
)" )"
echo "Generating bindings.rs..." echo "Generating bindings.rs..."
bindgen "$DEVKITPRO/libctru/include/3ds.h" \ cargo run --package bindgen-ctru-sys > src/bindings.rs
--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
echo "Formatting generated files..." echo "Formatting generated files..."
cargo fmt --all cargo fmt --all

7
ctru-sys/docstring-to-rustdoc/Cargo.toml

@ -1,7 +0,0 @@
[package]
name = "docstring-to-rustdoc"
version = "0.1.0"
edition = "2021"
[dependencies]
doxygen-rs = "0.3.1"

31
ctru-sys/docstring-to-rustdoc/src/main.rs

@ -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(())
}

10823
ctru-sys/src/bindings.rs generated

File diff suppressed because it is too large Load Diff

5
ctru-sys/src/lib.rs

@ -12,8 +12,7 @@ pub use bindings::*;
pub use result::*; pub use result::*;
/// In lieu of a proper errno function exposed by libc /// In lieu of a proper errno function exposed by libc
/// (<https://github.com/rust-lang/libc/issues/1995>), this will retrieve the /// (<https://github.com/rust-lang/libc/issues/1995>).
/// last error set in the global reentrancy struct.
pub unsafe fn errno() -> s32 { pub unsafe fn errno() -> s32 {
(*__getreent())._errno *__errno()
} }

Loading…
Cancel
Save