Skip to content
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
7 changes: 7 additions & 0 deletions program/c/makefile
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions program/c/src/oracle/for_cargo_test/cpyth_test.c
Original file line number Diff line number Diff line change
@@ -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 <solana.h>
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 );
}
4 changes: 4 additions & 0 deletions program/c/src/oracle/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
3 changes: 2 additions & 1 deletion scripts/build-bpf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down