Skip to content

Commit b28bb8d

Browse files
committed
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.
1 parent b319a95 commit b28bb8d

File tree

10 files changed

+131
-142
lines changed

10 files changed

+131
-142
lines changed

stdlib/LibCURL_jll/src/LibCURL_jll.jl

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,46 @@ 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[
23+
libz, libnghttp2, libssh2
24+
]
2425
if Sys.iswindows()
25-
const libcurl = "libcurl-4.dll"
26+
const _libcurl_path = BundledLazyLibraryPath("libcurl-4.dll")
2627
elseif Sys.isapple()
27-
const libcurl = "@rpath/libcurl.4.dylib"
28+
const _libcurl_path = BundledLazyLibraryPath("libcurl.4.dylib")
2829
else
29-
const libcurl = "libcurl.so.4"
30+
const _libcurl_path = BundledLazyLibraryPath("libcurl.so.4")
31+
append!(_libcurl_dependencies, [libssl, libcrypto])
3032
end
3133

34+
const libcurl = LazyLibrary(
35+
_libcurl_path,
36+
dependencies=_libcurl_dependencies,
37+
)
38+
39+
function eager_mode()
40+
Zlib_jll.eager_mode()
41+
nghttp2_jll.eager_mode()
42+
LibSSH2_jll.eager_mode()
43+
dlopen(libcurl)
44+
end
45+
is_available() = true
46+
3247
function __init__()
33-
global libcurl_handle = dlopen(libcurl)
34-
global libcurl_path = dlpath(libcurl_handle)
48+
global libcurl_path = string(_libcurl_path)
3549
global artifact_dir = dirname(Sys.BINDIR)
3650
LIBPATH[] = dirname(libcurl_path)
3751
push!(LIBPATH_list, LIBPATH[])
3852
end
3953

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
48-
4954
end # module LibCURL_jll

stdlib/LibGit2_jll/src/LibGit2_jll.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,42 @@ 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

22+
_libgit2_dependencies = LazyLibrary[libssh2]
2423
if Sys.iswindows()
25-
const libgit2 = "libgit2.dll"
24+
const _libgit2_path = BundledLazyLibraryPath("libgit2.dll")
2625
elseif Sys.isapple()
27-
const libgit2 = "@rpath/libgit2.1.9.dylib"
26+
const _libgit2_path = BundledLazyLibraryPath("libgit2.1.9.dylib")
2827
else
29-
const libgit2 = "libgit2.so.1.9"
28+
const _libgit2_path = BundledLazyLibraryPath("libgit2.so.1.9")
29+
append!(_libgit2_dependencies, [libcrypto, libssl])
3030
end
3131

32+
const libgit2 = LazyLibrary(_libgit2_path, dependencies=_libgit2_dependencies)
33+
34+
function eager_mode()
35+
LibSSH2_jll.eager_mode()
36+
@static if !(Sys.iswindows() || Sys.isapple())
37+
OpenSSL_jll.eager_mode()
38+
end
39+
dlopen(libgit2)
40+
end
41+
is_available() = true
42+
3243
function __init__()
33-
global libgit2_handle = dlopen(libgit2)
34-
global libgit2_path = dlpath(libgit2_handle)
44+
global libgit2_path = string(_libgit2_path)
3545
global artifact_dir = dirname(Sys.BINDIR)
3646
LIBPATH[] = dirname(libgit2_path)
3747
push!(LIBPATH_list, LIBPATH[])
3848
end
3949

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
48-
4950
end # module LibGit2_jll

stdlib/LibSSH2_jll/src/LibSSH2_jll.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,38 @@ if !Sys.iswindows()
99
using OpenSSL_jll
1010
end
1111

12-
const PATH_list = String[]
13-
const LIBPATH_list = String[]
14-
1512
export libssh2
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-
libssh2_handle::Ptr{Cvoid} = C_NULL
2220
libssh2_path::String = ""
2321

22+
23+
_libssh2_dependencies = LazyLibrary[]
2424
if Sys.iswindows()
25-
const libssh2 = "libssh2.dll"
25+
const _libssh2_path = BundledLazyLibraryPath("libssh2.dll")
2626
elseif Sys.isapple()
27-
const libssh2 = "@rpath/libssh2.1.dylib"
27+
const _libssh2_path = BundledLazyLibraryPath("libssh2.1.dylib")
28+
push!(_libssh2_dependencies, libcrypto)
2829
else
29-
const libssh2 = "libssh2.so.1"
30+
const _libssh2_path = BundledLazyLibraryPath("libssh2.so.1")
31+
push!(_libssh2_dependencies, libcrypto)
3032
end
3133

34+
const libssh2 = LazyLibrary(_libssh2_path, dependencies=_libssh2_dependencies)
35+
36+
function eager_mode()
37+
@static if !Sys.iswindows()
38+
OpenSSL_jll.eager_mode()
39+
end
40+
dlopen(libssh2)
41+
end
42+
is_available() = true
43+
3244
function __init__()
3345
global libssh2_handle = dlopen(libssh2)
3446
global libssh2_path = dlpath(libssh2_handle)
@@ -37,14 +49,4 @@ function __init__()
3749
push!(LIBPATH_list, LIBPATH[])
3850
end
3951

40-
41-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
42-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
43-
# there isn't one. It instead returns the overall Julia prefix.
44-
is_available() = true
45-
find_artifact_dir() = artifact_dir
46-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
47-
best_wrapper = nothing
48-
get_libssh2_path() = libssh2_path
49-
5052
end # module LibSSH2_jll

stdlib/LibUnwind_jll/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ uuid = "745a5e78-f969-53e9-954f-d19f2f74f4e3"
33
version = "1.8.1+2"
44

55
[deps]
6-
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
76
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
7+
CompilerSupportLibraries_jll = "e66e0078-7015-5450-92f7-15fbd957f2ae"
8+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
9+
Zlib_jll = "83775a58-1f1d-513f-b197-d71354ab007a"
810

911
[compat]
1012
julia = "1.6"

stdlib/LibUnwind_jll/src/LibUnwind_jll.jl

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,36 @@
44

55
baremodule LibUnwind_jll
66
using Base, Libdl
7-
8-
const PATH_list = String[]
9-
const LIBPATH_list = String[]
7+
using CompilerSupportLibraries_jll
8+
using Zlib_jll
109

1110
export libunwind
1211

1312
# These get calculated in __init__()
1413
const PATH = Ref("")
14+
const PATH_list = String[]
1515
const LIBPATH = Ref("")
16+
const LIBPATH_list = String[]
1617
artifact_dir::String = ""
17-
libunwind_handle::Ptr{Cvoid} = C_NULL
1818
libunwind_path::String = ""
1919

20-
const libunwind = "libunwind.so.8"
20+
const _libunwind_path = BundledLazyLibraryPath("libunwind.so.8")
21+
const libunwind = LazyLibrary(
22+
_libunwind_path, dependencies=[libgcc_s, libz]
23+
)
2124

22-
function __init__()
23-
# We only do something on Linux/FreeBSD
24-
@static if Sys.islinux() || Sys.isfreebsd()
25-
global libunwind_handle = dlopen(libunwind)
26-
global libunwind_path = dlpath(libunwind_handle)
27-
global artifact_dir = dirname(Sys.BINDIR)
28-
LIBPATH[] = dirname(libunwind_path)
29-
push!(LIBPATH_list, LIBPATH[])
30-
end
25+
function eager_mode()
26+
CompilerSupportLibraries_jll.eager_mode()
27+
Zlib_jll.eager_mode()
28+
dlopen(libunwind)
3129
end
30+
is_available() = @static(Sys.islinux() || Sys.isfreebsd()) ? true : false
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.islinux() || Sys.isfreebsd()) ? true : false
37-
find_artifact_dir() = artifact_dir
38-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
39-
best_wrapper = nothing
40-
get_libunwind_path() = libunwind_path
32+
function __init__()
33+
global libunwind_path = string(_libunwind_path)
34+
global artifact_dir = dirname(Sys.BINDIR)
35+
LIBPATH[] = dirname(libunwind_path)
36+
push!(LIBPATH_list, LIBPATH[])
37+
end
4138

4239
end # module LibUnwind_jll

stdlib/OpenBLAS_jll/Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
33
version = "0.3.29+0"
44

55
[deps]
6-
# See note in `src/OpenBLAS_jll.jl` about this dependency.
6+
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
77
CompilerSupportLibraries_jll = "e66e0078-7015-5450-92f7-15fbd957f2ae"
88
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
9-
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
109

1110
[compat]
1211
julia = "1.11"

stdlib/OpenBLAS_jll/src/OpenBLAS_jll.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## dummy stub for https://github.com/JuliaBinaryWrappers/OpenBLAS_jll.jl
44
baremodule OpenBLAS_jll
5-
using Base, Libdl, Base.BinaryPlatforms
5+
using Base, Libdl
66
using CompilerSupportLibraries_jll
77

88
export libopenblas

stdlib/OpenSSL_jll/src/OpenSSL_jll.jl

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,48 @@
55
baremodule OpenSSL_jll
66
using Base, Libdl, Base.BinaryPlatforms
77

8-
const PATH_list = String[]
9-
const LIBPATH_list = String[]
10-
118
export libcrypto, libssl
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-
libcrypto_handle::Ptr{Cvoid} = C_NULL
1816
libcrypto_path::String = ""
19-
libssl_handle::Ptr{Cvoid} = C_NULL
2017
libssl_path::String = ""
2118

2219
if Sys.iswindows()
2320
if arch(HostPlatform()) == "x86_64"
24-
const libcrypto = "libcrypto-3-x64.dll"
25-
const libssl = "libssl-3-x64.dll"
21+
const _libcrypto_path = BundledLazyLibraryPath("libcrypto-3-x64.dll")
22+
const _libssl_path = BundledLazyLibraryPath("libssl-3-x64.dll")
2623
else
27-
const libcrypto = "libcrypto-3.dll"
28-
const libssl = "libssl-3.dll"
24+
const _libcrypto_path = BundledLazyLibraryPath("libcrypto-3.dll")
25+
const _libssl_path = BundledLazyLibraryPath("libssl-3.dll")
2926
end
3027
elseif Sys.isapple()
31-
const libcrypto = "@rpath/libcrypto.3.dylib"
32-
const libssl = "@rpath/libssl.3.dylib"
28+
const _libcrypto_path = BundledLazyLibraryPath("libcrypto.3.dylib")
29+
const _libssl_path = BundledLazyLibraryPath("libssl.3.dylib")
3330
else
34-
const libcrypto = "libcrypto.so.3"
35-
const libssl = "libssl.so.3"
31+
const _libcrypto_path = BundledLazyLibraryPath("libcrypto.so.3")
32+
const _libssl_path = BundledLazyLibraryPath("libssl.so.3")
3633
end
3734

35+
const libcrypto = LazyLibrary(_libcrypto_path)
36+
const libssl = LazyLibrary(_libssl_path, dependencies=[libcrypto])
37+
38+
function eager_mode()
39+
dlopen(libcrypto)
40+
dlopen(libssl)
41+
end
42+
is_available() = true
43+
3844
function __init__()
39-
global libcrypto_handle = dlopen(libcrypto)
40-
global libcrypto_path = dlpath(libcrypto_handle)
41-
global libssl_handle = dlopen(libssl)
42-
global libssl_path = dlpath(libssl_handle)
45+
global libcrypto_path = string(_libcrypto_path)
46+
global libssl_path = string(_libssl_path)
4347
global artifact_dir = dirname(Sys.BINDIR)
4448
LIBPATH[] = dirname(libssl_path)
4549
push!(LIBPATH_list, LIBPATH[])
4650
end
4751

48-
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
49-
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
50-
# there isn't one. It instead returns the overall Julia prefix.
51-
is_available() = true
52-
find_artifact_dir() = artifact_dir
53-
dev_jll() = error("stdlib JLLs cannot be dev'ed")
54-
best_wrapper = nothing
55-
get_libcrypto_path() = libcrypto_path
56-
get_libssl_path() = libssl_path
57-
5852
end # module OpenSSL_jll

0 commit comments

Comments
 (0)