Package: cargo-generate-rpm
cargo-generate-rpmCargohelper command to generate a binaryRPM package(.rpm)
from Cargo project.This command does not depend onrpmbuildand generates an RPM package file without a spec file by
usingrpm-rs.Installcargoinstallcargo-generate-rpmUsagecargobuild--release
strip-starget/release/XXX
cargogenerate-rpmUpon runcargo generate-rpmon your cargo project, a binary RPM package file will be created
intarget/generate-rpm/XXX.rpm.
You can change the RPM package file location using-ooption.In advance, runcargo run --releaseand strip the debug symbols (strip -s target/release/XXX), because these are not
run uponcargo generate-rpmas of now.ConfigurationThis command generates RPM metadata
fromtheCargo.tomlfile:[package.metadata.generate-rpm]optionsname: the package name. If not present,package.nameis used.version: the package version. If not present,package.versionis used.license: the package license. If not present,package.licenseis used.summary: the package summary/description. If not present,package.descriptionis used.url: the package homepage url. If not present,package.homepageis used. If neither present,package.repositoryis
used.assets: (mandatory) the array of the files to be included in the packagesource: 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.755to 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 Requiresauto-req: optional string"no"to disable the automatic dependency processrequire-sh: optional booleanfalseto omit/bin/shfrom Requirementsobsoletes: optional list of Obsoletesconflicts: optional list of Conflictsprovides: optional list of Providesvendor: optional string of VendorAdding assets such as the binary file,.desktopfile, 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}]optionsDependencies 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 ofalternativeand all versions offilesystem3.0 or
higher.Following table lists the version comparisons:ComparisonMeaningpackage = "*"A package at any version numberpackage = "< version"A package with a version number less than versionpackage = "<= version"A package with a version number less than or equal to versionpackage = "= version"A package with a version number equal to versionpackage = "> version"A package with a version number greater than versionpackage = ">= version"A package with a version number greater than or equal to versionIt is necessary to place a space between version and symbols such as<,<=, etc...package = "version"is not accepted, instead usepackage = "= 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 setpackage.metadata.generate-rpm.auto-reqto"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:Ifpackage.metadata.generate-rpm.auto-reqset to"no"or"disabled", the process is disabled.If/usr/lib/rpm/find-requiresexists, 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 usinglddis used.--auto-req /path/to/find-requires: the specified external program is used. This behavior is the same as the
originalrpmbuild.--auto-req no: the process is disabled./bin/shis always added to the package requirements. To disable it, setpackage.metadata.generate-rpm.require-shtofalse. You should not do this if you use scripts such aspre_install_scriptor 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 asmetadata."παραλλαγή") 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.tomlwhere beta.toml
containsrelease = "beta"givesrelease = "beta".Advanced UsageWorkspaceTo generate an RPM package from a member of a workspace, executecargo generate-rpmin the workspace directory
with specifying the package (directory path) with option-p:cargobuild--release
strip-starget/release/XXX
cargogenerate-rpm-pXXX[package.metadata.generate-rpm]options should be written inXXX/Cargo.toml.When the option-pspecified, first, the asset filesourceshall 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-rpmshall fail with an error.For example,source = target/bin/XXXwould usually be treated as a relative path from the current directory.
Because all packages in the workspace share a common output directory that is locatedtargetin workspace directory.Cross compilationThis command supports--target-dirand--targetoption likecargo build.
Depending on these options, this command changes the RPM package file location and replacestarget/release/of
the source locations of the assets.cargobuild--release--targetx86_64-unknown-linux-gnu
cargogenerate-rpm--targetx86_64-unknown-linux-gnuWhen--target-dir TARGET-DIRand--target x86_64-unknown-linux-gnuare specified, a binary RPM file will be created
atTARGET-DIR/x86_64-unknown-linux-gnu/generate-rpm/XXX.rpminstead oftarget/generate-rpm/XXX.rpm.
In this case, the source of the asset{ source = "target/release/XXX", dest = "/usr/bin/XXX" }will be treated asTARGET-DIR/x86_64-unknown-linux-gnu/release/XXXinstead oftarget/release/XXX.You can useCARGO_BUILD_TARGETenvironment variable instead of--targetoption andCARGO_BUILD_TARGET_DIRorCARGO_TARGET_DIRinstead of--target-dir.Payload compress typeThe 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.