I’m trying to make easier for C projects to use the AV1 encoder I’m contributing to.
My ideal outcome is to make so random users could just do
cargo install crav1e and have everything they need:
- header files
- static libraries
- dynamic libraries
- pkgconfig files
We are really far from there.
Installation is completely on your own since this rfc is still being worked on, but probably we’ll get something to use sooner or later
cbindgen works already quite well so producing a
.h from the rust code is the easiest task by far.
You add it in your build.rs and you are pretty much sorted.
So far the bare basics are covered with the crate type
.a gets produced and if linked works, assuming you know which are the additional libraries you need to link beside the
There is a
cdylib crate type, but the produced library is missing a
soname and depending on the platform you might need to pass an
rpath and more linker information that are currently missing.
You need to provide a
.pc file to correctly link the static library and so far producing it is pretty ugly:
touch src/lib.rs && cargo rustc -- --print native-static-libs 2>&1 | grep note | cut -f 2 -d ":"`
Is the simplest way I figured out, maybe there is a better way.
What to improve
Right now the most sore point is on
cdylib and it is because you really want to give the linker additional information that
cargo does not pass.
If you want to produce something you may either relink the
staticlib and hope the code is already position-independent if needed.
Alternatively you may try your luck and use
cargo rustc or touch the sources and pass the needed flags through the env var
RUSTFLAGS or manually edit the produced library.
I already prepared a pr to have a mean to compute the correct linker flags in
build.rs and pass it to rustc, but there are some concerns somebody will misuse the feature.
An alternative is to make cargo provide by itself at least the linkflags to generate the
soversion on the supported platforms and restrict the ability to override this only for cdylibs.
On irc/discord one of the suggestions was to write down a pre-rfc before writing more code, so here I am.