@@ -14,7 +14,8 @@ use tokio::process::Command;
1414use crate :: services:: { CompilationRequest , CompilationResult } ;
1515
1616const TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
17- const DOCKER_IMAGE_BASE_NAME : & str = "ghcr.io/hyperledger/solang" ;
17+ // const DOCKER_IMAGE_BASE_NAME: &str = "ghcr.io/hyperledger-solang/solang@sha256:e6f687910df5dd9d4f5285aed105ae0e6bcae912db43e8955ed4d8344d49785d";
18+ const DOCKER_IMAGE_BASE_NAME : & str = "ghcr.io/hyperledger-solang/solang:latest" ;
1819const DOCKER_WORKDIR : & str = "/builds/contract/" ;
1920const DOCKER_OUTPUT : & str = "/playground-result" ;
2021
@@ -29,11 +30,12 @@ macro_rules! docker_command {
2930
3031/// Builds the compile command using solang docker image
3132pub fn build_compile_command ( input_file : & Path , output_dir : & Path ) -> Command {
33+ println ! ( "ip file: {:?}\n op dir: {:?}" , input_file, output_dir) ;
3234 // Base docker command
3335 let mut cmd = docker_command ! (
3436 "run" ,
3537 "--detach" ,
36- "--rm" ,
38+ // "--rm",
3739 "-it" ,
3840 "--cap-drop=ALL" ,
3941 "--cap-add=DAC_OVERRIDE" ,
@@ -65,15 +67,12 @@ pub fn build_compile_command(input_file: &Path, output_dir: &Path) -> Command {
6567 cmd. arg ( "--volume" ) . arg ( & mount_output_dir) ;
6668
6769 // Using the solang image
68- cmd. arg ( format ! (
69- "{}@sha256:8776a9bd756664f7bf8414710d1a799799bf6fedc1c8f9f0bda17e76749dea7a" ,
70- DOCKER_IMAGE_BASE_NAME
71- ) ) ;
70+ cmd. arg ( DOCKER_IMAGE_BASE_NAME ) ;
7271
7372 // Building the compile command
7473 let remove_command = format ! ( "rm -rf {}*.wasm {}*.contract" , DOCKER_OUTPUT , DOCKER_OUTPUT ) ;
7574 let compile_command = format ! (
76- "solang compile --target polkadot -o /playground-result {} > /playground-result/stdout.log 2> /playground-result/stderr.log" ,
75+ "solang compile --target soroban -o /playground-result {} > /playground-result/stdout.log 2> /playground-result/stderr.log" ,
7776 file_name
7877 ) ;
7978 let sh_command = format ! ( "{} && {}" , remove_command, compile_command) ;
@@ -102,7 +101,9 @@ impl Sandbox {
102101
103102 fs:: set_permissions ( & output_dir, PermissionsExt :: from_mode ( 0o777 ) )
104103 . context ( "failed to set output permissions" ) ?;
105-
104+
105+ File :: create ( & input_file) . context ( "failed to create input file" ) ?;
106+
106107 Ok ( Sandbox {
107108 scratch,
108109 input_file,
@@ -115,14 +116,15 @@ impl Sandbox {
115116 self . write_source_code ( & req. source ) ?;
116117
117118 let command = build_compile_command ( & self . input_file , & self . output_dir ) ;
118- println ! ( "Executing command: \n {:#?}" , command) ;
119+ // println!("Executing command: \n{:#?}", command);
119120
120121 let output = run_command ( command) ?;
122+ println ! ( "out: {:?}" , output) ;
121123 let file = fs:: read_dir ( & self . output_dir )
122124 . context ( "failed to read output directory" ) ?
123125 . flatten ( )
124126 . map ( |entry| entry. path ( ) )
125- . find ( |path| path. extension ( ) == Some ( OsStr :: new ( "contract " ) ) ) ;
127+ . find ( |path| path. extension ( ) == Some ( OsStr :: new ( "wasm " ) ) ) ;
126128
127129 // The file `stdout.log` is in the same directory as the contract file
128130 let compile_log_stdout_file_path = fs:: read_dir ( & self . output_dir )
@@ -187,9 +189,16 @@ impl Sandbox {
187189
188190 /// A helper function to write the source code to the input file
189191 fn write_source_code ( & self , code : & str ) -> Result < ( ) > {
192+ println ! ( "writing to {:?}" , self . input_file) ;
190193 fs:: write ( & self . input_file , code) . context ( "failed to write source code" ) ?;
194+ match fs:: read_to_string ( & self . input_file ) {
195+ Ok ( content) => println ! ( "Successfully read: {:?}" , content) ,
196+ Err ( e) => eprintln ! ( "Error reading file: {}" , e) ,
197+ }
191198 fs:: set_permissions ( & self . input_file , PermissionsExt :: from_mode ( 0o777 ) )
192199 . context ( "failed to set source permissions" ) ?;
200+ let s: String = code. chars ( ) . take ( 40 ) . collect ( ) ;
201+ println ! ( "Code: {:?}" , s) ;
193202 println ! ( "Wrote {} bytes of source to {}" , code. len( ) , self . input_file. display( ) ) ;
194203 Ok ( ( ) )
195204 }
@@ -204,7 +213,7 @@ fn read(path: &Path) -> Result<Option<Vec<u8>>> {
204213 } ;
205214 let mut f = BufReader :: new ( f) ;
206215 let metadata = fs:: metadata ( path) . expect ( "failed to read metadata" ) ;
207-
216+ println ! ( "meta: {:?}" , metadata ) ;
208217 let mut buffer = vec ! [ 0 ; metadata. len( ) as usize ] ;
209218 f. read_exact ( & mut buffer) . expect ( "buffer overflow" ) ;
210219 Ok ( Some ( buffer) )
@@ -219,14 +228,15 @@ async fn run_command(mut command: Command) -> Result<std::process::Output> {
219228 use std:: os:: unix:: process:: ExitStatusExt ;
220229
221230 let timeout = TIMEOUT ;
222- println ! ( "executing command!" ) ;
231+ println ! ( "executing command: {:?}" , command ) ;
223232 let output = command. output ( ) . await . context ( "failed to start compiler" ) ?;
224233
225234 let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
226235 let id = stdout. lines ( ) . next ( ) . context ( "missing compiler ID" ) ?. trim ( ) ;
227236 let stderr = & output. stderr ;
228-
237+
229238 let mut command = docker_command ! ( "wait" , id) ;
239+ println ! ( "ID: {:?}\n wait: {:?}" , id, command) ;
230240
231241 let timed_out = match tokio:: time:: timeout ( timeout, command. output ( ) ) . await {
232242 Ok ( Ok ( o) ) => {
@@ -239,17 +249,19 @@ async fn run_command(mut command: Command) -> Result<std::process::Output> {
239249 } ;
240250
241251 let mut command = docker_command ! ( "logs" , id) ;
252+ println ! ( "logs: {:?}" , command) ;
242253 let mut output = command. output ( ) . await . context ( "failed to get output from compiler" ) ?;
243-
244- let mut command = docker_command ! (
245- "rm" , // Kills container if still running
246- "--force" , id
247- ) ;
248- command. stdout ( std:: process:: Stdio :: null ( ) ) ;
249- command. status ( ) . await . context ( "failed to remove compiler" ) ?;
254+ println ! ( "op: {:?}" , output) ;
255+ // let mut command = docker_command!(
256+ // "rm", // Kills container if still running
257+ // "--force", id
258+ // );
259+ // println!("rm: {:?}", command);
260+ // command.stdout(std::process::Stdio::null());
261+ // command.status().await.context("failed to remove compiler")?;
250262
251263 let code = timed_out. context ( "compiler timed out" ) ?;
252-
264+ println ! ( "timedout: {:?}" , code ) ;
253265 output. status = code;
254266 output. stderr = stderr. to_owned ( ) ;
255267
0 commit comments