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)

  1. Install cargo:

    yum install -y epel-release
    yum install -y cargo
    
  2. Install Python 3 and activate:

     yum install -y centos-release-scl
     yum install -y rh-python36
     scl enable rh-python36 bash
    
  3. Create a virtualenv and activate:

    python -m venv my_project_venv
    source my_project_venv/bin/activate
    
  4. Pull the latest rust2rpm release.

  5. Install the rust2rpm package locally with pip

  6. Run:

    rust2rpm <PATH/TO/RUST/PROJECT>
    
  7. The generated spec will contain a number of crates listed as [dependencies] under BuildRequires and Requires. We won’t be using those directly; delete all those lines. In addition, remove BuildRequires: rust-packaging, and replace ExclusiveArch: %{rust_arches} with ExclusiveArch: x86_64 or whatever arches you plan to support.

  8. 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

  1. 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
    
  2. 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.

  3. Generate a local crate if the project you are building is not on crates.io:

    cargo package
    
  4. Take the resulting crate and put it into the rpmbuild SOURCES dir.

  5. grab all the deps. In the SOURCES dir:

    spectool -g <(rpmspec -P name.spec)
    
  6. build the spec:

    rpmbuild -bs <SPEC_NAME_HERE.spec>
    

Top of page