Building Rust RPMs
Software Contributor Documentation Table of Contents
Overview
Building Rust RPMs is still an early topic, and this document is subject to change over time.
Generating a spec
Creating a specfile can be sped up by using rust2rpm
.
Steps (Assuming RHEL 7)
-
Install cargo:
yum install -y epel-release yum install -y cargo
-
Install Python 3 and activate:
yum install -y centos-release-scl yum install -y rh-python36 scl enable rh-python36 bash
-
Create a virtualenv and activate:
python -m venv my_project_venv source my_project_venv/bin/activate
-
Pull the latest rust2rpm release.
-
Install the rust2rpm package locally with pip
-
Run:
rust2rpm <PATH/TO/RUST/PROJECT>
-
The generated spec will contain a number of crates listed as
[dependencies]
underBuildRequires
andRequires
. We won’t be using those directly; delete all those lines. In addition, removeBuildRequires: rust-packaging
, and replaceExclusiveArch: %{rust_arches}
withExclusiveArch: x86_64
or whatever arches you plan to support. -
If the package you are working with is part of a workspace, there are a few more edits. Add the following after the
Source0:
line:Source1: Cargo.lock %cargo_bundle_crates -l 1
Building the SRPM
-
Install the
rust-bundled-packaging
RPM, built on iml copr:yum install -y yum-plugin-copr yum -y copr enable -y managerforlustre/buildtools yum install -y rust-bundled-packaging spectool
-
If the package being used is in a workspace, you will need to copy the dir elsewhere. This is so the package is built in a standalone way. If so, copy the dir outside the tree so it’s not associated with the workspace. If you are not in a workspace, skip this step.
-
Generate a local crate if the project you are building is not on crates.io:
cargo package
-
Take the resulting crate and put it into the rpmbuild
SOURCES
dir. -
grab all the deps. In the
SOURCES
dir:spectool -g <(rpmspec -P name.spec)
-
build the spec:
rpmbuild -bs <SPEC_NAME_HERE.spec>