@@ -28,7 +28,8 @@ use crate::{
2828 } ,
2929 types:: { OutputStream , PackageType , SoarEnv } ,
3030 utils:: {
31- calc_magic_bytes, download, is_static_elf, pack_appimage, self_extract_appimage, temp_file,
31+ calc_magic_bytes, download, expand_env_vars, is_static_elf, pack_appimage,
32+ self_extract_appimage, temp_file,
3233 } ,
3334} ;
3435
@@ -116,6 +117,14 @@ impl BuildContext {
116117 let existing_envs: Vec < ( String , Option < String > ) > =
117118 inherit_keys. iter ( ) . map ( |key| get_env_var ( key) ) . collect ( ) ;
118119
120+ let arch = ARCH . to_string ( ) ;
121+ let arch_alt = match ARCH {
122+ "x86_64" => "amd64" ,
123+ "aarch64" => "arm64" ,
124+ _ => ARCH ,
125+ }
126+ . to_string ( ) ;
127+
119128 let paths = format ! ( "{}:{}" , soar_bin, paths) ;
120129 let mut vars: Vec < ( String , String ) > = [
121130 ( "pkg" , self . pkg . clone ( ) ) ,
@@ -128,6 +137,8 @@ impl BuildContext {
128137 ( "pkg_ver" , self . remote_pkgver . clone ( ) ) ,
129138 ( "pkgver" , self . pkgver . clone ( ) ) ,
130139 ( "remote_pkgver" , self . remote_pkgver . clone ( ) ) ,
140+ ( "arch" , arch) ,
141+ ( "arch_alt" , arch_alt) ,
131142 ]
132143 . into_iter ( )
133144 . flat_map ( |( key, value) | {
@@ -188,15 +199,23 @@ impl Builder {
188199 }
189200 }
190201
191- pub async fn download_build_assets ( & mut self , build_assets : & [ BuildAsset ] ) {
202+ pub async fn download_build_assets (
203+ & mut self ,
204+ build_assets : & [ BuildAsset ] ,
205+ context : & BuildContext ,
206+ ) {
207+ let env_vars = context. env_vars ( & self . soar_env . bin_path ) ;
192208 for asset in build_assets {
209+ let url = expand_env_vars ( & asset. url , & env_vars) ;
210+ let out = expand_env_vars ( & asset. out , & env_vars) ;
211+
193212 self . logger
194- . info ( format ! ( "Downloading build asset from {}" , asset . url) ) ;
213+ . info ( format ! ( "Downloading build asset from {}" , url) ) ;
195214
196- let out_path = format ! ( "SBUILD_TEMP/{}" , asset . out) ;
197- if download ( & asset . url , out_path) . await . is_err ( ) {
215+ let out_path = out. to_string ( ) ;
216+ if download ( & url, out_path) . await . is_err ( ) {
198217 self . logger
199- . error ( format ! ( "Failed to download build asset from {}" , asset . url) ) ;
218+ . error ( format ! ( "Failed to download build asset from {}" , url) ) ;
200219 std:: process:: exit ( 1 ) ;
201220 } ;
202221 }
@@ -270,7 +289,9 @@ impl Builder {
270289
271290 fs:: create_dir_all ( & context. tmpdir ) . unwrap ( ) ;
272291
273- if self . external {
292+ let is_container = build_config. x_exec . container . is_some ( ) ;
293+
294+ if self . external && !is_container {
274295 if let Some ( build_utils) = build_config. build_util . clone ( ) {
275296 let mut child = Command :: new ( "soar" )
276297 . env_clear ( )
@@ -291,17 +312,54 @@ impl Builder {
291312 }
292313
293314 if let Some ( ref build_assets) = build_config. build_asset {
294- self . download_build_assets ( build_assets) . await ;
315+ self . download_build_assets ( build_assets, context ) . await ;
295316 }
296317
297- let mut child = Command :: new ( & exec_file)
298- . env_clear ( )
299- . envs ( context. env_vars ( & self . soar_env . bin_path ) )
300- . stdout ( Stdio :: piped ( ) )
301- . stderr ( Stdio :: piped ( ) )
302- . stdin ( Stdio :: null ( ) )
303- . spawn ( )
304- . unwrap ( ) ;
318+ let mut child = if let Some ( ref container) = build_config. x_exec . container {
319+ let image = if container. contains ( ':' ) {
320+ container. clone ( )
321+ } else {
322+ format ! ( "{}:{}" , container, ARCH )
323+ } ;
324+
325+ let env_vars = context. env_vars ( & self . soar_env . bin_path ) ;
326+ let mut cmd = Command :: new ( "docker" ) ;
327+ cmd. args ( [ "run" , "--rm" , "--privileged" , "--net=host" , "--pull=always" ] ) ;
328+
329+ for ( key, value) in & env_vars {
330+ if key == "PATH" {
331+ continue ;
332+ }
333+ let val = match key. as_str ( ) {
334+ "sbuild_outdir" | "SBUILD_OUTDIR" => "/sbuild" . to_string ( ) ,
335+ "sbuild_tmpdir" | "SBUILD_TMPDIR" => "/sbuild/SBUILD_TEMP" . to_string ( ) ,
336+ _ => value. clone ( ) ,
337+ } ;
338+ cmd. arg ( "-e" ) . arg ( format ! ( "{}={}" , key, val) ) ;
339+ }
340+
341+ cmd. args ( [ "-v" , & format ! ( "{}:/sbuild:rw" , context. outdir. display( ) ) ] ) ;
342+ cmd. args ( [ "-v" , & format ! ( "{}:/exec_script:ro" , exec_file) ] ) ;
343+ cmd. args ( [ "-w" , "/sbuild" ] ) ;
344+ cmd. arg ( & image) ;
345+ cmd. arg ( "/exec_script" ) ;
346+
347+ cmd. env_clear ( )
348+ . stdout ( Stdio :: piped ( ) )
349+ . stderr ( Stdio :: piped ( ) )
350+ . stdin ( Stdio :: null ( ) )
351+ . spawn ( )
352+ . unwrap ( )
353+ } else {
354+ Command :: new ( & exec_file)
355+ . env_clear ( )
356+ . envs ( context. env_vars ( & self . soar_env . bin_path ) )
357+ . stdout ( Stdio :: piped ( ) )
358+ . stderr ( Stdio :: piped ( ) )
359+ . stdin ( Stdio :: null ( ) )
360+ . spawn ( )
361+ . unwrap ( )
362+ } ;
305363
306364 if let Err ( err) = self . prepare_resources ( & build_config, context) . await {
307365 self . logger . warn ( & err) ;
0 commit comments