Skip to content
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
11 changes: 8 additions & 3 deletions stdlib/Artifacts/src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,18 @@ access a single file/directory within an artifact. Example:
!!! compat "Julia 1.6"
Slash-indexing requires at least Julia 1.6.
"""
macro artifact_str(name, platform=nothing)
macro artifact_str(name, platform=nothing, artifacts_toml_path=nothing)
# Find Artifacts.toml file we're going to load from
srcfile = string(__source__.file)
if ((isinteractive() && startswith(srcfile, "REPL[")) || (!isinteractive() && srcfile == "none")) && !isfile(srcfile)
srcfile = pwd()
end
local artifacts_toml = find_artifacts_toml(srcfile)
# Sometimes we know the exact path to the Artifacts.toml file, so we can save some lookups
local artifacts_toml = if artifacts_toml_path === nothing || artifacts_toml_path == :(nothing)
find_artifacts_toml(srcfile)
else
eval(artifacts_toml_path)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try this @staticfloat? It seems to error for me:

In [3]: using Vulkan_Headers_jll
[ Info: Precompiling Vulkan_Headers_jll [8d446b21-f3ad-5576-a034-752265b9b6f9]
ERROR: LoadError: Evaluation into the closed module `Artifacts` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `Artifacts` with `eval` during precompilation - don't do this.
Stacktrace:
 [1] eval
   @ ./boot.jl:370 [inlined]
 [2] eval(x::String)
   @ Artifacts ~/julia/usr/share/julia/stdlib/v1.9/Artifacts/src/Artifacts.jl:3
 [3] var"@artifact_str"(__source__::LineNumberNode, __module__::Module, name::Any, platform::Any, artifacts_toml_path::Any)
   @ Artifacts ~/julia/usr/share/julia/stdlib/v1.9/Artifacts/src/Artifacts.jl:665

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I only tried it with the test set, which doesn't hit this error, apparently. @vtjnash what is the correct fix here? I don't really understand how to properly "get" the value of a string at compile-time I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was it that failed before this change? I tried it with JLLWrappers and it seemed to work ok without the eval.

end
if artifacts_toml === nothing
error(string(
"Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact '",
Expand Down Expand Up @@ -688,7 +693,7 @@ macro artifact_str(name, platform=nothing)

# If `name` is a constant, (and we're using the default `Platform`) we can actually load
# and parse the `Artifacts.toml` file now, saving the work from runtime.
if isa(name, AbstractString) && platform === nothing
if isa(name, AbstractString) && (platform === nothing || platform == :(nothing))
# To support slash-indexing, we need to split the artifact name from the path tail:
platform = HostPlatform()
artifact_name, artifact_path_tail, hash = artifact_slash_lookup(name, artifact_dict, artifacts_toml, platform)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/Artifacts/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ end
HelloWorldC_exe_path = joinpath(HelloWorldC_dir, "bin", "hello_world$(exeext)")
@test isfile(HelloWorldC_exe_path)

HelloWorldC_dir_explicit_artifact = eval(:(@artifact_str "HelloWorldC" nothing joinpath(@__DIR__, "Artifacts.toml")))
@test isdir(HelloWorldC_dir_explicit_artifact)

# Simple slash-indexed lookup
HelloWorldC_bin_path = artifact"HelloWorldC/bin"
@test isdir(HelloWorldC_bin_path)
Expand Down