Skip to content

Commit dfc76e7

Browse files
move sed commands to a patch file; add TEST_FLAGS to bpf.mk for criterion CLI
1 parent b51a6a4 commit dfc76e7

File tree

4 files changed

+87
-21
lines changed

4 files changed

+87
-21
lines changed

docker/Dockerfile

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,10 @@ RUN cd pyth-client && ./scripts/build.sh
4040
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
4141
| sh -s -- -y --default-toolchain none
4242

43-
# Copy solana sdk to modify makefile and header.
43+
# Copy solana sdk and apply patch.
4444
RUN mkdir solana
4545
RUN cp -a /usr/bin/sdk solana
46-
47-
# Enable all clang warnings.
48-
RUN sed -i \
49-
's/-Werror/-Wall -Wextra -Wconversion -Werror/g' \
50-
solana/sdk/bpf/c/bpf.mk
51-
52-
# Disallow missing symbols in ld.
53-
RUN sed -i \
54-
's/-z notext/-z notext -z defs/g' \
55-
solana/sdk/bpf/c/bpf.mk
56-
57-
# https://github.com/solana-labs/solana/issues/21198
58-
RUN sed -i \
59-
's/\(^uint64_t sol_invoke_signed_c(\)/__attribute__(( weak )) \1/g' \
60-
solana/sdk/bpf/c/inc/solana_sdk.h
46+
RUN ./pyth-client/scripts/patch-solana.sh
6147

6248
# Build and test the oracle program.
6349
RUN cd pyth-client && ./scripts/build-bpf.sh program

scripts/build-bpf.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88

99
set -eu
1010

11-
BUILD_DIR="$( cd "${1:-program}" && pwd )"
11+
BUILD_DIR="$( cd "${1:-.}" && pwd )"
1212

1313
if [[ ! -f "${BUILD_DIR}/makefile" ]]
1414
then
15-
>&2 echo "Not a makefile dir: ${BUILD_DIR}"
16-
exit 1
15+
if [[ -f "${BUILD_DIR}/program/makefile" ]]
16+
then
17+
BUILD_DIR="${BUILD_DIR}/program"
18+
else
19+
>&2 echo "Not a makefile dir: ${BUILD_DIR}"
20+
exit 1
21+
fi
1722
fi
1823

1924
if ! which cargo 2> /dev/null
@@ -25,6 +30,7 @@ fi
2530
set -x
2631

2732
cd "${BUILD_DIR}"
28-
make V=1 clean
29-
make V=1 "${@:2}"
33+
export V="${V:-1}"
34+
make clean
35+
make "${@:2}"
3036
sha256sum ../target/*.so

scripts/patch-solana.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Patch BPF makefile and solana_sdk.h:
4+
# - Build with `-Wall -Wextra -Wconversion`.
5+
# - Link with `-z defs` and mark `sol_invoke_signed_c` as weak.
6+
# - Add TEST_FLAGS for criterion CLI.
7+
#
8+
9+
set -eu
10+
11+
THIS_DIR="$( dirname "${BASH_SOURCE[0]}" )"
12+
THIS_DIR="$( cd "${THIS_DIR}" && pwd )"
13+
SOLANA="${SOLANA:-$THIS_DIR/../../solana}"
14+
SOLANA="$( cd "${SOLANA}" && pwd )"
15+
16+
set -x
17+
cd "${SOLANA}"
18+
patch -p1 -i "${THIS_DIR}/solana.patch"

scripts/solana.patch

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
diff --git a/sdk/bpf/c/bpf.mk b/sdk/bpf/c/bpf.mk
2+
index 4b3039db1..018e8deb4 100644
3+
--- a/sdk/bpf/c/bpf.mk
4+
+++ b/sdk/bpf/c/bpf.mk
5+
@@ -14,6 +14,12 @@ TEST_PREFIX ?= test_
6+
OUT_DIR ?= ./out
7+
OS := $(shell uname)
8+
9+
+ifeq ($(V),1)
10+
+TEST_FLAGS ?= --verbose
11+
+else
12+
+TEST_FLAGS ?=
13+
+endif
14+
+
15+
LLVM_DIR = $(LOCAL_PATH)../dependencies/bpf-tools/llvm
16+
LLVM_SYSTEM_INC_DIRS := $(LLVM_DIR)/lib/clang/12.0.1/include
17+
COMPILER_RT_DIR = $(LOCAL_PATH)../dependencies/bpf-tools/rust/lib/rustlib/bpfel-unknown-unknown/lib
18+
@@ -31,6 +37,9 @@ SYSTEM_INC_DIRS := \
19+
$(LLVM_SYSTEM_INC_DIRS) \
20+
21+
C_FLAGS := \
22+
+ -Wall \
23+
+ -Wextra \
24+
+ -Wconversion \
25+
-Werror \
26+
-O2 \
27+
-fno-builtin \
28+
@@ -59,6 +68,7 @@ BPF_CXX_FLAGS := \
29+
-march=bpfel+solana
30+
31+
BPF_LLD_FLAGS := \
32+
+ -z defs \
33+
-z notext \
34+
-shared \
35+
--Bdynamic \
36+
@@ -195,7 +205,7 @@ endef
37+
define TEST_EXEC_RULE
38+
$1: $2
39+
LD_LIBRARY_PATH=$(TESTFRAMEWORK_RPATH) \
40+
- $2$(\n)
41+
+ $2 $(TEST_FLAGS)$(\n)
42+
endef
43+
44+
.PHONY: $(INSTALL_SH)
45+
diff --git a/sdk/bpf/c/inc/solana_sdk.h b/sdk/bpf/c/inc/solana_sdk.h
46+
index b5cad9833..b3b496123 100644
47+
--- a/sdk/bpf/c/inc/solana_sdk.h
48+
+++ b/sdk/bpf/c/inc/solana_sdk.h
49+
@@ -565,6 +565,7 @@ uint64_t sol_try_find_program_address(
50+
/**
51+
* Internal cross-program invocation function
52+
*/
53+
+__attribute__(( weak ))
54+
uint64_t sol_invoke_signed_c(
55+
const SolInstruction *instruction,
56+
const SolAccountInfo *account_infos,

0 commit comments

Comments
 (0)