|
5 | 5 |
|
6 | 6 | [](http://codecov.io/github/JuliaLang/PackageCompiler.jl?branch=master) |
7 | 7 |
|
8 | | -Remove jit overhead from your package and compile it into a system image. |
9 | | - |
| 8 | +Remove just-in-time compilation overhead from your package and compile it into a system image. |
10 | 9 |
|
11 | 10 | ## Usage example |
12 | 11 | E.g. do: |
| 12 | + |
13 | 13 | ```Julia |
14 | 14 | using PackageCompiler |
15 | 15 |
|
16 | 16 | # This command will use the runtest.jl of Matcha + UnicodeFun to find out what functions to precompile! |
17 | | -# force = false to not force overwriting julia's current system image |
| 17 | +# `force = false` to not force overwriting Julia's current system image |
18 | 18 | compile_package("Matcha", "UnicodeFun", force = false, reuse = false) |
19 | 19 |
|
20 | | -# build again, reusing the snoop file |
| 20 | +# Build again, reusing the snoop file |
21 | 21 | compile_package("Matcha", "UnicodeFun", force = false, reuse = true) |
22 | 22 |
|
23 | 23 | # You can define a file that will get run for snooping explicitly like this: |
24 | 24 | # this makes sure, that binary gets cached for all functions called in `for_snooping.jl` |
25 | 25 | compile_package("Matcha", "relative/path/for_snooping.jl") |
26 | 26 |
|
27 | | -# if you used force and want your old system image back (force will overwrite the default system image Julia uses) you can run: |
| 27 | +# If you used force and want your old system image back (force will overwrite the default system image Julia uses) you can run: |
28 | 28 | revert() |
29 | 29 |
|
30 | 30 | # Or if you simply want to get a native system image e.g. when you have downloaded the generic Julia install: |
31 | 31 | force_native_image!() |
32 | 32 |
|
33 | | -# building an executable |
34 | | - |
| 33 | +# Build an executable |
35 | 34 | build_executable( |
36 | 35 | "hello.jl", # Julia script containing a `julia_main` function, e.g. like `examples/hello.jl` |
37 | 36 | snoopfile = "call_functions.jl", # Julia script which calls functions that you want to make sure to have precompiled [optional] |
38 | 37 | builddir = "path/to/builddir" # that's where the compiled artifacts will end up [optional] |
39 | 38 | ) |
40 | 39 |
|
41 | | -# Building a shared library |
| 40 | +# Build a shared library |
42 | 41 | build_shared_lib("hello.jl") |
43 | 42 | ``` |
44 | 43 |
|
45 | | - |
46 | 44 | ## Troubleshooting: |
47 | 45 |
|
48 | | -- You might need to tweak your runtest, since SnoopCompile can have problems with some statements. Please open issues about concrete problems! This is also why there is a way to point to a file different from runtests.jl, for the case it becomes impossible to combine testing and snoop compiling (just pass `("package", "snoopfile.jl")`)! |
| 46 | +- You might need to tweak your runtest, since `SnoopCompile` can have problems |
| 47 | +with some statements. Please open issues about concrete problems! This is also |
| 48 | +why there is a way to point to a file different from `runtests.jl`, for the case |
| 49 | +it becomes impossible to combine testing and snoop compiling, just pass |
| 50 | +`("package", "snoopfile.jl")`! |
49 | 51 |
|
50 | | -- non const globals are problematic, or globals defined in functions - removing those got me to 95% of making the package safe for static compilation |
| 52 | +- Non constant globals and globals defined in functions are problematic. |
| 53 | +Removing those got me to 95% of making the package safe for static compilation. |
51 | 54 |
|
52 | | -- type unstable code had some inference issues (around 2 occurrence, where I’m still not sure what was happening) - both cases happened with dictionaries… Only way to find those was investigating the segfaults with `gdb`, but then it was relatively easy to just juggle around the code, since the stacktraces accurately pointed to the problem. The non const globals might be related since they introduce type instabilities. |
| 55 | +- Type unstable code had some inference issues (around 2 occurrence, where I’m |
| 56 | +still not sure what was happening, and both cases happened with dictionaries). |
| 57 | +The only way to find those was investigating the segfaults with `gdb`, but then |
| 58 | +it was relatively easy to just juggle around the code, since the stacktraces |
| 59 | +accurately pointed to the problem. The non constant globals might be related |
| 60 | +since they introduce type instabilities. |
53 | 61 |
|
54 | | -- some generated functions needed reordering of the functions they call ( actually, even for normal compilation, all functions that get called in a generated function should be defined before it) |
| 62 | +- Some generated functions needed reordering of the functions they call |
| 63 | +(actually, even for normal compilation, all functions that get called in a |
| 64 | +generated function should be defined before it). |
55 | 65 |
|
56 | | -- I uncovered one out of bounds issue, that somehow was not coming up without static-compilation |
57 | | -- I used julia-debug to uncover most bugs, but actually, the last errors I was trying to uncover where due to using julia-debug! |
| 66 | +- I uncovered one out-of-bounds issue, that somehow was not coming up without |
| 67 | +static compilation. |
58 | 68 |
|
59 | | -- you’re pretty much on your own and need to use gdb to find the issues and I still don’t know what the underlying julia issues are and when they will get fixed :wink: See: https://github.com/JuliaLang/julia/issues/24533. Hopefully we look at a better story with Julia 1.0! |
| 69 | +- I used `julia-debug` to uncover most bugs, but actually the last errors I was |
| 70 | +trying to uncover where due to `julia-debug` itself! |
| 71 | + |
| 72 | +- You’re pretty much on your own and need to use `gdb` to find any issues and I |
| 73 | +still don’t know what the underlying julia issues are and when they will get |
| 74 | +fixed :wink: See: https://github.com/JuliaLang/julia/issues/24533. |
| 75 | +Hopefully we'll look at a better story with Julia 1.0! |
60 | 76 |
|
61 | 77 |
|
62 | 78 | # Static Julia Compiler |
@@ -170,7 +186,7 @@ Note that for a julia function to be callable from `C`, it must be defined with |
170 | 186 | `Base.@ccallable`, e.g. `Base.@ccallable foo()::Cint = 3`. |
171 | 187 |
|
172 | 188 | ## Building an executable |
173 | | -To compile a julia program into an executable, you can use either the julia |
| 189 | +To compile a Julia program into an executable, you can use either the julia |
174 | 190 | api, `build_executable("hello.jl", "hello")`, or the command line, `$ |
175 | 191 | juliac.jl -vae hello.jl`. |
176 | 192 |
|
|
194 | 210 |
|
195 | 211 | Please see |
196 | 212 | [examples/hello.jl](https://github.com/JuliaLang/PackageCompiler.jl/blob/master/examples/hello.jl) |
197 | | -for an example julia program. |
| 213 | +for an example Julia program. |
198 | 214 |
|
199 | 215 | ### Notes |
200 | 216 |
|
@@ -245,17 +261,11 @@ code. A driver script such as the one in `program.c` can then be used |
245 | 261 | to build a binary that runs the Julia code. |
246 | 262 |
|
247 | 263 | Instead of a driver script, the generated system image can be embedded |
248 | | -into a larger program following the embedding examples and relevant |
249 | | -sections in the Julia manual. Note that the name of the generated system |
| 264 | +into a larger program, see the |
| 265 | +[Embedding Julia](https://docs.julialang.org/en/stable/manual/embedding/) |
| 266 | +section of the Julia manual. Note that the name of the generated system |
250 | 267 | image (`"libhello"` for `hello.jl`) is accessible from C in the |
251 | 268 | preprocessor macro `JULIAC_PROGRAM_LIBNAME`. |
252 | 269 |
|
253 | | -With Julia 0.7, a single large binary can be created, which does not |
254 | | -require the driver program to load the shared library. An example of |
255 | | -that is in `program2.c`, where the image file is the binary itself. |
256 | | - |
257 | 270 | For more information on static Julia compilation see:\ |
258 | 271 | https://juliacomputing.com/blog/2016/02/09/static-julia.html |
259 | | - |
260 | | -For more information on embedding Julia see:\ |
261 | | -https://github.com/JuliaLang/julia/blob/master/doc/src/manual/embedding.md |
|
0 commit comments