LinuxCommandLibrary

cargo-deb

Create Debian packages from Rust projects

TLDR

Create a Debian package from a project

$ cargo deb
copy

Write the .deb file to the specified file or directory
$ cargo deb [[-o|--output]] [path/to/file_or_directory]
copy

Compile for the specified Rust target triple
$ cargo deb --target [x86_64-unknown-linux-gnu]
copy

Select which package to use in a Cargo workspace
$ cargo deb [[-p|--package]] [package_name]
copy

Immediately install the created package
$ cargo deb --install
copy

SYNOPSIS

cargo deb [OPTIONS]

PARAMETERS

--help
    Prints help information.

--version
    Prints version information.

--verbose, -v
    Use verbose output.

--quiet, -q
    Do not print cargo deb log messages.

--profile
    Build with the given profile (e.g., debug, release). Defaults to release.

--target
    Build for the target triple (e.g., x86_64-unknown-linux-gnu).

--no-strip
    Do not strip the debug symbols from the binary. This results in larger packages but can be useful for debugging.

--no-build
    Do not build the project, only create the Debian package from pre-built artifacts.

--deb-version
    Override the Debian version string specified in Cargo.toml. Useful for custom release cycles.

--output
    Write the .deb file to the specified path instead of the default target/debian/ directory.

--manifest-path
    Path to Cargo.toml.

--features
    Space-separated list of features to activate.

--all-features
    Activate all available features.

--no-default-features
    Do not activate the default feature.

DESCRIPTION

cargo-deb is a cargo subcommand that simplifies the process of creating Debian (.deb) packages directly from Rust projects. It automates the packaging of Rust binaries, libraries, and associated files into a standard Debian format, making it easier to distribute Rust applications on Debian-based Linux systems like Ubuntu.

When invoked, cargo-deb reads metadata from your project's Cargo.toml file, including project name, version, description, and optionally specific Debian-related configurations. It then compiles your Rust project, gathers the necessary artifacts (executables, shared libraries, man pages, etc.), and bundles them into a .deb archive compliant with Debian packaging standards. This tool significantly reduces the manual effort required to package Rust software for Linux distribution, bridging the gap between Rust's build system and the Debian ecosystem.

CAVEATS

cargo-deb relies heavily on metadata configured within your project's Cargo.toml file. Incorrect or missing information (especially under [package.metadata.deb]) can lead to malformed packages or errors. It also depends on system tools like dpkg and its dependencies for creating the final .deb archive, so these must be available on the build system. While powerful for common use cases, it may not support highly complex Debian packaging scenarios that require custom maintainer scripts or intricate file placement logic as robustly as manual debhelper configurations.

<CODE>CARGO.TOML</CODE> CONFIGURATION

cargo-deb extensively uses the [package.metadata.deb] section in your Cargo.toml to configure package metadata. This allows you to specify critical Debian-specific fields like:

  • Section: The Debian package section (e.g., utils, devel).
  • Priority: The package's priority (e.g., optional, required).
  • Depends: A list of runtime dependencies on other Debian packages.
  • ExtendedDescription: A more detailed, multi-line description of the package.
  • Maintainer: The package maintainer's name and email.
  • Homepage: The project's homepage URL.
  • assets: Defines files to be included in the package, allowing precise control over file paths and permissions.

HISTORY

Before cargo-deb, creating Debian packages for Rust projects often involved manual creation of the debian/ directory and its intricate control files, or using generic build system integrations. This was a cumbersome process for Rust developers aiming to distribute their applications on Debian-based systems. cargo-deb emerged to streamline this workflow, providing a native cargo subcommand that leverages existing project metadata from Cargo.toml to automatically generate valid .deb packages. Its development has focused on integrating seamlessly with the Rust build ecosystem, significantly lowering the barrier to entry for distributing Rust-based software on a wide array of Linux distributions.

SEE ALSO

cargo(1), rustc(1), dpkg(1), debhelper(7), apt(8)

Copied to clipboard