Skip to content

Commit

Permalink
fix: pass CPU targets as cmd args
Browse files Browse the repository at this point in the history
- Sysimages built with CPU targets as env var, tend to ignore them and result segfaults,  when relocated to the target machine
  • Loading branch information
ven-k committed Apr 18, 2023
1 parent e5a8410 commit be21075
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,11 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
TerminalSpinners.@spin spinner begin
cd(base_dir) do
# Create corecompiler.ji
cmd = if isdefined(Base, :Linking) # pkgimages feature flag
cmd = `$(get_julia_cmd()) --output-ji $tmp_corecompiler_ji $sysimage_build_args $compiler_source_path`
@debug "running $cmd" JULIA_CPU_TARGET = cpu_target
addenv(cmd, "JULIA_CPU_TARGET" => cpu_target)
else
cmd = `$(get_julia_cmd()) --cpu-target $cpu_target --output-ji $tmp_corecompiler_ji
$sysimage_build_args $compiler_source_path`
@debug "running $cmd"
cmd
end
cmd = `$(get_julia_cmd()) --cpu-target $cpu_target
--output-ji $tmp_corecompiler_ji $sysimage_build_args
$compiler_source_path`
@debug "running $cmd"

read(cmd)

# Use that to create sys.ji
Expand All @@ -250,18 +245,12 @@ function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String,
new_sysimage_source_path = joinpath(tmp, "sysimage_packagecompiler_$(uuid1()).jl")
write(new_sysimage_source_path, new_sysimage_content)
try
cmd = if isdefined(Base, :Linking) # pkgimages feature flag
cmd = `$(get_julia_cmd()) --sysimage=$tmp_corecompiler_ji
$sysimage_build_args --output-ji=$tmp_sys_ji $new_sysimage_source_path`
@debug "running $cmd" JULIA_CPU_TARGET = cpu_target
addenv(cmd, "JULIA_CPU_TARGET" => cpu_target)
else
cmd = `$(get_julia_cmd()) --cpu-target $cpu_target
--sysimage=$tmp_corecompiler_ji
$sysimage_build_args --output-ji=$tmp_sys_ji $new_sysimage_source_path`
@debug "running $cmd"
cmd
end
cmd = `$(get_julia_cmd()) --cpu-target $cpu_target
--sysimage=$tmp_corecompiler_ji
$sysimage_build_args --output-ji=$tmp_sys_ji
$new_sysimage_source_path`
@debug "running $cmd"

read(cmd)
finally
rm(new_sysimage_source_path; force=true)
Expand Down Expand Up @@ -408,17 +397,11 @@ function create_sysimg_object_file(object_file::String,
write(outputo_file, julia_code)
# Read the input via stdin to avoid hitting the maximum command line limit

cmd = if isdefined(Base, :Linking) # pkgimages feature flag
cmd = `$(get_julia_cmd()) $sysimage_build_args
--sysimage=$base_sysimage --project=$project --output-o=$(object_file) $outputo_file`
@debug "running $cmd" JULIA_CPU_TARGET = cpu_target
addenv(cmd, "JULIA_CPU_TARGET" => cpu_target)
else
cmd = `$(get_julia_cmd()) --cpu-target=$cpu_target $sysimage_build_args
--sysimage=$base_sysimage --project=$project --output-o=$(object_file) $outputo_file`
--sysimage=$base_sysimage --project=$project --output-o=$(object_file)
$outputo_file`
@debug "running $cmd"
cmd
end

non = incremental ? "" : "non"
spinner = TerminalSpinners.Spinner(msg = "PackageCompiler: compiling $(non)incremental system image")
@monitor_oom TerminalSpinners.@spin spinner run(cmd)
Expand Down Expand Up @@ -492,7 +475,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector
compat_level::String="major",
extra_precompiles::String = "",
)
# We call this at the very beginning to make sure that the user has a compiler available. Therefore, if no compiler
# 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.
get_compiler_cmd()

Expand Down Expand Up @@ -760,7 +743,7 @@ function create_app(package_dir::String,
sysimage_build_args::Cmd=``,
include_transitive_dependencies::Bool=true)
warn_official()
# We call this at the very beginning to make sure that the user has a compiler available. Therefore, if no compiler
# 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.
get_compiler_cmd()

Expand Down

0 comments on commit be21075

Please sign in to comment.