diff --git a/README.md b/README.md index 0295ec09e..d55d0b6b4 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,6 @@ root@pyth-dev# usermod -u 1002 -g 1004 -s /bin/bash pyth Finally, in docker extension inside VS Code click right and choose "Attach VS Code". If you're using a remote host in VS Code make sure to let this connection be open. -To get best experience from C++ IntelliSense, open entire `/home/pyth` in VS Code to include `solana` directory in home for lookup directories. - ### pre-commit hooks pre-commit is a tool that checks and fixes simple issues (formatting, ...) before each commit. You can install it by following [their website](https://pre-commit.com/). In order to enable checks for this repo run `pre-commit install` from command-line in the root of this repo. diff --git a/docker/Dockerfile b/docker/Dockerfile index 6b112c500..c18a12916 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,7 +40,7 @@ RUN useradd -m pyth # Fixes a bug in the solana docker image # https://github.com/solana-labs/solana/issues/20577 RUN mkdir /usr/bin/sdk/bpf/dependencies \ - && chmod 777 /usr/bin/sdk/bpf/dependencies + && chmod -R 777 /usr/bin/sdk/bpf USER pyth @@ -61,9 +61,7 @@ COPY --chown=pyth:pyth . pyth-client/ RUN cd pyth-client && ./scripts/build.sh RUN ./pyth-client/scripts/get-bpf-tools.sh -# Copy solana sdk and apply patch. -RUN mkdir solana -RUN cp -a /usr/bin/sdk solana +# Apply patch to solana RUN ./pyth-client/scripts/patch-solana.sh # Build and test the oracle program. diff --git a/pctest/setup_local.sh b/pctest/setup_local.sh index 144564cad..e49de111f 100755 --- a/pctest/setup_local.sh +++ b/pctest/setup_local.sh @@ -2,7 +2,8 @@ PYTH=./pyth PYTH_ADMIN=./pyth_admin -SOLANA=../../solana/target/release/solana +SOLANA_DIR="$(dirname $(which cargo-build-bpf))" +SOLANA="$SOLANA_DIR/solana" SOL_OPT="-u localhost --commitment finalized" RPC="-r localhost" FINAL="-c finalized" diff --git a/pctest/setup_pub.sh b/pctest/setup_pub.sh index d842d2407..1b66f0f9b 100755 --- a/pctest/setup_pub.sh +++ b/pctest/setup_pub.sh @@ -1,8 +1,10 @@ #!/bin/bash PYTH=./pyth -SOLANA=../../solana/target/release/solana -SOLANA_KEYGEN=../../solana/target/release/solana-keygen +SOLANA_DIR="$(dirname $(which cargo-build-bpf))" +SOLANA="$SOLANA_DIR/solana" +SOLANA_KEYGEN="$SOLANA_DIR/solana-keygen" + SOL_OPT="-u localhost --commitment finalized" RPC="-r localhost" FINAL="-c finalized" diff --git a/program/c/makefile b/program/c/makefile index aafd89d7e..3172e17fe 100644 --- a/program/c/makefile +++ b/program/c/makefile @@ -1,5 +1,5 @@ OUT_DIR := ./target -SOLANA := ../../../solana +SOLANA := $(shell dirname $(shell which cargo-build-bpf)) include $(SOLANA)/sdk/bpf/c/bpf.mk cpyth-bpf: diff --git a/program/rust/build.rs b/program/rust/build.rs index cca803790..2a8d94090 100644 --- a/program/rust/build.rs +++ b/program/rust/build.rs @@ -1,11 +1,17 @@ -use bindgen::Builder; +use { + bindgen::Builder, + std::{ + path::PathBuf, + process::Command, + }, +}; fn main() { println!("cargo:rustc-link-search=./program/c/target"); // Generate and write bindings let bindings = Builder::default() - .clang_arg("-I../../../solana/sdk/bpf/c/inc/") + .clang_arg(format!("-I{:}", get_solana_inc_path().display())) .header("./src/bindings.h") .rustfmt_bindings(true) .generate() @@ -14,3 +20,17 @@ fn main() { .write_to_file("./bindings.rs") .expect("Couldn't write bindings!"); } + +/// Find the Solana C header bindgen +fn get_solana_inc_path() -> PathBuf { + let which_stdout = Command::new("which") + .args(["cargo-build-bpf"]) + .output() + .unwrap() + .stdout; + let mut path = PathBuf::new(); + path.push(std::str::from_utf8(&which_stdout).unwrap()); + path.pop(); // + path.push("sdk/bpf/c/inc/"); + path +} diff --git a/scripts/patch-solana.sh b/scripts/patch-solana.sh index 054d36058..7db1b7f34 100755 --- a/scripts/patch-solana.sh +++ b/scripts/patch-solana.sh @@ -10,8 +10,7 @@ set -eu THIS_DIR="$( dirname "${BASH_SOURCE[0]}" )" THIS_DIR="$( cd "${THIS_DIR}" && pwd )" -SOLANA="${SOLANA:-$THIS_DIR/../../solana}" -SOLANA="$( cd "${SOLANA}" && pwd )" +SOLANA="$(dirname $(which cargo-build-bpf))" set -x cd "${SOLANA}"