Skip to content

Commit aea724a

Browse files
guibescosmajabbour
andauthored
Rust entrypoint (#184)
* added-rust-entry * fixed program path * removed test dockerfile * changed c archive name + used patched Solana + update solana * removed uneeded env variables * updated build script to new c name * Add comment * Reorder for better caching * Better comment * Better hack * removed uneeded sudo commands * added comments to build scripts * more robust way to find C and Rust directories * added comments * made entry-point safe * updated liscence * restructured repo * bumped version number Co-authored-by: Mark Jabbour <markmarjabbour@gmail.com> Co-authored-by: Guillermo Bescos <guibescos>
1 parent 289e33b commit aea724a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+84
-31
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif()
1212
set( CMAKE_INCLUDE_CURRENT_DIR ON )
1313

1414
# find oracle header files
15-
include_directories( program/src/ )
15+
include_directories( program/c/src/ )
1616

1717
# gcc compiler/linker flags
1818
add_compile_options( -ggdb -Wall -Wextra -Wsign-conversion -Werror -Wno-deprecated-declarations -m64 )
@@ -39,7 +39,7 @@ set( PC_SRC
3939
pc/request.cpp;
4040
pc/rpc_client.cpp;
4141
pc/user.cpp;
42-
program/src/oracle/model/price_model.c
42+
program/c/src/oracle/model/price_model.c
4343
)
4444

4545
set( PC_HDR
@@ -88,7 +88,7 @@ target_link_libraries( pyth_tx ${PC_DEP} )
8888
install( TARGETS pc DESTINATION lib )
8989
install( TARGETS pyth pyth_admin pythd pyth_csv pyth_tx DESTINATION bin )
9090
install( FILES ${PC_HDR} DESTINATION include/pc )
91-
install( FILES program/src/oracle/oracle.h DESTINATION include/oracle )
91+
install( FILES program/c/src/oracle/oracle.h DESTINATION include/oracle )
9292

9393
#
9494
# test programs
@@ -147,4 +147,4 @@ function( add_bpf_lib targ )
147147
endfunction()
148148

149149
# test_oracle.c includes oracle.c
150-
add_bpf_lib( test-oracle-bpf program/src/oracle/test_oracle.c )
150+
add_bpf_lib( test-oracle-bpf program/c/src/oracle/test_oracle.c )

docker/Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,37 @@ RUN apt-get install -qq \
2626
RUN echo "pyth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
2727
RUN useradd -m pyth
2828

29+
# Fixes a bug in the solana docker image
30+
# https://github.com/solana-labs/solana/issues/20577
31+
RUN mkdir /usr/bin/sdk/bpf/dependencies \
32+
&& chmod 777 /usr/bin/sdk/bpf/dependencies
33+
34+
2935
USER pyth
3036
WORKDIR /home/pyth
31-
COPY --chown=pyth:pyth . pyth-client/
37+
38+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
39+
| sh -s -- -y
40+
3241

3342
RUN echo "\n\
34-
export PATH=\"\${PATH}:\${HOME}/pyth-client/build\"\n\
43+
export PATH=\"\${PATH}:\${HOME}/pyth-client/build:\${HOME}/.cargo/bin\"\n\
3544
export PYTHONPATH=\"\${PYTHONPATH:+\$PYTHONPATH:}\${HOME}/pyth-client\"\n\
3645
" >> .profile
3746

47+
COPY --chown=pyth:pyth . pyth-client/
48+
3849
# Build off-chain binaries.
3950
RUN cd pyth-client && ./scripts/build.sh
4051

41-
# Install rust and add ". ~/.cargo/env" to ~/.profile.
42-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
43-
| sh -s -- -y --default-toolchain none
4452

4553
# Copy solana sdk and apply patch.
4654
RUN mkdir solana
4755
RUN cp -a /usr/bin/sdk solana
4856
RUN ./pyth-client/scripts/patch-solana.sh
4957

5058
# Build and test the oracle program.
51-
RUN cd pyth-client && ./scripts/build-bpf.sh program
59+
RUN cd pyth-client && ./scripts/build-bpf.sh .
5260
RUN /bin/bash -l -c "pytest-3 --pyargs pyth"
5361

5462
ENTRYPOINT []

program/c/makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
OUT_DIR := ./target
2+
SOLANA := ../../../solana
3+
include $(SOLANA)/sdk/bpf/c/bpf.mk
4+
cpyth:
5+
bash -c "ar rcs target/libcpyth.a target/**/*.o"
File renamed without changes.

program/src/oracle/oracle.c renamed to program/c/src/oracle/oracle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static uint64_t dispatch( SolParameters *prm, SolAccountInfo *ka )
548548
}
549549
}
550550

551-
extern uint64_t entrypoint(const uint8_t *input)
551+
extern uint64_t c_entrypoint(const uint8_t *input)
552552
{
553553
SolAccountInfo ka[4];
554554
SolParameters prm[1];
File renamed without changes.

0 commit comments

Comments
 (0)