Skip to content

Commit 084d75b

Browse files
authored
[AutoBuild] Implement platform-dependent dependencies in JLLs (#1129)
* [AutoBuild] Implement platform-dependent dependencies in JLLs * Add a test for platform-dependent dependencies in the generated JLL
1 parent 35c373a commit 084d75b

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

Manifest.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
2828

2929
[[BinaryBuilderBase]]
3030
deps = ["CodecZlib", "Downloads", "InteractiveUtils", "JSON", "LibGit2", "Libdl", "Logging", "OutputCollectors", "Pkg", "Random", "SHA", "Scratch", "SimpleBufferStream", "TOML", "Tar", "UUIDs", "p7zip_jll", "pigz_jll"]
31-
git-tree-sha1 = "9f3b1dcfdd68214851417aded5f159557b4f27b7"
31+
git-tree-sha1 = "66c3eb2778203fb29254cfa1ba5a780c528f389f"
3232
repo-rev = "master"
3333
repo-url = "https://github.com/JuliaPackaging/BinaryBuilderBase.jl.git"
3434
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
35-
version = "1.1.0"
35+
version = "1.2.0"
3636

3737
[[CodecZlib]]
3838
deps = ["TranscodingStreams", "Zlib_jll"]
@@ -42,9 +42,9 @@ version = "0.7.0"
4242

4343
[[Compat]]
4444
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
45-
git-tree-sha1 = "dce3e3fea680869eaa0b774b2e8343e9ff442313"
45+
git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582"
4646
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
47-
version = "3.40.0"
47+
version = "3.41.0"
4848

4949
[[DataAPI]]
5050
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
@@ -53,9 +53,9 @@ version = "1.9.0"
5353

5454
[[DataStructures]]
5555
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
56-
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02"
56+
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
5757
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
58-
version = "0.18.10"
58+
version = "0.18.11"
5959

6060
[[DataValueInterfaces]]
6161
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
@@ -252,9 +252,9 @@ version = "0.1.0"
252252

253253
[[Parsers]]
254254
deps = ["Dates"]
255-
git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc"
255+
git-tree-sha1 = "d7fa6237da8004be601e19bd6666083056649918"
256256
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
257-
version = "2.1.2"
257+
version = "2.1.3"
258258

259259
[[Pidfile]]
260260
deps = ["FileWatching", "Test"]
@@ -309,15 +309,15 @@ version = "1.2.9"
309309

310310
[[RegistryTools]]
311311
deps = ["AutoHashEquals", "LibGit2", "Pkg", "SHA", "UUIDs"]
312-
git-tree-sha1 = "e5bc4ecbdd55f030b9f2644aa4a625f34a868ea0"
312+
git-tree-sha1 = "7ba3c65d4f40a399e5a2f0ec5abc89de871604e5"
313313
uuid = "d1eb7eb1-105f-429d-abf5-b0f65cb9e2c4"
314-
version = "1.6.0"
314+
version = "1.7.0"
315315

316316
[[Requires]]
317317
deps = ["UUIDs"]
318-
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
318+
git-tree-sha1 = "8f82019e525f4d5c669692772a6f4b0a58b06a6a"
319319
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
320-
version = "1.1.3"
320+
version = "1.2.0"
321321

322322
[[SHA]]
323323
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
@@ -375,9 +375,9 @@ version = "1.0.1"
375375

376376
[[Tables]]
377377
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
378-
git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0"
378+
git-tree-sha1 = "bb1064c9a84c52e277f1096cf41434b675cd368b"
379379
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
380-
version = "1.6.0"
380+
version = "1.6.1"
381381

382382
[[Tar]]
383383
deps = ["ArgTools", "SHA"]

src/AutoBuild.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
256256
# If the user passed in a platform (or a few, comma-separated) on the
257257
# command-line, use that instead of our default platforms
258258
if length(ARGS) > 0
259-
parse_platform(p::AbstractString) = p == "any" ? AnyPlatform() : parse(Platform, p; validate_strict=true)
260-
platforms = parse_platform.(split(ARGS[1], ","))
259+
platforms = BinaryBuilderBase.parse_platform.(split(ARGS[1], ","))
261260
end
262261

263262
# Check to make sure we have the necessary environment stuff
@@ -713,8 +712,10 @@ function autobuild(dir::AbstractString,
713712
default_host_platform;
714713
verbose=verbose,
715714
)
716-
host_artifact_paths = setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in dependencies if is_host_dependency(d)], default_host_platform; verbose=verbose)
717-
target_artifact_paths = setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in dependencies if is_target_dependency(d)], concrete_platform; verbose=verbose)
715+
setup_deps(f, prefix, dependencies, platform, verbose) =
716+
setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in filter_platforms(dependencies, platform) if f(d)], platform; verbose)
717+
host_artifact_paths = setup_deps(is_host_dependency, prefix, dependencies, default_host_platform, verbose)
718+
target_artifact_paths = setup_deps(is_target_dependency, prefix, dependencies, concrete_platform, verbose)
718719

719720
# Create a runner to work inside this workspace with the nonce built-in
720721
ur = preferred_runner()(
@@ -1162,7 +1163,7 @@ function build_jll_package(src_name::String,
11621163
export $(join(sort(variable_name.(first.(collect(products_info)))), ", "))
11631164
""")
11641165
end
1165-
for dep in dependencies
1166+
for dep in filter_platforms(dependencies, platform)
11661167
println(io, "using $(getname(dep))")
11671168
end
11681169

@@ -1193,7 +1194,7 @@ function build_jll_package(src_name::String,
11931194

11941195
print(io, """
11951196
function __init__()
1196-
JLLWrappers.@generate_init_header($(join(getname.(dependencies), ", ")))
1197+
JLLWrappers.@generate_init_header($(join(getname.(filter_platforms(dependencies, platform)), ", ")))
11971198
""")
11981199

11991200
for (p, p_info) in sort(products_info)
@@ -1284,7 +1285,7 @@ function build_jll_package(src_name::String,
12841285
# In this case we can easily add a direct link to the repo
12851286
println(io, "* [`", depname, "`](https://github.com/JuliaBinaryWrappers/", depname, ".jl)")
12861287
else
1287-
println(io, "* `", depname, ")`")
1288+
println(io, "* `", depname, "`")
12881289
end
12891290
end
12901291
print_product(io, p::Product) = println(io, "* `", typeof(p), "`: `", variable_name(p), "`")
@@ -1320,6 +1321,8 @@ function build_jll_package(src_name::String,
13201321
for p in sort(collect(platforms), by = triplet)
13211322
println(io, "* `", p, "` (`", triplet(p), "`)")
13221323
end
1324+
# Note: here we list _all_ runtime dependencies, including those that may be
1325+
# required only for some platforms.
13231326
if length(dependencies) > 0
13241327
println(io)
13251328
println(io, """
@@ -1370,7 +1373,8 @@ function build_jll_package(src_name::String,
13701373
# We used to have a duplicate license file, remove it.
13711374
rm(joinpath(code_dir, "LICENSE.md"); force=true)
13721375

1373-
# Add a Project.toml
1376+
# Add a Project.toml. Note: here we list _all_ runtime dependencies, including those
1377+
# that may be required only for some platforms.
13741378
project = build_project_dict(src_name, build_version, dependencies, julia_compat; lazy_artifacts=lazy_artifacts)
13751379
open(joinpath(code_dir, "Project.toml"), "w") do io
13761380
Pkg.TOML.print(io, project)

test/jll.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ end
3838
sources = [DirectorySource(build_tests_dir)]
3939
# Build for this platform and a platform that isn't this one for sure:
4040
# FreeBSD.
41-
platforms = [platform, Platform("x86_64", "freebsd")]
42-
dependencies = [Dependency("Zlib_jll")]
41+
freebsd = Platform("x86_64", "freebsd")
42+
platforms = [platform, freebsd]
43+
# We depend on Zlib_jll only on the host platform, but not on FreeBSD
44+
dependencies = [Dependency("Zlib_jll"; platforms=[platform])]
4345
# The buffer where we'll write the JSON meta data
4446
buff = IOBuffer()
4547

@@ -142,6 +144,13 @@ end
142144
mkpath(env_dir)
143145
Pkg.activate(env_dir)
144146
Pkg.develop(PackageSpec(path=code_dir))
147+
# Make sure we use Zlib_jll only in the wrapper for the host
148+
# platform and not the FreeBSD one.
149+
platform_wrapper = joinpath(code_dir, "src", "wrappers", triplet(platform) * ".jl")
150+
freebsd_wrapper = joinpath(code_dir, "src", "wrappers", triplet(freebsd) * ".jl")
151+
@test contains(readchomp(platform_wrapper), "using Zlib_jll")
152+
@test !contains(readchomp(freebsd_wrapper), "using Zlib_jll")
153+
# Load JLL package and run some actual code from it.
145154
@eval TestJLL using libfoo_jll
146155
@test 6.08 @eval TestJLL ccall((:foo, libfoo), Cdouble, (Cdouble, Cdouble), 2.3, 4.5)
147156
@test @eval TestJLL libfoo_jll.is_available()

0 commit comments

Comments
 (0)