From d54abef3186517cfe84a194a7b7491ab70e5d029 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Sat, 18 May 2024 18:00:45 -0400 Subject: [PATCH] Catch binding conflicts between libc/citro3d/ctru --- citro3d-sys/Cargo.toml | 8 +++++++- citro3d-sys/build.rs | 5 ++++- citro3d-sys/src/lib.rs | 19 +++++++++++++++++-- citro3d/Cargo.toml | 2 +- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/citro3d-sys/Cargo.toml b/citro3d-sys/Cargo.toml index 797e9cb..74590bd 100644 --- a/citro3d-sys/Cargo.toml +++ b/citro3d-sys/Cargo.toml @@ -11,9 +11,15 @@ libc = "0.2.116" ctru-sys = { git = "https://github.com/rust3ds/ctru-rs.git" } [build-dependencies] -bindgen = { version = "0.68.1", features = ["experimental"] } cc = "1.0.83" doxygen-rs = "0.4.2" +[build-dependencies.bindgen] +# Use 0.* so that we take the same version ctru-sys uses by default +version = "0.*" +features = ["experimental"] +git = "https://github.com/ian-h-chamberlain/rust-bindgen.git" +rev = "fa88e08fb5abf8d17e596243846016776ac32c2f" + [dev-dependencies] shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" } diff --git a/citro3d-sys/build.rs b/citro3d-sys/build.rs index ac7b8df..17ac791 100644 --- a/citro3d-sys/build.rs +++ b/citro3d-sys/build.rs @@ -65,7 +65,6 @@ fn main() { .ctypes_prefix("::libc") .prepend_enum_name(false) .fit_macro_constants(true) - .raw_line("use ctru_sys::*;") .must_use_type("Result") .blocklist_type("u(8|16|32|64)") .opaque_type("(GPU|GFX)_.*") @@ -74,6 +73,10 @@ fn main() { .allowlist_file(".*/tex3ds[.]h") .blocklist_file(".*/3ds/.*[.]h") .blocklist_file(".*/sys/.*[.]h") + .blocklist_type("FILE") + // ctru-sys already generates one of these, let's reuse it instead of + // regenerating another one in citro3d-sys bindings. + .blocklist_type("__BindgenBitfieldUnit") .wrap_static_fns(true) .wrap_static_fns_path(out_dir.join(static_fns_path)) .clang_args([ diff --git a/citro3d-sys/src/lib.rs b/citro3d-sys/src/lib.rs index c2a8fb8..ee3b5c3 100644 --- a/citro3d-sys/src/lib.rs +++ b/citro3d-sys/src/lib.rs @@ -3,6 +3,7 @@ #![allow(warnings)] #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] +#![deny(ambiguous_glob_reexports)] #![allow(clippy::all)] #![doc(html_root_url = "https://rust3ds.github.io/citro3d-rs/crates")] #![doc( @@ -12,11 +13,25 @@ html_logo_url = "https://user-images.githubusercontent.com/11131775/225929072-2fa1741c-93ae-4b47-9bdf-af70f3d59910.png" )] -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +// During testing, re-export types to trigger `ambiguous_glob_reexports` +// if we ended up regenerating the same type as upstream ctru-sys or libc. +#[cfg(test)] +pub use ctru_sys::*; +#[cfg(test)] +pub use libc::*; + +mod bindings { + use ctru_sys::*; + use libc::*; + + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} + +pub use bindings::*; pub mod gx; pub use gx::*; // Prevent linking errors from the standard `test` library when running `cargo 3ds test --lib`. -#[cfg(test)] +#[cfg(all(test, not(rust_analyzer)))] extern crate shim_3ds; diff --git a/citro3d/Cargo.toml b/citro3d/Cargo.toml index 705d601..b96ca1e 100644 --- a/citro3d/Cargo.toml +++ b/citro3d/Cargo.toml @@ -25,7 +25,7 @@ approx = ["dep:approx"] glam = ["dep:glam"] [dev-dependencies] -test-runner = { git = "https://github.com/rust3ds/test-runner.git" } +test-runner = { git = "https://github.com/rust3ds/ctru-rs.git" } [dev-dependencies.citro3d] # Basically, this works like `cargo 3ds test --features ...` for building tests