Relocability problems about Requires.jl

I compiled my package, which depends on HDF5.jl. I compiled it in docker and then use the compiled executable directly in the host machine. It generally works fine, but there is a warning:

┌ Warning: Error requiring `MPI` from `HDF5.Drivers`
│   exception =
│    IOError: stat("/root/.julia/packages/HDF5/HtnQZ/src/drivers/mpio.jl"): permission denied (EACCES)
│    ... something omitted
│     [15] __init__()
│        @ HDF5.Drivers /root/.julia/packages/HDF5/HtnQZ/src/drivers/drivers.jl:92
└ @ Requires /root/.julia/packages/Requires/Z8rfN/src/require.jl:51

The problematic line is very clear:

@require MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195" include("mpio.jl")

The reason seems to be simple: the @require macro make the include happen in run time, when I can no longer get mpio.jl, because I compile the package in docker but run it in the host machine.

After check, I found Requires.jl offers a @include macro, which seems to be fit for the problem.

If this is the case, should every package that currently use @require...include change to @require...@include?

There are currently many such packages, like Adapt.jl, ArrayInterface.jl, StaticArrayInterface.jl, MPI.jl, HDF5.jl, to name but a few.

1 Like

In this case, it might be easier dev the package and either remove the line or always include it depending on if you are using MPI or not.

With pkgimages around the corner with Julia 1.9, we’ll probably be engineering this a bit differently.

To be clear, are you running Julia as the root user?

I run the executable as a normal user. But, since I compile the package in docker, I suppose it should be as the root user in the docker.

It is a workable solution, at least for packages I directly depend on. But my package only depends on Adapt.jl indirectly through StructArrays.jl, I suppose I also need to dev StructArrays.jl?
I’m not familiar with PkgImages.jl, maybe I can have a look at it.

It’s not PkgImages.jl that I’m thinking about. Rather it’s the integration into Julia 1.9. From Julia 1.9 on, we will replace Requires.jl with the Julia 1.9 package extension mechanism.

No, you should only need to dev HDF5.jl. All dependencies will use your modified version.