JuliaPackaging/JLLWrappers.jl

JLL packages tries to do something on OS where there is no matching artifact

Closed this issue · 2 comments

Using a JLL generated with master BB and latest Julia nightly:

julia> using Libmount_jll
[ Info: Precompiling Libmount_jll [4b2f31a3-9ecc-558c-b454-b3730dcb73e9]
ERROR: LoadError: LoadError: Cannot locate artifact 'Libmount' in '/Users/kristoffercarlsson/.julia/dev/Libmount_jll/Artifacts.toml'
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] artifact_slash_lookup(name::String, artifact_dict::Dict{String, Any}, artifacts_toml::String, platform::Base.BinaryPlatforms.Platform)
    @ Artifacts ~/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:555
  [3] @artifact_str(__source__::LineNumberNode, __module__::Module, name::Any, platform::Nothing)
    @ Artifacts ~/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:611
  [4] @artifact_str(__source__::LineNumberNode, __module__::Module, name::Any)
    @ Artifacts ~/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:584
  [5] include
    @ ./Base.jl:379 [inlined]
  [6] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1144
  [7] top-level scope
    @ none:1
  [8] eval
    @ ./boot.jl:345 [inlined]
  [9] eval(x::Expr)
    @ Base.MainInclude ./client.jl:446
 [10] top-level scope
    @ none:1
in expression starting at /Users/kristoffercarlsson/.julia/dev/Libmount_jll/src/Libmount_jll.jl:8
in expression starting at /Users/kristoffercarlsson/.julia/dev/Libmount_jll/src/Libmount_jll.jl:2

This occurred when trying to load GTK3_jll on mac.

I can reproduce the issue on Julia nightly, but not v1.5:

julia> using OpenLibm_jll
[ Info: Precompiling OpenLibm_jll [05823500-19ac-5b8b-9628-191a04bc5112]

julia> OpenLibm_jll.is_available()
false

julia> OpenLibm_jll.find_artifact_dir()
ERROR: Cannot locate artifact 'OpenLibm' in '/home/mose/.julia/dev/JLLWrappers/test/OpenLibm_jll/Artifacts.toml'
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] do_artifact_str(::String, ::Dict{String,Any}, ::String, ::Module) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Pkg/src/Artifacts.jl:1023
 [3] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [4] invokelatest at ./essentials.jl:709 [inlined]
 [5] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Pkg/src/Artifacts.jl:1068 [inlined]
 [6] find_artifact_dir() at /home/mose/.julia/packages/JLLWrappers/OsFPO/src/toplevel_generators.jl:100
 [7] top-level scope at REPL[9]:1

find_artifact() is only called in __init__(), but the error in Julia v1.6 happens during precompilation. It looks like something changed with regard to expansion of (nested?) macros

Yeah, it looks like the inner macro @artifact_str is evaluated very eagerly in Julia v1.6:

julia> using Libdl, Artifacts, Base.BinaryPlatforms

julia> using Artifacts: load_artifacts_toml, unpack_platform

julia> using Base.BinaryPlatforms: triplet, select_platform

julia> using JLLWrappers

julia> @macroexpand JLLWrappers.@generate_main_file("OpenLibm", UUID("05823500-19ac-5b8b-9628-191a04bc5112"))
ERROR: LoadError: Cannot locate artifact 'OpenLibm' in '/home/mose/.julia/dev/JLLWrappers/test/OpenLibm_jll/Artifacts.toml'
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] artifact_slash_lookup(name::String, artifact_dict::Dict{String, Any}, artifacts_toml::String, platform::Platform)
   @ Artifacts ~/repo/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:555
 [3] @artifact_str(__source__::LineNumberNode, __module__::Module, name::Any, platform::Nothing)
   @ Artifacts ~/repo/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:611
 [4] @artifact_str(__source__::LineNumberNode, __module__::Module, name::Any)
   @ Artifacts ~/repo/julia/usr/share/julia/stdlib/v1.6/Artifacts/src/Artifacts.jl:584
 [5] #macroexpand#44
   @ ./expr.jl:112 [inlined]
 [6] top-level scope
   @ REPL[5]:1
in expression starting at REPL[5]:1

Compare with v1.5:

julia> using Libdl, Pkg, Pkg.BinaryPlatforms, Pkg.Artifacts

julia> using Pkg.Artifacts: load_artifacts_toml, unpack_platform

julia> using Pkg.BinaryPlatforms: triplet, select_platform

julia> HostPlatform() = platform_key_abi()
HostPlatform (generic function with 1 method)

julia> using JLLWrappers

julia> @macroexpand JLLWrappers.@generate_main_file("OpenLibm", UUID("05823500-19ac-5b8b-9628-191a04bc5112"))
quote
    #= /home/mose/.julia/dev/JLLWrappers/src/toplevel_generators.jl:79 =#
    begin
        [...]
    end
end