Skip to content

Convert more stdlibs to LazyLibraries #58405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions stdlib/LLVMLibUnwind_jll/src/LLVMLibUnwind_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,28 @@
baremodule LLVMLibUnwind_jll
using Base, Libdl

const PATH_list = String[]
const LIBPATH_list = String[]

export llvmlibunwind

# These get calculated in __init__()
const PATH = Ref("")
const PATH_list = String[]
const LIBPATH = Ref("")
const LIBPATH_list = String[]
artifact_dir::String = ""
llvmlibunwind_handle::Ptr{Cvoid} = C_NULL
llvmlibunwind_path::String = ""

const llvmlibunwind = "libunwind"
const _llvmlibunwind_path = BundledLazyLibraryPath("libunwind")
const llvmlibunwind = LazyLibrary(_llvmlibunwind_path)
function eager_mode()
dlopen(llvmlibunwind)
end
is_available() = @static Sys.isapple() ? true : false

function __init__()
# We only dlopen something on MacOS
@static if Sys.isapple()
global llvmlibunwind_handle = dlopen(llvmlibunwind)
global llvmlibunwind_path = dlpath(llvmlibunwind_handle)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(llvmlibunwind_path)
push!(LIBPATH_list, LIBPATH[])
end
global llvmlibunwind_path = string(_llvmlibunwind_path)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(llvmlibunwind_path)
push!(LIBPATH_list, LIBPATH[])
end

# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
# there isn't one. It instead returns the overall Julia prefix.
is_available() = @static Sys.isapple() ? true : false
find_artifact_dir() = artifact_dir
dev_jll() = error("stdlib JLLs cannot be dev'ed")
best_wrapper = nothing
get_llvmlibunwind_path() = llvmlibunwind_path

end # module LLVMLibUnwind_jll
18 changes: 8 additions & 10 deletions stdlib/LLVMLibUnwind_jll/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Test, Libdl
using LLVMLibUnwind_jll: llvmlibunwind_handle

using Test, Libdl, LLVMLibUnwind_jll
@testset "LLVMLibUnwind_jll" begin
if Sys.isapple()
@test dlsym(llvmlibunwind_handle, :unw_getcontext; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_init_local; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_init_local_dwarf; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_step; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_get_reg; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_set_reg; throw_error=false) !== nothing
@test dlsym(llvmlibunwind_handle, :unw_resume; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_getcontext; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_init_local; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_init_local_dwarf; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_step; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_get_reg; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_set_reg; throw_error=false) !== nothing
@test dlsym(llvmlibunwind, :unw_resume; throw_error=false) !== nothing
end
end
41 changes: 23 additions & 18 deletions stdlib/LibCURL_jll/src/LibCURL_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,46 @@ if !(Sys.iswindows() || Sys.isapple())
using OpenSSL_jll
end

const PATH_list = String[]
const LIBPATH_list = String[]

export libcurl

# These get calculated in __init__()
const PATH = Ref("")
const PATH_list = String[]
const LIBPATH = Ref("")
const LIBPATH_list = String[]
artifact_dir::String = ""
libcurl_handle::Ptr{Cvoid} = C_NULL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm slightly worried about with this move is that we lose the handle. Some time ago I wanted to use the libblastrampoline handle in a package, and realised that's gone, so I resorted to dlopening libblastrampoline again. Rest looks good to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it is a slight change in internal API but I think it’s worth it, so that all users of handle-based operations must flow through the dlopen interface to allow for lazy loading

libcurl_path::String = ""

_libcurl_dependencies = LazyLibrary[
libz, libnghttp2, libssh2
]
if Sys.iswindows()
const libcurl = "libcurl-4.dll"
const _libcurl_path = BundledLazyLibraryPath("libcurl-4.dll")
elseif Sys.isapple()
const libcurl = "@rpath/libcurl.4.dylib"
const _libcurl_path = BundledLazyLibraryPath("libcurl.4.dylib")
else
const libcurl = "libcurl.so.4"
const _libcurl_path = BundledLazyLibraryPath("libcurl.so.4")
append!(_libcurl_dependencies, [libssl, libcrypto])
end

const libcurl = LazyLibrary(
_libcurl_path,
dependencies=_libcurl_dependencies,
)

function eager_mode()
Zlib_jll.eager_mode()
nghttp2_jll.eager_mode()
LibSSH2_jll.eager_mode()
dlopen(libcurl)
end
is_available() = true

function __init__()
global libcurl_handle = dlopen(libcurl)
global libcurl_path = dlpath(libcurl_handle)
global libcurl_path = string(_libcurl_path)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(libcurl_path)
push!(LIBPATH_list, LIBPATH[])
end

# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
# there isn't one. It instead returns the overall Julia prefix.
is_available() = true
find_artifact_dir() = artifact_dir
dev_jll() = error("stdlib JLLs cannot be dev'ed")
best_wrapper = nothing
get_libcurl_path() = libcurl_path

end # module LibCURL_jll
37 changes: 19 additions & 18 deletions stdlib/LibGit2_jll/src/LibGit2_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,42 @@ if !(Sys.iswindows() || Sys.isapple())
using OpenSSL_jll
end

const PATH_list = String[]
const LIBPATH_list = String[]

export libgit2

# These get calculated in __init__()
const PATH = Ref("")
const PATH_list = String[]
const LIBPATH = Ref("")
const LIBPATH_list = String[]
artifact_dir::String = ""
libgit2_handle::Ptr{Cvoid} = C_NULL
libgit2_path::String = ""

_libgit2_dependencies = LazyLibrary[libssh2]
if Sys.iswindows()
const libgit2 = "libgit2.dll"
const _libgit2_path = BundledLazyLibraryPath("libgit2.dll")
elseif Sys.isapple()
const libgit2 = "@rpath/libgit2.1.9.dylib"
const _libgit2_path = BundledLazyLibraryPath("libgit2.1.9.dylib")
else
const libgit2 = "libgit2.so.1.9"
const _libgit2_path = BundledLazyLibraryPath("libgit2.so.1.9")
append!(_libgit2_dependencies, [libcrypto, libssl])
end

const libgit2 = LazyLibrary(_libgit2_path, dependencies=_libgit2_dependencies)

function eager_mode()
LibSSH2_jll.eager_mode()
@static if !(Sys.iswindows() || Sys.isapple())
OpenSSL_jll.eager_mode()
end
dlopen(libgit2)
end
is_available() = true

function __init__()
global libgit2_handle = dlopen(libgit2)
global libgit2_path = dlpath(libgit2_handle)
global libgit2_path = string(_libgit2_path)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(libgit2_path)
push!(LIBPATH_list, LIBPATH[])
end

# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
# there isn't one. It instead returns the overall Julia prefix.
is_available() = true
find_artifact_dir() = artifact_dir
dev_jll() = error("stdlib JLLs cannot be dev'ed")
best_wrapper = nothing
get_libgit2_path() = libgit2_path

end # module LibGit2_jll
36 changes: 19 additions & 17 deletions stdlib/LibSSH2_jll/src/LibSSH2_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,38 @@ if !Sys.iswindows()
using OpenSSL_jll
end

const PATH_list = String[]
const LIBPATH_list = String[]

export libssh2

# These get calculated in __init__()
const PATH = Ref("")
const PATH_list = String[]
const LIBPATH = Ref("")
const LIBPATH_list = String[]
artifact_dir::String = ""
libssh2_handle::Ptr{Cvoid} = C_NULL
libssh2_path::String = ""


_libssh2_dependencies = LazyLibrary[]
if Sys.iswindows()
const libssh2 = "libssh2.dll"
const _libssh2_path = BundledLazyLibraryPath("libssh2.dll")
elseif Sys.isapple()
const libssh2 = "@rpath/libssh2.1.dylib"
const _libssh2_path = BundledLazyLibraryPath("libssh2.1.dylib")
push!(_libssh2_dependencies, libcrypto)
else
const libssh2 = "libssh2.so.1"
const _libssh2_path = BundledLazyLibraryPath("libssh2.so.1")
push!(_libssh2_dependencies, libcrypto)
end

const libssh2 = LazyLibrary(_libssh2_path, dependencies=_libssh2_dependencies)

function eager_mode()
@static if !Sys.iswindows()
OpenSSL_jll.eager_mode()
end
dlopen(libssh2)
end
is_available() = true

function __init__()
global libssh2_handle = dlopen(libssh2)
global libssh2_path = dlpath(libssh2_handle)
Expand All @@ -37,14 +49,4 @@ function __init__()
push!(LIBPATH_list, LIBPATH[])
end


# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
# there isn't one. It instead returns the overall Julia prefix.
is_available() = true
find_artifact_dir() = artifact_dir
dev_jll() = error("stdlib JLLs cannot be dev'ed")
best_wrapper = nothing
get_libssh2_path() = libssh2_path

end # module LibSSH2_jll
4 changes: 3 additions & 1 deletion stdlib/LibUnwind_jll/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ uuid = "745a5e78-f969-53e9-954f-d19f2f74f4e3"
version = "1.8.1+2"

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

[compat]
julia = "1.6"
Expand Down
41 changes: 19 additions & 22 deletions stdlib/LibUnwind_jll/src/LibUnwind_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,36 @@

baremodule LibUnwind_jll
using Base, Libdl

const PATH_list = String[]
const LIBPATH_list = String[]
using CompilerSupportLibraries_jll
using Zlib_jll

export libunwind

# These get calculated in __init__()
const PATH = Ref("")
const PATH_list = String[]
const LIBPATH = Ref("")
const LIBPATH_list = String[]
artifact_dir::String = ""
libunwind_handle::Ptr{Cvoid} = C_NULL
libunwind_path::String = ""

const libunwind = "libunwind.so.8"
const _libunwind_path = BundledLazyLibraryPath("libunwind.so.8")
const libunwind = LazyLibrary(
_libunwind_path, dependencies=[libgcc_s, libz]
)

function __init__()
# We only do something on Linux/FreeBSD
@static if Sys.islinux() || Sys.isfreebsd()
global libunwind_handle = dlopen(libunwind)
global libunwind_path = dlpath(libunwind_handle)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(libunwind_path)
push!(LIBPATH_list, LIBPATH[])
end
function eager_mode()
CompilerSupportLibraries_jll.eager_mode()
Zlib_jll.eager_mode()
dlopen(libunwind)
end
is_available() = @static(Sys.islinux() || Sys.isfreebsd()) ? true : false

# JLLWrappers API compatibility shims. Note that not all of these will really make sense.
# For instance, `find_artifact_dir()` won't actually be the artifact directory, because
# there isn't one. It instead returns the overall Julia prefix.
is_available() = @static (Sys.islinux() || Sys.isfreebsd()) ? true : false
find_artifact_dir() = artifact_dir
dev_jll() = error("stdlib JLLs cannot be dev'ed")
best_wrapper = nothing
get_libunwind_path() = libunwind_path
function __init__()
global libunwind_path = string(_libunwind_path)
global artifact_dir = dirname(Sys.BINDIR)
LIBPATH[] = dirname(libunwind_path)
push!(LIBPATH_list, LIBPATH[])
end

end # module LibUnwind_jll
2 changes: 1 addition & 1 deletion stdlib/LibUnwind_jll/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ using Test, Libdl, LibUnwind_jll

@testset "LibUnwind_jll" begin
if !Sys.isapple() && !Sys.iswindows()
@test dlsym(LibUnwind_jll.libunwind_handle, :unw_backtrace; throw_error=false) !== nothing
@test dlsym(LibUnwind_jll.libunwind, :unw_backtrace; throw_error=false) !== nothing
end
end
3 changes: 1 addition & 2 deletions stdlib/OpenBLAS_jll/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.29+0"

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

[compat]
julia = "1.11"
Expand Down
2 changes: 1 addition & 1 deletion stdlib/OpenBLAS_jll/src/OpenBLAS_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## dummy stub for https://github.com/JuliaBinaryWrappers/OpenBLAS_jll.jl
baremodule OpenBLAS_jll
using Base, Libdl, Base.BinaryPlatforms
using Base, Libdl
using CompilerSupportLibraries_jll

export libopenblas
Expand Down
Loading