Where is juliac developed

Likely inference limits on depth and tuple length, I suppose :wink:

Link?

2 Likes

The map and mapreduce implementation in Julia right now is a bit of an abomination. it needs a rewerite.

3 Likes

What are concrete problems with them? Abomination sounds bad but what could be so wrong about them? They seem simple functions on the surface. Never checked their implementation, though.

They sure feel like they should be simple, but theyā€™re super performance critical and encapsulate many do-what-you-mean behaviors in not-very-well-defined ways. You can just scan through the fold label on GitHub to get a sense of the concrete issues.

4 Likes

Honestly, after seeing a type dispatch error I just assumed (guessed) that rather then pass a Matrix{Float64} that I should convert to Symmetric and thatā€™s all I needed to do.

2 Likes

Does --output-lib require an entry point? The --compile-ccallable option seems to include the target functions in the shared library.

I havenā€™t tried the --output-lib option, but it shouldnā€™t be necessary to have an entry point in a shared library. When an entry point is included in a file and compiled with --output-exe, the compiler links and compiles the functions called by the entry point. Any unused code is removed in the compiled file, so we need to link them or, at the very least, prevent the compiler from deleting them. Specifically, --compile-ccallable (if exists) seems to be handling this issue.

Then what does --output-lib without --compile-ccallable do? Note that the @ccallable I am experimenting with works with StaticCompiler and doesnā€™t require a runtime. I would assume a more general version needs a workload (as seen from the entry point) to compile (and initializes the runtime somehow?) .

1 Like

I think --compile-lib without any additional arguments + an entry point should not include the library functions (one can try it out using nm library.so | grep funcname) and you might be right, because the entry point triggers jl_init() call.

Suppose the code is

module MyLibrary

Base.@ccallable function myfunc(x::Float64)::Float64
    return x^2
end

end

When itā€™s compiled using

julia +nightly juliac.jl --output-lib mylib.so --trim mylib.jl

generates mylib.so without the exported function myfunc. When we introduce the --compile-callable option

julia +nightly juliac.jl --output-lib mylib.so --trim --compile-ccallable mylib.jl

produces the mylib.so with the function myfunc included:

#> nm ./mylib.so | grep myfunc
000000000000de00 t jfptr_myfunc_21486
0000000000023ed0 t jlcapi_myfunc_21488
000000000001d0c0 t julia_myfunc_21485
0000000000023ed0 T myfunc
5 Likes

generates mylib.so without the exported function myfunc . When we introduce the --compile-callable option

This helps me a lot. Thank you!!!

4 Likes

That example is very helpful for those who plan to generate dynamic link libraries and later use them within C, C++, Rust or any other language with useful FFI. Thank you.

I think it is now time to fix the juliac.jl --help documentation. The other step is to prepare the official docs about the compiler.

3 Likes

just as a very quick question in here. Does juliac only work with Linux or does it also work on Windows?

5 Likes

Iā€™m not on Windows to confirm, but it seems it would work. I see nothing platform-specific in the files juliac-buildscript.jl and juliac.jl, only in julia-config.jl, that is used by Juliac:

function ldflags(doframework)
    doframework && return "-F$(shell_escape(frameworkDir()))"
    fl = "-L$(shell_escape(libDir()))"
    if Sys.iswindows()
        fl = fl * " -Wl,--stack,8388608"
    elseif !Sys.isapple()
        fl = fl * " -Wl,--export-dynamic"
    end
    return fl
end
2 Likes

If your Windows machine has cc command (C compiler), juliac.jl should work. In fact, my script in my repository libcalcpi_juliac could be generated as libcalcpi.dll.

This article Installing the MinGW-w64 toolchain guides us how to install the cc command on Windows.

3 Likes

I wrote a script build.jl to make juliac and clang work together in Windows, but there is an error when executing the compiled exe:

  1. There is no output when running the exe directly
  2. Copy the exe to the Julia bin directory and run it. The error is as follows:
[26424] signal 11: SIGSEGV
in expression starting at none:0
crt_sig_handler at C:/workdir/src\signals-win.c:99
.text at C:\Users\***\AppData\Local\julias\julia-latest\bin\cal.exe (unknown line)
_C_specific_handler at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
_chkstk at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
RtlFindCharInUnicodeString at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
KiUserExceptionDispatcher at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
crc32c_sse42 at C:/workdir/src\crc32c.c:112
ijl_restore_system_image_data at C:/workdir/src\staticdata.c:4033
jl_load_sysimg_so at C:/workdir/src\staticdata.c:660 [inlined]
ijl_restore_system_image at C:/workdir/src\staticdata.c:4005
_finish_julia_init at C:/workdir/src\init.c:858
static_init at E:\codes\compile_jl\.\jl_nXpgrg\init.c:5
__do_global_ctors at C:\Users\***\AppData\Local\julias\julia-latest\bin\cal.exe (unknown line)        
__main at C:\Users\***\AppData\Local\julias\julia-latest\bin\cal.exe (unknown line)
__tmainCRTStartup at C:\Users\***\AppData\Local\julias\julia-latest\bin\cal.exe (unknown line)        
.l_start at C:\Users\***\AppData\Local\julias\julia-latest\bin\cal.exe (unknown line)
BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
Allocations: 0 (Pool: 0; Big: 0); GC: 0

the build.jl:

using Clang_jll

function update_juliac()
    Base.run(`curl https://raw.githubusercontent.com/JuliaLang/julia/refs/heads/master/contrib/juliac-buildscript.jl -o juliac-buildscript.jl`)
    Base.run(`curl https://raw.githubusercontent.com/JuliaLang/julia/refs/heads/master/contrib/juliac.jl -o juliac.jl`)
end

if findfirst(x -> x == "--update", ARGS) !== nothing
    update_juliac()
    exit(0)
else
    if !isfile("juliac.jl") || !isfile("juliac-buildscript.jl")
        update_juliac()
    end

    if Sys.iswindows()
        clang_lib = normpath(joinpath(Clang_jll.PATH[], "../bin"))
        paths = clang_lib * ";" * Clang_jll.PATH[] * join(Clang_jll.LIBPATH, ";") * ";" * ENV["PATH"]
        # hack cmd to use clang instead of cc
        run = (cmd::Cmd) -> begin
            println("šŸ“Œ")
            cc = withenv(clang, "PATH" => paths)
            for flag in cmd.exec[2:end]
                push!(cc.exec, flag)
            end
            println(cc.exec)
            Base.run(cc)
            println()
        end
        # hack temp dir into current working directory
        mktempdir(; cleanup=true) = Base.mktempdir(normpath("."), cleanup=cleanup)
    end

    include("juliac.jl")
end

juliac has new commits!

now, the --verbose option works for a more loud compilation.

One can try compiling their code like

julia +nightly juliac.jl --output-exe hello --trim --verbose hello.jl

after downloading the latest contrib folder

5 Likes