diff --git a/program/rust/build.rs b/program/rust/build.rs index d1dbfb6ab..0f1048838 100644 --- a/program/rust/build.rs +++ b/program/rust/build.rs @@ -19,9 +19,14 @@ fn main() { let out_dir = PathBuf::from(out_dir); let mut make_extra_flags = vec![]; + let mut clang_extra_flags = vec![]; if has_feat_pythnet { + // Define PC_PYTHNET for the *.so build make_extra_flags.push("CFLAGS=-DPC_PYTHNET=1"); + + // Define PC_PYTHNET for the bindings build + clang_extra_flags.push("-DPC_PYTHNET=1"); } let mut make_targets = vec![]; @@ -73,10 +78,12 @@ fn main() { // Generate and write bindings let bindings = Builder::default() .clang_arg(format!("-I{:}", get_solana_inc_path().display())) + .clang_args(clang_extra_flags) .header("./src/bindings.h") .rustfmt_bindings(true) .generate() .expect("Unable to generate bindings"); + bindings .write_to_file("./codegen/bindings.rs") .expect("Couldn't write bindings!"); diff --git a/program/rust/src/tests/test_sizes.rs b/program/rust/src/tests/test_sizes.rs index a14d1c664..e9588a026 100644 --- a/program/rust/src/tests/test_sizes.rs +++ b/program/rust/src/tests/test_sizes.rs @@ -12,6 +12,7 @@ use { PythAccount, }, c_oracle_header::{ + PC_COMP_SIZE, PC_MAP_TABLE_SIZE, PC_VERSION, ZSTD_UPPER_BOUND, @@ -58,6 +59,9 @@ fn test_sizes() { c_oracle_header::PC_COMP_SIZE_PYTHNET, }; + // Sanity-check the Pythnet PC_COMP_SIZE + assert_eq!(PC_COMP_SIZE, 64); + assert_eq!( size_of::(), 48 + u64::BITS as usize @@ -75,6 +79,10 @@ fn test_sizes() { #[cfg(not(feature = "pythnet"))] { use crate::c_oracle_header::PC_COMP_SIZE_SOLANA; + + // Sanity-check the Solana PC_COMP_SIZE + assert_eq!(PC_COMP_SIZE, PC_COMP_SIZE_SOLANA); + assert_eq!( size_of::(), 48 + u64::BITS as usize