Skip to content

Commit

Permalink
feat(JLLEnvs): try to load local Artifacts.toml if existed
Browse files Browse the repository at this point in the history
This commit provides two changes:

- By default, use the stable release version of `Artifacts.toml` provided by
  binarybuilderbase. previously it uses the master version, which can sometimes
  be breaking and troublesome.
- it utilizes the local disk cache and thus pkg server so that we don't need to
  fetch resources from GitHub.com and thus is more friendly to users behind the
  firewall.

As a consequence of getting rid of the need to download from remote server,
this commit makes `@time using Clang` much faster: from 1.7s to 0.4s in Julia
1.7, macOS Intel i9-9880H.
  • Loading branch information
johnnychen94 committed Jan 31, 2022
1 parent 007b171 commit d28f558
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 25 additions & 2 deletions src/shards/JLLEnvs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d28f558

Please sign in to comment.