The reason the artifacts code works when relocated is because Julia has special code to find Pkg directories at runtime, and all paths are based off of that. The artifacts code doesn’t magically solve the issue of @__DIR__ not working properly at runtime when a precompiled package has been transported. Artifacts do not have any idea where your package code is, and won’t be able to find something like data/myfile any better than any other piece of Julia code.
If you want to do something like what Pkg does to find its depots, you could have something like the following in your package’s __init__():
using Pkg
# This will be re-initialized at __init__() time.
pkg_dir = @__DIR__
function __init__()
# Get the current manifest, look up our own package by UUID
env = Pkg.Types.Context().env
pkg_uuid = Pkg.Types.UUID("12aac903-9f7c-5d81-afc2-d9565ea332ae")
entry = env.manifest[pkg_uuid]
# Convert the PkgEntry into a PackageSpec
spec = Pkg.Types.PackageSpec(
name=entry.name,
uuid=pkg_uuid,
version=entry.version,
path=entry.path,
repo=entry.repo,
tree_hash=entry.tree_hash,
)
# Ask `Pkg` to find our source path
global pkg_dir = Pkg.Operations.source_path(spec)
end
So as long as the package is still in its “correct” location (relative to the julia depot) at runtime, this should reconstruct the location to the source. I haven’t tested this thoroughly, but this is the best idea I have for now for how to solve your issue. ![]()