diff --git a/Project.toml b/Project.toml index 2e957260..02e47a86 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100" Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] CEnum = "0.4" diff --git a/src/shards/JLLEnvs.jl b/src/shards/JLLEnvs.jl index 677e5aee..24be3cdf 100644 --- a/src/shards/JLLEnvs.jl +++ b/src/shards/JLLEnvs.jl @@ -3,18 +3,41 @@ module JLLEnvs using Pkg using Pkg.Artifacts using Downloads +using UUIDs include("utils.jl") const JLL_ENV_SHARDS_URL = "https://raw.githubusercontent.com/JuliaPackaging/BinaryBuilderBase.jl/master/Artifacts.toml" const JLL_ENV_SHARDS = Dict{String,Any}() +function _checked_import(pkgid) + Base.root_module_exists(pkgid) && return Base.root_module(pkgid) + Base.require(pkgid) +end + function __init__() if haskey(ENV, "JULIA_CLANG_SHARDS_URL") && !isempty(get(ENV, "JULIA_CLANG_SHARDS_URL", "")) merge!(JLL_ENV_SHARDS, Artifacts.load_artifacts_toml(ENV["JULIA_CLANG_SHARDS_URL"])) - else - merge!(JLL_ENV_SHARDS, Artifacts.load_artifacts_toml(Downloads.download(JLL_ENV_SHARDS_URL))) + return end + + # If possible, try to load stable version of Artifacts.toml from local disk cache and thus + # makes `using Clang` faster. This requires `BinaryBuilderBase` available in `DEPOT_PATH`, + # e.g., via `(@v1.7) pkg> add BinaryBuilderBase`. + id_BinaryBuilderBase = Base.PkgId(UUID("7f725544-6523-48cd-82d1-3fa08ff4056e"), "BinaryBuilderBase") + artifact_file = "" + try + artifact_file = joinpath(pkgdir(_checked_import(id_BinaryBuilderBase)), "Artifacts.toml") + catch e + @debug e + end + if isfile(artifact_file) + merge!(JLL_ENV_SHARDS, Artifacts.load_artifacts_toml(artifact_file)) + end + isempty(JLL_ENV_SHARDS) || return + + @debug "Failed to load package `BinaryBuilderBase`, fetching from remote resources..." + merge!(JLL_ENV_SHARDS, Artifacts.load_artifacts_toml(Downloads.download(JLL_ENV_SHARDS_URL))) end const JLL_ENV_HOST_TRIPLE = "x86_64-linux-musl"