How to use juliac.jl?

I watched this talk on juliac which I am eager to try out but I can’t figure out how. I looked through the dev docs and the relevant PR, but no such luck, so am posting here.

To get started I ran this:

juliaup update nightly
juliaup default nightly

Then, the first (naive) thing I tried was the exact syntax from the talk

# main.jl
module MyApp
Base.@ccallable function myfunc()::Cint
    println(Core.stdout, "Hello, world!")
    return 0
end
end
julia juliac.jl --output-exe main --trim main.jl

to which I realised that juliac.jl is an actual file somewhere and not a special subcommand. I found it sitting in ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl so went with that. Here’s the first error:

> julia ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

Ok, so I tried adding --experimental on the end:

> julia ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim --experimental main.jl

Unexpected argument `--experimental`

Weird. Where should --experimental go? Maybe as an argument to julia itself? This is what I tried next:

> julia --experimental \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

Even weirder. Maybe I am supposed to pass --trim to the julia binary too?

> julia --experimental --trim \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main main.jl

ld: warning: ignoring duplicate libraries: '-ljulia'
Undefined symbols for architecture arm64:
  "_main", referenced from:
      <initial-undefines>
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compilation failed.

I also tried putting all the flags in both spots, but got back to the first error:

> julia --experimental --trim \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

Does anybody know how to get this cool new feature working? Maybe it doesn’t yet support arm64, or perhaps it’s not compatible with juliaup, or perhaps I just need to do something like fix my $LD_LIBRARY_PATH to point to the right julia library files?


[disclaimer: I understand juliac is highly experimental etc and don’t expect full support on it yet; just was curious to check it out!]

3 Likes

See pass experimental flag in juliac script by baggepinnen · Pull Request #56602 · JuliaLang/julia · GitHub

For general juliac setup you might find Runic.jl/juliac at master · fredrikekre/Runic.jl · GitHub useful.

3 Likes

Oh @MilesCranmer , you may find this write-up I made earlier interesting: Pushing the Limits of Small Binary Creation

Here is the reproducible repo I set-up for that post: GitHub - TheCedarPrince/InteroperableJuliaBinaries: Experiments in making Julia binaries interoperable within other language C interfaces.

Also, something I haven’t had a chance to explore is this tweet from @jbytecode :

Seems like there may be some regressions compared to my last effort. I’d be curious what you find out, Miles!

2 Likes

Also, in my GitHub repo I linked, I discuss a little bit about LD_PATHing as at the time, something was breaking but I found a workaround.

2 Likes