### Systemd Unit File Example Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md A basic systemd service file defining the unit's description, the command to execute, and the target it should be installed under. ```systemd [Unit] Description=Example [Service] ExecStart=/usr/bin/example [Install] WantedBy=multi-user.target ``` -------------------------------- ### Example Postinst Maintainer Script Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md Demonstrates the injected shell script fragments in the postinst maintainer script for systemd unit management, including enabling and starting services. ```sh #!/bin/sh set -e # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if deb-systemd-helper debian-installed example.service; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask example.service >/dev/null || true if deb-systemd-helper --quiet was-enabled example.service; then # Create new symlinks, if any. deb-systemd-helper enable example.service >/dev/null || true fi fi # Update the statefile to add new symlinks (if any), which need to be cleaned # up on purge. Also remove old symlinks. deb-systemd-helper update-state example.service >/dev/null || true fi # End automatically added section # Automatically added by cargo-deb if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi deb-systemd-invoke $_dh_action example.service >/dev/null || true fi fi # End automatically added section ``` -------------------------------- ### Rust Main Function Example Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md A simple Rust program that prints 'Hello World!' to standard output. ```rust fn main() { println!("Hello World!"); } ``` -------------------------------- ### Install cargo-deb Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Installs the cargo-deb command-line tool. Ensure your Rust toolchain is up-to-date. ```sh rustup update # Bookworm's Rust is too outdated, use Trixie or rustup.rs cargo install cargo-deb ``` -------------------------------- ### Install cargo-deb with static LZMA Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Install cargo-deb with the static-lzma feature to resolve 'Undefined reference to `lzma_stream_encoder_mt`' errors. ```sh cargo install cargo-deb --features=static-lzma ``` -------------------------------- ### Example of Merging Assets in Cargo.toml Variants Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Demonstrates how to merge asset lists within different build variants in Cargo.toml using 'append', 'by.dest', and 'by.src' strategies. Explicit paths take precedence over '$auto'. ```toml # Example parent asset list [package.metadata.deb] assets = [ # binary ["target/release/example", "usr/bin/", "755"], # assets ["assets/*", "var/lib/example", "644"], ["target/release/assets/*", "var/lib/example", "644"], ["3.txt", "var/lib/example/3.txt", "644"], ["3.txt", "var/lib/example/merged.txt", "644"], ] # Example merging by appending asset list [package.metadata.deb.variants.mergeappend] merge-assets.append = [ ["4.txt", "var/lib/example/appended/4.txt", "644"] ] # Example merging by `dest` path [package.metadata.deb.variants.mergedest] merge-assets.by.dest = [ ["4.txt", "var/lib/example/merged.txt", "644"] ] # Example merging by `src` path [package.metadata.deb.variants.mergesrc] merge-assets.by.src = [ ["3.txt", "var/lib/example/merged-2.txt", "644"] ] # Example merging by appending and by `src` path [package.metadata.deb.variants.mergeappendandsrc] merge-assets.append = [ ["4.txt", "var/lib/example/appended/4.txt", "644"] ] merge-assets.by.src = [ ["3.txt", "var/lib/example/merged-2.txt", "644"] ] ``` -------------------------------- ### Minimal Systemd Unit Configuration in Cargo.toml Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md Defines a single systemd unit for a package. `enable = false` prevents the unit from being enabled by default on installation. ```toml [package.metadata.deb] maintainer-scripts = "debian/" systemd-units = { enable = false } ``` -------------------------------- ### Enable maximum logging Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Increase logging verbosity for troubleshooting using -vv or RUST_LOG=debug. ```sh cargo deb -vv ``` ```sh RUST_LOG=debug cargo deb -vv ``` -------------------------------- ### Specify package metadata crate in workspaces Source: https://github.com/kornelski/cargo-deb/blob/main/README.md When using workspaces, select the crate for package metadata using -p crate_name or --manifest-path. ```sh cargo deb -p crate_name ``` ```sh cargo deb --manifest-path= ``` -------------------------------- ### Multiple Systemd Units Configuration in Cargo.toml Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md Specifies multiple systemd unit files for a package. Each entry in the `systemd-units` array defines a unit's name and whether it should be enabled by default. ```toml [package.metadata.deb] maintainer-scripts = "debian/" systemd-units = [ { unit-name = "unit-one", enable = false }, { unit-name = "unit-two", enable = false } ] ``` -------------------------------- ### Custom Cargo.toml Metadata for Debian Packages Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Configure Debian package metadata like maintainer, copyright, license file, extended description, dependencies, section, priority, and assets directly in Cargo.toml. ```toml [package.metadata.deb] maintainer = "Michael Aaron Murphy " copyright = "2017, Michael Aaron Murphy " 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 path is special, and gets replaced by cargo-deb with the actual target dir path. ["target/release/cargo-deb", "usr/bin/", "755"], # both array and object syntaxes are equivalent: { source = "README.md", dest = "usr/share/doc/cargo-deb/README", mode = "644"}, ] # assets = ["$auto"] # the default if assets are not specified ``` -------------------------------- ### Override deb version and revision Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Customize the version string with --deb-version or the revision suffix with --deb-revision. ```sh cargo deb --deb-version 1.my-custom-version ``` ```sh cargo deb --deb-revision 1.my-custom-revision ``` -------------------------------- ### Invoke cargo-deb with Verbose Output Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md Command to build a Debian package with cargo-deb, showing detailed build information and file processing steps. ```sh $ cargo-deb -v ``` -------------------------------- ### Cross-compile with cargo-deb Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Use the --target flag to specify cross-compilation targets. Multiple targets can be built in parallel. Archives are saved in target/debian/. ```sh cargo deb --target=i686-unknown-linux-gnu ``` ```sh cargo deb --target=x86_64-unknown-linux-gnu --target=aarch64-unknown-linux-gnu ``` -------------------------------- ### Configure Release Profile for Debug Symbols Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Set the debug information level for the release profile in Cargo.toml. Use 'line-tables-only' for minimal debug info or '1' for more detailed information. ```toml [profile.release] debug = "line-tables-only" # or debug = 1 for fatter debug info ``` -------------------------------- ### Build Debian Package with cargo-deb Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Builds a Debian package for your Cargo project. The package is created in the target/debian directory by default. ```sh cargo deb ``` -------------------------------- ### Generate Separate Debug Symbol Package Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Use the `--dbgsym` flag to create a separate -dbgsym.ddeb package containing only debug symbols, removing them from the main executables. Requires GNU objcopy. ```sh cargo deb --dbgsym ``` -------------------------------- ### Pass custom cargo build flags Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Use --no-build to prevent cargo-deb from rebuilding the project and pass custom flags to cargo build after --. ```sh cargo deb -- ``` -------------------------------- ### Inspect Debian Package Maintainer Scripts Source: https://github.com/kornelski/cargo-deb/blob/main/systemd.md Commands to extract maintainer scripts from a generated Debian package and list the extracted files. ```sh $ dpkg -e target/debian/example_1.2.3_amd64.deb deb_out $ ls -la deb_out/ ``` -------------------------------- ### Separate Debug Symbols in the Same Package Source: https://github.com/kornelski/cargo-deb/blob/main/README.md Use `--separate-debug-symbols` to place debug symbols in separate files within the package, and optionally `--compress-debug-symbols` to compress them. Requires GNU objcopy. ```sh cargo deb --separate-debug-symbols --compress-debug-symbols ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.