Building cdylibs written in Rust for Debian
Premise
Complete C-compatible libraries written in Rust are, while not yet common, a thing. This tries to give maintainers some guidance if they want to package such a library.
With cargo-c
Build-Depend on cargo-c:native
in debian/control, in addition to existing
cargo, rustc, librust-*-dev, etc. Adapt this example debian/rules:
#!/usr/bin/make -f
include /usr/share/dpkg/architecture.mk
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
NUMJOBS = 1
endif
CARGO_C_FLAGS = --release \
--destdir=debian/tmp \
--prefix=/usr \
--libdir=/usr/lib/${DEB_HOST_MULTIARCH} \
--offline \
-v \
-j $(NUMJOBS)
%:
dh $@ --buildsystem cargo
execute_after_dh_auto_build:
CARGO_HOME=debian/cargo_home \
/usr/share/cargo/bin/cargo cbuild $(CARGO_C_FLAGS)
override_dh_auto_install:
CARGO_HOME=debian/cargo_home \
/usr/share/cargo/bin/cargo cinstall $(CARGO_C_FLAGS)
dh_auto_install
execute_after_dh_install:
find debian -name Cargo.lock -delete
Then run sbuild a few times to "guess" the correct missing build dependecies for cargo-c. Unfortunately Cargo.toml isn't helpful here. Once a clean build succeeds, create a foo-cdylib.install file that installs the .so in the correct location.
Since cargo-c builds a foo.pc pkgconf file and foo.a static library file by default you might want to create a not-installed file preventing the install of either one (or both), depending on your needs.
If the package you're targeting is already a crate packaged with the Debian
Rust team you need a custom d/rules and d/control, so touch them first in the
crates' debian folder and then run ./update.sh <crate>
again. Then you can copy
the rules/control.debcargo.hint file to rules/control respectively and edit
them accordingly.
Example: rav1e, gstreamer1.0-gtk4
With other build systems
Package all crates as usual. Then follow Gnome Team's Rust packaging guide as rough guideline. Debhelper will automatically pick up the buildsystem which in turn will build the library for you. It should just work⢠like with C. In case you run into any issues feel free to ask on the #debian-rust IRC channel on OFTC.
Example: librsvg