Skip to content

Commit 01bcdef

Browse files
vchuravymaleadt
authored andcommitted
Support augment_platform in BB
1 parent a174790 commit 01bcdef

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

src/AutoBuild.jl

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,18 @@ supported ones. A few additional keyword arguments are accept:
140140
package. This can for example be used to invoke an initialization API of a
141141
shared library.
142142
143+
* `augment_platform_block` may be set to a string containing Julia code; if
144+
present, this code will be inserted into the top-level of the
145+
generated JLL package. It must define a function `augment_platform!` that takes
146+
as a single argument, the target platform and returns the target platform, with
147+
amended tags. This augmented platform will then be used by the JLL wrapper to select
148+
the artifact.
149+
143150
!!! note
144151
145-
The `init_block` keyword argument is experimental and may be removed
146-
in a future version of this package. Please use it sparingly.
152+
The `init_block` and `augment_platform_block` keyword arguments are experimental
153+
and may be removed in a future version of this package. Please use it sparingly.
154+
147155
"""
148156
function build_tarballs(ARGS, src_name, src_version, sources, script,
149157
platforms, products, dependencies;
@@ -304,7 +312,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
304312
# Dependencies that must be downloaded
305313
dependencies,
306314
)
307-
extra_kwargs = extract_kwargs(kwargs, (:lazy_artifacts, :init_block))
315+
extra_kwargs = extract_kwargs(kwargs, (:lazy_artifacts, :init_block, :augment_platform_block))
308316

309317
if meta_json_stream !== nothing
310318
# If they've asked for the JSON metadata, by all means, give it to them!
@@ -596,7 +604,8 @@ function get_meta_json(
596604
dependencies::Vector{<:AbstractDependency};
597605
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
598606
lazy_artifacts::Bool = false,
599-
init_block::String = "")
607+
init_block::String = "",
608+
augment_platform_block::String = "")
600609

601610
dict = Dict(
602611
"name" => src_name,
@@ -608,6 +617,7 @@ function get_meta_json(
608617
"julia_compat" => julia_compat,
609618
"lazy_artifacts" => lazy_artifacts,
610619
"init_block" => init_block,
620+
"augment_platform_block" => augment_platform_block,
611621
)
612622
# Do not write the list of platforms when building only for `AnyPlatform`
613623
if platforms != [AnyPlatform()]
@@ -1063,6 +1073,7 @@ function rebuild_jll_package(obj::Dict;
10631073
lazy_artifacts = lazy_artifacts,
10641074
julia_compat = get(obj, "julia_compat", DEFAULT_JULIA_VERSION_SPEC),
10651075
init_block = get(obj, "init_block", ""),
1076+
augment_platform_block = get(obj, "augment_platform_block", ""),
10661077
from_scratch = from_scratch,
10671078
)
10681079
end
@@ -1167,7 +1178,8 @@ function build_jll_package(src_name::String,
11671178
verbose::Bool = false,
11681179
julia_compat::String = DEFAULT_JULIA_VERSION_SPEC,
11691180
lazy_artifacts::Bool = false,
1170-
init_block = "")
1181+
init_block = "",
1182+
augment_platform_block = "",)
11711183
# Make way, for prince artifacti
11721184
mkpath(joinpath(code_dir, "src", "wrappers"))
11731185

@@ -1290,6 +1302,36 @@ function build_jll_package(src_name::String,
12901302
end
12911303
end
12921304

1305+
if !isempty(augment_platform_block)
1306+
pkg_dir = joinpath(code_dir, ".pkg")
1307+
!ispath(pkg_dir) && mkdir(pkg_dir)
1308+
open(joinpath(pkg_dir, "platform_augmentation.jl"), "w") do io
1309+
println(io, """
1310+
$(augment_platform_block)
1311+
""")
1312+
end
1313+
1314+
open(joinpath(pkg_dir, "select_artifacts.jl"), "w") do io
1315+
println(io, """
1316+
using TOML, Artifacts, Base.BinaryPlatforms
1317+
include("./platform_augmentation.jl")
1318+
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
1319+
1320+
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
1321+
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
1322+
1323+
# Augment this platform object with any special tags we require
1324+
platform = augment_platform!(HostPlatform(parse(Platform, target_triplet)))
1325+
1326+
# Select all downloadable artifacts that match that platform
1327+
artifacts = select_downloadable_artifacts(artifacts_toml; platform)
1328+
1329+
#Output the result to `stdout` as a TOML dictionary
1330+
TOML.print(stdout, artifacts)
1331+
""")
1332+
end
1333+
end
1334+
12931335
# Generate target-demuxing main source file.
12941336
open(joinpath(code_dir, "src", "$(src_name)_jll.jl"), "w") do io
12951337
print(io, """
@@ -1301,6 +1343,14 @@ function build_jll_package(src_name::String,
13011343
if lazy_artifacts
13021344
println(io, "using LazyArtifacts")
13031345
end
1346+
1347+
if !isempty(augment_platform_block)
1348+
print(io, """
1349+
include(path) = Base.include(@__MODULE__, path)
1350+
include(joinpath("..", ".pkg", "platform_augmentation.jl"))
1351+
""")
1352+
end
1353+
13041354
print(io, """
13051355
import JLLWrappers
13061356
@@ -1503,7 +1553,7 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
15031553
"deps" => Dict{String,Any}(),
15041554
# We require at least Julia 1.3+, for Pkg.Artifacts support, but we only claim
15051555
# Julia 1.0+ by default so that empty JLLs can be installed on older versions.
1506-
"compat" => Dict{String,Any}("JLLWrappers" => "1.2.0",
1556+
"compat" => Dict{String,Any}("JLLWrappers" => "1.4.0",
15071557
"julia" => "$(julia_compat)")
15081558
)
15091559

test/basic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ end
199199
@test dict["name"] == "$(name)_jll"
200200
@test dict["version"] == "1.0.0"
201201
@test dict["uuid"] == "8fcd9439-76b0-55f4-a525-bad0597c05d8"
202-
@test dict["compat"] == Dict{String,Any}("julia" => "1.0", "JLLWrappers" => "1.2.0")
202+
@test dict["compat"] == Dict{String,Any}("julia" => "1.0", "JLLWrappers" => "1.4.0")
203203
@test all(in.(
204204
(
205205
"Pkg" => "44cfe95a-1eb2-52ea-b672-e2afdf69b78f",
@@ -224,10 +224,10 @@ end
224224

225225
# Ensure passing a Julia dependency bound works
226226
dict = build_project_dict(name, version, dependencies, "1.4")
227-
@test dict["compat"] == Dict{String,Any}("julia" => "1.4", "JLLWrappers" => "1.2.0")
227+
@test dict["compat"] == Dict{String,Any}("julia" => "1.4", "JLLWrappers" => "1.4.0")
228228

229229
dict = build_project_dict(name, version, dependencies, "~1.4")
230-
@test dict["compat"] == Dict{String,Any}("julia" => "~1.4", "JLLWrappers" => "1.2.0")
230+
@test dict["compat"] == Dict{String,Any}("julia" => "~1.4", "JLLWrappers" => "1.4.0")
231231

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

test/jll.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module TestJLL end
2424
"Scratch" => "6c6a2e73-6563-6170-7368-637461726353")
2525
@test project["name"] == "LibFoo_jll"
2626
@test project["uuid"] == "b250f842-3251-58d3-8ee4-9a24ab2bab3f"
27-
@test project["compat"] == Dict("julia" => "1.0", "XZ_jll" => "=2.4.6", "JLLWrappers" => "1.2.0")
27+
@test project["compat"] == Dict("julia" => "1.0", "XZ_jll" => "=2.4.6", "JLLWrappers" => "1.4.0")
2828
@test project["version"] == "1.3.5"
2929
# Make sure BuildDependency's don't find their way to the project
3030
@test_throws MethodError build_project_dict("LibFoo", v"1.3.5", [Dependency("Zlib_jll"), BuildDependency("Xorg_util_macros_jll")])

0 commit comments

Comments
 (0)