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?

sophros
  • 14,672
  • 11
  • 46
  • 75
opus111
  • 2,744
  • 4
  • 25
  • 41

1 Answers1

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

Kristoffer Carlsson
  • 2,768
  • 9
  • 16
  • Ah, that makes sense. Thank you. So, I guess the answer is PackageCompiler is intended to compile code that is in packages ;-) – opus111 Dec 09 '19 at 01:26