Skip to content

Commit 96dd5f3

Browse files
authored
fix lazy artifacts (#696)
1 parent f2014b2 commit 96dd5f3

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
99
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1010
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1111
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
12+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1213
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1314

1415
[compat]

examples/MyApp/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1010
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
1111
HelloWorldC_jll = "dca1746e-5efc-54fc-8249-22745bc95a49"
1212
LLVMExtra_jll = "dad2f222-ce93-54a1-a47d-0025e8a3acab"
13+
MKL_jll = "856f044c-d86e-5d09-b602-aeab76dc8ba7"
1314
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

examples/MyApp/src/MyApp.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ using HelloWorldC_jll
55
using Artifacts
66
using Distributed
77
using Random
8-
using LLVMExtra_jll
8+
if VERSION >= v"1.7.0"
9+
using LLVMExtra_jll
10+
end
11+
12+
using MKL_jll
913

1014
const myrand = rand()
1115

@@ -81,10 +85,18 @@ function real_main()
8185
@eval @everywhere using Example
8286
@everywhere println(Example.domath(3))
8387

84-
if isfile(LLVMExtra_jll.libLLVMExtra_path)
85-
println("LLVMExtra path: ok!")
88+
if VERSION >= v"1.7.0"
89+
if isfile(LLVMExtra_jll.libLLVMExtra_path)
90+
println("LLVMExtra path: ok!")
91+
else
92+
println("LLVMExtra path: fail!")
93+
end
94+
end
95+
96+
if isfile(MKL_jll.libmkl_core_path)
97+
println("MKL_jll path: ok!")
8698
else
87-
println("LLVMExtra path: fail!")
99+
println("MKL_jll path: fail!")
88100
end
89101
return
90102
end

src/PackageCompiler.jl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using Artifacts
88
using LazyArtifacts
99
using UUIDs: UUID, uuid1
1010
using RelocatableFolders
11+
using TOML
1112

1213
export create_sysimage, create_app, create_library
1314

@@ -1055,6 +1056,40 @@ function pretty_byte_str(size)
10551056
return @sprintf("%.3f %s", bytes, Base._mem_units[mb])
10561057
end
10571058

1059+
# Copy pasted from Pkg since `collect_artifacts` doesn't allow lazy artifacts to get installed
1060+
function _collect_artifacts(pkg_root::String; platform::Base.BinaryPlatforms.AbstractPlatform=HostPlatform(), include_lazy::Bool)
1061+
# Check to see if this package has an (Julia)Artifacts.toml
1062+
artifacts_tomls = Tuple{String,Base.TOML.TOMLDict}[]
1063+
1064+
for f in Artifacts.artifact_names
1065+
artifacts_toml = joinpath(pkg_root, f)
1066+
if isfile(artifacts_toml)
1067+
selector_path = joinpath(pkg_root, ".pkg", "select_artifacts.jl")
1068+
1069+
# If there is a dynamic artifact selector, run that in an appropriate sandbox to select artifacts
1070+
if isfile(selector_path)
1071+
# Despite the fact that we inherit the project, since the in-memory manifest
1072+
# has not been updated yet, if we try to load any dependencies, it may fail.
1073+
# Therefore, this project inheritance is really only for Preferences, not dependencies.
1074+
code = try Pkg.Operations.gen_build_code(selector_path; inherit_project=true)
1075+
catch e
1076+
e isa MethodError || rethrow()
1077+
Pkg.Operations.gen_build_code(selector_path)
1078+
end
1079+
select_cmd = Cmd(`$code $(Base.BinaryPlatforms.triplet(platform))`)
1080+
meta_toml = String(read(select_cmd))
1081+
push!(artifacts_tomls, (artifacts_toml, TOML.parse(meta_toml)))
1082+
else
1083+
# Otherwise, use the standard selector from `Artifacts`
1084+
artifacts = Pkg.Artifacts.select_downloadable_artifacts(artifacts_toml; platform, include_lazy)
1085+
push!(artifacts_tomls, (artifacts_toml, artifacts))
1086+
end
1087+
break
1088+
end
1089+
end
1090+
return artifacts_tomls
1091+
end
1092+
10581093
function bundle_artifacts(ctx, dest_dir; include_lazy_artifacts::Bool)
10591094
pkgs = load_all_deps(ctx)
10601095

@@ -1076,7 +1111,7 @@ function bundle_artifacts(ctx, dest_dir; include_lazy_artifacts::Bool)
10761111
pkg_source_path === nothing && continue
10771112
bundled_artifacts_pkg = Pair{String, String}[]
10781113
if isdefined(Pkg.Operations, :collect_artifacts)
1079-
for (artifacts_toml, artifacts) in Pkg.Operations.collect_artifacts(pkg_source_path; platform)
1114+
for (artifacts_toml, artifacts) in _collect_artifacts(pkg_source_path; platform, include_lazy=include_lazy_artifacts)
10801115
for (name, data) in artifacts
10811116
Pkg.ensure_artifact_installed(name, artifacts[name], artifacts_toml; platform)
10821117
hash = Base.SHA1(data["git-tree-sha1"])

test/runtests.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ end
6161
for filter in filter_stdlibs
6262
tmp_app_source_dir = joinpath(tmp, "MyApp")
6363
cp(app_source_dir, tmp_app_source_dir)
64-
create_app(tmp_app_source_dir, app_compiled_dir; incremental=incremental, force=true, filter_stdlibs=filter,
64+
create_app(tmp_app_source_dir, app_compiled_dir; incremental=incremental, force=true, filter_stdlibs=filter, include_lazy_artifacts=true,
6565
precompile_execution_file=joinpath(app_source_dir, "precompile_app.jl"),
6666
executables=["MyApp" => "julia_main",
6767
"SecondApp" => "second_main",
@@ -111,7 +111,10 @@ end
111111
@test occursin("From worker 4:\t8", app_output)
112112
@test occursin("From worker 5:\t8", app_output)
113113

114-
@test occursin("LLVMExtra path: ok!", app_output)
114+
if VERSION >= v"1.7.0"
115+
@test occursin("LLVMExtra path: ok!", app_output)
116+
end
117+
@test occursin("MKL_jll path: ok!", app_output)
115118

116119
# Test second app
117120
app_output = read(`$(app_path("SecondApp"))`, String)

0 commit comments

Comments
 (0)