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

[WIP] Allow setting a command prefix for the sysimage build command #870

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
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: 26 additions & 4 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,12 @@ 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_prefix::Cmd,
precompile_file::Union{String, Nothing}, precompile_dir::String)
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 = `$precompile_prefix $(get_julia_cmd()) --sysimage=$(sysimg) --compile=all --trace-compile=$tracefile $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 @@ -299,6 +300,7 @@ function create_sysimg_object_file(object_file::String,
project::String,
base_sysimage::String,
precompile_execution_file::Vector{String},
precompile_execution_prefix::Cmd,
precompile_statements_file::Vector{String},
cpu_target::String,
script::Union{Nothing, String},
Expand Down Expand Up @@ -326,7 +328,8 @@ 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, precompile_execution_prefix,
file, precompile_dir)
push!(precompile_files, tracefile)
end
append!(precompile_files, abspath.(precompile_statements_file))
Expand Down Expand Up @@ -487,11 +490,16 @@ 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_prefix::Cmd`: A set of commands and command line options that will be
prefixed to the call to Julia when executing files specified by `precompile_execution_file`,
for example `srun`.
"""
function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector{Symbol}}=nothing;
sysimage_path::String,
project::String=dirname(active_project()),
precompile_execution_file::Union{String, Vector{String}}=String[],
precompile_execution_prefix::Cmd=``,
precompile_statements_file::Union{String, Vector{String}}=String[],
incremental::Bool=true,
filter_stdlibs::Bool=false,
Expand Down Expand Up @@ -599,6 +607,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
project,
base_sysimage,
precompile_execution_file,
precompile_execution_prefix,
precompile_statements_file,
cpu_target,
script,
Expand Down Expand Up @@ -789,11 +798,16 @@ compiler (can also include extra arguments to the compiler, like `-g`).
for example `-O1 --check-bounds=yes`.

- `script::String`: Path to a file that gets executed in the `--output-o` process.

- `precompile_execution_prefix::Cmd`: A set of commands and command line options that will be
prefixed to the call to Julia when executing files specified by `precompile_execution_file`,
for example `srun`.
"""
function create_app(package_dir::String,
app_dir::String;
executables::Union{Nothing, Vector{Pair{String, String}}}=nothing,
precompile_execution_file::Union{String, Vector{String}}=String[],
precompile_execution_prefix::Cmd=``,
precompile_statements_file::Union{String, Vector{String}}=String[],
incremental::Bool=false,
filter_stdlibs::Bool=false,
Expand Down Expand Up @@ -848,6 +862,7 @@ function create_app(package_dir::String,
incremental,
filter_stdlibs,
precompile_execution_file,
precompile_execution_prefix,
precompile_statements_file,
cpu_target,
sysimage_build_args,
Expand Down Expand Up @@ -986,11 +1001,16 @@ 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_prefix::Cmd`: A set of commands and command line options that will be
prefixed to the call to Julia when executing files specified by `precompile_execution_file`,
for example `srun`.
"""
function create_library(package_or_project::String,
dest_dir::String;
lib_name=nothing,
precompile_execution_file::Union{String, Vector{String}}=String[],
precompile_execution_prefix::Cmd=``,
precompile_statements_file::Union{String, Vector{String}}=String[],
incremental::Bool=false,
filter_stdlibs::Bool=false,
Expand Down Expand Up @@ -1051,7 +1071,7 @@ function create_library(package_or_project::String,
compat_file = get_library_filename(lib_name; version, compat_level)
soname = (Sys.isunix() && !Sys.isapple()) ? compat_file : nothing

create_sysimage_workaround(ctx, sysimg_path, precompile_execution_file,
create_sysimage_workaround(ctx, sysimg_path, precompile_execution_file, precompile_execution_prefix,
precompile_statements_file, incremental, filter_stdlibs, cpu_target;
sysimage_build_args, include_transitive_dependencies, julia_init_c_file,
julia_init_h_file, version, soname, script)
Expand Down Expand Up @@ -1108,6 +1128,7 @@ function create_sysimage_workaround(
ctx,
sysimage_path::String,
precompile_execution_file::Union{String, Vector{String}},
precompile_execution_prefix::Cmd,
precompile_statements_file::Union{String, Vector{String}},
incremental::Bool,
filter_stdlibs::Bool,
Expand Down Expand Up @@ -1143,6 +1164,7 @@ function create_sysimage_workaround(
incremental=true,
script=script,
precompile_execution_file,
precompile_execution_prefix,
precompile_statements_file,
cpu_target,
base_sysimage,
Expand Down
Loading