Skip to content

Commit 0fc4caf

Browse files
authored
link with c only when target is bpf (#195)
* link with c only when targer is bpf * provided a no op definition for C entrypoint during unit tests
1 parent 2d81559 commit 0fc4caf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

program/rust/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
//to reflect the current status of oracle.h
33
mod c_oracle_header;
44

5+
//do not link with C during unit tests (which are built in native architecture, unlike libpyth.o)
6+
#[cfg(target_arch = "bpf")]
57
#[link(name = "cpyth")]
68
extern "C" {
79
fn c_entrypoint(input: *mut u8) -> u64;
810
}
911

12+
//make the C entrypoint a no-op when running cargo test
13+
#[cfg(not(target_arch = "bpf"))]
14+
pub extern "C" fn c_entrypoint(input: *mut u8) -> u64{
15+
0//SUCCESS value
16+
}
17+
18+
1019
#[no_mangle]
1120
pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
1221
let c_ret_val = unsafe{c_entrypoint(input)};

scripts/build-bpf.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ cd "${RUST_DIR}"
4343
cargo install bindgen
4444
bindgen ./src/bindings.h -o ./src/c_oracle_header.rs
4545
cargo clean
46+
cargo test
47+
cargo clean
4648
cargo build-bpf
49+
4750
sha256sum ./target/**/*.so
4851
rm ./target/**/*-keypair.json
4952
rm -r $PYTH_DIR/target || true
@@ -52,3 +55,5 @@ mv ./target $PYTH_DIR/target
5255

5356

5457

58+
59+

0 commit comments

Comments
 (0)