Skip to content

Commit 22dc59b

Browse files
authored
fix using PackageCompiler with local Julia builds in some cases (#1077)
1 parent c1e37c4 commit 22dc59b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/PackageCompiler.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ function create_fresh_base_sysimage(; cpu_target::String, sysimage_build_args::C
296296
@static if VERSION >= v"1.12.0-DEV.1617"
297297
compiler_source_path = joinpath(base_dir, "Base_compiler.jl")
298298
buildroot = ""
299-
dataroot = relpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR), base_dir) * "/"
299+
# Use realpath to handle symlinked directories (common in local Julia builds)
300+
dataroot = relpath(realpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR)), realpath(base_dir)) * "/"
300301
compiler_args = `--buildroot $buildroot --dataroot $dataroot` # build path
301302
else
302303
compiler_source_path = joinpath(base_dir, "compiler", "compiler.jl")
@@ -948,6 +949,7 @@ function create_app(package_dir::String,
948949
include_preferences && bundle_preferences(ctx, app_dir)
949950
bundle_cert(app_dir)
950951

952+
# Sysimage always goes in lib/julia/ (this is hardcoded in the Julia binary)
951953
sysimage_path = joinpath(app_dir, "lib", "julia", "sys." * Libdl.dlext)
952954

953955
package_name = ctx.env.pkg.name
@@ -1367,13 +1369,18 @@ function bundle_julia_libraries(dest_dir, stdlibs)
13671369
app_libjulia_dir = Sys.isunix() ? joinpath(app_lib_dir, "julia") : app_lib_dir
13681370
lib_dir = julia_libdir()
13691371
libjulia_dir = Sys.isunix() ? joinpath(lib_dir, "julia") : lib_dir
1370-
# File structure is slightly different on locally built julias:
1371-
if !isempty(glob(glob_pattern_lib("libLLVM"), lib_dir))
1372+
# File structure is different on locally built julias:
1373+
# libraries are in lib/ directly instead of lib/julia/, and the DEP_LIBS
1374+
# embedded in libjulia.so reflect this. We must copy libraries to the same
1375+
# relative location to match the binary's expectations.
1376+
if is_local_julia_build()
13721377
libjulia_dir = lib_dir
1378+
app_libjulia_dir = app_lib_dir
13731379
end
13741380

13751381
mkpath(app_lib_dir)
1376-
Sys.isunix() && mkpath(app_libjulia_dir)
1382+
# Always create lib/julia/ for the sysimage (even for local builds where libraries go to lib/)
1383+
Sys.isunix() && mkpath(joinpath(app_lib_dir, "julia"))
13771384

13781385
tot_libsize = 0
13791386
printstyled("PackageCompiler: bundled libraries:\n")

src/juliaconfig.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ function julia_libdir()
1313
return dirname(abspath(Libdl.dlpath(libname)))
1414
end
1515

16+
# Detect if Julia is a local build (libraries in lib/ directly instead of lib/julia/)
17+
function is_local_julia_build()
18+
lib_dir = julia_libdir()
19+
# In local builds, libLLVM is directly in lib/, not in lib/julia/
20+
return any(startswith(f, "libLLVM") for f in readdir(lib_dir))
21+
end
22+
1623
function julia_private_libdir()
1724
if Base.DARWIN_FRAMEWORK # taken from Libdl tests
1825
if isdebugbuild() != 0

0 commit comments

Comments
 (0)