diff --git a/src/julia/compile.jl b/src/julia/compile.jl index 6e61562a..2008bf45 100644 --- a/src/julia/compile.jl +++ b/src/julia/compile.jl @@ -1,4 +1,4 @@ -compiler_env, script, output, base_sysimage = ARGS +compiler_env, pycall_env, script, output, base_sysimage = ARGS if VERSION < v"0.7-" error("Unsupported Julia version $VERSION") @@ -11,40 +11,42 @@ Pkg.activate(compiler_env) @info "Loading PackageCompiler..." using PackageCompiler -@info "Installing PyCall..." -Pkg.activate(".") -Pkg.add([ - Pkg.PackageSpec( - name = "PyCall", - uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0", - ), -]) +Pkg.activate(pycall_env) +if pycall_env == "." + @info "Installing PyCall..." + Pkg.add([ + Pkg.PackageSpec( + name = "PyCall", + uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0", + ), + ]) +end if VERSION >= v"1.5-" mktempdir() do dir tmpimg = joinpath(dir, basename(output)) - @info "Compiling a temporary system image without `PyCall`..." + @info "Compiling a temporary system image without PyCall..." create_sysimage( Symbol[]; sysimage_path = tmpimg, - project = ".", + project = pycall_env, base_sysimage = isempty(base_sysimage) ? nothing : base_sysimage, ) - @info "Compiling system image..." + @info "Compiling system image with PyCall from $pycall_env..." create_sysimage( [:PyCall]; sysimage_path = output, - project = ".", + project = pycall_env, precompile_execution_file = script, base_sysimage = tmpimg, ) end else - @info "Compiling system image..." + @info "Compiling system image with PyCall from $pycall_env..." create_sysimage( [:PyCall], sysimage_path = output, - project = ".", + project = pycall_env, precompile_execution_file = script, base_sysimage = isempty(base_sysimage) ? nothing : base_sysimage, ) diff --git a/src/julia/sysimage.py b/src/julia/sysimage.py index a5548c46..5cf32749 100644 --- a/src/julia/sysimage.py +++ b/src/julia/sysimage.py @@ -79,6 +79,7 @@ def build_sysimage( script=script_path("precompile.jl"), debug=False, compiler_env="", + pycall_env="", base_sysimage=None, ): if debug: @@ -90,15 +91,24 @@ def build_sysimage( julia_py = julia_py_executable() with temporarydirectory(prefix="tmp.pyjulia.sysimage.") as path: - if not compiler_env: + + if compiler_env: + compiler_env = os.path.abspath(compiler_env) + else: compiler_env = os.path.join(path, "compiler_env") # Not using julia-py to install PackageCompiler to reduce # method re-definition warnings: check_call(install_packagecompiler_cmd(julia, compiler_env), cwd=path) + if pycall_env: + pycall_env = os.path.abspath(pycall_env) + else: + pycall_env = "." + # Arguments to ./compile.jl script: compile_args = [ compiler_env, + pycall_env, # script -- ./precompile.jl by default os.path.realpath(script), # output -- path to sys.o file @@ -131,10 +141,18 @@ def main(args=None): "--compiler-env", default="", help=""" - Path to a Julia project with PackageCompiler to be used for - system image compilation. Create a temporary environment with - appropriate PackageCompiler by default or when an empty string - is given. + Path to a Julia project with PackageCompiler to be used for system image + compilation. If none is provided, will create a temporary environment + with the latest version of PackageCompiler. + """, + ) + parser.add_argument( + "--pycall-env", + default="", + help=""" + Path to a Julia project with PyCall to be used for system image + compilation. If none is provided, will create a temporary environment + with the latest version of PyCall. """, ) parser.add_argument(