2

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 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, that makes sense. Thank you. So, I guess the answer is PackageCompiler is intended to compile code that is in packages ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.