From 7247504d612bfafb5c0c7f8cace7230e131c5577 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 | 18 +++++++++++++++++- wrapper.h | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index dbfba09..7b56df3 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,19 @@ 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("-DPD_INTERNAL=1") + .clang_arg("-DHAVE_C11_ATOMICS=0") + .clang_arg("-D__STDC_VERSION__=201112L") .clang_arg("-std=c11") // 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..76bad2e 100644 --- a/wrapper.h +++ b/wrapper.h @@ -1,4 +1,8 @@ -// Headers in pure data submodule +// Headers from c++11 + +#if !defined(__STDC_NO_ATOMICS__) +#include +#endif // #include "libpd/pure-data/src/d_soundfile.h" // #include "libpd/pure-data/src/g_all_guis.h"