Skip to content

Commit

Permalink
get trimming test working again (#56689)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Nov 28, 2024
1 parent 7e2e0ae commit 680803c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
19 changes: 8 additions & 11 deletions contrib/juliac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
cmd = Base.julia_cmd()
cmd = `$cmd --startup-file=no --history-file=no`
output_type = nothing # exe, sharedlib, sysimage
trim = nothing
outname = nothing
file = nothing
add_ccallables = false
Expand All @@ -15,13 +14,16 @@ if help !== nothing
println(
"""
Usage: julia juliac.jl [--output-exe | --output-lib | --output-sysimage] <name> [options] <file.jl>
--trim=<no,safe,unsafe,unsafe-warn> Only output code statically determined to be reachable
--experimental --trim=<no,safe,unsafe,unsafe-warn> Only output code statically determined to be reachable
--compile-ccallable Include all methods marked `@ccallable` in output
--verbose Request verbose output
""")
exit(0)
end

# arguments to forward to julia compilation process
julia_args = []

let i = 1
while i <= length(ARGS)
arg = ARGS[i]
Expand All @@ -31,17 +33,13 @@ let i = 1
i == length(ARGS) && error("Output specifier requires an argument")
global outname = ARGS[i+1]
i += 1
elseif startswith(arg, "--trim")
arg = split(arg, '=')
if length(arg) == 1
global trim = "safe"
else
global trim = arg[2]
end
elseif arg == "--compile-ccallable"
global add_ccallables = true
elseif arg == "--verbose"
global verbose = true
elseif startswith(arg, "--trim") || arg == "--experimental"
# forwarded args
push!(julia_args, arg)
else
if arg[1] == '-' || !isnothing(file)
println("Unexpected argument `$arg`")
Expand Down Expand Up @@ -79,8 +77,7 @@ open(initsrc_path, "w") do io
""")
end

static_call_graph_arg() = isnothing(trim) ? `` : `--trim=$(trim)`
cmd = addenv(`$cmd --project=$(Base.active_project()) --output-o $img_path --output-incremental=no --strip-ir --strip-metadata $(static_call_graph_arg()) $(joinpath(@__DIR__,"juliac-buildscript.jl")) $absfile $output_type $add_ccallables`, "OPENBLAS_NUM_THREADS" => 1, "JULIA_NUM_THREADS" => 1)
cmd = addenv(`$cmd --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)
verbose && println("Running: $cmd")
if !success(pipeline(cmd; stdout, stderr))
println(stderr, "\nFailed to compile $file")
Expand Down
1 change: 1 addition & 0 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,7 @@ static void strip_specializations_(jl_method_instance_t *mi)
if (inferred && inferred != jl_nothing) {
if (jl_options.strip_ir) {
record_field_change((jl_value_t**)&codeinst->inferred, jl_nothing);
record_field_change((jl_value_t**)&codeinst->edges, (jl_value_t*)jl_emptysvec);
}
else if (jl_options.strip_metadata) {
jl_value_t *stripped = strip_codeinfo_meta(mi->def.method, inferred, codeinst);
Expand Down
2 changes: 1 addition & 1 deletion test/trimming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs) -ljulia-internal
release: hello$(EXE)

hello.o: $(SRCDIR)/hello.jl $(BUILDSCRIPT)
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --trim $(BUILDSCRIPT) $(SRCDIR)/hello.jl --output-exe true
$(JULIA) -t 1 -J $(BIN)/../lib/julia/sys.so --startup-file=no --history-file=no --output-o $@ --output-incremental=no --strip-ir --strip-metadata --experimental --trim $(BUILDSCRIPT) $(SRCDIR)/hello.jl --output-exe true

init.o: $(SRCDIR)/init.c
$(CC) -c -o $@ $< $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS)
Expand Down

0 comments on commit 680803c

Please sign in to comment.