@@ -7,6 +7,7 @@ import LibGit2
7
7
import PkgLicenses
8
8
9
9
const DEFAULT_JULIA_VERSION_SPEC = " 1.0"
10
+ const DEFAULT_JLLWRAPPERS_VERSION_SPEC = " 1.2.0"
10
11
const PKG_VERSIONS = Base. VERSION >= v " 1.7-" ? Pkg. Versions : Pkg. Types
11
12
12
13
mutable struct BuildTimer
@@ -140,10 +141,19 @@ supported ones. A few additional keyword arguments are accept:
140
141
package. This can for example be used to invoke an initialization API of a
141
142
shared library.
142
143
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
+
143
152
!!! note
144
153
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
+
147
157
"""
148
158
function build_tarballs (ARGS , src_name, src_version, sources, script,
149
159
platforms, products, dependencies;
@@ -304,7 +314,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
304
314
# Dependencies that must be downloaded
305
315
dependencies,
306
316
)
307
- extra_kwargs = extract_kwargs (kwargs, (:lazy_artifacts , :init_block ))
317
+ extra_kwargs = extract_kwargs (kwargs, (:lazy_artifacts , :init_block , :augment_platform_block ))
308
318
309
319
if meta_json_stream != = nothing
310
320
# 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;
523
533
gh_auth= Wizard. github_auth (;allow_anonymous= false ),
524
534
gh_username= gh_get_json (DEFAULT_API, " /user" ; auth= gh_auth)[" login" ],
525
535
lazy_artifacts:: Bool = false ,
536
+ augment_platform_block= " " ,
526
537
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-.\n Change `julia_compat` to require at least Julia v1.6" )
541
+ end
542
+
527
543
# Calculate tree hash of wrapper code
528
544
wrapper_tree_hash = bytes2hex (Pkg. GitTools. tree_hash (code_dir))
529
545
wrapper_commit_hash = LibGit2. head (code_dir)
@@ -533,7 +549,8 @@ function register_jll(name, build_version, dependencies, julia_compat;
533
549
cache = RegistryTools. RegistryCache (joinpath (Pkg. depots1 (), " registries_binarybuilder" ))
534
550
registry_url = " https://$(gh_username) :$(gh_auth. token) @github.com/JuliaRegistries/General"
535
551
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))
537
554
errors = setdiff (RegistryTools. registrator_errors, [:version_less_than_all_existing ])
538
555
reg_branch = RegistryTools. register (
539
556
" https://github.com/$(deploy_repo) .git" ,
@@ -596,7 +613,8 @@ function get_meta_json(
596
613
dependencies:: Vector{<:AbstractDependency} ;
597
614
julia_compat:: String = DEFAULT_JULIA_VERSION_SPEC,
598
615
lazy_artifacts:: Bool = false ,
599
- init_block:: String = " " )
616
+ init_block:: String = " " ,
617
+ augment_platform_block:: String = " " )
600
618
601
619
dict = Dict (
602
620
" name" => src_name,
@@ -608,6 +626,7 @@ function get_meta_json(
608
626
" julia_compat" => julia_compat,
609
627
" lazy_artifacts" => lazy_artifacts,
610
628
" init_block" => init_block,
629
+ " augment_platform_block" => augment_platform_block,
611
630
)
612
631
# Do not write the list of platforms when building only for `AnyPlatform`
613
632
if platforms != [AnyPlatform ()]
@@ -1063,6 +1082,7 @@ function rebuild_jll_package(obj::Dict;
1063
1082
lazy_artifacts = lazy_artifacts,
1064
1083
julia_compat = get (obj, " julia_compat" , DEFAULT_JULIA_VERSION_SPEC),
1065
1084
init_block = get (obj, " init_block" , " " ),
1085
+ augment_platform_block = get (obj, " augment_platform_block" , " " ),
1066
1086
from_scratch = from_scratch,
1067
1087
)
1068
1088
end
@@ -1167,7 +1187,8 @@ function build_jll_package(src_name::String,
1167
1187
verbose:: Bool = false ,
1168
1188
julia_compat:: String = DEFAULT_JULIA_VERSION_SPEC,
1169
1189
lazy_artifacts:: Bool = false ,
1170
- init_block = " " )
1190
+ init_block = " " ,
1191
+ augment_platform_block = " " ,)
1171
1192
# Make way, for prince artifacti
1172
1193
mkpath (joinpath (code_dir, " src" , " wrappers" ))
1173
1194
@@ -1290,6 +1311,38 @@ function build_jll_package(src_name::String,
1290
1311
end
1291
1312
end
1292
1313
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
+
1293
1346
# Generate target-demuxing main source file.
1294
1347
open (joinpath (code_dir, " src" , " $(src_name) _jll.jl" ), " w" ) do io
1295
1348
print (io, """
@@ -1301,6 +1354,13 @@ function build_jll_package(src_name::String,
1301
1354
if lazy_artifacts
1302
1355
println (io, " using LazyArtifacts" )
1303
1356
end
1357
+
1358
+ if ! isempty (augment_platform_block)
1359
+ print (io, """
1360
+ Base.include(@__MODULE__, joinpath("..", ".pkg", "platform_augmentation.jl"))
1361
+ """ )
1362
+ end
1363
+
1304
1364
print (io, """
1305
1365
import JLLWrappers
1306
1366
@@ -1429,7 +1489,8 @@ function build_jll_package(src_name::String,
1429
1489
1430
1490
# Add a Project.toml. Note: here we list _all_ runtime dependencies, including those
1431
1491
# 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)
1433
1494
open (joinpath (code_dir, " Project.toml" ), " w" ) do io
1434
1495
Pkg. TOML. print (io, project)
1435
1496
end
@@ -1502,7 +1563,12 @@ function find_uuid(ctx, pkg)
1502
1563
""" )
1503
1564
end
1504
1565
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... )
1506
1572
Pkg. Types. semver_spec (julia_compat) # verify julia_compat is valid
1507
1573
project = Dict (
1508
1574
" name" => " $(name) _jll" ,
@@ -1511,7 +1577,7 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
1511
1577
" deps" => Dict {String,Any} (),
1512
1578
# We require at least Julia 1.3+, for Pkg.Artifacts support, but we only claim
1513
1579
# 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) " ,
1515
1581
" julia" => " $(julia_compat) " )
1516
1582
)
1517
1583
@@ -1538,6 +1604,9 @@ function build_project_dict(name, version, dependencies::Array{Dependency}, juli
1538
1604
if lazy_artifacts
1539
1605
project[" deps" ][" LazyArtifacts" ] = " 4af54fe1-eca0-43a8-85a7-787d91b784e3"
1540
1606
end
1607
+ if ! isempty (augment_platform_block)
1608
+ project[" deps" ][" TOML" ] = " fa267f1f-6049-4f14-aa54-33bafae1ed76"
1609
+ end
1541
1610
1542
1611
return project
1543
1612
end
0 commit comments