For instance, some code files need to be communicated with cooperators, but with critical information concealed. All the files could be compiled as .dll (in windows), so the question is whether it is possible to call a .dll compiled via the julia itself.
https://www.reddit.com/r/Julia/comments/17tot82/state_of_compile_to_binary_in_late_2023/
GitHub - tshort/StaticCompiler.jl: Compiles Julia code to a standalone library (experimental) can do this, but only for a very limited subset of Julia.
PackageCompiler.jl might be an alternative, but the result is very large.
At the moment, you still have to initialize the Julia runtime. But then you can call functions marked by @ccallable
.
See GitHub - simonbyrne/libcg for an example.
Soon this will be outdated.
I know how to compile dll via PackageCompiler.jl, but let me reiterate my question that whether .dll files compiled by PackageCompiler.jl could be called by the Julia language via ccall?
What I know is that you cannot embed two FMUs that contain Julia dlls created with package compiler into one Simulink model because you would then have to include the Julia runtime twice which does not work.
I never tried to embed a Julia dll into a Julia program, so I do not know if it works, but why not? Just try it out.
Let me repeat the answer.
Follow the template used by libcg:
A ccallable function can be called as a regular C function in the system image. See the libcg code.
Expect the answer to be different in a week.
āsoonā as in āa PR was posted already two days agoā: add --static-call-graph option for generating smaller binaries by JeffBezanson Ā· Pull Request #55047 Ā· JuliaLang/julia Ā· GitHub (this is only for executables though, not yet for shared libraries, although I think most of the work to get there is already laid out).
While Iām also very curious about where this will eventually go, letās not overhype ourselves. The āHello Worldā example from that PR comes in at a whopping 900KB (stripped from debug symbols etc - without that, itās 1.6MB), which includes a whole bunch of stuff that isnāt needed at runtime at all. For example, thereās error strings for string
calls on <:Integer
("For negative `x`, `base` must be negative."
), some stuff for PCRE (even though there are no regexes used in the āHello Worldā example) and lots of things that only make sense when reflection is used. All that is visible through a simple strings hello | less
.
In comparison, a similar example with StaticCompiler.jl comes in at 9KB(!) - thatās 100x overhead, presumably for some runtime initialization (since things like array allocations seem to work, which donāt with StaticCompiler?). I suspect that this is due to the different approaches taken to arrive at the binary - the binary produced by that PR seems to just dump its internal state in a sysimage, placed in a opaque section in the ELF, loaded & reinitialized at runtime. Thatās not very optimizable with standard tooling, which assumes adherence to ELF sections
For the curious, when comparing other languages to this PR, weād end up somewhere between D and C# size-wise, with StaticCompiler.jl ending up somewhere between Zig and Nim (with C, C++ & Rust squarely inbetween those ranges themselves). This is of course amazingly better than the 300MB+ we had so far, but also shows that thereās still a lot of room for improvement left
On the upside, the āstartup timeā for this is
[sukera@tower juliac]$ time ./hello
Hello, world!
real 0m0.032s
user 0m0.005s
sys 0m0.032s
(though of course, thereās also room for improvement there; we donāt really need to initialize all threads for example, which does happen - strace ./hello
does not look very kind here )
I guess weāll have to wait & see what will be presented in the talk & what the future plans for this are. Incremental improvements have been the name of the game so far after all, and paid off very well for loading times & general performance. Still though - letās not overhype ourselves just yet, and be a bit patient
A PR to showcase building a shared library with juliac
just landed: