Skip to content

Commit 0eca8c5

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 0eca8c5

File tree

13 files changed

+152
-175
lines changed

13 files changed

+152
-175
lines changed

stdlib/LLVMLibUnwind_jll/src/LLVMLibUnwind_jll.jl

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,28 @@
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
41-
4232
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: 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/LibUnwind_jll/test/runtests.jl

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

55
@testset "LibUnwind_jll" begin
66
if !Sys.isapple() && !Sys.iswindows()
7-
@test dlsym(LibUnwind_jll.libunwind_handle, :unw_backtrace; throw_error=false) !== nothing
7+
@test dlsym(LibUnwind_jll.libunwind, :unw_backtrace; throw_error=false) !== nothing
88
end
99
end

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

0 commit comments

Comments
 (0)