From 0cb16e595ec5be0448382579c91fc6b3efcae3ed Mon Sep 17 00:00:00 2001 From: Mark Jabbour Date: Thu, 21 Jul 2022 03:36:00 +0000 Subject: [PATCH 1/2] link with c only when targer is bpf --- program/rust/src/lib.rs | 4 ++++ scripts/build-bpf.sh | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/program/rust/src/lib.rs b/program/rust/src/lib.rs index 0e84109f5..93ae2fff8 100644 --- a/program/rust/src/lib.rs +++ b/program/rust/src/lib.rs @@ -2,11 +2,15 @@ //to reflect the current status of oracle.h mod c_oracle_header; +//do not link with C during unit tests (which are built in native architecture, unlike libpyth.o) +#[cfg(target_arch = "bpf")] #[link(name = "cpyth")] extern "C" { fn c_entrypoint(input: *mut u8) -> u64; } +//do not add an entry point during unit tests (which can't be linked to the C entrypoint as explained above) +#[cfg(target_arch = "bpf")] #[no_mangle] pub extern "C" fn entrypoint(input: *mut u8) -> u64 { let c_ret_val = unsafe{c_entrypoint(input)}; diff --git a/scripts/build-bpf.sh b/scripts/build-bpf.sh index e7a552352..95818a2ad 100755 --- a/scripts/build-bpf.sh +++ b/scripts/build-bpf.sh @@ -43,7 +43,10 @@ cd "${RUST_DIR}" cargo install bindgen bindgen ./src/bindings.h -o ./src/c_oracle_header.rs cargo clean +cargo test +cargo clean cargo build-bpf + sha256sum ./target/**/*.so rm ./target/**/*-keypair.json rm -r $PYTH_DIR/target || true @@ -52,3 +55,5 @@ mv ./target $PYTH_DIR/target + + From adc96fadfbedfe8d82bb2bf7d27853d11d256ff7 Mon Sep 17 00:00:00 2001 From: Mark Jabbour Date: Thu, 21 Jul 2022 04:05:22 +0000 Subject: [PATCH 2/2] provided a no op definition for C entrypoint during unit tests --- program/rust/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/program/rust/src/lib.rs b/program/rust/src/lib.rs index 93ae2fff8..560202684 100644 --- a/program/rust/src/lib.rs +++ b/program/rust/src/lib.rs @@ -9,8 +9,13 @@ extern "C" { fn c_entrypoint(input: *mut u8) -> u64; } -//do not add an entry point during unit tests (which can't be linked to the C entrypoint as explained above) -#[cfg(target_arch = "bpf")] +//make the C entrypoint a no-op when running cargo test +#[cfg(not(target_arch = "bpf"))] +pub extern "C" fn c_entrypoint(input: *mut u8) -> u64{ + 0//SUCCESS value +} + + #[no_mangle] pub extern "C" fn entrypoint(input: *mut u8) -> u64 { let c_ret_val = unsafe{c_entrypoint(input)};