Skip to content

Commit 4be6122

Browse files
authored
Fix build for newer solana versions (#345)
* make it build * allow negative prices * clean up comments * doc * fixme * revert
1 parent 3f10185 commit 4be6122

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ This command runs a recent pyth-client docker image that already has the necessa
4444
Therefore, once the container is running, all you have to do is run `cd pyth-client && ./scripts/build.sh`.
4545
Note that updates to the `pyth-client` directory made inside the docker container will be persisted to the host filesystem (which is probably desirable).
4646

47+
### Local development
48+
49+
First, make sure you're building on the x86_64 architecture.
50+
On a mac, this command will switch your shell to x86_64:
51+
52+
`env /usr/bin/arch -x86_64 /bin/bash --login`
53+
54+
then in the `program/c` directory, run:
55+
56+
```
57+
make
58+
make cpyth-bpf
59+
make cpyth-native
60+
```
61+
62+
then in the `program/rust` directory, run:
63+
64+
```
65+
cargo build-bpf
66+
cargo test
67+
```
68+
69+
Note that the tests depend on the bpf build!
70+
4771
### Fuzzing
4872

4973
Build a docker image for running fuzz tests:

program/c/makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
OUT_DIR := ./target
22
SOLANA := $(shell dirname $(shell which cargo-build-bpf))
3-
include $(SOLANA)/sdk/bpf/c/bpf.mk
3+
4+
ifneq ("$(wildcard $(SOLANA)/sdk/bpf/c/bpf.mk)","")
5+
$(info using Solana BPF SDK)
6+
include $(SOLANA)/sdk/bpf/c/bpf.mk
7+
else
8+
$(info using Solana SBF SDK)
9+
include $(SOLANA)/sdk/sbf/c/sbf.mk
10+
endif
411

512
cpyth-bpf:
613
# Bundle C code compiled to bpf for use by rust

program/rust/build.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ fn get_solana_inc_path() -> PathBuf {
3131
let mut path = PathBuf::new();
3232
path.push(std::str::from_utf8(&which_stdout).unwrap());
3333
path.pop(); //
34-
path.push("sdk/bpf/c/inc/");
35-
path
34+
let mut bpf_path = path.clone();
35+
// Older solana version have the SDK in the bpf/ folder, while newer version have
36+
// it in the sbf/ folder
37+
bpf_path.push("sdk/bpf/c/inc/");
38+
if bpf_path.exists() {
39+
bpf_path
40+
} else {
41+
path.push("sdk/sbf/c/inc/");
42+
path
43+
}
3644
}

0 commit comments

Comments
 (0)