@@ -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"""
148156function 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!
@@ -585,7 +593,8 @@ function get_meta_json(
585593 dependencies:: Vector{<:AbstractDependency} ;
586594 julia_compat:: String = DEFAULT_JULIA_VERSION_SPEC,
587595 lazy_artifacts:: Bool = false ,
588- init_block:: String = " " )
596+ init_block:: String = " " ,
597+ augment_platform_block:: String = " " )
589598
590599 dict = Dict (
591600 " name" => src_name,
@@ -597,6 +606,7 @@ function get_meta_json(
597606 " julia_compat" => julia_compat,
598607 " lazy_artifacts" => lazy_artifacts,
599608 " init_block" => init_block,
609+ " augment_platform_block" => augment_platform_block,
600610 )
601611 # Do not write the list of platforms when building only for `AnyPlatform`
602612 if platforms != [AnyPlatform ()]
@@ -1024,6 +1034,7 @@ function rebuild_jll_package(obj::Dict;
10241034 lazy_artifacts = lazy_artifacts,
10251035 julia_compat = get (obj, " julia_compat" , DEFAULT_JULIA_VERSION_SPEC),
10261036 init_block = get (obj, " init_block" , " " ),
1037+ augment_platform_block = get (obj, " augment_platform_block" , " " ),
10271038 from_scratch = from_scratch,
10281039 )
10291040end
@@ -1128,7 +1139,8 @@ function build_jll_package(src_name::String,
11281139 verbose:: Bool = false ,
11291140 julia_compat:: String = DEFAULT_JULIA_VERSION_SPEC,
11301141 lazy_artifacts:: Bool = false ,
1131- init_block = " " )
1142+ init_block = " " ,
1143+ augment_platform_block = " " ,)
11321144 # Make way, for prince artifacti
11331145 mkpath (joinpath (code_dir, " src" , " wrappers" ))
11341146
@@ -1251,6 +1263,36 @@ function build_jll_package(src_name::String,
12511263 end
12521264 end
12531265
1266+ if ! isempty (augment_platform_block)
1267+ pkg_dir = joinpath (code_dir, " .pkg" )
1268+ ! ispath (pkg_dir) && mkdir (pkg_dir)
1269+ open (joinpath (pkg_dir, " platform_augmentation.jl" ), " w" ) do io
1270+ println (io, """
1271+ $(augment_platform_block)
1272+ """ )
1273+ end
1274+
1275+ open (joinpath (pkg_dir, " select_artifacts.jl" ), " w" ) do io
1276+ println (io, """
1277+ using TOML, Artifacts, Base.BinaryPlatforms
1278+ include("./platform_augmentation.jl")
1279+ artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
1280+
1281+ # Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
1282+ target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
1283+
1284+ # Augment this platform object with any special tags we require
1285+ platform = augment_platform!(HostPlatform(parse(Platform, target_triplet)))
1286+
1287+ # Select all downloadable artifacts that match that platform
1288+ artifacts = select_downloadable_artifacts(artifacts_toml; platform)
1289+
1290+ #Output the result to `stdout` as a TOML dictionary
1291+ TOML.print(stdout, artifacts)
1292+ """ )
1293+ end
1294+ end
1295+
12541296 # Generate target-demuxing main source file.
12551297 open (joinpath (code_dir, " src" , " $(src_name) _jll.jl" ), " w" ) do io
12561298 print (io, """
@@ -1262,6 +1304,14 @@ function build_jll_package(src_name::String,
12621304 if lazy_artifacts
12631305 println (io, " using LazyArtifacts" )
12641306 end
1307+
1308+ if ! isempty (augment_platform_block)
1309+ print (io, """
1310+ include(path) = Base.include(@__MODULE__, path)
1311+ include(joinpath("..", ".pkg", "platform_augmentation.jl"))
1312+ """ )
1313+ end
1314+
12651315 print (io, """
12661316 import JLLWrappers
12671317
@@ -1464,7 +1514,7 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
14641514 " deps" => Dict {String,Any} (),
14651515 # We require at least Julia 1.3+, for Pkg.Artifacts support, but we only claim
14661516 # Julia 1.0+ by default so that empty JLLs can be installed on older versions.
1467- " compat" => Dict {String,Any} (" JLLWrappers" => " 1.2 .0" ,
1517+ " compat" => Dict {String,Any} (" JLLWrappers" => " 1.4 .0" ,
14681518 " julia" => " $(julia_compat) " )
14691519 )
14701520
0 commit comments