@@ -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!
@@ -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 )
10681079end
@@ -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
0 commit comments