Skip to content

Commit 488c8e9

Browse files
staticfloatIanButterworth
authored andcommitted
Convert more stdlibs to LazyLibraries
This converts more JLL stdlibs to use lazily-loaded libraries, and as a useful side-effect, causes them to be loaded by absolute path, isolating them all from `LD_LIBRARY_PATH`-like effects. fixups lazify dSFMT_jll lazify GMP_jll lazify libLLVM_jll lazify MPFR_jll lazify OpenLibm_jll lazify PCRE2_jll lazify SuiteSparse_jll add small precompiles Add `is_available()` for `LibUV_jll` Add initial `stdlib_dependencies` test This allows for auditing the expressed library dependencies in our LazyLibrary JLL definitions, to ensure that we don't get out of sync with the actual binaries. fix typo add stdlib_dependencies.jl to choosetests test fixes etc. test fixes etc. more test fixes morefix missing eager_modes dep fixes
1 parent f03e9c3 commit 488c8e9

File tree

35 files changed

+753
-409
lines changed

35 files changed

+753
-409
lines changed

stdlib/CompilerSupportLibraries_jll/src/CompilerSupportLibraries_jll.jl

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,30 @@ if @isdefined(_libatomic_path)
6464
const libatomic = LazyLibrary(_libatomic_path)
6565
end
6666
const libgcc_s = LazyLibrary(_libgcc_s_path)
67-
libgfortran_deps = [libgcc_s]
68-
if @isdefined _libquadmath_path
69-
const libquadmath = LazyLibrary(_libquadmath_path)
70-
push!(libgfortran_deps, libquadmath)
67+
68+
@static if Sys.isfreebsd()
69+
_libgfortran_deps = LazyLibrary[]
70+
else
71+
_libgfortran_deps = [libgcc_s]
72+
if @isdefined _libquadmath_path
73+
const libquadmath = LazyLibrary(_libquadmath_path)
74+
push!(_libgfortran_deps, libquadmath)
75+
end
76+
end
77+
78+
const libgfortran = LazyLibrary(_libgfortran_path, dependencies=_libgfortran_deps)
79+
80+
if Sys.isfreebsd()
81+
_libstdcxx_dependencies = LazyLibrary[]
82+
elseif Sys.isapple()
83+
_libstdcxx_dependencies = LazyLibrary[libgcc_s]
84+
elseif Sys.islinux()
85+
_libstdcxx_dependencies = LazyLibrary[libgcc_s]
86+
else
87+
_libstdcxx_dependencies = LazyLibrary[libgcc_s, libgfortran]
7188
end
72-
const libgfortran = LazyLibrary(_libgfortran_path, dependencies=libgfortran_deps)
73-
const libstdcxx = LazyLibrary(_libstdcxx_path, dependencies=[libgcc_s])
89+
const libstdcxx = LazyLibrary(_libstdcxx_path, dependencies=_libstdcxx_dependencies)
90+
7491
const libgomp = LazyLibrary(_libgomp_path)
7592

7693
# Some installations (such as those from-source) may not have `libssp`
@@ -116,4 +133,9 @@ function __init__()
116133
push!(LIBPATH_list, LIBPATH[])
117134
end
118135

136+
if Base.generating_output()
137+
precompile(eager_mode, ())
138+
precompile(is_available, ())
139+
end
140+
119141
end # module CompilerSupportLibraries_jll

stdlib/GMP_jll/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "6.3.0+2"
44

55
[deps]
66
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
7+
CompilerSupportLibraries_jll = "e66e0078-7015-5450-92f7-15fbd957f2ae"
78
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
89

910
[compat]

stdlib/GMP_jll/src/GMP_jll.jl

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,62 @@
22

33
## dummy stub for https://github.com/JuliaBinaryWrappers/GMP_jll.jl
44
baremodule GMP_jll
5-
using Base, Libdl
6-
7-
const PATH_list = String[]
8-
const LIBPATH_list = String[]
5+
using Base, Libdl, CompilerSupportLibraries_jll
96

107
export libgmp, libgmpxx
118

129
# These get calculated in __init__()
1310
const PATH = Ref("")
11+
const PATH_list = String[]
1412
const LIBPATH = Ref("")
13+
const LIBPATH_list = String[]
1514
artifact_dir::String = ""
16-
libgmp_handle::Ptr{Cvoid} = C_NULL
1715
libgmp_path::String = ""
18-
libgmpxx_handle::Ptr{Cvoid} = C_NULL
1916
libgmpxx_path::String = ""
2017

2118
if Sys.iswindows()
22-
const libgmp = "libgmp-10.dll"
23-
const libgmpxx = "libgmpxx-4.dll"
19+
const _libgmp_path = BundledLazyLibraryPath("libgmp-10.dll")
20+
const _libgmpxx_path = BundledLazyLibraryPath("libgmpxx-4.dll")
2421
elseif Sys.isapple()
25-
const libgmp = "@rpath/libgmp.10.dylib"
26-
const libgmpxx = "@rpath/libgmpxx.4.dylib"
22+
const _libgmp_path = BundledLazyLibraryPath("libgmp.10.dylib")
23+
const _libgmpxx_path = BundledLazyLibraryPath("libgmpxx.4.dylib")
2724
else
28-
const libgmp = "libgmp.so.10"
29-
const libgmpxx = "libgmpxx.so.4"
25+
const _libgmp_path = BundledLazyLibraryPath("libgmp.so.10")
26+
const _libgmpxx_path = BundledLazyLibraryPath("libgmpxx.so.4")
3027
end
3128

29+
const libgmp = LazyLibrary(_libgmp_path)
30+
31+
if Sys.isapple()
32+
_libgmpxx_dependencies = LazyLibrary[libgmp]
33+
elseif Sys.isfreebsd()
34+
_libgmpxx_dependencies = LazyLibrary[]
35+
else
36+
_libgmpxx_dependencies = LazyLibrary[libgmp, libstdcxx, libgcc_s]
37+
end
38+
const libgmpxx = LazyLibrary(
39+
_libgmpxx_path,
40+
dependencies=_libgmpxx_dependencies,
41+
)
42+
43+
function eager_mode()
44+
CompilerSupportLibraries_jll.eager_mode()
45+
dlopen(libgmp)
46+
dlopen(libgmpxx)
47+
end
48+
is_available() = true
49+
3250
function __init__()
33-
global libgmp_handle = dlopen(libgmp)
34-
global libgmp_path = dlpath(libgmp_handle)
35-
global libgmpxx_handle = dlopen(libgmpxx)
36-
global libgmpxx_path = dlpath(libgmpxx_handle)
51+
global libgmp_path = string(_libgmp_path)
52+
global libgmpxx_path = string(_libgmpxx_path)
3753
global artifact_dir = dirname(Sys.BINDIR)
3854
LIBPATH[] = dirname(libgmp_path)
3955
push!(LIBPATH_list, LIBPATH[])
4056
end
4157

42-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
43-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
44-
# there isn't one. It instead returns the overall Julia prefix.
45-
is_available() = true
46-
find_artifact_dir() = artifact_dir
47-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
48-
best_wrapper = nothing
49-
get_libgmp_path() = libgmp_path
50-
get_libgmpxx_path() = libgmpxx_path
58+
if Base.generating_output()
59+
precompile(eager_mode, ())
60+
precompile(is_available, ())
61+
end
5162

5263
end # module GMP_jll

stdlib/GMP_jll/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
using Test, Libdl, GMP_jll
44

55
@testset "GMP_jll" begin
6-
vn = VersionNumber(unsafe_string(unsafe_load(cglobal((:__gmp_version, libgmp), Ptr{Cchar}))))
6+
vn = VersionNumber(unsafe_string(unsafe_load(cglobal(dlsym(libgmp, :__gmp_version), Ptr{Cchar}))))
77
@test vn == v"6.3.0"
88
end

stdlib/LLVMLibUnwind_jll/src/LLVMLibUnwind_jll.jl

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,33 @@
55
baremodule LLVMLibUnwind_jll
66
using Base, Libdl
77

8-
const PATH_list = String[]
9-
const LIBPATH_list = String[]
10-
118
export llvmlibunwind
129

1310
# These get calculated in __init__()
1411
const PATH = Ref("")
12+
const PATH_list = String[]
1513
const LIBPATH = Ref("")
14+
const LIBPATH_list = String[]
1615
artifact_dir::String = ""
17-
llvmlibunwind_handle::Ptr{Cvoid} = C_NULL
1816
llvmlibunwind_path::String = ""
1917

20-
const llvmlibunwind = "libunwind"
18+
const _llvmlibunwind_path = BundledLazyLibraryPath("libunwind")
19+
const llvmlibunwind = LazyLibrary(_llvmlibunwind_path)
20+
function eager_mode()
21+
dlopen(llvmlibunwind)
22+
end
23+
is_available() = @static Sys.isapple() ? true : false
2124

2225
function __init__()
23-
# We only dlopen something on MacOS
24-
@static if Sys.isapple()
25-
global llvmlibunwind_handle = dlopen(llvmlibunwind)
26-
global llvmlibunwind_path = dlpath(llvmlibunwind_handle)
27-
global artifact_dir = dirname(Sys.BINDIR)
28-
LIBPATH[] = dirname(llvmlibunwind_path)
29-
push!(LIBPATH_list, LIBPATH[])
30-
end
26+
global llvmlibunwind_path = string(_llvmlibunwind_path)
27+
global artifact_dir = dirname(Sys.BINDIR)
28+
LIBPATH[] = dirname(llvmlibunwind_path)
29+
push!(LIBPATH_list, LIBPATH[])
3130
end
3231

33-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
34-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
35-
# there isn't one. It instead returns the overall Julia prefix.
36-
is_available() = @static Sys.isapple() ? true : false
37-
find_artifact_dir() = artifact_dir
38-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
39-
best_wrapper = nothing
40-
get_llvmlibunwind_path() = llvmlibunwind_path
32+
if Base.generating_output()
33+
precompile(eager_mode, ())
34+
precompile(is_available, ())
35+
end
4136

4237
end # module LLVMLibUnwind_jll
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Test, Libdl
4-
using LLVMLibUnwind_jll: llvmlibunwind_handle
5-
3+
using Test, Libdl, LLVMLibUnwind_jll
64
@testset "LLVMLibUnwind_jll" begin
75
if Sys.isapple()
8-
@test dlsym(llvmlibunwind_handle, :unw_getcontext; throw_error=false) !== nothing
9-
@test dlsym(llvmlibunwind_handle, :unw_init_local; throw_error=false) !== nothing
10-
@test dlsym(llvmlibunwind_handle, :unw_init_local_dwarf; throw_error=false) !== nothing
11-
@test dlsym(llvmlibunwind_handle, :unw_step; throw_error=false) !== nothing
12-
@test dlsym(llvmlibunwind_handle, :unw_get_reg; throw_error=false) !== nothing
13-
@test dlsym(llvmlibunwind_handle, :unw_set_reg; throw_error=false) !== nothing
14-
@test dlsym(llvmlibunwind_handle, :unw_resume; throw_error=false) !== nothing
6+
@test dlsym(llvmlibunwind, :unw_getcontext; throw_error=false) !== nothing
7+
@test dlsym(llvmlibunwind, :unw_init_local; throw_error=false) !== nothing
8+
@test dlsym(llvmlibunwind, :unw_init_local_dwarf; throw_error=false) !== nothing
9+
@test dlsym(llvmlibunwind, :unw_step; throw_error=false) !== nothing
10+
@test dlsym(llvmlibunwind, :unw_get_reg; throw_error=false) !== nothing
11+
@test dlsym(llvmlibunwind, :unw_set_reg; throw_error=false) !== nothing
12+
@test dlsym(llvmlibunwind, :unw_resume; throw_error=false) !== nothing
1513
end
1614
end

stdlib/LibCURL_jll/src/LibCURL_jll.jl

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,56 @@ if !(Sys.iswindows() || Sys.isapple())
99
using OpenSSL_jll
1010
end
1111

12-
const PATH_list = String[]
13-
const LIBPATH_list = String[]
14-
1512
export libcurl
1613

1714
# These get calculated in __init__()
1815
const PATH = Ref("")
16+
const PATH_list = String[]
1917
const LIBPATH = Ref("")
18+
const LIBPATH_list = String[]
2019
artifact_dir::String = ""
21-
libcurl_handle::Ptr{Cvoid} = C_NULL
2220
libcurl_path::String = ""
2321

22+
if Sys.isfreebsd()
23+
_libcurl_dependencies = LazyLibrary[]
24+
else
25+
_libcurl_dependencies = LazyLibrary[libz, libnghttp2, libssh2]
26+
if !(Sys.iswindows() || Sys.isapple())
27+
append!(_libcurl_dependencies, [libssl, libcrypto])
28+
end
29+
end
30+
2431
if Sys.iswindows()
25-
const libcurl = "libcurl-4.dll"
32+
const _libcurl_path = BundledLazyLibraryPath("libcurl-4.dll")
2633
elseif Sys.isapple()
27-
const libcurl = "@rpath/libcurl.4.dylib"
34+
const _libcurl_path = BundledLazyLibraryPath("libcurl.4.dylib")
2835
else
29-
const libcurl = "libcurl.so.4"
36+
const _libcurl_path = BundledLazyLibraryPath("libcurl.so.4")
3037
end
3138

39+
const libcurl = LazyLibrary(
40+
_libcurl_path,
41+
dependencies=_libcurl_dependencies,
42+
)
43+
44+
function eager_mode()
45+
Zlib_jll.eager_mode()
46+
nghttp2_jll.eager_mode()
47+
LibSSH2_jll.eager_mode()
48+
dlopen(libcurl)
49+
end
50+
is_available() = true
51+
3252
function __init__()
33-
global libcurl_handle = dlopen(libcurl)
34-
global libcurl_path = dlpath(libcurl_handle)
53+
global libcurl_path = string(_libcurl_path)
3554
global artifact_dir = dirname(Sys.BINDIR)
3655
LIBPATH[] = dirname(libcurl_path)
3756
push!(LIBPATH_list, LIBPATH[])
3857
end
3958

40-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
41-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
42-
# there isn't one. It instead returns the overall Julia prefix.
43-
is_available() = true
44-
find_artifact_dir() = artifact_dir
45-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
46-
best_wrapper = nothing
47-
get_libcurl_path() = libcurl_path
59+
if Base.generating_output()
60+
precompile(eager_mode, ())
61+
precompile(is_available, ())
62+
end
4863

4964
end # module LibCURL_jll

stdlib/LibGit2_jll/src/LibGit2_jll.jl

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,52 @@ if !(Sys.iswindows() || Sys.isapple())
99
using OpenSSL_jll
1010
end
1111

12-
const PATH_list = String[]
13-
const LIBPATH_list = String[]
14-
1512
export libgit2
1613

1714
# These get calculated in __init__()
1815
const PATH = Ref("")
16+
const PATH_list = String[]
1917
const LIBPATH = Ref("")
18+
const LIBPATH_list = String[]
2019
artifact_dir::String = ""
21-
libgit2_handle::Ptr{Cvoid} = C_NULL
2220
libgit2_path::String = ""
2321

2422
if Sys.iswindows()
25-
const libgit2 = "libgit2.dll"
23+
const _libgit2_path = BundledLazyLibraryPath("libgit2.dll")
2624
elseif Sys.isapple()
27-
const libgit2 = "@rpath/libgit2.1.9.dylib"
25+
const _libgit2_path = BundledLazyLibraryPath("libgit2.1.9.dylib")
26+
else
27+
const _libgit2_path = BundledLazyLibraryPath("libgit2.so.1.9")
28+
end
29+
30+
if Sys.isfreebsd()
31+
_libgit2_dependencies = LazyLibrary[]
32+
elseif Sys.islinux()
33+
_libgit2_dependencies = LazyLibrary[libssh2, libssl, libcrypto]
2834
else
29-
const libgit2 = "libgit2.so.1.9"
35+
_libgit2_dependencies = LazyLibrary[libssh2]
36+
end
37+
const libgit2 = LazyLibrary(_libgit2_path, dependencies=_libgit2_dependencies)
38+
39+
function eager_mode()
40+
LibSSH2_jll.eager_mode()
41+
@static if !(Sys.iswindows() || Sys.isapple())
42+
OpenSSL_jll.eager_mode()
43+
end
44+
dlopen(libgit2)
3045
end
46+
is_available() = true
3147

3248
function __init__()
33-
global libgit2_handle = dlopen(libgit2)
34-
global libgit2_path = dlpath(libgit2_handle)
49+
global libgit2_path = string(_libgit2_path)
3550
global artifact_dir = dirname(Sys.BINDIR)
3651
LIBPATH[] = dirname(libgit2_path)
3752
push!(LIBPATH_list, LIBPATH[])
3853
end
3954

40-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
41-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
42-
# there isn't one. It instead returns the overall Julia prefix.
43-
is_available() = true
44-
find_artifact_dir() = artifact_dir
45-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
46-
best_wrapper = nothing
47-
get_libgit2_path() = libgit2_path
55+
if Base.generating_output()
56+
precompile(eager_mode, ())
57+
precompile(is_available, ())
58+
end
4859

4960
end # module LibGit2_jll

stdlib/LibSSH2_jll/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "1.11.3+1"
66
OpenSSL_jll = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
77
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
88
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
9+
Zlib_jll = "83775a58-1f1d-513f-b197-d71354ab007a"
910

1011
[compat]
1112
julia = "1.8"

0 commit comments

Comments
 (0)