Skip to content

Commit 6f34f91

Browse files
topolarityKristofferC
authored andcommitted
trimming: Avoid --strip-ir when compiling with --trim=no (#57659)
Both `--trim=no` and `--trim=safe` are supposed to be safe options by default, so let's not get overzealous and throw out all the IR even though we're not trimming Allows `juliac.jl` to use/test the sysimage creation pipeline unrelated to `--trim` support, as in #57656 (comment) (cherry picked from commit f9e5af1)
1 parent 2294722 commit 6f34f91

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

contrib/juliac.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ end
3030

3131
# arguments to forward to julia compilation process
3232
julia_args = []
33+
enable_trim::Bool = false
3334

3435
let i = 1
3536
while i <= length(ARGS)
@@ -46,9 +47,11 @@ let i = 1
4647
global verbose = true
4748
elseif arg == "--relative-rpath"
4849
global relative_rpath = true
49-
elseif startswith(arg, "--trim") || arg == "--experimental"
50-
# forwarded args
51-
push!(julia_args, arg)
50+
elseif startswith(arg, "--trim")
51+
global enable_trim = arg != "--trim=no"
52+
push!(julia_args, arg) # forwarded arg
53+
elseif arg == "--experimental"
54+
push!(julia_args, arg) # forwarded arg
5255
else
5356
if arg[1] == '-' || !isnothing(file)
5457
println("Unexpected argument `$arg`")
@@ -102,9 +105,17 @@ function precompile_env()
102105
end
103106
end
104107

105-
function compile_products()
108+
function compile_products(enable_trim::Bool)
109+
110+
# Only strip IR / metadata if not `--trim=no`
111+
strip_args = String[]
112+
if enable_trim
113+
push!(strip_args, "--strip-ir")
114+
push!(strip_args, "--strip-metadata")
115+
end
116+
106117
# Compile the Julia code
107-
cmd = addenv(`$julia_cmd_target --project=$(Base.active_project()) --output-o $img_path --output-incremental=no --strip-ir --strip-metadata $julia_args $(joinpath(@__DIR__,"juliac-buildscript.jl")) $absfile $output_type $add_ccallables`, "OPENBLAS_NUM_THREADS" => 1, "JULIA_NUM_THREADS" => 1)
118+
cmd = addenv(`$julia_cmd_target --project=$(Base.active_project()) --output-o $img_path --output-incremental=no $strip_args $julia_args $(joinpath(@__DIR__,"juliac-buildscript.jl")) $absfile $output_type $add_ccallables`, "OPENBLAS_NUM_THREADS" => 1, "JULIA_NUM_THREADS" => 1)
108119
verbose && println("Running: $cmd")
109120
if !success(pipeline(cmd; stdout, stderr))
110121
println(stderr, "\nFailed to compile $file")
@@ -154,5 +165,5 @@ function link_products()
154165
end
155166

156167
precompile_env()
157-
compile_products()
168+
compile_products(enable_trim)
158169
link_products()

0 commit comments

Comments
 (0)