Making a Julia Binary
Compile your Julia project with PackageCompiler for portability
Julia is a JIT language; however, sometimes it might be nice to have an
executable. There are two ways to interact with PackageCompiler: Using the CLI
juliac and by adding PackageCompiler as part of your script. This
article will go over both.
- If you are using powershell, make sure you have Setup Your Powershell Profile
- Install Julia 1.1.0 if absent
- Install PackageCompiler and Deps
Alias PackageCompiler to
The full command to compile is
julia /variable/path/to/juliac.jl. The path to
this file is dependent on where PackageCompiler is stored and different on every
system. We are going to save time by using an alias.
Use your shell of choice below.
No introduction is complete without a Hello World. In this example, we’ll compile a Julia version.
We will use
juliac hello_world.jl -tavern hello_world to generate the
executable. I will cover options here briefly for sake of completeness (use
juliac -h for full details).
- -t Remove temp build files
- -a Automatically build required dependencies
- -v Verbose
- -e Make executable
- -r Implies -O3 -g0 [Max (-O)ptimize and debu(-g) at the lowest level]
- -n Output file name
Time to compile will be several minutes, so go grab a ☕!
Once it has compiled, execute it:
The two relevant files in builddir are
hello_world and a dynamically linked
hello_world.$(dll). We can use a wildcard to tar both of them.
tar -cvzf hello_world.tar.gz builddir/*
To end result shoud be approximately 26MB, regardless of system.
In this article, we constructed a Julia binary.
- Other, similar articles