Packaging a Rust project for Debian
I have started to package rust things for Debian, and the process have been pretty smooth so far, but it was very hard finding information on how to start, so here is a small writeup on how I packaged my first rust crate for Debian.
This was a totally uncomplicated crate without anything special in it.
1) Add my name and email to
DEBEMAIL="email@example.com" DEBFULLNAME="First-name Last-name" CHROOT=unstable-amd64-sbuild export DEBEMAIL DEBFULLNAME CHROOT
We also added a CHROOT variable, this is explained in point 9.
2) git clone https://salsa.debian.org/rust-team/debcargo-conf.git
All Debian’s rust package information lives in one big repository on salsa.debian.org.
3) cd debcargo-conf
4) ./update.sh crate-name
This is the script that does most of the work, it looks at the crate named
crate-name on crates.io
and pre-populates what it can in the files in the
5) cd src/crate-name/debian/
The Debian directory is where all the meta information that Debian needs about a package lives.
6) cp copyright.debcargo.hint copyright
The update.sh script tries to obtain the correct copyright information, but it
guesses a lot and often needs to be touched up afterwards. The original guess work
copyright.debcargo.hint and should not be modified, but committed as is.
7) Fix copyright
After copying the original guess we need to go over it and fix the things it didn’t manage to generate correctly.
Common things to fix is:
- The years that the work was produced in, as this information isn’t in the crate. I normally look at the git repository and take the years for the first and last commit.
- Copyright for the license files, it often singles out the license files and have those as separate sections. It’s unclear if the license text is under copyright, most likely not, and it should just be deleted from the file.
- Add license text. It the crate only refers to a license, without including the text in a license file, and it’s not one of Debian’s well known licenses, then it needs to be added manually.
8) Add dependencies to native packages like this in
If your rust code depends on a native library, then you need to tell specify the name of that Debian package.
[packages.lib] depends = ["libyaml-dev"]
9) Setup a repeatable build env.
We need to test that the crate can be built without problems, and for that we need a build environment.
sudo apt install devscripts reprepro debootstrap sbuild dh-cargo sudo sbuild-createchroot --include=eatmydata,ccache,gnupg,dh-cargo,cargo,lintian,perl-openssl-defaults \ --chroot-prefix debcargo-unstable unstable \ /srv/chroot/debcargo-unstable-amd64-sbuild http://deb.debian.org/debian
10) cd ../../../build && ./build.sh crate-name
This performs a test build of the crate, and runs the lintian tool in order to detect common mistakes.
These two lintian failures always happens with new crates, and can be ignored:
E: rust-gpgme-sys changes: bad-distribution-in-changes-file UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO W: librust-gpgme-sys-dev: new-package-should-close-itp-bug
11) Add RFS file
When everything builds and lintian doesn’t complain, then it’s time to ask a Debian maintainer to upload the package to Debian. This is done by adding a file named RFS to the Debian directory.
12) Add everything to a branch
cd .. git branch package-crate-name git checkout package-crate-name git add . git commit -m "package version X.Y.Z of crate-name"
13) git push firstname.lastname@example.org:capitol-guest/debcargo-conf.git
Push your branch to your fork of the debcargo-conf project, and create a pull request from it.
14) Join #debian-rust on irc.oftc.net on irc
The people in the channel was really helpful and answered all my stupid questions about how the process works when I tried to learn it.