@@ -249,7 +249,8 @@ function create_sysimg_object_file(object_file::String,
249249 precompile_statements_file:: Vector{String} ,
250250 cpu_target:: String ,
251251 script:: Union{Nothing, String} ,
252- sysimage_build_args:: Cmd )
252+ sysimage_build_args:: Cmd ,
253+ extra_precompiles:: String )
253254 # Handle precompilation
254255 precompile_files = String[]
255256 @debug " running precompilation execution script..."
@@ -301,6 +302,9 @@ function create_sysimg_object_file(object_file::String,
301302 @debug "failed to execute \$ statement"
302303 end
303304 end
305+ @eval PrecompileStagingArea begin
306+ $extra_precompiles
307+ end
304308 end # module
305309 """
306310
@@ -418,6 +422,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
418422 version= nothing ,
419423 soname= nothing ,
420424 compat_level:: String = " major" ,
425+ extra_precompiles:: String = " " ,
421426 )
422427
423428 if filter_stdlibs && incremental
@@ -506,7 +511,8 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
506511 precompile_statements_file,
507512 cpu_target,
508513 script,
509- sysimage_build_args)
514+ sysimage_build_args,
515+ extra_precompiles)
510516 object_files = [object_file]
511517 if julia_init_c_file != = nothing
512518 push! (object_files, compile_c_init_julia (julia_init_c_file, basename (sysimage_path)))
@@ -700,14 +706,24 @@ function create_app(package_dir::String,
700706 package_name = ctx. env. pkg. name
701707 project = dirname (ctx. env. project_file)
702708
709+ # add precompile statements for functions that will be called from the C main() wrapper
710+ precompiles = String[]
711+ for (_, julia_main) in executables
712+ push! (precompiles, " isdefined($package_name , :$julia_main ) && precompile(Tuple{typeof($package_name .$julia_main )})" )
713+ end
714+ push! (precompiles, " precompile(Tuple{typeof(append!), Vector{String}, Vector{Any}})" )
715+ push! (precompiles, " precompile(Tuple{typeof(empty!), Vector{String}})" )
716+ push! (precompiles, " precompile(Tuple{typeof(popfirst!), Vector{String}})" )
717+
703718 create_sysimage ([package_name]; sysimage_path, project,
704719 incremental,
705720 filter_stdlibs,
706721 precompile_execution_file,
707722 precompile_statements_file,
708723 cpu_target,
709724 sysimage_build_args,
710- include_transitive_dependencies)
725+ include_transitive_dependencies,
726+ extra_precompiles = join (precompiles, " \n " ))
711727
712728 for (app_name, julia_main) in executables
713729 create_executable_from_sysimg (joinpath (app_dir, " bin" , app_name), c_driver_program, string (package_name, " ." , julia_main))
717733
718734function create_executable_from_sysimg (exe_path:: String ,
719735 c_driver_program:: String ,
720- julia_main:: String )
736+ julia_main:: String )
721737 c_driver_program = abspath (c_driver_program)
722738 mkpath (dirname (exe_path))
723739 flags = Base. shell_split (join ((cflags (), ldflags (), ldlibs ()), " " ))
0 commit comments