Skip to content

Commit ae84d4a

Browse files
authored
Setup and cleanup host dependencies during the build (#995)
1 parent 3eb83ae commit ae84d4a

File tree

6 files changed

+84
-59
lines changed

6 files changed

+84
-59
lines changed

Manifest.toml

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

2929
[[BinaryBuilderBase]]
3030
deps = ["CodecZlib", "Downloads", "InteractiveUtils", "JSON", "LibGit2", "Libdl", "Logging", "OutputCollectors", "Pkg", "Random", "SHA", "SimpleBufferStream", "TOML", "Tar", "UUIDs", "p7zip_jll"]
31-
git-tree-sha1 = "b89a4d163105a65e4e3ad0f211e4e68d7dead95f"
31+
git-tree-sha1 = "61cbfed1cfaa5d1486fca1784682b75e8f1986f8"
3232
repo-rev = "master"
3333
repo-url = "https://github.com/JuliaPackaging/BinaryBuilderBase.jl.git"
3434
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
@@ -41,9 +41,9 @@ uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
4141
version = "0.7.0"
4242

4343
[[DataAPI]]
44-
git-tree-sha1 = "ad84f52c0b8f05aa20839484dbaf01690b41ff84"
44+
git-tree-sha1 = "25ccd31003243d2ce83e474cf11663dddf48035f"
4545
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
46-
version = "1.4.0"
46+
version = "1.4.1"
4747

4848
[[DataStructures]]
4949
deps = ["InteractiveUtils", "OrderedCollections"]
@@ -185,9 +185,9 @@ version = "1.0.3"
185185

186186
[[MbedTLS_jll]]
187187
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
188-
git-tree-sha1 = "bf50d4a1911612ee8f662d0038fc05dda1bea57d"
188+
git-tree-sha1 = "47e19f64fc939b86dea2b9b5e38c29c787f0d581"
189189
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
190-
version = "2.25.0+0"
190+
version = "2.24.0+1"
191191

192192
[[Mmap]]
193193
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
@@ -319,9 +319,9 @@ version = "1.0.0"
319319

320320
[[Tables]]
321321
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
322-
git-tree-sha1 = "240d19b8762006ff04b967bdd833269ad642d550"
322+
git-tree-sha1 = "8dc2bb7d3548e315d890706547b24502ed79504f"
323323
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
324-
version = "1.2.2"
324+
version = "1.3.1"
325325

326326
[[Tar]]
327327
deps = ["ArgTools", "SHA"]
@@ -357,9 +357,9 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
357357

358358
[[WebSockets]]
359359
deps = ["Base64", "Dates", "HTTP", "Logging", "Sockets"]
360-
git-tree-sha1 = "a07c280e068acb96a7aeb0a6d35c801ba526e364"
360+
git-tree-sha1 = "f91a602e25fe6b89afc93cf02a4ae18ee9384ce3"
361361
uuid = "104b5d7c-a370-577a-8038-80a2059c5097"
362-
version = "1.5.7"
362+
version = "1.5.9"
363363

364364
[[ZMQ]]
365365
deps = ["FileWatching", "Sockets", "ZeroMQ_jll"]

src/AutoBuild.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
283283

284284
# For deploy discard build-only dependencies
285285
# and make sure we get a `Vector{Dependency}`
286-
dependencies = Dependency[dep for dep in dependencies if !isa(dep, BuildDependency)]
286+
dependencies = Dependency[dep for dep in dependencies if is_runtime_dependency(dep)]
287287

288288
# The location the binaries will be available from
289289
bin_path = "https://github.com/$(deploy_jll_repo)/releases/download/$(tag)"
@@ -659,10 +659,13 @@ function autobuild(dir::AbstractString,
659659

660660
prefix = setup_workspace(
661661
build_path,
662-
source_files;
662+
source_files,
663+
concrete_platform,
664+
default_host_platform;
663665
verbose=verbose,
664666
)
665-
artifact_paths = setup_dependencies(prefix, getpkg.(dependencies), concrete_platform; verbose=verbose)
667+
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)
668+
target_artifact_paths = setup_dependencies(prefix, Pkg.Types.PackageSpec[getpkg(d) for d in dependencies if is_target_dependency(d)], concrete_platform; verbose=verbose)
666669

667670
# Create a runner to work inside this workspace with the nonce built-in
668671
ur = preferred_runner()(
@@ -718,7 +721,7 @@ function autobuild(dir::AbstractString,
718721
$(script)
719722
"""
720723

721-
dest_prefix = Prefix(joinpath(prefix.path, "destdir"))
724+
dest_prefix = Prefix(BinaryBuilderBase.destdir(prefix.path, concrete_platform))
722725
did_succeed = with_logfile(dest_prefix, "$(src_name).log") do io
723726
# Let's start the presentations with BinaryBuilder.jl
724727
write(io, "BinaryBuilder.jl version: $(get_bb_version())\n\n")
@@ -792,7 +795,8 @@ function autobuild(dir::AbstractString,
792795
end
793796

794797
# Unsymlink all the deps from the dest_prefix
795-
cleanup_dependencies(prefix, artifact_paths)
798+
cleanup_dependencies(prefix, host_artifact_paths)
799+
cleanup_dependencies(prefix, target_artifact_paths)
796800

797801
# Search for dead links in dest_prefix; raise warnings about them.
798802
Auditor.warn_deadlinks(dest_prefix.path)
@@ -1067,7 +1071,7 @@ function build_jll_package(src_name::String,
10671071
mkpath(joinpath(code_dir, "src", "wrappers"))
10681072

10691073
# Drop BuildDependency objects
1070-
dependencies = Dependency[d for d in dependencies if !isa(d, BuildDependency)]
1074+
dependencies = Dependency[d for d in dependencies if is_runtime_dependency(d)]
10711075

10721076
platforms = keys(build_output_meta)
10731077
products_info = Dict{Product,Any}

src/BinaryBuilder.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export AnyPlatform
2525
export Product, LibraryProduct, FileProduct, ExecutableProduct, FrameworkProduct, satisfied,
2626
locate, write_deps_file, variable_name
2727
# BinaryBuilderBase/src/Dependency.jl
28-
export Dependency, BuildDependency
28+
export Dependency, BuildDependency, HostBuildDependency
2929
# BinaryBuilderBase/src/Sources.jl
3030
export ArchiveSource, FileSource, GitSource, DirectorySource
3131
# Auditor.jl

src/wizard/interactive_build.jl

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
using BinaryBuilderBase: get_concrete_platform
1+
using BinaryBuilderBase: get_concrete_platform, destdir
22

33
include("hints.jl")
44

5+
# Add new method to `get_concrete_platform`: this is a common pattern throughout
6+
# this file.
7+
BinaryBuilderBase.get_concrete_platform(platform::AbstractPlatform, state::WizardState) =
8+
get_concrete_platform(platform;
9+
preferred_gcc_version = state.preferred_gcc_version,
10+
preferred_llvm_version = state.preferred_llvm_version,
11+
compilers = state.compilers)
12+
513
# When rerunning the script generated during the wizard we want to fail on error
614
# and automatically install license at the end.
715
full_wizard_script(state::WizardState) =
@@ -17,10 +25,11 @@ function step4(state::WizardState, ur::Runner, platform::AbstractPlatform,
1725
build_path::AbstractString, prefix::Prefix)
1826
printstyled(state.outs, "\t\t\t# Step 4: Select build products\n\n", bold=true)
1927

28+
concrete_platform = get_concrete_platform(platform, state)
2029
# Collect all executable/library files, explicitly exclude everything that is
2130
# a symlink to the artifacts directory, as usual.
22-
destdir = joinpath(prefix, "destdir")
23-
files = filter(f -> startswith(f, destdir), collapse_symlinks(collect_files(destdir)))
31+
destdir_path = destdir(prefix, concrete_platform)
32+
files = filter(f -> startswith(f, destdir_path), collapse_symlinks(collect_files(destdir_path)))
2433
files = filter_object_files(files)
2534

2635
# Check if we can load them as an object file
@@ -31,7 +40,7 @@ function step4(state::WizardState, ur::Runner, platform::AbstractPlatform,
3140
end
3241

3342
# Strip out the prefix from filenames
34-
state.files = map(file->replace(file, "$(destdir)/" => ""), files)
43+
state.files = map(file->replace(file, "$(destdir_path)/" => ""), files)
3544
state.file_kinds = map(files) do f
3645
readmeta(f) do oh
3746
if isexecutable(oh)
@@ -63,10 +72,7 @@ function step4(state::WizardState, ur::Runner, platform::AbstractPlatform,
6372

6473
if choice == 1
6574
# Link dependencies into the prefix again
66-
concrete_platform = get_concrete_platform(platform;
67-
preferred_gcc_version = state.preferred_gcc_version,
68-
preferred_llvm_version = state.preferred_llvm_version,
69-
compilers = state.compilers)
75+
concrete_platform = get_concrete_platform(platform, state)
7076
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), concrete_platform)
7177
return step3_interactive(state, prefix, platform, ur, build_path, artifact_paths)
7278
elseif choice == 2
@@ -214,10 +220,7 @@ function bb_add(client, state::WizardState, prefix::Prefix, platform::AbstractPl
214220
new_dep = Dependency(jll)
215221
try
216222
# This will redo some work, but that may be ok
217-
concrete_platform = get_concrete_platform(platform;
218-
preferred_gcc_version = state.preferred_gcc_version,
219-
preferred_llvm_version = state.preferred_llvm_version,
220-
compilers = state.compilers)
223+
concrete_platform = get_concrete_platform(platform, state)
221224
# Clear out the prefix artifacts directory in case this change caused
222225
# any previous dependencies to change
223226
let artifacts_dir = joinpath(prefix, "artifacts")
@@ -408,7 +411,8 @@ function step3_interactive(state::WizardState, prefix::Prefix,
408411
cleanup_dependencies(prefix, artifact_paths)
409412
state.step = :step3_retry
410413
else
411-
step3_audit(state, platform, joinpath(prefix, "destdir"))
414+
concrete_platform = get_concrete_platform(platform, state)
415+
step3_audit(state, platform, destdir(prefix, concrete_platform))
412416
# Unsymlink all the deps from the dest_prefix before moving to the next step
413417
cleanup_dependencies(prefix, artifact_paths)
414418
return step4(state, ur, platform, build_path, prefix)
@@ -429,11 +433,8 @@ function step3_retry(state::WizardState)
429433

430434
build_path = tempname()
431435
mkpath(build_path)
432-
prefix = setup_workspace(build_path, vcat(state.source_files, state.patches); verbose=false)
433-
concrete_platform = get_concrete_platform(platform;
434-
preferred_gcc_version = state.preferred_gcc_version,
435-
preferred_llvm_version = state.preferred_llvm_version,
436-
compilers = state.compilers)
436+
concrete_platform = get_concrete_platform(platform, state)
437+
prefix = setup_workspace(build_path, vcat(state.source_files, state.patches), concrete_platform; verbose=false)
437438
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), concrete_platform)
438439

439440
ur = preferred_runner()(
@@ -448,7 +449,7 @@ function step3_retry(state::WizardState)
448449
with_logfile(joinpath(build_path, "out.log")) do io
449450
run(ur, `/bin/bash -c $(full_wizard_script(state))`, io; verbose=true, tee_stream=state.outs)
450451
end
451-
step3_audit(state, platform, joinpath(prefix, "destdir"))
452+
step3_audit(state, platform, destdir(prefix, concrete_platform))
452453
# Unsymlink all the deps from the dest_prefix before moving to the next step
453454
cleanup_dependencies(prefix, artifact_paths)
454455

@@ -514,15 +515,13 @@ function step34(state::WizardState)
514515
build_path = tempname()
515516
mkpath(build_path)
516517
state.history = ""
518+
concrete_platform = get_concrete_platform(platform, state)
517519
prefix = setup_workspace(
518520
build_path,
519-
vcat(state.source_files, state.patches);
521+
vcat(state.source_files, state.patches),
522+
concrete_platform;
520523
verbose=false
521524
)
522-
concrete_platform = get_concrete_platform(platform;
523-
preferred_gcc_version = state.preferred_gcc_version,
524-
preferred_llvm_version = state.preferred_llvm_version,
525-
compilers = state.compilers)
526525
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), concrete_platform; verbose=true)
527526

528527
provide_hints(state, joinpath(prefix, "srcdir"))
@@ -564,13 +563,10 @@ function step5_internal(state::WizardState, platform::AbstractPlatform)
564563
prefix_artifacts = Dict{Prefix,Vector{String}}()
565564
while !ok
566565
cd(build_path) do
567-
prefix = setup_workspace(build_path, vcat(state.source_files, state.patches); verbose=true)
566+
concrete_platform = get_concrete_platform(platform, state)
567+
prefix = setup_workspace(build_path, vcat(state.source_files, state.patches), concrete_platform; verbose=true)
568568
# Clean up artifacts in case there are some
569569
cleanup_dependencies(prefix, get(prefix_artifacts, prefix, String[]))
570-
concrete_platform = get_concrete_platform(platform;
571-
preferred_gcc_version = state.preferred_gcc_version,
572-
preferred_llvm_version = state.preferred_llvm_version,
573-
compilers = state.compilers)
574570
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), concrete_platform; verbose=true)
575571
# Record newly added artifacts for this prefix
576572
prefix_artifacts[prefix] = artifact_paths
@@ -597,7 +593,7 @@ function step5_internal(state::WizardState, platform::AbstractPlatform)
597593
msg = "The build script failed (see above).\n"
598594
println(state.outs, msg)
599595
else
600-
audit(Prefix(joinpath(prefix, "destdir")); io=state.outs,
596+
audit(Prefix(destdir(prefix, concrete_platform)); io=state.outs,
601597
platform=platform, verbose=true, autofix=true, require_license=true)
602598

603599
ok = isempty(match_files(state, prefix, platform, state.files))
@@ -638,17 +634,15 @@ function step5_internal(state::WizardState, platform::AbstractPlatform)
638634
elseif choice == 2
639635
rm(build_path; force=true, recursive=true)
640636
mkpath(build_path)
637+
concrete_platform = get_concrete_platform(platform, state)
641638
prefix = setup_workspace(
642639
build_path,
643-
vcat(state.source_files, state.patches);
640+
vcat(state.source_files, state.patches),
641+
concrete_platform;
644642
verbose=true,
645643
)
646644
# Clean up artifacts in case there are some
647645
cleanup_dependencies(prefix, get(prefix_artifacts, prefix, String[]))
648-
concrete_platform = get_concrete_platform(platform;
649-
preferred_gcc_version = state.preferred_gcc_version,
650-
preferred_llvm_version = state.preferred_llvm_version,
651-
compilers = state.compilers)
652646
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), platform; verbose=true)
653647
# Record newly added artifacts for this prefix
654648
prefix_artifacts[prefix] = artifact_paths
@@ -775,15 +769,13 @@ function step5c(state::WizardState)
775769
mkpath(build_path)
776770
local ok = true
777771

772+
concrete_platform = get_concrete_platform(platform, state)
778773
prefix = setup_workspace(
779774
build_path,
780-
vcat(state.source_files, state.patches);
775+
vcat(state.source_files, state.patches),
776+
concrete_platform;
781777
verbose=false,
782778
)
783-
concrete_platform = get_concrete_platform(platform;
784-
preferred_gcc_version = state.preferred_gcc_version,
785-
preferred_llvm_version = state.preferred_llvm_version,
786-
compilers = state.compilers)
787779
artifact_paths = setup_dependencies(prefix, getpkg.(state.dependencies), concrete_platform; verbose=false)
788780
ur = preferred_runner()(
789781
prefix.path;
@@ -799,7 +791,7 @@ function step5c(state::WizardState)
799791
end
800792

801793
if ok
802-
audit(Prefix(joinpath(prefix, "destdir"));
794+
audit(Prefix(destdir(prefix, concrete_platform));
803795
io=state.outs,
804796
platform=platform,
805797
verbose=false,

test/building.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,35 @@ end
229229
end
230230
end
231231

232+
@testset "HostBuildDependency" begin
233+
# A platform for which we certainly can't run executable
234+
p = Platform("x86_64", "freebsd")
235+
mktempdir() do build_path
236+
build_output_meta = autobuild(
237+
build_path,
238+
"host_dep",
239+
v"1.0.0",
240+
# No sources
241+
DirectorySource[],
242+
# Script: run hello_world from the HostBuildDependency
243+
raw"""
244+
hello_world
245+
""",
246+
# Platform
247+
[p],
248+
Product[],
249+
# Install `HelloWorldC_jll` for both the target and the host.
250+
[
251+
HostBuildDependency("HelloWorldC_jll"),
252+
Dependency("HelloWorldC_jll"),
253+
];
254+
# Don't do audit passes
255+
skip_audit=true,
256+
)
257+
@test haskey(build_output_meta, p)
258+
end
259+
end
260+
232261
@testset "Invalid Arguments" begin
233262
mktempdir() do build_path
234263
# Test that invalid JLL names both @warn and error()

test/jll.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ end
9999
version = merged["version"]
100100
# Filter out build-time dependencies that will not go into the dependencies of
101101
# the JLL packages.
102-
dependencies = Dependency[dep for dep in merged["dependencies"] if !isa(dep, BuildDependency)]
102+
dependencies = Dependency[dep for dep in merged["dependencies"] if is_runtime_dependency(dep)]
103103
lazy_artifacts = merged["lazy_artifacts"]
104104
build_version = BinaryBuilder.get_next_wrapper_version(name, version)
105105
repo = "JuliaBinaryWrappers/$(name)_jll.jl"
@@ -109,7 +109,7 @@ end
109109
# Skip init of the remote repository
110110
# Filter out build-time dependencies also here
111111
for json_obj in [merged, objs_unmerged...]
112-
json_obj["dependencies"] = Dependency[dep for dep in json_obj["dependencies"] if !isa(dep, BuildDependency)]
112+
json_obj["dependencies"] = Dependency[dep for dep in json_obj["dependencies"] if is_runtime_dependency(dep)]
113113
end
114114

115115
tag = "$(name)-v$(build_version)"

0 commit comments

Comments
 (0)