Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a julia script?

I have noticed that the version 0.4.* of julia has a --compile option.

Strangely, I cannot find any documentation about it.

I was trying (in Ubuntu), to compile a julia script to an executable LLVM bytecode file. But until here, I failed:

julia --compile=yes --output-bc test.bc test.jl
Segmentation fault (core dumped)

I also can get this error message:

julia --compile=yes --output-bc test.bc test.jl
ERROR: could not open file boot.jl

This error does not appear anymore, if I put a boot.jl file in the same folder.

How should I do to compile a julia script to an executable/obfuscated bytecode ?

Edit: FYI, my test.jl file contains only print(123)

like image 996
Oli Avatar asked Dec 08 '15 02:12

Oli


People also ask

Can you compile Julia code?

You can save loaded packages and compiled functions into a file (called a sysimage) that you pass to julia upon startup. Typically the goal is to reduce latency on your machine; for example, you could load the packages and compile the functions used in common plotting workflows use that saved image by default.

Does Julia need to compile?

The results of compilation are cached within the running Julia process which means that no compilation artifacts are written to disk and everything needs to be recompiled once Julia is restarted.

How do I run a script in Julia?

You can run a Julia file (via Ctrl+F5, which will run whatever Julia file you have open and active), execute Julia commands via the REPL, or even execute a specific block of code from a file you have open. To learn more about these options, head to Julia in VS Code - Running Code.


1 Answers

Here's an example, from a julia source build on OS X, with /tmp/test.jl as:

function foo()
    print(123)
end

precompile(foo, ())

And julia/base/userimg.jl as include("/tmp/test.jl")

Execute the following inside the julia/base directory:

julia --compile=yes --output-bc test.bc -J ../usr/lib/julia/inference.ji sysimg.jl

Then run llvm-dis test.bc -o test.ll. Somewhere in the (enormous) image we have the relevant bytecode for the test function:

define internal %jl_value_t* @julia_foo_22542() {
top:
  %0 = alloca [4 x %jl_value_t*], align 8, !dbg !51528 
...

That said, as of now (Dec. 2015), Julia is not usable for ahead-of-time compilation of stand-alone executables. However, the following may be of interest:

  • https://github.com/dhoegh/BuildExecutable.jl (doesn't use --output-bc, as yet, but has a nicer user interface and that option would be easy to add)
  • https://github.com/JuliaLang/julia/pull/13677
like image 189
Isaiah Norton Avatar answered Oct 07 '22 15:10

Isaiah Norton