Skip to content

Commit 3106ebc

Browse files
authored
Rewrite maximum call in base sysimg.jl to fix error when stdlibs is e… (#325)
* Rewrite maximum call in base sysimg.jl to fix error when stdlibs is empty. * Add a test for generating an empty sysimage.
1 parent 427f28f commit 3106ebc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/PackageCompiler.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ function rewrite_sysimg_jl_only_needed_stdlibs(stdlibs::Vector{String})
103103
sysimg_content = read(sysimg_source_path, String)
104104
# replaces the hardcoded list of stdlibs in sysimg.jl with
105105
# the stdlibs that is given as argument
106-
return replace(sysimg_content,
106+
content = replace(sysimg_content,
107107
r"stdlibs = \[(.*?)\]"s => string("stdlibs = [", join(":" .* stdlibs, ",\n"), "]"))
108+
# Also replace a maximum call which fails for empty collections,
109+
# see https://github.com/JuliaLang/julia/pull/34727
110+
content = replace(content, "maximum(textwidth.(string.(stdlibs)))" =>
111+
"reduce(max, textwidth.(string.(stdlibs)); init=0)")
112+
return content
108113
end
109114

110115
function create_fresh_base_sysimage(stdlibs::Vector{String}; cpu_target::String)

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,13 @@ end
7171
@test occursin("HelloWorld artifact at $(realpath(app_compiled_dir))", app_output)
7272
end
7373
end
74+
# Test creating an empty sysimage
75+
if !is_slow_ci
76+
tmp = mktempdir()
77+
sysimage_path = joinpath(tmp, "empty." * Libdl.dlext)
78+
foreach(x -> touch(joinpath(tmp, x)), ["Project.toml", "Manifest.toml"])
79+
create_sysimage(; sysimage_path=sysimage_path, incremental=false, filter_stdlibs=true, project=tmp)
80+
hello = read(`$(Base.julia_cmd()) -J $(sysimage_path) -e 'print("hello, world")'`, String)
81+
@test hello == "hello, world"
82+
end
7483
end

0 commit comments

Comments
 (0)