@@ -17,15 +17,15 @@ fn main() {
1717 let target_dir = contracts_dir. join ( "target/dev" ) ;
1818 let build_dir = Path :: new ( "build" ) ;
1919
20- // Check if scarb is available
21- let scarb_available = Command :: new ( "scarb " )
22- . arg ( " --version")
20+ // Check if asdf is available (used to manage scarb versions)
21+ let asdf_available = Command :: new ( "asdf " )
22+ . args ( [ "exec" , "scarb" , " --version"] )
2323 . output ( )
2424 . map ( |output| output. status . success ( ) )
2525 . unwrap_or ( false ) ;
2626
27- if !scarb_available {
28- println ! ( "cargo:warning=scarb not found in PATH , skipping contract compilation" ) ;
27+ if !asdf_available {
28+ println ! ( "cargo:warning=asdf or scarb not found, skipping contract compilation" ) ;
2929 return ;
3030 }
3131
@@ -34,11 +34,11 @@ fn main() {
3434 return ;
3535 }
3636
37- println ! ( "cargo:warning=Building contracts with scarb..." ) ;
37+ println ! ( "cargo:warning=Building main contracts with scarb..." ) ;
3838
39- // Run scarb build in the contracts directory
40- let output = Command :: new ( "scarb " )
41- . arg ( " build")
39+ // Run scarb build in the contracts directory (uses asdf to pick correct scarb version)
40+ let output = Command :: new ( "asdf " )
41+ . args ( [ "exec" , "scarb" , " build"] )
4242 . current_dir ( contracts_dir)
4343 . output ( )
4444 . expect ( "Failed to execute scarb build" ) ;
@@ -56,24 +56,39 @@ fn main() {
5656 . join ( "\n " ) ;
5757
5858 panic ! (
59- "Contract compilation build script failed. Below are the last 50 lines of `scarb \
60- build` output:\n \n {last_n_lines}"
59+ "Main contracts compilation failed. Below are the last 50 lines of `scarb build` \
60+ output:\n \n {last_n_lines}"
6161 ) ;
6262 }
6363
64+ // Build VRF contracts (uses different scarb version via asdf)
65+ let vrf_dir = contracts_dir. join ( "vrf" ) ;
66+ build_vrf_contracts ( & vrf_dir) ;
67+
6468 // Create build directory if it doesn't exist
6569 if let Err ( e) = fs:: create_dir_all ( build_dir) {
6670 panic ! ( "Failed to create build directory: {e}" ) ;
6771 }
6872
69- // Copy artifacts from target/dev to build directory
73+ // Copy main contract artifacts from target/dev to build directory
7074 if target_dir. exists ( ) {
7175 if let Err ( e) = copy_dir_contents ( & target_dir, build_dir) {
72- panic ! ( "Failed to copy contract artifacts: {e}" ) ;
76+ panic ! ( "Failed to copy main contract artifacts: {e}" ) ;
7377 }
74- println ! ( "cargo:warning=Contract artifacts copied to build directory" ) ;
78+ println ! ( "cargo:warning=Main contract artifacts copied to build directory" ) ;
7579 } else {
76- println ! ( "cargo:warning=No contract artifacts found in target/dev" ) ;
80+ println ! ( "cargo:warning=No main contract artifacts found in target/dev" ) ;
81+ }
82+
83+ // Copy VRF contract artifacts from vrf/target/dev to build directory
84+ let vrf_target_dir = vrf_dir. join ( "target/dev" ) ;
85+ if vrf_target_dir. exists ( ) {
86+ if let Err ( e) = copy_dir_contents ( & vrf_target_dir, build_dir) {
87+ panic ! ( "Failed to copy VRF contract artifacts: {e}" ) ;
88+ }
89+ println ! ( "cargo:warning=VRF contract artifacts copied to build directory" ) ;
90+ } else {
91+ println ! ( "cargo:warning=No VRF contract artifacts found in vrf/target/dev" ) ;
7792 }
7893}
7994
@@ -89,3 +104,31 @@ fn copy_dir_contents(src: &Path, dst: &Path) -> std::io::Result<()> {
89104 }
90105 Ok ( ( ) )
91106}
107+
108+ fn build_vrf_contracts ( vrf_dir : & Path ) {
109+ println ! ( "cargo:warning=Building VRF contracts with scarb..." ) ;
110+
111+ let output = Command :: new ( "asdf" )
112+ . args ( [ "exec" , "scarb" , "build" ] )
113+ . current_dir ( vrf_dir)
114+ . output ( )
115+ . expect ( "Failed to execute scarb build for VRF contracts" ) ;
116+
117+ if !output. status . success ( ) {
118+ let logs = String :: from_utf8_lossy ( & output. stdout ) ;
119+ let last_n_lines = logs
120+ . split ( '\n' )
121+ . rev ( )
122+ . take ( 50 )
123+ . collect :: < Vec < & str > > ( )
124+ . into_iter ( )
125+ . rev ( )
126+ . collect :: < Vec < & str > > ( )
127+ . join ( "\n " ) ;
128+
129+ panic ! (
130+ "VRF contracts compilation failed. Below are the last 50 lines of `scarb build` \
131+ output:\n \n {last_n_lines}"
132+ ) ;
133+ }
134+ }
0 commit comments