From 397016066404730daa8830ec218626aff3cb1821 Mon Sep 17 00:00:00 2001 From: Ali Somay Date: Thu, 28 Nov 2024 16:57:22 +0100 Subject: [PATCH] Define PD_INTERNAL as true --- build.rs | 17 +++++++++++++++-- wrapper.h | 6 ++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index dbfba09..6b59f40 100644 --- a/build.rs +++ b/build.rs @@ -39,6 +39,15 @@ const PD_FLOATSIZE: &str = "64"; const WISH: &str = "\"\\\"wish86.exe\\\"\""; fn main() { + // Get the target endianness from Cargo + let target_endian = std::env::var("CARGO_CFG_TARGET_ENDIAN").unwrap(); + // Prepare the endianness defines + let endian_define = match target_endian.as_str() { + "little" => vec!["-DLITTLE_ENDIAN=1234", "-DBYTE_ORDER=LITTLE_ENDIAN"], + "big" => vec!["-DBIG_ENDIAN=4321", "-DBYTE_ORDER=BIG_ENDIAN"], + _ => panic!("Unknown target endian: {}", target_endian), + }; + // Directories let project_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -240,12 +249,16 @@ fn main() { .clang_arg(format!("-I{}", libpd_wrapper_dir.to_str().unwrap())) .clang_arg(format!("-I{}", pd_source.to_str().unwrap())) .clang_arg(format!("-DPD_FLOATSIZE={PD_FLOATSIZE}")) - .clang_arg("-DPD_INTERNAL=0") // Undefine PD_INTERNAL because it is not needed for bindings and cmake complains about it. - .clang_arg("-std=c11") + .clang_arg("-DPD_INTERNAL=1") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())); + // Add the endianness defines + for arg in endian_define { + bindings_builder = bindings_builder.clang_arg(arg); + } + #[cfg(target_os = "windows")] let bindings = bindings_builder .clang_arg(format!("-DWISH={}", WISH)) diff --git a/wrapper.h b/wrapper.h index 1f0ddf9..6902133 100644 --- a/wrapper.h +++ b/wrapper.h @@ -1,4 +1,4 @@ -// Headers in pure data submodule +// Headers from c++11 // #include "libpd/pure-data/src/d_soundfile.h" // #include "libpd/pure-data/src/g_all_guis.h" @@ -21,7 +21,9 @@ // Headers in libpd_wrapper -#include "libpd/libpd_wrapper/util/z_ringbuffer.h" +// It is not easy to bind this due to the inclusion of atomic_int, please open an issue if you need this +// libpd-rs does not need this header bound. +// #include "libpd/libpd_wrapper/util/z_ringbuffer.h" #include "libpd/libpd_wrapper/util/z_print_util.h" #include "libpd/libpd_wrapper/util/z_queued.h" #include "libpd/libpd_wrapper/z_hooks.h"