Skip to main content

Generate a binary RPM package (.rpm) from Cargo projects

Project description

cargo-generate-rpm

Cargo helper command to generate a binary RPM package (.rpm) from Cargo project.

This command does not depend on rpmbuild and generates an RPM package file without a spec file by using rpm-rs.

Rust cargo-generate-rpm at crates.io

Install

cargo install cargo-generate-rpm

Usage

cargo build --release
strip -s target/release/XXX
cargo generate-rpm

Upon run cargo generate-rpm on your cargo project, a binary RPM package file will be created in target/generate-rpm/XXX.rpm. You can change the RPM package file location using -o option.

In advance, run cargo run --release and strip the debug symbols (strip -s target/release/XXX), because these are not run upon cargo generate-rpm as of now.

Configuration

This command generates RPM metadata from the Cargo.toml file:

[package.metadata.generate-rpm] options

  • name: the package name. If not present, package.name is used.
  • version: the package version. If not present, package.version is used.
  • license: the package license. If not present, package.license is used.
  • summary: the package summary/description. If not present, package.description is used.
  • url: the package homepage url. If not present, package.homepage is used. If neither present, package.repository is used.
  • assets: (mandatory) the array of the files to be included in the package
    • source: the location of that asset in the Rust project. (e.g. target/release/XXX) Wildcard character * is allowed.
    • dest: the install-destination. (e.g. /usr/bin/XXX) It shall be a file path or a directory path ending /. If source contains wildcard character *, it must be a directory, not a file path.
    • mode: the permissions as octal string. (e.g. 755 to indicate -rwxr-xr-x)
    • config: set true if it is a configuration file.
    • doc: set true if it is a document file.
    • user: the owner of the file.
    • group: the group owner of the file.
  • release: optional string of release.
  • epoch: optional number of epoch.
  • pre_install_script: optional string of pre_install_script.
  • pre_uninstall_script: optional string of pre_uninstall_script.
  • post_install_script: optional string of post_install_script.
  • post_uninstall_script: optional string of post_uninstall_script.
  • requires: optional list of Requires
  • auto-req: optional string "no" to disable the automatic dependency process
  • require-sh: optional boolean false to omit /bin/sh from Requirements
  • obsoletes: optional list of Obsoletes
  • conflicts: optional list of Conflicts
  • provides: optional list of Provides
  • vendor: optional string of Vendor

Adding assets such as the binary file, .desktop file, or icons, shall be written in the following way.

[package.metadata.generate-rpm]
assets = [
    { source = "target/release/XXX", dest = "/usr/bin/XXX", mode = "755" },
    { source = "<path_relative_to_project_root>/XXX.desktop", dest = "/usr/share/applications/XXX.desktop", mode = "644" },
    { source = "<path_relative_to_project_root>/*/apps/XXX.png", dest = "/usr/share/icons/hicolor/", mode = "644" },
]

[package.metadata.generate-rpm.{requires,obsoletes,conflicts,provides}] options

Dependencies such as "requires", "obsoletes", "conflicts", and "provides" shall be written in similar way as dependencies in Cargo.toml.

[package.metadata.generate-rpm.requires]
alternative = "*"
filesystem = ">= 3"

This example states that the package requires with any versions of alternative and all versions of filesystem 3.0 or higher.

Following table lists the version comparisons:

Comparison Meaning
package = "*" A package at any version number
package = "< version" A package with a version number less than version
package = "<= version" A package with a version number less than or equal to version
package = "= version" A package with a version number equal to version
package = "> version" A package with a version number greater than version
package = ">= version" A package with a version number greater than or equal to version

It is necessary to place a space between version and symbols such as <, <=, etc... package = "version" is not accepted, instead use package = "= version".

This command automatically determines what shared libraries a package requires. There may be times when the automatic dependency processing is not desired. In this case, the package author may set package.metadata.generate-rpm.auto-req to "no" or the user who executes this command may specify command line option --auto-req no.

  • --auto-req auto: The following rules are used to determine the preferred automatic dependency process:
    • If package.metadata.generate-rpm.auto-req set to "no" or "disabled", the process is disabled.
    • If /usr/lib/rpm/find-requires exists, it is used (same behaviour as --auto-req /usr/lib/rpm/find-requires).
    • Otherwise, builtin procedure is used (same behaviour as --auto-req builtin).
  • --auto-req builtin: the builtin procedure using ldd is used.
  • --auto-req /path/to/find-requires: the specified external program is used. This behavior is the same as the original rpmbuild.
  • --auto-req no: the process is disabled.

/bin/sh is always added to the package requirements. To disable it, set package.metadata.generate-rpm.require-sh to false. You should not do this if you use scripts such as pre_install_script or if your assets contain shell scripts.

Overwrite configuration

[package.metadata.generate-rpm] can be overwritten. The following command line options are used:

  • --metadata-overwrite=TOML_FILE.toml : Overwrite the [package.metadata.generate-rpm] options with the contents of the specified TOML file.
  • --metadata-overwrite=TOML_FILE.toml#TOML.PATH : Overwrites the [package.metadata.generate-rpm] options with the table specified in the TOML path of the TOML file. Only a sequence of bare keys connected by dots is acceptable for the TOML path. Path containing quoted keys (such as metadata."παραλλαγή") cannot be acceptable.
  • -s 'toml "text"' or --set-metadata='toml "text"' : Overwrite the [package.metadata.generate-rpm] options with inline TOML text. The argument text --- inline TOML text must be enclosed in quotation marks since it contains spaces.
  • --variant=VARIANT : Overwrites the [package.metadata.generate-rpm] options with the table specified in [package.metadata.generate-rpm.variants.VARIANT] of the TOML file. It is a shortcut to --metadata-overwrite=path/to/Cargo.toml#package.metadata.generate-rpm.variants.VARIANT. It is intended for providing multiple variants of the metadata in a Cargo.toml and ability for the users to select the variant using --variant=name option.

These options can be specified more than once, with the last written one specified being applied. For example, the arguments -s 'release = "alpha"' --metadata-overwrite=beta.toml where beta.toml contains release = "beta" gives release = "beta".

Advanced Usage

Workspace

To generate an RPM package from a member of a workspace, execute cargo generate-rpm in the workspace directory with specifying the package (directory path) with option -p:

cargo build --release
strip -s target/release/XXX
cargo generate-rpm -p XXX

[package.metadata.generate-rpm] options should be written in XXX/Cargo.toml.

When the option -p specified, first, the asset file source shall be treated as a relative path from the current directory. If not found, it shall be treated as a relative path from the directory of the package. If both not found, cargo generate-rpm shall fail with an error.

For example, source = target/bin/XXX would usually be treated as a relative path from the current directory. Because all packages in the workspace share a common output directory that is located target in workspace directory.

Cross compilation

This command supports --target-dir and --target option like cargo build. Depending on these options, this command changes the RPM package file location and replaces target/release/ of the source locations of the assets.

cargo build --release --target x86_64-unknown-linux-gnu
cargo generate-rpm --target x86_64-unknown-linux-gnu

When --target-dir TARGET-DIR and --target x86_64-unknown-linux-gnu are specified, a binary RPM file will be created at TARGET-DIR/x86_64-unknown-linux-gnu/generate-rpm/XXX.rpm instead of target/generate-rpm/XXX.rpm. In this case, the source of the asset { source = "target/release/XXX", dest = "/usr/bin/XXX" } will be treated as TARGET-DIR/x86_64-unknown-linux-gnu/release/XXX instead of target/release/XXX.

You can use CARGO_BUILD_TARGET environment variable instead of --target option and CARGO_BUILD_TARGET_DIR or CARGO_TARGET_DIR instead of --target-dir.

Payload compress type

The default payload compress type of the generated RPM file is zstd. You can specify the payload compress type with --payload-compress TYPE: none, gzip, or zstd.

For the legacy system (e.g. centos7), specify legacy compress type explicitly e.g. --payload-compress none.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

cargo_generate_rpm-0.10.1-py3-none-win_amd64.whl (967.1 kB view details)

Uploaded Python 3 Windows x86-64

cargo_generate_rpm-0.10.1-py3-none-win32.whl (903.1 kB view details)

Uploaded Python 3 Windows x86

cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (2.2 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ i686

cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_generate_rpm-0.10.1-py3-none-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded Python 3 macOS 11.0+ ARM64

cargo_generate_rpm-0.10.1-py3-none-macosx_10_7_x86_64.whl (1.3 MB view details)

Uploaded Python 3 macOS 10.7+ x86-64

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 041c4142e562410dd9d65e75dd1ad8ca7cbde28350373304c535c373715e2488
MD5 1d92c4ca9598933c52884b2de2565421
BLAKE2b-256 c6e00cea335b05e0baf41ad7ba91fdfc8b3f7f7174fdb3ac62be08423faaaf66

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-win32.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 e781dda0f4f75e207e7c7350c13b1b4ab539dfe6541e439c3fcdf434e7b5daaa
MD5 ee35f942db845e2f444be54e618e6387
BLAKE2b-256 214f46d741f2ed77cfe40b9a984887a298b026bcbf702b8717844c5fbd841848

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd066930eaadc548f3267a9188ffb5abfc9c76bbf0e1a96e8e4eeeeb388ced3d
MD5 6bfe738666112c4c5c49a7a64f2c6ab1
BLAKE2b-256 834ec7edde5f6df21c70f1826c91fe37e2e8f14b0928087713369f7ba3cc3e38

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fbbc7fe843269d26a4ffb4c2511540e217cfb9d7db765775a8faf83edb4915f4
MD5 5a8cd18aad9ca63361173d6f4d610926
BLAKE2b-256 427f9929a93a7d4af473060467c1a82463daa00db7bd9d560e318d1499185572

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1300a5487a51cb23378318f8aec3eadfe73671e70226aa1c5c6f36fd77920feb
MD5 227d4c7610c8b38026b307578044780f
BLAKE2b-256 c9775a947bdd2508713cfbf36149426ad0b13a68bda073eaeb5235bc964460b8

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b2d2d76177e2f82c9aede6b1fef482ccf0a1abb2badb3bb7bb997f0e1054fa7
MD5 f5fc99eb80f18fed053380db63cfa9b8
BLAKE2b-256 8d08ced4457355313c87d12eb1ef2103ed98a5dd2ae97e8092721cfdcf15d505

See more details on using hashes here.

File details

Details for the file cargo_generate_rpm-0.10.1-py3-none-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for cargo_generate_rpm-0.10.1-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b9741b1c12b79dd9d2ddddebecca17621c68dc21e1265f248f8b96ea2da2e6dd
MD5 e369a85e5dffcbd1e24ad7c9b191fd21
BLAKE2b-256 226e3d21b5fcf53deea3a23e23d9f694f4f83bcf8e1b8fed63b597d90642a080

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page