Compile C code with Julia package


I am currently thinking about migrating an R package with underlying C/C++ code to a Julia package. However, in the short term the large C/C++ codebase should be reused and therefore is intended to be called from within Julia instead of R.

My problem is now, that I neither want to ship binaries nor do I want the user having to install make, gcc etc. and compile the files. Instead I would like to have a singular Julia package which does this process for the user (similar to R CMD INSTALL). I have not found much beside BinaryBuilder.jl and CMake.jl so far. How can I achieve this and what is best practise?

I guess that by “I neither want to ship binaries […]” you mean that you don’t want to do this manually? In this case, you could contribute your C code as a recipe to GitHub - JuliaPackaging/Yggdrasil: Collection of builder repositories for BinaryBuilder.jl, which creates binaries which can be installed like a normal julia package and which would serve as a dependency for your pure julia package.


Thanks for your reply! It took me some time to read into the topic, please excuse my ghosting.

What I tried to express was: I was wondering whether there is a proper way to work without cross-compilation. My understanding is that BinaryBuilder + Yggdrasil is used to cross-compile reliably and distribute the binaries. Another approach would be to have the user compile the binaries on his own machine.

The question arises since in the R ecosystem this is possible and sometimes even necessary because the CRAN requirements are quite strict.

You could add a deps/build.jl to your package:

More packages used to do this, but this created a rather terrible user experience. Most now use BinaryBuilder via Yggdrasil because this works quite reliably and does not impose many requirements upon the user. This will produce a JLL package.

If the user really wanted to build the binaries on their machine, they can use the JLL override mechanism via a Override.toml in the Julia depot or a LocalPreferences.toml with the Julia project.

1 Like

Any specific reason why you want to avoid that?

1 Like

Tbh the more I think about it, the less sense it makes.

I strongly encourage the BinaryBuilder approach.


That doesn’t answer my question, your comments are vague and unspecific.

Ok. Maybe this does: I had some potential issues in mind which I thought could arise with the cross-compilation approach. However in the meantime I have come to the conclusion that these potential issues are actually nonsense. Being more specific would mean presenting you some flawed argument which probably doesn’t benefit anyone.

In other words: No, I don’t have a specific reason :smiley: