Skip to content

Commit 796e560

Browse files
committed
Fix switching tags on 1.7 and 1.6 in general
1 parent 5bfbed2 commit 796e560

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/toplevel_generators.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function generate_imports(src_name)
4141
using Libdl, Artifacts, JLLWrappers.Preferences, Base.BinaryPlatforms
4242
using Artifacts: load_artifacts_toml, unpack_platform
4343
using Base.BinaryPlatforms: triplet, select_platform
44+
import Pkg
4445
if !@isdefined(augment_platform!)
4546
augment_platform!(platform) = platform
4647
end
@@ -170,6 +171,12 @@ function generate_wrapper_load(src_name, pkg_uuid, __source__)
170171
end
171172
end
172173

174+
if VERSION >= v"1.6"
175+
function ensure_artifact_installed(platform=host_platform)
176+
Pkg.Artifacts.ensure_artifact_installed($(src_name), joinpath($(pkg_dir), "..", "Artifacts.toml"); platform=platform, pkg_uuid=$(pkg_uuid))
177+
end
178+
end
179+
173180
# Load in the wrapper, if it's not `nothing`!
174181
if best_wrapper === nothing
175182
@debug(string("Unable to load ", $(src_name), "; unsupported platform ", triplet(host_platform)))

src/wrapper_generators.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ macro generate_wrapper_header(src_name)
2020
return $(artifact_expr)
2121
end
2222
end
23+
function find_or_instantiate_artifact_dir()
24+
@static if VERSION < v"1.6"
25+
return find_artifact_dir()
26+
else
27+
try
28+
return find_artifact_dir()
29+
catch
30+
# 1.6 does not call `.pkg/select_artifacts.jl`
31+
# 1.7+ User might switch the tag, without calling `Pkg.instantiate()`
32+
ensure_artifact_installed(host_platform)
33+
return find_artifact_dir()
34+
end
35+
end
36+
end
2337
end)
2438
end
2539

@@ -37,7 +51,7 @@ macro generate_init_header(dependencies...)
3751

3852
return excat(
3953
# This either calls `@artifact_str()`, or returns a constant string if we're overridden.
40-
:(global artifact_dir = find_artifact_dir()),
54+
:(global artifact_dir = find_or_instantiate_artifact_dir()),
4155

4256
# Initialize PATH_list and LIBPATH_list
4357
deps_path_add...,

0 commit comments

Comments
 (0)