diff --git a/src/JLLWrappers.jl b/src/JLLWrappers.jl index d885b77..2040335 100644 --- a/src/JLLWrappers.jl +++ b/src/JLLWrappers.jl @@ -8,6 +8,8 @@ if VERSION >= v"1.6.0-DEV" using Preferences end +const global_typeassert_available = VERSION >= v"1.8.0" + # We need to glue expressions together a lot function excat(exs::Union{Expr,Nothing}...) ex = Expr(:block) diff --git a/src/products/executable_generators.jl b/src/products/executable_generators.jl index 105f990..55d323a 100644 --- a/src/products/executable_generators.jl +++ b/src/products/executable_generators.jl @@ -22,15 +22,19 @@ function declare_old_executable_product(product_name) JLLWrappers.withenv_executable_wrapper, f, $(Symbol("$(product_name)_path")), - PATH[], - LIBPATH[], + @static($global_typeassert_available ? PATH : PATH[]), + @static($global_typeassert_available ? LIBPATH : LIBPATH[]), adjust_PATH, adjust_LIBPATH, ) end - # This will eventually be replaced with a `Ref{String}` - $(path_name) = "" + + @static if $global_typeassert_available + $(path_name)::Union{String,Nothing} = "" + else + $(path_name) = "" + end function $(Symbol(string("get_", product_name, "_path")))() return $(path_name)::String end @@ -61,8 +65,8 @@ function declare_new_executable_product(product_name) env = Base.invokelatest( JLLWrappers.adjust_ENV!, copy(ENV), - PATH[], - LIBPATH[], + @static($global_typeassert_available ? PATH : PATH[]), + @static($global_typeassert_available ? LIBPATH : LIBPATH[]), adjust_PATH, adjust_LIBPATH, ) diff --git a/src/products/file_generators.jl b/src/products/file_generators.jl index 844c8cf..54ae748 100644 --- a/src/products/file_generators.jl +++ b/src/products/file_generators.jl @@ -3,8 +3,13 @@ macro declare_file_product(product_name) path_name = Symbol(string(product_name, "_path")) return esc(quote # These will be filled in by init_file_product(). - $(path_name) = $(emit_preference_path_load(string(product_name, "_path"))) - $(product_name) = "" + @static if $global_typeassert_available + $(product_name) = "" + $(path_name) = $(emit_preference_path_load(string(product_name, "_path"))) + else + $(product_name)::String = "" + $(path_name)::Union{Nothing,String} = $(emit_preference_path_load(string(product_name, "_path"))) + end function $(get_path_name)() return $(path_name)::String end diff --git a/src/products/library_generators.jl b/src/products/library_generators.jl index 4603c06..6a1c877 100644 --- a/src/products/library_generators.jl +++ b/src/products/library_generators.jl @@ -10,15 +10,24 @@ macro declare_library_product(product_name, product_soname) else lib_declaration = quote # On Julia 1.6+, this doesn't have to be `const`! Thanks Jeff! - $(product_name) = "" + @static if $global_typeassert_available + $(product_name)::String = "" + else + $(product_name) = "" + end end end - + return excat( quote # These will be filled in by init_library_product() - $(handle_name) = C_NULL - $(path_name) = $(emit_preference_path_load(string(product_name, "_path"))) + @static if $global_typeassert_available + $(handle_name)::Ptr{Cvoid} = C_NULL + $(path_name)::Union{Nothing,String} = $(emit_preference_path_load(string(product_name, "_path"))) + else + $(handle_name) = C_NULL + $(path_name) = $(emit_preference_path_load(string(product_name, "_path"))) + end function $(get_path_name)() return $(path_name)::String end diff --git a/src/toplevel_generators.jl b/src/toplevel_generators.jl index 16aef54..2ef04d4 100644 --- a/src/toplevel_generators.jl +++ b/src/toplevel_generators.jl @@ -82,8 +82,13 @@ function generate_toplevel_definitions(src_name, __source__) """ function is_available end - const PATH = Ref{String}("") - const LIBPATH = Ref{String}("") + @static if $global_typeassert_available + PATH::String = "" + LIBPATH::String = "" + else + const PATH = Ref{String}("") + const LIBPATH = Ref{String}("") + end # We put these inter-JLL-package API values here so that they are always defined, even if there # is no underlying wrapper held within this JLL package. const PATH_list = String[] @@ -115,7 +120,11 @@ function generate_wrapper_load(src_name, pkg_uuid, __source__) end return quote - global best_wrapper + @static if $global_typeassert_available + global best_wrapper::Union{Nothing,String} + else + global best_wrapper + end # Load Artifacts.toml file and select best platform at compile-time, since this is # running at toplevel, and therefore will be run completely at compile-time. We use # a `let` block here to avoid storing unnecessary data in our `.ji` files @@ -197,6 +206,7 @@ macro generate_main_file_header(src_name) generate_compiler_options(src_name), # import Artifacts module generate_imports(src_name), + global_typeassert_available ? :(global artifact_dir::String) : :() ) end diff --git a/src/wrapper_generators.jl b/src/wrapper_generators.jl index 3be7f20..f694948 100644 --- a/src/wrapper_generators.jl +++ b/src/wrapper_generators.jl @@ -47,8 +47,13 @@ macro generate_init_footer() # Filter out duplicate and empty entries in our PATH and LIBPATH entries unique!(PATH_list) unique!(LIBPATH_list) - PATH[] = join(PATH_list, $(pathsep)) - LIBPATH[] = join(vcat(LIBPATH_list, Base.invokelatest(JLLWrappers.get_julia_libpaths))::Vector{String}, $(pathsep)) + @static if $global_typeassert_available + global PATH = join(PATH_list, $(pathsep)) + global LIBPATH = join(vcat(LIBPATH_list, Base.invokelatest(JLLWrappers.get_julia_libpaths))::Vector{String}, $(pathsep)) + else + PATH[] = join(PATH_list, $(pathsep)) + LIBPATH[] = join(vcat(LIBPATH_list, Base.invokelatest(JLLWrappers.get_julia_libpaths))::Vector{String}, $(pathsep)) + end end) end diff --git a/test/runtests.jl b/test/runtests.jl index 8309b2c..18ca2e3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,8 +40,13 @@ module TestJLL end @test isfile(@eval TestJLL Vulkan_Headers_jll.get_vulkan_hpp_path()) end @test isdir(@eval TestJLL Vulkan_Headers_jll.artifact_dir) - @test isempty(@eval TestJLL Vulkan_Headers_jll.PATH[]) - @test occursin(Sys.BINDIR, @eval TestJLL Vulkan_Headers_jll.LIBPATH[]) + if JLLWrappers.global_typeassert_available + @test isempty(@eval TestJLL Vulkan_Headers_jll.PATH) + @test occursin(Sys.BINDIR, @eval TestJLL Vulkan_Headers_jll.LIBPATH) + else + @test isempty(@eval TestJLL Vulkan_Headers_jll.PATH[]) + @test occursin(Sys.BINDIR, @eval TestJLL Vulkan_Headers_jll.LIBPATH[]) + end # Package with an ExecutableProduct Pkg.develop(PackageSpec(path=joinpath(@__DIR__, "HelloWorldC_jll"))) @@ -54,8 +59,13 @@ module TestJLL end @test isfile(@eval TestJLL HelloWorldC_jll.hello_world_path) @test isfile(@eval TestJLL HelloWorldC_jll.get_hello_world_path()) @test isdir(@eval TestJLL HelloWorldC_jll.artifact_dir) - @test !isempty(@eval TestJLL HelloWorldC_jll.PATH[]) - @test occursin(Sys.BINDIR, @eval TestJLL HelloWorldC_jll.LIBPATH[]) + if JLLWrappers.global_typeassert_available + @test !isempty(@eval TestJLL HelloWorldC_jll.PATH) + @test occursin(Sys.BINDIR, @eval TestJLL HelloWorldC_jll.LIBPATH) + else + @test !isempty(@eval TestJLL HelloWorldC_jll.PATH[]) + @test occursin(Sys.BINDIR, @eval TestJLL HelloWorldC_jll.LIBPATH[]) + end @test !isfile(@eval TestJLL HelloWorldC_jll.goodbye_world_path) @test !isfile(@eval TestJLL HelloWorldC_jll.get_goodbye_world_path()) @static if VERSION >= v"1.6.0-DEV" @@ -73,8 +83,13 @@ module TestJLL end @test isfile(@eval TestJLL OpenLibm_jll.libopenlibm_path) @test isfile(@eval TestJLL OpenLibm_jll.get_libopenlibm_path()) @test isdir(@eval TestJLL OpenLibm_jll.artifact_dir) - @test isempty(@eval TestJLL OpenLibm_jll.PATH[]) - @test occursin(Sys.BINDIR, @eval TestJLL OpenLibm_jll.LIBPATH[]) + if JLLWrappers.global_typeassert_available + @test isempty(@eval TestJLL OpenLibm_jll.PATH) + @test occursin(Sys.BINDIR, @eval TestJLL OpenLibm_jll.LIBPATH) + else + @test isempty(@eval TestJLL OpenLibm_jll.PATH[]) + @test occursin(Sys.BINDIR, @eval TestJLL OpenLibm_jll.LIBPATH[]) + end @test C_NULL == @eval TestJLL OpenLibm_jll.libnonexisting_handle @static if VERSION >= v"1.6.0-DEV" @@ -101,9 +116,13 @@ module TestJLL end @test @eval TestJLL LAMMPS_jll.abi == (Sys.iswindows() ? :MicrosoftMPI : :MPICH) @test isfile(@eval TestJLL LAMMPS_jll.liblammps_path) @test isfile(@eval TestJLL LAMMPS_jll.get_liblammps_path()) - @test isdir(@eval TestJLL LAMMPS_jll.artifact_dir) - @test occursin(Sys.BINDIR, @eval TestJLL LAMMPS_jll.LIBPATH[]) + @test isdir(@eval TestJLL LAMMPS_jll.artifact_dir) + if JLLWrappers.global_typeassert_available + @test occursin(Sys.BINDIR, @eval TestJLL LAMMPS_jll.LIBPATH) + else + @test occursin(Sys.BINDIR, @eval TestJLL LAMMPS_jll.LIBPATH[]) + end artifact_dir = @eval TestJLL LAMMPS_jll.artifact_dir if !Sys.iswindows()