From e26d01f78269b025ed016bdc7df08726054eb064 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sun, 27 Nov 2022 19:36:58 -0700 Subject: [PATCH] Don't generate bindings Also fix some minor clippy lints + document the helper script a bit more. --- bindgen-citro3d/Cargo.toml | 1 + bindgen-citro3d/src/main.rs | 18 +++- citro3d-sys/build.rs | 2 +- citro3d-sys/src/bindings.rs | 201 ------------------------------------ 4 files changed, 17 insertions(+), 205 deletions(-) diff --git a/bindgen-citro3d/Cargo.toml b/bindgen-citro3d/Cargo.toml index 3231842..86ac6e5 100644 --- a/bindgen-citro3d/Cargo.toml +++ b/bindgen-citro3d/Cargo.toml @@ -2,6 +2,7 @@ name = "bindgen-citro3d" version = "0.1.0" edition = "2021" +description = "Helper tool to generate citro3d-sys bindings." [dependencies] bindgen = "0.62.0" diff --git a/bindgen-citro3d/src/main.rs b/bindgen-citro3d/src/main.rs index 6d1282b..ea12c12 100644 --- a/bindgen-citro3d/src/main.rs +++ b/bindgen-citro3d/src/main.rs @@ -1,3 +1,7 @@ +//! This is meant to be run as a "script" to generate bindings to `citro3d`. +//! We use this instead of `bindgen-cli` to enable the use of [`CustomCallbacks`] +//! with [`bindgen`] as a library for finer grained control of the bindings. + use std::iter::FromIterator; use std::path::PathBuf; @@ -8,7 +12,7 @@ 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(devkitpro).join(PathBuf::from_iter(["libctru", "include"])); + let include_path = PathBuf::from_iter([devkitpro.as_str(), "libctru", "include"]); let header = include_path.join("tex3ds.h"); let sysroot = PathBuf::from(devkitarm).join("arm-none-eabi"); @@ -25,13 +29,13 @@ fn main() { .fit_macro_constants(true) .raw_line("use ctru_sys::*;") .must_use_type("Result") - // TODO functions,types,vars .blocklist_type("u(8|16|32|64)") .opaque_type("(GPU|GFX)_.*") .opaque_type("float24Uniform_s") - .blocklist_file(".*/3ds/.*[.]h") .allowlist_file(".*/c3d/.*[.]h") .allowlist_file(".*/tex3ds[.]h") + .blocklist_file(".*/3ds/.*[.]h") + .blocklist_file(".*/sys/.*[.]h") .clang_args([ "--target=arm-none-eabi", "--sysroot", @@ -57,6 +61,14 @@ fn main() { .expect("failed to write bindings"); } +/// Custom callback struct to allow us to mark some "known good types" as +/// [`Copy`], which in turn allows using Rust `union` instead of bindgen union +/// types. See +/// +/// for more info. +/// +/// We do the same for [`Debug`] just for the convenience of derived Debug impls +/// on some `citro3d` types. #[derive(Debug)] struct CustomCallbacks; diff --git a/citro3d-sys/build.rs b/citro3d-sys/build.rs index ff80359..e865214 100644 --- a/citro3d-sys/build.rs +++ b/citro3d-sys/build.rs @@ -6,7 +6,7 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-env-changed=DEVKITPRO"); - println!("cargo:rustc-link-search=native={}/libctru/lib", dkp_path); + println!("cargo:rustc-link-search=native={dkp_path}/libctru/lib"); println!( "cargo:rustc-link-lib=static={}", match debug_symbols.as_str() { diff --git a/citro3d-sys/src/bindings.rs b/citro3d-sys/src/bindings.rs index c6fc58e..76ca7ad 100644 --- a/citro3d-sys/src/bindings.rs +++ b/citro3d-sys/src/bindings.rs @@ -92,210 +92,9 @@ pub const C3D_DEFAULT_CMDBUF_SIZE: u32 = 262144; pub const C3DF_LightEnv_IsCP_Any: u32 = 66846720; pub const C3DF_LightEnv_LutDirtyAll: u32 = 4227858432; pub type __int64_t = ::libc::c_longlong; -pub type _LOCK_T = i32; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __lock_t { - pub lock: _LOCK_T, - pub thread_tag: u32, - pub counter: u32, -} -pub type _LOCK_RECURSIVE_T = __lock_t; pub type _off_t = __int64_t; pub type _fpos_t = __int64_t; pub type wint_t = ::libc::c_int; -#[repr(C)] -#[derive(Copy, Clone)] -pub struct _mbstate_t { - pub __count: ::libc::c_int, - pub __value: _mbstate_t__bindgen_ty_1, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union _mbstate_t__bindgen_ty_1 { - pub __wch: wint_t, - pub __wchb: [::libc::c_uchar; 4usize], -} -pub type __ULong = ::libc::c_ulong; -pub type _flock_t = _LOCK_RECURSIVE_T; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __locale_t { - _unused: [u8; 0], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _Bigint { - pub _next: *mut _Bigint, - pub _k: ::libc::c_int, - pub _maxwds: ::libc::c_int, - pub _sign: ::libc::c_int, - pub _wds: ::libc::c_int, - pub _x: [__ULong; 1usize], -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __tm { - pub __tm_sec: ::libc::c_int, - pub __tm_min: ::libc::c_int, - pub __tm_hour: ::libc::c_int, - pub __tm_mday: ::libc::c_int, - pub __tm_mon: ::libc::c_int, - pub __tm_year: ::libc::c_int, - pub __tm_wday: ::libc::c_int, - pub __tm_yday: ::libc::c_int, - pub __tm_isdst: ::libc::c_int, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _on_exit_args { - pub _fnargs: [*mut ::libc::c_void; 32usize], - pub _dso_handle: [*mut ::libc::c_void; 32usize], - pub _fntypes: __ULong, - pub _is_cxa: __ULong, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _atexit { - pub _next: *mut _atexit, - pub _ind: ::libc::c_int, - pub _fns: [::core::option::Option; 32usize], - pub _on_exit_args: _on_exit_args, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct __sbuf { - pub _base: *mut ::libc::c_uchar, - pub _size: ::libc::c_int, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct __sFILE { - pub _p: *mut ::libc::c_uchar, - pub _r: ::libc::c_int, - pub _w: ::libc::c_int, - pub _flags: ::libc::c_short, - pub _file: ::libc::c_short, - pub _bf: __sbuf, - pub _lbfsize: ::libc::c_int, - pub _cookie: *mut ::libc::c_void, - pub _read: ::core::option::Option< - unsafe extern "C" fn( - arg1: *mut _reent, - arg2: *mut ::libc::c_void, - arg3: *mut ::libc::c_char, - arg4: ::libc::c_int, - ) -> ::libc::c_int, - >, - pub _write: ::core::option::Option< - unsafe extern "C" fn( - arg1: *mut _reent, - arg2: *mut ::libc::c_void, - arg3: *const ::libc::c_char, - arg4: ::libc::c_int, - ) -> ::libc::c_int, - >, - pub _seek: ::core::option::Option< - unsafe extern "C" fn( - arg1: *mut _reent, - arg2: *mut ::libc::c_void, - arg3: _fpos_t, - arg4: ::libc::c_int, - ) -> _fpos_t, - >, - pub _close: ::core::option::Option< - unsafe extern "C" fn(arg1: *mut _reent, arg2: *mut ::libc::c_void) -> ::libc::c_int, - >, - pub _ub: __sbuf, - pub _up: *mut ::libc::c_uchar, - pub _ur: ::libc::c_int, - pub _ubuf: [::libc::c_uchar; 3usize], - pub _nbuf: [::libc::c_uchar; 1usize], - pub _lb: __sbuf, - pub _blksize: ::libc::c_int, - pub _offset: _off_t, - pub _data: *mut _reent, - pub _lock: _flock_t, - pub _mbstate: _mbstate_t, - pub _flags2: ::libc::c_int, -} -pub type __FILE = __sFILE; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _glue { - pub _next: *mut _glue, - pub _niobs: ::libc::c_int, - pub _iobs: *mut __FILE, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _rand48 { - pub _seed: [::libc::c_ushort; 3usize], - pub _mult: [::libc::c_ushort; 3usize], - pub _add: ::libc::c_ushort, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct _reent { - pub _errno: ::libc::c_int, - pub _stdin: *mut __FILE, - pub _stdout: *mut __FILE, - pub _stderr: *mut __FILE, - pub _inc: ::libc::c_int, - pub _emergency: [::libc::c_char; 25usize], - pub _unspecified_locale_info: ::libc::c_int, - pub _locale: *mut __locale_t, - pub __sdidinit: ::libc::c_int, - pub __cleanup: ::core::option::Option, - pub _result: *mut _Bigint, - pub _result_k: ::libc::c_int, - pub _p5s: *mut _Bigint, - pub _freelist: *mut *mut _Bigint, - pub _cvtlen: ::libc::c_int, - pub _cvtbuf: *mut ::libc::c_char, - pub _new: _reent__bindgen_ty_1, - pub _atexit: *mut _atexit, - pub _atexit0: _atexit, - pub _sig_func: *mut ::core::option::Option, - pub __sglue: _glue, - pub __sf: [__FILE; 3usize], - pub deviceData: *mut ::libc::c_void, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union _reent__bindgen_ty_1 { - pub _reent: _reent__bindgen_ty_1__bindgen_ty_1, - pub _unused: _reent__bindgen_ty_1__bindgen_ty_2, -} -#[repr(C)] -#[derive(Copy, Clone)] -pub struct _reent__bindgen_ty_1__bindgen_ty_1 { - pub _unused_rand: ::libc::c_uint, - pub _strtok_last: *mut ::libc::c_char, - pub _asctime_buf: [::libc::c_char; 26usize], - pub _localtime_buf: __tm, - pub _gamma_signgam: ::libc::c_int, - pub _rand_next: ::libc::c_ulonglong, - pub _r48: _rand48, - pub _mblen_state: _mbstate_t, - pub _mbtowc_state: _mbstate_t, - pub _wctomb_state: _mbstate_t, - pub _l64a_buf: [::libc::c_char; 8usize], - pub _signal_buf: [::libc::c_char; 24usize], - pub _getdate_err: ::libc::c_int, - pub _mbrlen_state: _mbstate_t, - pub _mbrtowc_state: _mbstate_t, - pub _mbsrtowcs_state: _mbstate_t, - pub _wcrtomb_state: _mbstate_t, - pub _wcsrtombs_state: _mbstate_t, - pub _h_errno: ::libc::c_int, -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct _reent__bindgen_ty_1__bindgen_ty_2 { - pub _nextf: [*mut ::libc::c_uchar; 30usize], - pub _nmalloc: [::libc::c_uint; 30usize], -} pub type C3D_IVec = u32_; #[doc = " @struct C3D_FVec"] #[doc = " @brief Float vector"]