Skip to content

Commit a62acdf

Browse files
authored
more effectively record precompile signatures from package precompilation (#37710)
* more effectively record precompile signatures from package precompilation
1 parent d148eb2 commit a62acdf

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

base/loading.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ end
11521152
@assert precompile(include_package_for_output, (PkgId,String,Vector{String},Vector{String},Vector{String},typeof(_concrete_dependencies),Nothing))
11531153
@assert precompile(include_package_for_output, (PkgId,String,Vector{String},Vector{String},Vector{String},typeof(_concrete_dependencies),String))
11541154

1155+
const PRECOMPILE_TRACE_COMPILE = Ref{String}()
11551156
function create_expr_cache(pkg::PkgId, input::String, output::String, concrete_deps::typeof(_concrete_dependencies), show_errors::Bool = true)
11561157
rm(output, force=true) # Remove file if it exists
11571158
depot_path = map(abspath, DEPOT_PATH)
@@ -1174,10 +1175,12 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, concrete_d
11741175
end
11751176
deps = repr(eltype(concrete_deps)) * "[" * join(deps_strs, ",") * "]"
11761177

1178+
trace = isassigned(PRECOMPILE_TRACE_COMPILE) ? `--trace-compile=$(PRECOMPILE_TRACE_COMPILE[])` : ``
11771179
io = open(pipeline(`$(julia_cmd()::Cmd) -O0
11781180
--output-ji $output --output-incremental=yes
11791181
--startup-file=no --history-file=no --warn-overwrite=yes
11801182
--color=$(have_color === nothing ? "auto" : have_color ? "yes" : "no")
1183+
$trace
11811184
--eval 'eval(Meta.parse(read(stdin,String)))'`, stderr=show_errors ? stderr : devnull),
11821185
"w", stdout)
11831186
# write data over stdin to avoid the (unlikely) case of exceeding max command line size

contrib/generate_precompile.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,31 @@ end
122122
function generate_precompile_statements()
123123
start_time = time_ns()
124124
debug_output = devnull # or stdout
125+
sysimg = Base.unsafe_string(Base.JLOptions().image_file)
125126

126127
# Precompile a package
128+
global hardcoded_precompile_statements
129+
127130
mktempdir() do prec_path
128-
push!(DEPOT_PATH, prec_path)
129-
push!(LOAD_PATH, prec_path)
130131
pkgname = "__PackagePrecompilationStatementModule"
131132
mkpath(joinpath(prec_path, pkgname, "src"))
132-
write(joinpath(prec_path, pkgname, "src", "$pkgname.jl"),
133+
path = joinpath(prec_path, pkgname, "src", "$pkgname.jl")
134+
write(path,
133135
"""
134136
module $pkgname
135137
end
136138
""")
137-
@eval using __PackagePrecompilationStatementModule
138-
empty!(LOAD_PATH)
139-
empty!(DEPOT_PATH)
139+
tmp = tempname()
140+
# Running compilecache on buildbots fails with
141+
# `More than one command line CPU targets specified without a `--output-` flag specified`
142+
# so start a new process without a CPU target specified
143+
s = """
144+
push!(DEPOT_PATH, $(repr(prec_path)));
145+
Base.PRECOMPILE_TRACE_COMPILE[] = $(repr(tmp));
146+
Base.compilecache(Base.PkgId($(repr(pkgname))), $(repr(path)))
147+
"""
148+
run(`$(julia_exepath()) -O0 --sysimage $sysimg -Cnative -e $s`)
149+
hardcoded_precompile_statements *= "\n" * read(tmp, String)
140150
end
141151

142152
mktemp() do precompile_file, precompile_file_h
@@ -154,7 +164,6 @@ function generate_precompile_statements()
154164
"JULIA_PROJECT" => nothing, # remove from environment
155165
"JULIA_LOAD_PATH" => Sys.iswindows() ? "@;@stdlib" : "@:@stdlib",
156166
"TERM" => "") do
157-
sysimg = Base.unsafe_string(Base.JLOptions().image_file)
158167
run(```$(julia_exepath()) -O0 --trace-compile=$precompile_file --sysimage $sysimg
159168
--cpu-target=native --startup-file=no --color=yes
160169
-e 'import REPL; REPL.Terminals.is_precompiling[] = true'

test/precompile.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ try
293293
:Profile, :Random, :Serialization, :SharedArrays, :SparseArrays, :SuiteSparse, :Test,
294294
:Unicode, :REPL, :InteractiveUtils, :Pkg, :LibGit2, :SHA, :UUIDs, :Sockets,
295295
:Statistics, :TOML, :MozillaCACerts_jll, :LibCURL_jll, :LibCURL, :Downloads,]),
296-
# Plus precompilation module generated at build time
297-
let id = Base.PkgId("__PackagePrecompilationStatementModule")
298-
Dict(id => Base.module_build_id(Base.root_module(id)))
299-
end
300296
)
301297
@test discard_module.(deps) == deps1
302298
modules, (deps, requires), required_modules = Base.parse_cache_header(cachefile; srcfiles_only=true)

0 commit comments

Comments
 (0)