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.
sh
cargo install cargo-generate-rpm
sh
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.
This command obtains RPM metadata from the Cargo.toml
file:
[package.metadata.generate-rpm]
optionspackage.name
is used.package.version
is used.package.license
is used.package.description
is used.target/release/XXX
)/usr/bin/XXX
)755
to indicate -rwxr-xr-x
)"no"
to disable the automatic dependency process[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.
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:
package.metadata.generate-rpm.auto-req
set to "no"
or "disabled"
, the process is disabled./usr/lib/rpm/find-requires
exists, it is used (same behaviour as --auto-req /usr/lib/rpm/find-requires
).--auto-req buitin
).--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.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
:
sh
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.