PackageCompile Julia system image with local code

349 Views Asked by At

Seeking an understanding of Julia PackageCompiler.

I am building a system image like this

python3 -m julia.sysimage --script="pc.jl" foo.dylib

and my precompile script (pc.jl) contains this

module Foo
bah() = "bah"
end

If I include pc.jl in the REPL it works as expected

julia> include("pc.jl")
Main.Foo
julia> Main.Foo.bah()
"bah"

But if I start Julia from my sysimage, Foo is nowhere to be found

$ julia --sysimage=foo.dylib               _
...
julia> Main.Foo
ERROR: UndefVarError: Foo not defined
julia> Foo
ERROR: UndefVarError: Foo not defined

Does PackageCompiler work with code that is not published as a package? Can one use it to precompile local personal code?

1

There are 1 best solutions below

1
Kristoffer Carlsson On

I think PackageCompiler puts all code that gets included into an anonymous module to explicitly prevent it from being accessed from Main:

https://github.com/JuliaLang/PackageCompiler.jl/blob/54c0c1255227c8a94de402b41e05d22ea98b5013/src/incremental.jl#L22-L24