Skip to content

Commit

Permalink
Fix bindgen build for pythnet, test_sizes: add PC_COMP_SIZE asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
drozdziak1 committed Oct 9, 2023
1 parent 88d236a commit 4001805
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions program/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down Expand Up @@ -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!");
Expand Down
8 changes: 8 additions & 0 deletions program/rust/src/tests/test_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {
PythAccount,
},
c_oracle_header::{
PC_COMP_SIZE,
PC_MAP_TABLE_SIZE,
PC_VERSION,
ZSTD_UPPER_BOUND,
Expand Down Expand Up @@ -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::<PriceAccount>(),
48 + u64::BITS as usize
Expand All @@ -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::<PriceAccount>(),
48 + u64::BITS as usize
Expand Down

0 comments on commit 4001805

Please sign in to comment.