Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to set julia-args for precompile execution #931

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ function ensurecompiled(project, packages, sysimage)
return
end

function run_precompilation_script(project::String, sysimg::String, precompile_file::Union{String, Nothing}, precompile_dir::String)
function run_precompilation_script(project::String, sysimg::String, precompile_file::Union{String, Nothing}, precompile_dir::String, julia_args::Cmd)
tracefile, io = mktemp(precompile_dir; cleanup=false)
close(io)
arg = precompile_file === nothing ? `-e ''` : `$precompile_file`
cmd = `$(get_julia_cmd()) --sysimage=$(sysimg) --compile=all --trace-compile=$tracefile $arg`
cmd = `$(get_julia_cmd()) --sysimage=$(sysimg) --compile=all --trace-compile=$tracefile $julia_args $arg`
# --project is not propagated well with Distributed, so use environment
splitter = Sys.iswindows() ? ';' : ':'
@debug "run_precompilation_script: running $cmd" JULIA_LOAD_PATH = "$project$(splitter)@stdlib"
Expand All @@ -319,7 +319,8 @@ function create_sysimg_object_file(object_file::String,
script::Union{Nothing, String},
sysimage_build_args::Cmd,
extra_precompiles::String,
incremental::Bool)
incremental::Bool,
precompile_execution_args::Cmd)
julia_code_buffer = IOBuffer()
# include all packages into the sysimg
print(julia_code_buffer, """
Expand All @@ -341,7 +342,7 @@ function create_sysimg_object_file(object_file::String,
@debug "running precompilation execution script..."
precompile_dir = mktempdir(; prefix="jl_packagecompiler_", cleanup=false)
for file in (isempty(precompile_execution_file) ? (nothing,) : precompile_execution_file)
tracefile = run_precompilation_script(project, base_sysimage, file, precompile_dir)
tracefile = run_precompilation_script(project, base_sysimage, file, precompile_dir, precompile_execution_args)
push!(precompile_files, tracefile)
end
append!(precompile_files, abspath.(precompile_statements_file))
Expand Down Expand Up @@ -517,6 +518,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).

- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
for example `-O1 --check-bounds=yes`.

- `precompile_execution_args::Cmd`: A set of command line options that is used in the Julia process running the
precompile execution file, for example `-O0`.
"""
function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector{Symbol}}=nothing;
sysimage_path::String,
Expand All @@ -537,6 +541,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
soname=nothing,
compat_level::String="major",
extra_precompiles::String = "",
precompile_execution_args::Cmd=``
sjkelly marked this conversation as resolved.
Show resolved Hide resolved
)
# We call this at the very beginning to make sure that the user has a compiler available. Therefore, if no compiler
# is found, we throw an error immediately, instead of making the user wait a while before the error is thrown.
Expand Down Expand Up @@ -634,7 +639,8 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
script,
sysimage_build_args,
extra_precompiles,
incremental)
incremental,
precompile_execution_args)
object_files = [object_file]
if julia_init_c_file !== nothing
if julia_init_c_file isa String
Expand Down Expand Up @@ -818,6 +824,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).
- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
for example `-O1 --check-bounds=yes`.

- `precompile_execution_args::Cmd`: A set of command line options that is used in the Julia process running the
precompile execution file, for example `-O0`.

- `script::String`: Path to a file that gets executed in the `--output-o` process.
"""
function create_app(package_dir::String,
Expand All @@ -834,7 +843,8 @@ function create_app(package_dir::String,
sysimage_build_args::Cmd=``,
include_transitive_dependencies::Bool=true,
include_preferences::Bool=true,
script::Union{Nothing, String}=nothing)
script::Union{Nothing, String}=nothing,
precompile_execution_args::Cmd=``)
warn_official()
if filter_stdlibs && incremental
error("must use `incremental=false` to use `filter_stdlibs=true`")
Expand Down Expand Up @@ -887,7 +897,8 @@ function create_app(package_dir::String,
sysimage_build_args,
include_transitive_dependencies,
extra_precompiles = join(precompiles, "\n"),
script)
script,
precompile_execution_args)

for (app_name, julia_main) in executables
create_executable_from_sysimg(joinpath(app_dir, "bin", app_name), c_driver_program, string(package_name, ".", julia_main))
Expand Down Expand Up @@ -1020,6 +1031,9 @@ compiler (can also include extra arguments to the compiler, like `-g`).

- `sysimage_build_args::Cmd`: A set of command line options that is used in the Julia process building the sysimage,
for example `-O1 --check-bounds=yes`.

- `precompile_execution_args::Cmd`: A set of command line options that is used in the Julia process running the
precompile execution file, for example `-O0`.
"""
function create_library(package_or_project::String,
dest_dir::String;
Expand Down Expand Up @@ -1421,7 +1435,7 @@ function bundle_julia_libexec(ctx, dest_dir)
p7zip_exe = basename(p7zip_path)
cp(p7zip_path, joinpath(bundle_libexec_dir, p7zip_exe))

return
return
end

function recursive_dir_size(path)
Expand Down
Loading