forked from JuliaPy/PyCall.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make PyCall.jl AOT-compilable (JuliaPy#651)
* Support PackageCompiler.jl; clear out global states * Add scripts to run PackageCompiler * Run tests with AOT-compiled PyCall in Travis * Clear other global states * Add aot/README.md * Name Travis Jobs * Add MacroTools to aot/Project.toml * Add Pkg.activate in aot/precompile.jl * Add Pkg.build("PyCall") in aot/compile.jl
- Loading branch information
Showing
8 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
aot/Manifest.toml | ||
aot/Project.toml | ||
aot/_julia_path | ||
aot/sys.* | ||
deps/deps.jl | ||
deps/PYTHON | ||
deps/build.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Ahead-of-time compilation for PyCall | ||
|
||
This directory contains a set of scripts for testing compatibility of PyCall.jl | ||
with [PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl). | ||
|
||
See `.travis.yml` for how it is actually used. | ||
|
||
## How to compile system image | ||
|
||
To create a system image with PyCall.jl, run `aot/compile.jl` (which | ||
is executable in *nix): | ||
|
||
```sh | ||
aot/compile.jl --color=yes | ||
JULIA=PATH/TO/CUSTOM/julia aot/compile.jl # to specify a julia binary | ||
``` | ||
|
||
Resulting system image is stored at `aot/sys.so`. | ||
|
||
## How to use compiled system image | ||
|
||
To use compiled system image, run `aot/julia.sh`, e.g.: | ||
|
||
```sh | ||
aot/julia.sh --compiled-modules=no --startup-file=no | ||
``` | ||
|
||
Note that Julia binary used for compiling the system image is cached | ||
and automatically picked by `aot/julia.sh`. You don't need to specify | ||
the Julia binary. | ||
|
||
Since Julia needs to re-compile packages when switching system images, | ||
it is recommended to pass `--compiled-modules=no` if you are using it | ||
in your machine with a standard Julia setup. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
# -*- mode: julia -*- | ||
#= | ||
exec "${JULIA:-julia}" "$@" ${BASH_SOURCE[0]} | ||
=# | ||
|
||
using Pkg | ||
Pkg.activate(@__DIR__) | ||
Pkg.add("MacroTools") | ||
Pkg.develop(PackageSpec(path=dirname(@__DIR__))) | ||
Pkg.build("PyCall") | ||
Pkg.activate() | ||
|
||
using PackageCompiler | ||
sysout, _curr_syso = compile_incremental( | ||
joinpath(@__DIR__, "Project.toml"), | ||
joinpath(@__DIR__, "precompile.jl"), | ||
) | ||
|
||
pysysout = joinpath(@__DIR__, basename(sysout)) | ||
cp(sysout, pysysout, force=true) | ||
|
||
write(joinpath(@__DIR__, "_julia_path"), Base.julia_cmd().exec[1]) | ||
|
||
@info "System image: $pysysout" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
thisdir="$(dirname "${BASH_SOURCE[0]}")" | ||
JULIA="${JULIA:-$(cat "$thisdir/_julia_path")}" | ||
exec "${JULIA}" --sysimage="$thisdir/sys.so" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Activate ./Project.toml. Excluding `"@v#.#"` from `Base.LOAD_PATH` | ||
# to make compilation more reproducible. | ||
using Pkg | ||
empty!(Base.LOAD_PATH) | ||
append!(Base.LOAD_PATH, ["@", "@stdlib"]) | ||
Pkg.activate(@__DIR__) | ||
|
||
# Manually invoking `__init__` to workaround: | ||
# https://github.com/JuliaLang/julia/issues/22910 | ||
|
||
import MacroTools | ||
isdefined(MacroTools, :__init__) && MacroTools.__init__() | ||
|
||
using PyCall | ||
PyCall.__init__() | ||
PyCall.pyimport("sys")[:executable] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
thisdir="$(dirname "${BASH_SOURCE[0]}")" | ||
exec "$thisdir/julia.sh" --startup-file=no --color=yes -e ' | ||
using Pkg | ||
Pkg.test("PyCall") | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters