Skip to content

Commit e945cb7

Browse files
vchuravymaleadtgiordano
authored
Support augment_platform in BB (#1128)
Co-authored-by: Tim Besard <tim.besard@gmail.com> Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent 1795408 commit e945cb7

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

src/AutoBuild.jl

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import LibGit2
77
import PkgLicenses
88

99
const DEFAULT_JULIA_VERSION_SPEC = "1.0"
10+
const DEFAULT_JLLWRAPPERS_VERSION_SPEC = "1.2.0"
1011
const PKG_VERSIONS = Base.VERSION >= v"1.7-" ? Pkg.Versions : Pkg.Types
1112

1213
mutable struct BuildTimer
@@ -140,10 +141,19 @@ supported ones. A few additional keyword arguments are accept:
140141
package. This can for example be used to invoke an initialization API of a
141142
shared library.
142143
144+
* `augment_platform_block` may be set to a string containing Julia code; if
145+
present, this code will be inserted into the top-level of the
146+
generated JLL package. It must define a function `augment_platform!` that
147+
takes as a single argument, the target platform and returns the target
148+
platform, with amended tags. This augmented platform will then be used by the
149+
JLL wrapper to select the artifact. Note that this option requires the Julia
150+
compatibility `julia_compat` to be 1.6 or higher.
151+
143152
!!! note
144153
145-
The `init_block` keyword argument is experimental and may be removed
146-
in a future version of this package. Please use it sparingly.
154+
The `init_block` and `augment_platform_block` keyword arguments are experimental
155+
and may be removed in a future version of this package. Please use them sparingly.
156+
147157
"""
148158
function build_tarballs(ARGS, src_name, src_version, sources, script,
149159
platforms, products, dependencies;
@@ -304,7 +314,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
304314
# Dependencies that must be downloaded
305315
dependencies,
306316
)
307-
extra_kwargs = extract_kwargs(kwargs, (:lazy_artifacts, :init_block))
317+
extra_kwargs = extract_kwargs(kwargs, (:lazy_artifacts, :init_block, :augment_platform_block))
308318

309319
if meta_json_stream !== nothing
310320
# If they've asked for the JSON metadata, by all means, give it to them!
@@ -523,7 +533,13 @@ function register_jll(name, build_version, dependencies, julia_compat;
523533
gh_auth=Wizard.github_auth(;allow_anonymous=false),
524534
gh_username=gh_get_json(DEFAULT_API, "/user"; auth=gh_auth)["login"],
525535
lazy_artifacts::Bool=false,
536+
augment_platform_block="",
526537
kwargs...)
538+
if !isempty(augment_platform_block) &&
539+
minimum(VersionNumber(rng.lower.t) for rng in PKG_VERSIONS.semver_spec(julia_compat).ranges) < v"1.6"
540+
error("Augmentation blocks cannot be used with Julia v1.5-.\nChange `julia_compat` to require at least Julia v1.6")
541+
end
542+
527543
# Calculate tree hash of wrapper code
528544
wrapper_tree_hash = bytes2hex(Pkg.GitTools.tree_hash(code_dir))
529545
wrapper_commit_hash = LibGit2.head(code_dir)
@@ -533,7 +549,8 @@ function register_jll(name, build_version, dependencies, julia_compat;
533549
cache = RegistryTools.RegistryCache(joinpath(Pkg.depots1(), "registries_binarybuilder"))
534550
registry_url = "https://$(gh_username):$(gh_auth.token)@github.com/JuliaRegistries/General"
535551
cache.registries[registry_url] = Base.UUID("23338594-aafe-5451-b93e-139f81909106")
536-
project = Pkg.Types.Project(build_project_dict(name, build_version, dependencies, julia_compat; lazy_artifacts=lazy_artifacts))
552+
jllwrappers_compat = isempty(augment_platform_block) ? DEFAULT_JLLWRAPPERS_VERSION_SPEC : "1.4.0"
553+
project = Pkg.Types.Project(build_project_dict(name, build_version, dependencies, julia_compat; jllwrappers_compat, lazy_artifacts=lazy_artifacts))
537554
errors = setdiff(RegistryTools.registrator_errors, [:version_less_than_all_existing])
538555
reg_branch = RegistryTools.register(
539556
"https://github.com/$(deploy_repo).git",
@@ -596,7 +613,8 @@ function get_meta_json(
596613
dependencies::Vector{<:AbstractDependency};
597614
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
598615
lazy_artifacts::Bool = false,
599-
init_block::String = "")
616+
init_block::String = "",
617+
augment_platform_block::String = "")
600618

601619
dict = Dict(
602620
"name" => src_name,
@@ -608,6 +626,7 @@ function get_meta_json(
608626
"julia_compat" => julia_compat,
609627
"lazy_artifacts" => lazy_artifacts,
610628
"init_block" => init_block,
629+
"augment_platform_block" => augment_platform_block,
611630
)
612631
# Do not write the list of platforms when building only for `AnyPlatform`
613632
if platforms != [AnyPlatform()]
@@ -1063,6 +1082,7 @@ function rebuild_jll_package(obj::Dict;
10631082
lazy_artifacts = lazy_artifacts,
10641083
julia_compat = get(obj, "julia_compat", DEFAULT_JULIA_VERSION_SPEC),
10651084
init_block = get(obj, "init_block", ""),
1085+
augment_platform_block = get(obj, "augment_platform_block", ""),
10661086
from_scratch = from_scratch,
10671087
)
10681088
end
@@ -1167,7 +1187,8 @@ function build_jll_package(src_name::String,
11671187
verbose::Bool = false,
11681188
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
11691189
lazy_artifacts::Bool = false,
1170-
init_block = "")
1190+
init_block = "",
1191+
augment_platform_block = "",)
11711192
# Make way, for prince artifacti
11721193
mkpath(joinpath(code_dir, "src", "wrappers"))
11731194

@@ -1290,6 +1311,38 @@ function build_jll_package(src_name::String,
12901311
end
12911312
end
12921313

1314+
if !isempty(augment_platform_block)
1315+
pkg_dir = joinpath(code_dir, ".pkg")
1316+
!ispath(pkg_dir) && mkdir(pkg_dir)
1317+
open(joinpath(pkg_dir, "platform_augmentation.jl"), "w") do io
1318+
println(io, """
1319+
$(augment_platform_block)
1320+
""")
1321+
end
1322+
1323+
open(joinpath(pkg_dir, "select_artifacts.jl"), "w") do io
1324+
println(io, """
1325+
push!(Base.LOAD_PATH, dirname(@__DIR__))
1326+
1327+
using TOML, Artifacts, Base.BinaryPlatforms
1328+
include("./platform_augmentation.jl")
1329+
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
1330+
1331+
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
1332+
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
1333+
1334+
# Augment this platform object with any special tags we require
1335+
platform = augment_platform!(HostPlatform(parse(Platform, target_triplet)))
1336+
1337+
# Select all downloadable artifacts that match that platform
1338+
artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true)
1339+
1340+
#Output the result to `stdout` as a TOML dictionary
1341+
TOML.print(stdout, artifacts)
1342+
""")
1343+
end
1344+
end
1345+
12931346
# Generate target-demuxing main source file.
12941347
open(joinpath(code_dir, "src", "$(src_name)_jll.jl"), "w") do io
12951348
print(io, """
@@ -1301,6 +1354,13 @@ function build_jll_package(src_name::String,
13011354
if lazy_artifacts
13021355
println(io, "using LazyArtifacts")
13031356
end
1357+
1358+
if !isempty(augment_platform_block)
1359+
print(io, """
1360+
Base.include(@__MODULE__, joinpath("..", ".pkg", "platform_augmentation.jl"))
1361+
""")
1362+
end
1363+
13041364
print(io, """
13051365
import JLLWrappers
13061366
@@ -1429,7 +1489,8 @@ function build_jll_package(src_name::String,
14291489

14301490
# Add a Project.toml. Note: here we list _all_ runtime dependencies, including those
14311491
# that may be required only for some platforms.
1432-
project = build_project_dict(src_name, build_version, dependencies, julia_compat; lazy_artifacts=lazy_artifacts)
1492+
jllwrappers_compat = isempty(augment_platform_block) ? "1.2.0" : "1.4.0"
1493+
project = build_project_dict(src_name, build_version, dependencies, julia_compat; lazy_artifacts=lazy_artifacts, jllwrappers_compat)
14331494
open(joinpath(code_dir, "Project.toml"), "w") do io
14341495
Pkg.TOML.print(io, project)
14351496
end
@@ -1502,7 +1563,12 @@ function find_uuid(ctx, pkg)
15021563
""")
15031564
end
15041565

1505-
function build_project_dict(name, version, dependencies::Array{Dependency}, julia_compat::String=DEFAULT_JULIA_VERSION_SPEC; lazy_artifacts::Bool=false, kwargs...)
1566+
function build_project_dict(name, version, dependencies::Array{Dependency},
1567+
julia_compat::String=DEFAULT_JULIA_VERSION_SPEC;
1568+
jllwrappers_compat::String=DEFAULT_JLLWRAPPERS_VERSION_SPEC,
1569+
lazy_artifacts::Bool=false,
1570+
augment_platform_block="",
1571+
kwargs...)
15061572
Pkg.Types.semver_spec(julia_compat) # verify julia_compat is valid
15071573
project = Dict(
15081574
"name" => "$(name)_jll",
@@ -1511,7 +1577,7 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
15111577
"deps" => Dict{String,Any}(),
15121578
# We require at least Julia 1.3+, for Pkg.Artifacts support, but we only claim
15131579
# Julia 1.0+ by default so that empty JLLs can be installed on older versions.
1514-
"compat" => Dict{String,Any}("JLLWrappers" => "1.2.0",
1580+
"compat" => Dict{String,Any}("JLLWrappers" => "$(jllwrappers_compat)",
15151581
"julia" => "$(julia_compat)")
15161582
)
15171583

@@ -1538,6 +1604,9 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
15381604
if lazy_artifacts
15391605
project["deps"]["LazyArtifacts"] = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
15401606
end
1607+
if !isempty(augment_platform_block)
1608+
project["deps"]["TOML"] = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1609+
end
15411610

15421611
return project
15431612
end

test/basic.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ end
231231

232232
@test_throws ErrorException build_project_dict(name, version, dependencies, "nonsense")
233233

234+
# Ensure passing a JLLWrappers dependency bound works
235+
dict = build_project_dict(name, version, dependencies; jllwrappers_compat="1.4.0")
236+
@test dict["compat"] == Dict{String,Any}("julia" => "1.0", "JLLWrappers" => "1.4.0")
237+
234238
# Ensure passing compat bounds works
235239
dependencies = [
236240
Dependency(PackageSpec(name="libLLVM_jll"), compat="=9.0.0"),

0 commit comments

Comments
 (0)