Including a binary (a "*.so") with a package?

We have a vendor C API that we are currently trying to wrap in Julia. I just have their headers and a dynamic library. Presently I am using ] generate to create new projects because of the way that our source is stored. We store everyone’s work in one gigantic git repo[1], so I am not sure that I can use PkgTemplates in a “no git repo” situation.

I looked around at other projects, like Interpolations and thought that a subdirectory like ./ext might be appropriate to store the *.so in? After that, I was thinking of hard-coding the path to the *.so into a global variable in the main Julia file:

src/NEAT.jl:

neatlib::String = "../ext/libneat.so"

function neatthing()
    @ccall neatlib.do_neat()::Cvoid
end

  1. NOT my idea, and sooner or later I’ll convince “them” to change it. ↩︎

1 Like

I’m not sure how you got that idea from Interpolations as it doesn’t ship any shared library.

1 Like

It has an ./ext folder though, seemed reasonable to put external things in a directory named like that.

That’s for Package Extensions

I guess in that case, perhaps just right alongside the *.jl files?

To follow up, let me explain that .so files are usually distributed in a package artifact, and in turn these artifacts are usually listed in a JLL package, which you then list as a dependency of your Julia package. This way, when you load your Julia package, the JLL automatically grabs the correct .so file for the current platform.

JLL packages and their artifacts, in turn, are usually generated by a BinaryBuilder script. The easiest way to do this, at least for open-source software, is to make a pull request to the Yggdrasil repository, which will automatically run your script to generate cross-compiled binaries for all supported Julia platforms, and will then automatically upload and register the JLL package.

7 Likes

Note that BinaryBuilder and Yggdrasil also work for non open-source software that is provided by a vendor merely as a collection of .so files. See, for example the script to build a JLL for MKL.

7 Likes