@@ -220,7 +220,8 @@ function rewrite_sysimg_jl_only_needed_stdlibs(stdlibs::Vector{String})
220220 r" stdlibs = \[ (.*?)\] " s => string (" stdlibs = [" , join (" :" .* stdlibs, " ,\n " ), " ]" ))
221221end
222222
223- function create_fresh_base_sysimage (stdlibs:: Vector{String} ; cpu_target:: String , sysimage_build_args:: Cmd )
223+ function create_fresh_base_sysimage (stdlibs:: Vector{String} ; cpu_target:: String ,
224+ sysimage_build_args:: Cmd , sysimage_build_prefix:: Cmd )
224225 tmp = mktempdir ()
225226 sysimg_source_path = Base. find_source_file (" sysimg.jl" )
226227 base_dir = dirname (sysimg_source_path)
@@ -238,7 +239,7 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
238239 TerminalSpinners. @spin spinner begin
239240 cd (base_dir) do
240241 # Create corecompiler.ji
241- cmd = ` $(get_julia_cmd ()) --cpu-target $cpu_target
242+ cmd = ` $sysimage_build_prefix $ (get_julia_cmd ()) --cpu-target $cpu_target
242243 --output-ji $tmp_corecompiler_ji $sysimage_build_args
243244 $compiler_source_path `
244245 @debug " running $cmd "
@@ -251,7 +252,7 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
251252 new_sysimage_source_path = joinpath (tmp, " sysimage_packagecompiler_$(uuid1 ()) .jl" )
252253 write (new_sysimage_source_path, new_sysimage_content)
253254 try
254- cmd = ` $(get_julia_cmd ()) --cpu-target $cpu_target
255+ cmd = ` $sysimage_build_prefix $ (get_julia_cmd ()) --cpu-target $cpu_target
255256 --sysimage=$tmp_corecompiler_ji
256257 $sysimage_build_args --output-ji=$tmp_sys_ji
257258 $new_sysimage_source_path `
@@ -303,6 +304,7 @@ function create_sysimg_object_file(object_file::String,
303304 cpu_target:: String ,
304305 script:: Union{Nothing, String} ,
305306 sysimage_build_args:: Cmd ,
307+ sysimage_build_prefix:: Cmd ,
306308 extra_precompiles:: String ,
307309 incremental:: Bool )
308310 julia_code_buffer = IOBuffer ()
@@ -429,7 +431,7 @@ function create_sysimg_object_file(object_file::String,
429431 write (outputo_file, julia_code)
430432 # Read the input via stdin to avoid hitting the maximum command line limit
431433
432- cmd = ` $(get_julia_cmd ()) --cpu-target=$cpu_target $sysimage_build_args
434+ cmd = ` $sysimage_build_prefix $ (get_julia_cmd ()) --cpu-target=$cpu_target $sysimage_build_args
433435 --sysimage=$base_sysimage --project=$project --output-o=$(object_file)
434436 $outputo_file `
435437 @debug " running $cmd "
@@ -487,6 +489,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).
487489
488490- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
489491 for example `-O1 --check-bounds=yes`.
492+
493+ - `sysimage_build_prefix::Cmd`: A set of commands and command line options that will be
494+ prefixed to the call to Julia for building the sysimage, for example `srun -n 1`.
490495"""
491496function create_sysimage (packages:: Union{Nothing, Symbol, Vector{String}, Vector{Symbol}} = nothing ;
492497 sysimage_path:: String ,
@@ -498,6 +503,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
498503 cpu_target:: String = NATIVE_CPU_TARGET,
499504 script:: Union{Nothing, String} = nothing ,
500505 sysimage_build_args:: Cmd = ` ` ,
506+ sysimage_build_prefix:: Cmd = ` ` ,
501507 include_transitive_dependencies:: Bool = true ,
502508 # Internal args
503509 base_sysimage:: Union{Nothing, String} = nothing ,
@@ -545,7 +551,8 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
545551 error (" cannot specify `base_sysimage` when `incremental=false`" )
546552 end
547553 sysimage_stdlibs = filter_stdlibs ? gather_stdlibs_project (ctx) : stdlibs_in_sysimage ()
548- base_sysimage = create_fresh_base_sysimage (sysimage_stdlibs; cpu_target, sysimage_build_args)
554+ base_sysimage = create_fresh_base_sysimage (sysimage_stdlibs; cpu_target,
555+ sysimage_build_args, sysimage_build_prefix)
549556 else
550557 base_sysimage = something (base_sysimage, unsafe_string (Base. JLOptions (). image_file))
551558 end
@@ -603,6 +610,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
603610 cpu_target,
604611 script,
605612 sysimage_build_args,
613+ sysimage_build_prefix,
606614 extra_precompiles,
607615 incremental)
608616 object_files = [object_file]
@@ -788,6 +796,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).
788796- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
789797 for example `-O1 --check-bounds=yes`.
790798
799+ - `sysimage_build_prefix::Cmd`: A set of commands and command line options that will be
800+ prefixed to the call to Julia for building the sysimage, for example `srun -n 1`.
801+
791802- `script::String`: Path to a file that gets executed in the `--output-o` process.
792803"""
793804function create_app (package_dir:: String ,
@@ -802,6 +813,7 @@ function create_app(package_dir::String,
802813 cpu_target:: String = default_app_cpu_target (),
803814 include_lazy_artifacts:: Bool = false ,
804815 sysimage_build_args:: Cmd = ` ` ,
816+ sysimage_build_prefix:: Cmd = ` ` ,
805817 include_transitive_dependencies:: Bool = true ,
806818 include_preferences:: Bool = true ,
807819 script:: Union{Nothing, String} = nothing )
@@ -851,6 +863,7 @@ function create_app(package_dir::String,
851863 precompile_statements_file,
852864 cpu_target,
853865 sysimage_build_args,
866+ sysimage_build_prefix,
854867 include_transitive_dependencies,
855868 extra_precompiles = join (precompiles, " \n " ),
856869 script)
@@ -986,6 +999,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).
986999
9871000- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
9881001 for example `-O1 --check-bounds=yes`.
1002+
1003+ - `sysimage_build_prefix::Cmd`: A set of commands and command line options that will be
1004+ prefixed to the call to Julia for building the sysimage, for example `srun -n 1`.
9891005"""
9901006function create_library (package_or_project:: String ,
9911007 dest_dir:: String ;
@@ -1003,6 +1019,7 @@ function create_library(package_or_project::String,
10031019 cpu_target:: String = default_app_cpu_target (),
10041020 include_lazy_artifacts:: Bool = false ,
10051021 sysimage_build_args:: Cmd = ` ` ,
1022+ sysimage_build_prefix:: Cmd = ` ` ,
10061023 include_transitive_dependencies:: Bool = true ,
10071024 include_preferences:: Bool = true ,
10081025 script:: Union{Nothing,String} = nothing
@@ -1053,7 +1070,8 @@ function create_library(package_or_project::String,
10531070
10541071 create_sysimage_workaround (ctx, sysimg_path, precompile_execution_file,
10551072 precompile_statements_file, incremental, filter_stdlibs, cpu_target;
1056- sysimage_build_args, include_transitive_dependencies, julia_init_c_file,
1073+ sysimage_build_args, sysimage_build_prefix,
1074+ include_transitive_dependencies, julia_init_c_file,
10571075 julia_init_h_file, version, soname, script)
10581076
10591077 if version != = nothing && Sys. isunix ()
@@ -1113,6 +1131,7 @@ function create_sysimage_workaround(
11131131 filter_stdlibs:: Bool ,
11141132 cpu_target:: String ;
11151133 sysimage_build_args:: Cmd ,
1134+ sysimage_build_prefix:: Cmd ,
11161135 include_transitive_dependencies:: Bool ,
11171136 julia_init_c_file:: Union{Nothing,String,Vector{String}} ,
11181137 julia_init_h_file:: Union{Nothing,String,Vector{String}} ,
@@ -1151,6 +1170,7 @@ function create_sysimage_workaround(
11511170 version,
11521171 soname,
11531172 sysimage_build_args,
1173+ sysimage_build_prefix,
11541174 include_transitive_dependencies)
11551175
11561176 return
0 commit comments