Skip to content

[AutoBuild] Implement platform-dependent dependencies in JLLs #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

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

[[CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
Expand All @@ -42,9 +42,9 @@ version = "0.7.0"

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

[[DataAPI]]
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
Expand All @@ -53,9 +53,9 @@ version = "1.9.0"

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

[[DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
Expand Down Expand Up @@ -252,9 +252,9 @@ version = "0.1.0"

[[Parsers]]
deps = ["Dates"]
git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc"
git-tree-sha1 = "d7fa6237da8004be601e19bd6666083056649918"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.1.2"
version = "2.1.3"

[[Pidfile]]
deps = ["FileWatching", "Test"]
Expand Down Expand Up @@ -309,15 +309,15 @@ version = "1.2.9"

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

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
git-tree-sha1 = "8f82019e525f4d5c669692772a6f4b0a58b06a6a"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"
version = "1.2.0"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down Expand Up @@ -375,9 +375,9 @@ version = "1.0.1"

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

[[Tar]]
deps = ["ArgTools", "SHA"]
Expand Down
20 changes: 12 additions & 8 deletions src/AutoBuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
# If the user passed in a platform (or a few, comma-separated) on the
# command-line, use that instead of our default platforms
if length(ARGS) > 0
parse_platform(p::AbstractString) = p == "any" ? AnyPlatform() : parse(Platform, p; validate_strict=true)
platforms = parse_platform.(split(ARGS[1], ","))
platforms = BinaryBuilderBase.parse_platform.(split(ARGS[1], ","))
end

# Check to make sure we have the necessary environment stuff
Expand Down Expand Up @@ -713,8 +712,10 @@ function autobuild(dir::AbstractString,
default_host_platform;
verbose=verbose,
)
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)
target_artifact_paths = setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in dependencies if is_target_dependency(d)], concrete_platform; verbose=verbose)
setup_deps(f, prefix, dependencies, platform, verbose) =
setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in filter_platforms(dependencies, platform) if f(d)], platform; verbose)
host_artifact_paths = setup_deps(is_host_dependency, prefix, dependencies, default_host_platform, verbose)
target_artifact_paths = setup_deps(is_target_dependency, prefix, dependencies, concrete_platform, verbose)

# Create a runner to work inside this workspace with the nonce built-in
ur = preferred_runner()(
Expand Down Expand Up @@ -1162,7 +1163,7 @@ function build_jll_package(src_name::String,
export $(join(sort(variable_name.(first.(collect(products_info)))), ", "))
""")
end
for dep in dependencies
for dep in filter_platforms(dependencies, platform)
println(io, "using $(getname(dep))")
end

Expand Down Expand Up @@ -1193,7 +1194,7 @@ function build_jll_package(src_name::String,

print(io, """
function __init__()
JLLWrappers.@generate_init_header($(join(getname.(dependencies), ", ")))
JLLWrappers.@generate_init_header($(join(getname.(filter_platforms(dependencies, platform)), ", ")))
""")

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

# Add a Project.toml
# Add a Project.toml. Note: here we list _all_ runtime dependencies, including those
# that may be required only for some platforms.
project = build_project_dict(src_name, build_version, dependencies, julia_compat; lazy_artifacts=lazy_artifacts)
open(joinpath(code_dir, "Project.toml"), "w") do io
Pkg.TOML.print(io, project)
Expand Down
13 changes: 11 additions & 2 deletions test/jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ end
sources = [DirectorySource(build_tests_dir)]
# Build for this platform and a platform that isn't this one for sure:
# FreeBSD.
platforms = [platform, Platform("x86_64", "freebsd")]
dependencies = [Dependency("Zlib_jll")]
freebsd = Platform("x86_64", "freebsd")
platforms = [platform, freebsd]
# We depend on Zlib_jll only on the host platform, but not on FreeBSD
dependencies = [Dependency("Zlib_jll"; platforms=[platform])]
# The buffer where we'll write the JSON meta data
buff = IOBuffer()

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