This is a Cargo helper command which automatically creates Debian packages (.deb) from Cargo projects.
sh
cargo install cargo-deb
Requires Rust 1.19+, Debian/Ubuntu, dpkg, ldd, and optionally liblzma-dev.
sh
cargo deb
Upon running cargo deb from the base directory of your Rust project, the Debian package will be created in target/debian/<project_name>_<version>_<arch>.deb. This package can be installed with dpkg -i target/debian/*.deb.
If you would like to handle the build process yourself, you can use cargo deb --no-build so that the cargo-deb command will not attempt to rebuild your project.
Debug symbols are stripped from the main binary by default. To keep debug symbols, either set [profile.release] debug = true in Cargo.toml or run cargo deb --no-strip.
cargo deb --install builds and installs the project system-wide.
This command obtains basic information it needs from the Cargo.toml file. It uses Cargo fields: name, version, license, license-file, description, readme, homepage, and repository. However, as these fields are not enough for a complete Debian package, you may also define a new table, [package.metadata.deb] that contains maintainer, copyright, license-file, changelog, depends, conflicts, breaks, replaces, provides, extended-description, section, priority, and assets.
[package.metadata.deb] optionsEverything is optional:
license-file is used.$auto keyword.readme file is used as a fallback.required or optional.[[bin]] (copied to /usr/bin/) and package readme (copied to usr/share/doc/…).
target/release/ in asset paths, even if Cargo is configured to cross-compile or use custom CARGO_TARGET_DIR. The target dir paths will be automatically corrected./ it will be inferred that the target is the directory where the file will be copied.preinst, postinst, prerm, or postrm scripts.features list (default true).Cargo.toml additionstoml
[package.metadata.deb]
maintainer = "Michael Aaron Murphy <mmstickman@gmail.com>"
copyright = "2017, Michael Aaron Murphy <mmstickman@gmail.com>"
license-file = ["LICENSE", "4"]
extended-description = """\
A simple subcommand for the Cargo package manager for \
building Debian packages from Rust projects."""
depends = "$auto"
section = "utility"
priority = "optional"
assets = [
["target/release/cargo-deb", "usr/bin/", "755"],
["README.md", "usr/share/doc/cargo-deb/README", "644"],
]
Systemd Manager:
toml
[package.metadata.deb]
maintainer = "Michael Aaron Murphy <mmstickman@gmail.com>"
copyright = "2015-2016, Michael Aaron Murphy <mmstickman@gmail.com>"
license-file = ["LICENSE", "3"]
depends = "$auto, systemd"
extended-description = """\
Written safely in Rust, this systemd manager provides a simple GTK3 GUI interface \
that allows you to enable/disable/start/stop services, monitor service logs, and \
edit unit files without ever using the terminal."""
section = "admin"
priority = "optional"
assets = [
["assets/org.freedesktop.policykit.systemd-manager.policy", "usr/share/polkit-1/actions/", "644"],
["assets/systemd-manager.desktop", "usr/share/applications/", "644"],
["assets/systemd-manager-pkexec", "usr/bin/", "755"],
["target/release/systemd-manager", "usr/bin/", "755"]
]
cargo deb supports a --target flag, which takes Rust target triple. See rustc --print target-list for the list of supported values.
The target has to be installed for Rust (e.g. rustup target add i686-unknown-linux-gnu) and has to be installed for Debian (e.g. apt-get install libc6-dev-i386). Note that Rust's and Debian's architecture names are different.
sh
cargo deb --target=i686-unknown-linux-gnu
Cross compiled archives are saved in target/<target triple>/debian/*.deb. The actual archive path is printed on success.
In .cargo/config you can add [target.<target triple>] strip = { path = "…" } to specify a path to the architecture-specific strip command.