Skip to content

Commit

Permalink
Support static inline functions in ctru-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
FenrirWolf committed Jul 26, 2023
1 parent 54c6359 commit 35d299f
Show file tree
Hide file tree
Showing 6 changed files with 567 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ctru-sys/bindgen-ctru-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bindgen = "0.65.1"
bindgen = { version = "0.65.1", features = ["experimental"] }
doxygen-rs = "0.4.2"
1 change: 1 addition & 0 deletions ctru-sys/bindgen-ctru-sys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {
.blocklist_type("__va_list")
.opaque_type("MiiData")
.derive_default(true)
.wrap_static_fns(true)
.clang_args([
"--target=arm-none-eabi",
"--sysroot",
Expand Down
9 changes: 9 additions & 0 deletions ctru-sys/bindgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ cargo run --package bindgen-ctru-sys > src/bindings.rs
echo "Formatting generated files..."
cargo fmt --all

echo "Compiling static inline wrappers..."
arm-none-eabi-gcc -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft \
-I${DEVKITPRO}/libctru/include \
-I${DEVKITPRO}/libctru/include/3ds \
-O -c -o extern.o /tmp/bindgen/extern.c
arm-none-eabi-ar -rcs libextern.a extern.o
rm extern.o


echo "Generated bindings for ctru-sys version \"${CTRU_SYS_VERSION}.x+${LIBCTRU_VERSION}\""
11 changes: 9 additions & 2 deletions ctru-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::process::{Command, Output, Stdio};
fn main() {
let dkp_path = env::var("DEVKITPRO").unwrap();
let profile = env::var("PROFILE").unwrap();
let pwd = env::var("CARGO_MANIFEST_DIR").unwrap();

// Link to libctru
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=DEVKITPRO");
println!("cargo:rustc-link-search=native={dkp_path}/libctru/lib");
Expand All @@ -17,6 +19,10 @@ fn main() {
}
);

// Link to static inline fns wrapper
println!("cargo:rustc-link-search=native={}", pwd);
println!("cargo:rustc-link-lib=static=extern");

match check_libctru_version() {
Ok((maj, min, patch)) => {
eprintln!("using libctru version {maj}.{min}.{patch}");
Expand Down Expand Up @@ -77,8 +83,9 @@ fn check_libctru_version() -> Result<(String, String, String), Box<dyn Error>> {
.output()?;

for line in String::from_utf8_lossy(&stdout).split('\n') {
let Some((_pkg, file)) = line.split_once(char::is_whitespace)
else { continue };
let Some((_pkg, file)) = line.split_once(char::is_whitespace) else {
continue;
};

println!("cargo:rerun-if-changed={file}");
}
Expand Down
Binary file added ctru-sys/libextern.a
Binary file not shown.
Loading

0 comments on commit 35d299f

Please sign in to comment.