Compile C code with Julia package

Hi,

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.

9 Likes

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:
https://pkgdocs.julialang.org/v1/creating-packages/#Adding-a-build-step-to-the-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.
https://docs.binarybuilder.org/stable/jll/#Overriding-specific-products

1 Like

Any specific reason why you want to avoid that?

1 Like