Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow building sysimage with custom PyCall #422

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/julia/compile.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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,
)
Expand Down
28 changes: 23 additions & 5 deletions src/julia/sysimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def build_sysimage(
script=script_path("precompile.jl"),
debug=False,
compiler_env="",
pycall_env="",
base_sysimage=None,
):
if debug:
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down