diff --git a/src/JLLWrappers.jl b/src/JLLWrappers.jl index d885b77..0cfb94b 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.9.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..cceffe6 100644 --- a/src/products/executable_generators.jl +++ b/src/products/executable_generators.jl @@ -29,8 +29,12 @@ function declare_old_executable_product(product_name) ) 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 diff --git a/src/products/file_generators.jl b/src/products/file_generators.jl index 844c8cf..60c8602 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)::String = "" + $(path_name)::Union{Nothing,String} = $(emit_preference_path_load(string(product_name, "_path"))) + else + $(product_name) = "" + $(path_name) = $(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 bb02eae..7295d37 100644 --- a/src/toplevel_generators.jl +++ b/src/toplevel_generators.jl @@ -115,7 +115,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 +201,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