11# This file is a part of Julia. License is MIT: https://julialang.org/license
22
33module Precompile
4+ # Can't use this during incremental: `@eval Module() begin``
45
56import .. Client
67import Pkg
78import REPL
89import InteractiveUtils
910
10- # Can't use this during incremental: `@eval Module() begin``
11+ # Since we are not Base we need to import names,
12+ # would be better if we had FQDN
13+ import Pkg: TOML
14+ import Pkg. PlatformEngines: Downloads, SHA, Tar
15+ import Pkg. GitTools: LibGit2, Printf
16+ import Pkg. Types: FileWatching
17+ import Pkg. API: Logging, Dates
18+ import Pkg. PlatformEngines: p7zip_jll
19+ import Pkg. Artifacts: Artifacts
20+ import REPL: Markdown
1121
12- # using PrecompileTools
13- include (" invalidations.jl" )
1422
1523Base. include (@__MODULE__ , joinpath (Sys. BINDIR, " .." , " share" , " julia" , " test" , " testhelpers" , " FakePTYs.jl" ))
1624import . FakePTYs: open_fake_pty
1725using Base. Meta
1826
27+ # # Debugging options
28+ # Disable parallel precompiles generation by setting `false`
29+ const PARALLEL_PRECOMPILATION = true
30+
1931# View the code sent to the repl by setting this to `stdout`
2032const debug_output = devnull # or stdout
2133
@@ -71,10 +83,7 @@ procenv = Dict{String,Any}(
7183 " TERM" => " " ,
7284 " JULIA_MINIMAL_CLIENT" => " 0" ) # Turn Client.jl on
7385
74- generate_precompile_statements () = try # Make sure `ansi_enablecursor` is printed
75- start_time = time_ns ()
76- sysimg = Base. unsafe_string (Base. JLOptions (). image_file)
77-
86+ generate_precompile_statements () = try
7887 # Extract the precompile statements from the precompile file
7988 statements_step = Channel {String} (Inf )
8089
@@ -83,7 +92,7 @@ generate_precompile_statements() = try # Make sure `ansi_enablecursor` is printe
8392 touch (precompile_file)
8493 pts, ptm = open_fake_pty ()
8594 cmdargs = ` -e 'import REPL; REPL.Terminals.is_precompiling[] = true'`
86- p = run (addenv (addenv (``` $(julia_exepath ()) -O0 --trace-compile=$precompile_file --sysimage $sysimg
95+ p = run (addenv (addenv (``` $(julia_exepath ()) -O0 --trace-compile=$precompile_file
8796 --cpu-target=native --startup-file=no --compiled-modules=existing --color=yes -i $cmdargs ``` , procenv),
8897 " JULIA_PKG_PRECOMPILE_AUTO" => " 0" ),
8998 pts, pts, pts; wait= false )
@@ -166,6 +175,7 @@ generate_precompile_statements() = try # Make sure `ansi_enablecursor` is printe
166175 close (statements_step)
167176 return :ok
168177 end
178+ ! PARALLEL_PRECOMPILATION && wait (step)
169179
170180 # Make statements unique
171181 statements = Set {String} ()
@@ -174,23 +184,6 @@ generate_precompile_statements() = try # Make sure `ansi_enablecursor` is printe
174184 # Main should be completely clean
175185 occursin (" Main." , statement) && continue
176186 Base. in! (statement, statements) && continue
177- end
178-
179- fetch (step) == :ok || throw (" Collecting precompiles failed." )
180- return statements
181- finally
182- GC. gc (true ); GC. gc (false ); # reduce memory footprint
183- end
184-
185- statements = generate_precompile_statements ()
186-
187- # As a last step in system image generation,
188- # remove some references to build time environment for a more reproducible build.
189- Base. Filesystem. temp_cleanup_purge (force= true )
190-
191- @compile_workload begin
192- precompile (Tuple{typeof (getproperty), REPL. REPLBackend, Symbol})
193- for statement in statements
194187 try
195188 ps = Meta. parse (statement)
196189 if ! isexpr (ps, :call )
@@ -211,5 +204,18 @@ Base.Filesystem.temp_cleanup_purge(force=true)
211204 @warn " Failed to precompile expression" form= statement exception= ex _module= nothing _file= nothing _line= 0
212205 end
213206 end
214- end # @compile_workload
207+
208+ fetch (step) == :ok || throw (" Collecting precompiles failed." )
209+ return nothing
210+ finally
211+ GC. gc (true ); GC. gc (false ); # reduce memory footprint
212+ end
213+
214+ generate_precompile_statements ()
215+
216+ # As a last step in system image generation,
217+ # remove some references to build time environment for a more reproducible build.
218+ Base. Filesystem. temp_cleanup_purge (force= true )
219+
220+ precompile (Tuple{typeof (getproperty), REPL. REPLBackend, Symbol})
215221end # Precompile
0 commit comments