Skip to content

link with c only when target is bpf #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions program/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
//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;
}

//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)};
Expand Down
5 changes: 5 additions & 0 deletions scripts/build-bpf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,3 +55,5 @@ mv ./target $PYTH_DIR/target