File tree Expand file tree Collapse file tree 4 files changed +63
-8
lines changed Expand file tree Collapse file tree 4 files changed +63
-8
lines changed Original file line number Diff line number Diff line change 1
- OUT_DIR := ./target
1
+ # Use the OUT_DIR env variable as the output directory if available, otherwise
2
+ # default to ./target
3
+ OUT_DIR := $(if $(OUT_DIR ) ,$(OUT_DIR ) ,./target)
2
4
SOLANA := $(shell dirname $(shell which cargo-build-bpf) )
3
5
include $(SOLANA ) /sdk/bpf/c/bpf.mk
4
6
7
+
8
+ # Bundle C code compiled to bpf for use by rust
9
+ .PHONY : cpyth-bpf
5
10
cpyth-bpf :
6
- # Bundle C code compiled to bpf for use by rust
7
- bash -c "ar rcs target/libcpyth-bpf.a target/**/*.o"
11
+ bash -c " ar rcs $( OUT_DIR) /libcpyth-bpf.a target/**/*.o"
12
+
13
+
14
+ # 2-Stage Contract Build
15
+ #
16
+ # 1) Compile C code to system architecture for use by rust's cargo test
17
+ # 2) Bundle C code compiled to system architecture for use by rust's cargo test
18
+ .PHONY : cpyth-native
8
19
cpyth-native :
9
- # Compile C code to system architecture for use by rust's cargo test
10
- gcc -c ./src/oracle/native/upd_aggregate.c -o ./target/cpyth-native.o -fPIC
11
- # Bundle C code compiled to system architecture for use by rust's cargo test
12
- ar rcs target/libcpyth-native.a ./target/cpyth-native.o
20
+ gcc -c ./src/oracle/native/upd_aggregate.c -o $(OUT_DIR ) /cpyth-native.o -fPIC
21
+ ar rcs $(OUT_DIR ) /libcpyth-native.a $(OUT_DIR ) /cpyth-native.o
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ bincode = "1.3.3"
26
26
27
27
[features ]
28
28
debug = []
29
+ library = []
29
30
30
31
[lib ]
31
32
crate-type = [" cdylib" , " lib" ]
Original file line number Diff line number Diff line change 7
7
} ;
8
8
9
9
fn main ( ) {
10
- println ! ( "cargo:rustc-link-search=./program/c/target" ) ;
10
+ // Cargo exposes ENV variables for feature flags that can be used to determine whether to do a
11
+ // self-contained build that compiles the C components automatically.
12
+ if std:: env:: var ( "CARGO_FEATURE_LIBRARY" ) . is_ok ( ) {
13
+ // OUT_DIR is the path cargo provides to a build directory under `target/` specifically for
14
+ // isolated build artifacts. We use this to build the C program and then link against the
15
+ // resulting static library. This allows building the program when used as a dependency of
16
+ // another crate.
17
+ let out_dir = std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ;
18
+ let out_dir = PathBuf :: from ( out_dir) ;
19
+
20
+ // We must forward OUT_DIR as an env variable to the make script otherwise it will output
21
+ // its artifacts to the wrong place.
22
+ std:: process:: Command :: new ( "make" )
23
+ . env ( "VERBOSE" , "1" )
24
+ . env ( "OUT_DIR" , out_dir. display ( ) . to_string ( ) )
25
+ . current_dir ( "../c" )
26
+ . args ( & [ "cpyth-native" ] )
27
+ . status ( )
28
+ . expect ( "Failed to build C program" ) ;
29
+
30
+ // Emit instructions for cargo to link against the built static library.
31
+ println ! ( "cargo:rustc-link-lib=static=cpyth-native" ) ;
32
+ println ! ( "cargo:rustc-link-search={}" , out_dir. display( ) ) ;
33
+ } else {
34
+ // Otherwise fall back to the old relative-path C style build we used to have.
35
+ println ! ( "cargo:rustc-link-search=./program/c/target" ) ;
36
+ }
11
37
12
38
// Generate and write bindings
13
39
let bindings = Builder :: default ( )
Original file line number Diff line number Diff line change @@ -17,6 +17,25 @@ mod tests;
17
17
#[ cfg( feature = "debug" ) ]
18
18
mod log;
19
19
20
+ // When compiled in `library` mode the on-chain definitions provided by this library are
21
+ // exported. This is useful when other libraries wish to directly utilise the exact Solana specific
22
+ // on-chain definitions of the Pyth program.
23
+ //
24
+ // While we have `pyth-sdk-rs` which exposes a more friendly interface, this is still useful when a
25
+ // downstream user wants to confirm for example that they can compile against the binary interface
26
+ // of this program for their specific solana version.
27
+ #[ cfg( feature = "library" ) ]
28
+ pub use accounts:: {
29
+ AccountHeader ,
30
+ MappingAccount ,
31
+ PermissionAccount ,
32
+ PriceAccount ,
33
+ PriceComponent ,
34
+ PriceEma ,
35
+ PriceInfo ,
36
+ ProductAccount ,
37
+ PythAccount ,
38
+ } ;
20
39
use {
21
40
crate :: error:: OracleError ,
22
41
processor:: process_instruction,
You can’t perform that action at this time.
0 commit comments