Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cargo subcommand for building .rpm releases of Rust projects

License

Notifications You must be signed in to change notification settings

learnrust/cargo-rpm

 
 

Repository files navigation

🚨 UNMAINTAINED! 🚨

This crate is no longer maintained. For more information, please see the maintenance status issue.

We recommend either of the following as alternatives:

cargo-rpm

Crate Build Status Safety Dance MSRV Apache 2.0 Licensed Gitter Chat

cargo subcommand for building .rpm releases of Rust projects.

Requirements

  • Rust 1.41+

Installation

Install cargo rpm by running: cargo install cargo-rpm.

Configuring a crate

To configure your crate for RPM releases, run cargo rpm init

This will create a .rpm/YOURCRATENAME.spec file which is passed to the rpmbuild command. Though the generated spec should work out of the box, it may need some customization if the resulting RPM has dependencies or files other than target binaries.

You can also specify the --output argument to save the .spec file into a different directory. However, you will then also need to add config entry in the [package.metadata.rpm] section of the Cargo.toml file pointing to that directory, or run build command with --config argument.

For more information on spec files, see: http://ftp.rpm.org/max-rpm/s1-rpm-build-creating-spec-file.html

Building RPMs

Once your crate has been configured, run cargo rpm build to build release targets for your project and package them into an RPM.

If you encounter errors, you may need to see more information about why rpmbuild failed. Run cargo rpm build -v to enable verbose mode.

Finished .rpm files will be placed in target/release/rpmbuild/RPMs/<arch>.

You can also specify the --output argument (or add the output entry in Cargo.lock) to change the location of .rpm file. It can either be a file or a directory:

  • If the arg value ends in a / (or if it is already an existent directory), the value is treated as a directory path and rpm is created inside it with the default naming scheme (<name>-<version>-<release>.<arch>.rpm).
  • For other arg values, the value is treated as a file path (the default naming scheme won't be followed in this case).
  • Both relative and absolute paths work as input (relative paths will be normalized to be absolute when passing over to rpmbuild).
  • Parent directories in the path are auto-created, if not present (this is handled by rpmbuild).

More Examples

  • Use cargo new to create a helloworld crate.
 cargo new helloworld   --bin
 cd helloworld
 use edito to add description= "my helloworld" line.
  • Create a /usr/bin/helloworld rpm
[pi@centos7 helloworld]$ cargo rpm init -f
    Deleting /home/pi/gb/helloworld/.rpm (forced)
     Created /home/pi/gb/helloworld/.rpm
    Rendered /home/pi/gb/helloworld/.rpm/helloworld.spec
    Updating /home/pi/gb/helloworld/Cargo.toml
    Finished helloworld configured (type "cargo rpm build" to build)
[pi@centos7 helloworld]$

  • create a /usr/sbin rpm
[pi@centos7 helloworld]$ cargo rpm init  --sbin
error: destination `/home/pi/gb/helloworld/.rpm` already exists!
[pi@centos7 helloworld]$ cargo rpm init  --sbin -f
    Deleting /home/pi/gb/helloworld/.rpm (forced)
     Created /home/pi/gb/helloworld/.rpm
    Rendered /home/pi/gb/helloworld/.rpm/helloworld.spec
    Updating /home/pi/gb/helloworld/Cargo.toml
    Finished helloworld configured (type "cargo rpm build" to build)
[pi@centos7 helloworld]$

  • create a sbin with your own spec file template
[pi@centos7 helloworld]$ cargo rpm init --sbin --template=/tmp/t.template
     Created /home/pi/gb/helloworld/.rpm
    Rendered /home/pi/gb/helloworld/.rpm/helloworld.spec
    Updating /home/pi/gb/helloworld/Cargo.toml
    Finished helloworld configured (type "cargo rpm build" to build)
[pi@centos7 helloworld]$

  • building the rpm with vebose option
[pi@centos7 helloworld]$ cargo rpm build -vv
     Running cargo build --release
    Finished release [optimized] target(s) in 0.02s
    Creating release archive: helloworld-0.1.0.tar.gz
    Building helloworld-0.1.0.rpm (using rpmbuild 4.11.3)
     Running /usr/bin/rpmbuild -D _topdir /home/pi/gb/helloworld/target/release/rpmbuild -D _tmppath /home/pi/gb/helloworld/target/release/rpmbuild/tmp -ba SPECS/helloworld.spec
error: License field must be present in package: (main package)
error: error running /usr/bin/rpmbuild (exit status: exit code: 1)
[pi@centos7 helloworld]$

  • template example
[pi@centos7 helloworld]$ cat /tmp/t.template
%define __spec_install_post %{nil}
%define __os_install_post %{_dbpath}/brp-compress
%define debug_package %{nil}

Name: {{ name }}
Summary: {{ summary }}
Version: @@VERSION@@
Release: 1
{{#if license ~}}
License: {{ license }}
{{/if ~}}
{{#if service ~}}
Group: System Environment/Daemons
{{else ~}}
Group: Applications/System
{{/if ~}}
Source0: %{name}-%{version}.tar.gz
{{#if url ~}}
URL: {{ url }}
{{/if}}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
{{#if service ~}}
BuildRequires: systemd

Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd
{{/if}}
%description
%{summary}

%prep
%setup -q

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
cp -a * %{buildroot}

%clean
rm -rf %{buildroot}

{{#if service ~}}
%systemd_post {{service}}

%preun
%systemd_preun {{service}}

%postun
%systemd_postun_with_restart {{service}}

{{/if ~}}

%files
%defattr(-,root,root,-)
{{#if use_sbin ~}}
%{_sbindir}/*
{{else ~}}
%{_bindir}/*
{{/if ~}}
{{#if service ~}}
%{_unitdir}/{{service}}
{{/if ~}}
[pi@centos7 helloworld]$

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Cargo subcommand for building .rpm releases of Rust projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 97.9%
  • Handlebars 2.1%