Skip to content

Commit 1afe38a

Browse files
staticfloatgiordano
authored andcommitted
Convert more stdlibs to LazyLibraries. Add tests for dep tree.
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. Adds tests that audits the expressed library dependencies in our LazyLibrary JLL definitions, to ensure that we don't get out of sync with the actual binaries. Co-Authored-By: Mosè Giordano <[email protected]> Co-Authored-By: Elliot Saba <[email protected]>
1 parent f8ece05 commit 1afe38a

File tree

35 files changed

+722
-413
lines changed

35 files changed

+722
-413
lines changed

stdlib/CompilerSupportLibraries_jll/src/CompilerSupportLibraries_jll.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ 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]
67+
68+
_libgfortran_deps = [libgcc_s]
6869
if @isdefined _libquadmath_path
6970
const libquadmath = LazyLibrary(_libquadmath_path)
70-
push!(libgfortran_deps, libquadmath)
71+
push!(_libgfortran_deps, libquadmath)
7172
end
72-
const libgfortran = LazyLibrary(_libgfortran_path, dependencies=libgfortran_deps)
73-
const libstdcxx = LazyLibrary(_libstdcxx_path, dependencies=[libgcc_s])
73+
74+
const libgfortran = LazyLibrary(_libgfortran_path, dependencies=_libgfortran_deps)
75+
76+
_libstdcxx_dependencies = LazyLibrary[libgcc_s]
77+
const libstdcxx = LazyLibrary(_libstdcxx_path, dependencies=_libstdcxx_dependencies)
78+
7479
const libgomp = LazyLibrary(_libgomp_path)
7580

7681
# Some installations (such as those from-source) may not have `libssp`
@@ -116,4 +121,9 @@ function __init__()
116121
push!(LIBPATH_list, LIBPATH[])
117122
end
118123

124+
if Base.generating_output()
125+
precompile(eager_mode, ())
126+
precompile(is_available, ())
127+
end
128+
119129
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")
21+
elseif Sys.isapple()
22+
const _libgmp_path = BundledLazyLibraryPath("libgmp.10.dylib")
23+
const _libgmpxx_path = BundledLazyLibraryPath("libgmpxx.4.dylib")
24+
else
25+
const _libgmp_path = BundledLazyLibraryPath("libgmp.so.10")
26+
const _libgmpxx_path = BundledLazyLibraryPath("libgmpxx.so.4")
27+
end
28+
29+
const libgmp = LazyLibrary(_libgmp_path)
30+
31+
if Sys.isfreebsd()
32+
_libgmpxx_dependencies = LazyLibrary[libgmp, libgcc_s]
2433
elseif Sys.isapple()
25-
const libgmp = "@rpath/libgmp.10.dylib"
26-
const libgmpxx = "@rpath/libgmpxx.4.dylib"
34+
_libgmpxx_dependencies = LazyLibrary[libgmp]
2735
else
28-
const libgmp = "libgmp.so.10"
29-
const libgmpxx = "libgmpxx.so.4"
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)
3047
end
48+
is_available() = true
3149

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: 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 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+
_libcurl_dependencies = LazyLibrary[libz, libnghttp2, libssh2]
23+
if !(Sys.iswindows() || Sys.isapple())
24+
append!(_libcurl_dependencies, [libssl, libcrypto])
25+
end
26+
2427
if Sys.iswindows()
25-
const libcurl = "libcurl-4.dll"
28+
const _libcurl_path = BundledLazyLibraryPath("libcurl-4.dll")
2629
elseif Sys.isapple()
27-
const libcurl = "@rpath/libcurl.4.dylib"
30+
const _libcurl_path = BundledLazyLibraryPath("libcurl.4.dylib")
2831
else
29-
const libcurl = "libcurl.so.4"
32+
const _libcurl_path = BundledLazyLibraryPath("libcurl.so.4")
3033
end
3134

35+
const libcurl = LazyLibrary(
36+
_libcurl_path,
37+
dependencies=_libcurl_dependencies,
38+
)
39+
40+
function eager_mode()
41+
Zlib_jll.eager_mode()
42+
nghttp2_jll.eager_mode()
43+
LibSSH2_jll.eager_mode()
44+
dlopen(libcurl)
45+
end
46+
is_available() = true
47+
3248
function __init__()
33-
global libcurl_handle = dlopen(libcurl)
34-
global libcurl_path = dlpath(libcurl_handle)
49+
global libcurl_path = string(_libcurl_path)
3550
global artifact_dir = dirname(Sys.BINDIR)
3651
LIBPATH[] = dirname(libcurl_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_libcurl_path() = libcurl_path
55+
if Base.generating_output()
56+
precompile(eager_mode, ())
57+
precompile(is_available, ())
58+
end
4859

4960
end # module LibCURL_jll

stdlib/LibGit2_jll/src/LibGit2_jll.jl

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,50 @@ 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[libssh2, libssl, libcrypto]
2832
else
29-
const libgit2 = "libgit2.so.1.9"
33+
_libgit2_dependencies = LazyLibrary[libssh2]
34+
end
35+
const libgit2 = LazyLibrary(_libgit2_path, dependencies=_libgit2_dependencies)
36+
37+
function eager_mode()
38+
LibSSH2_jll.eager_mode()
39+
@static if !(Sys.iswindows() || Sys.isapple())
40+
OpenSSL_jll.eager_mode()
41+
end
42+
dlopen(libgit2)
3043
end
44+
is_available() = true
3145

3246
function __init__()
33-
global libgit2_handle = dlopen(libgit2)
34-
global libgit2_path = dlpath(libgit2_handle)
47+
global libgit2_path = string(_libgit2_path)
3548
global artifact_dir = dirname(Sys.BINDIR)
3649
LIBPATH[] = dirname(libgit2_path)
3750
push!(LIBPATH_list, LIBPATH[])
3851
end
3952

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
53+
if Base.generating_output()
54+
precompile(eager_mode, ())
55+
precompile(is_available, ())
56+
end
4857

4958
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)