@@ -93,8 +93,8 @@ function source_path(ctx, pkg)
9393end
9494
9595const _STDLIBS = readdir (Sys. STDLIB)
96- sysimage_modules () = map (x -> x . name, Base. _sysimage_modules)
97- stdlibs_in_sysimage () = intersect ( _STDLIBS, sysimage_modules ())
96+ sysimage_modules () = Base. _sysimage_modules
97+ stdlibs_in_sysimage () = filter (pkg -> pkg . name in _STDLIBS, sysimage_modules ())
9898
9999# TODO : Also check UUIDs for stdlibs, not only names<
100100function gather_stdlibs_project (ctx)
@@ -207,16 +207,15 @@ function get_julia_cmd()
207207end
208208
209209
210- function rewrite_sysimg_jl_only_needed_stdlibs (stdlibs :: Vector{String} )
210+ function rewrite_sysimg_jl_only_needed_stdlibs ()
211211 sysimg_source_path = Base. find_source_file (" sysimg.jl" )
212212 sysimg_content = read (sysimg_source_path, String)
213- # replaces the hardcoded list of stdlibs in sysimg.jl with
214- # the stdlibs that is given as argument
215- return replace (sysimg_content,
216- r" stdlibs = \[ (.*?)\] " s => string (" stdlibs = [" , join (" :" .* stdlibs, " ,\n " ), " ]" ))
213+ # replaces the hardcoded list of stdlibs in sysimg.jl with an empty list
214+ # TODO : Use the mechanism in https://github.com/JuliaLang/PackageCompiler.jl/pull/997
215+ return replace (sysimg_content, r" stdlibs = \[ (.*?)\] " s => " stdlibs = []" )
217216end
218217
219- function create_fresh_base_sysimage (stdlibs :: Vector{String} ; cpu_target:: String , sysimage_build_args:: Cmd )
218+ function create_fresh_base_sysimage (; cpu_target:: String , sysimage_build_args:: Cmd )
220219 tmp = mktempdir ()
221220 sysimg_source_path = Base. find_source_file (" sysimg.jl" )
222221 base_dir = dirname (sysimg_source_path)
@@ -267,16 +266,15 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
267266 spinner = TerminalSpinners. Spinner (msg = " PackageCompiler: compiling fresh sysimage (incremental=false)" )
268267 TerminalSpinners. @spin spinner begin
269268 # Use the compiler sysimage to create sys.ji
270- new_sysimage_content = rewrite_sysimg_jl_only_needed_stdlibs (stdlibs )
269+ new_sysimage_content = rewrite_sysimg_jl_only_needed_stdlibs ()
271270 new_sysimage_content *= " \n empty!(Base.atexit_hooks)\n "
272271 new_sysimage_source_path = joinpath (tmp, " sysimage_packagecompiler_$(uuid1 ()) .jl" )
273272 write (new_sysimage_source_path, new_sysimage_content)
274273 try
275274 cmd = addenv (` $(get_julia_cmd ()) --cpu-target $cpu_target
276275 --sysimage=$tmp_corecompiler_sl
277276 $sysimage_build_args --output-o=$tmp_sys_o
278- $new_sysimage_source_path $compiler_args ` ,
279- " JULIA_LOAD_PATH" => " @stdlib" )
277+ $new_sysimage_source_path $compiler_args ` )
280278 @debug " running $cmd "
281279
282280 read (cmd)
@@ -595,8 +593,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
595593 if base_sysimage != = nothing
596594 error (" cannot specify `base_sysimage` when `incremental=false`" )
597595 end
598- sysimage_stdlibs = filter_stdlibs ? String[] : stdlibs_in_sysimage ()
599- base_sysimage = create_fresh_base_sysimage (sysimage_stdlibs; cpu_target, sysimage_build_args)
596+ base_sysimage = create_fresh_base_sysimage (; cpu_target, sysimage_build_args)
600597 else
601598 base_sysimage = something (base_sysimage, unsafe_string (Base. JLOptions (). image_file))
602599 end
@@ -643,6 +640,11 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
643640 end
644641 end
645642
643+ # Add stdlibs to packages_sysimg when building from fresh base sysimage
644+ if ! incremental && ! filter_stdlibs
645+ union! (packages_sysimg, stdlibs_in_sysimage ())
646+ end
647+
646648 # Create the sysimage
647649 object_file = tempname () * " -o.a"
648650 # This naming convention (`-o.a`) is necessary to make the sysimage
@@ -872,7 +874,7 @@ function create_app(package_dir::String,
872874 try_rm_dir (app_dir; force)
873875 stdlibs = gather_stdlibs_project (ctx)
874876 if ! filter_stdlibs
875- stdlibs = unique (vcat (stdlibs, stdlibs_in_sysimage ()))
877+ stdlibs = unique (vcat (stdlibs, map (pkg -> pkg . name, stdlibs_in_sysimage () )))
876878 end
877879 bundle_julia_libraries (app_dir, stdlibs)
878880 bundle_julia_libexec (ctx, app_dir)
@@ -1089,7 +1091,7 @@ function create_library(package_or_project::String,
10891091 mkpath (dest_dir)
10901092 stdlibs = gather_stdlibs_project (ctx)
10911093 if ! filter_stdlibs
1092- stdlibs = unique (vcat (stdlibs, stdlibs_in_sysimage ()))
1094+ stdlibs = unique (vcat (stdlibs, map (pkg -> pkg . name, stdlibs_in_sysimage () )))
10931095 end
10941096 bundle_julia_libraries (dest_dir, stdlibs)
10951097 bundle_julia_libexec (ctx, dest_dir)
0 commit comments