diff --git a/program/c/makefile b/program/c/makefile index 5bf090afe..a33fcc4dd 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -1,5 +1,12 @@ OUT_DIR := ./target SOLANA := ../../../solana include $(SOLANA)/sdk/bpf/c/bpf.mk + cpyth: +# Bundle C code compiled to bpf for use by rust bash -c "ar rcs target/libcpyth.a target/**/*.o" +cpythtest: +# Compile C code to system architecture for use by rust's cargo test + $(CC) -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o +# Bundle C code compiled to system architecture for use by rust's cargo test + ar rcs target/libcpythtest.a ./target/cpyth_test.o diff --git a/program/c/src/oracle/for_cargo_test/cpyth_test.c b/program/c/src/oracle/for_cargo_test/cpyth_test.c new file mode 100644 index 000000000..72f21a49a --- /dev/null +++ b/program/c/src/oracle/for_cargo_test/cpyth_test.c @@ -0,0 +1,22 @@ +/// The goal of this file is to provide the upd_aggregate function to local rust tests + +/// We need to allocate some heap space for upd_aggregate +/// When compiling for the solana runtime, the heap space is preallocated and PC_HEAP_START is provided by +char heap_start[8192]; +#define PC_HEAP_START (heap_start) +#define static_assert _Static_assert + +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long int int64_t; +typedef unsigned long int uint64_t; + +#include "../upd_aggregate.h" + +extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){ + return upd_aggregate(ptr, slot, timestamp ); +} diff --git a/program/c/src/oracle/oracle.c b/program/c/src/oracle/oracle.c index 1f0a9d705..c82d56a85 100644 --- a/program/c/src/oracle/oracle.c +++ b/program/c/src/oracle/oracle.c @@ -171,3 +171,7 @@ extern uint64_t c_entrypoint(const uint8_t *input) } return dispatch( prm, ka ); } + +extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){ + return upd_aggregate(ptr, slot, timestamp ); +} diff --git a/scripts/build-bpf.sh b/scripts/build-bpf.sh index 15aaf503f..c49e5ab8b 100755 --- a/scripts/build-bpf.sh +++ b/scripts/build-bpf.sh @@ -30,13 +30,14 @@ export V="${V:-1}" make clean make "${@:2}" make cpyth +make cpythtest rm ./target/*-keypair.json #build Rust and link it with C cd "${PYTH_DIR}" cargo clean -cargo test +cargo test-bpf cargo clean cargo build-bpf