From Fedora Project Wiki

< PackagingDrafts

Revision as of 16:46, 7 August 2017 by Ignatenkobrain (talk | contribs) (Created page with "{{Draft}} {{Admon/note|Consider using rust2rpm| The rust2rpm tool, available as a Fedora package or at https://pagure.io/fedora-rust/rust2rpm, automates many of these steps. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Warning.png
This page is a draft only
It is still under construction and content may change. Do not rely on the information on this page.
Note.png
Consider using rust2rpm
The rust2rpm tool, available as a Fedora package or at https://pagure.io/fedora-rust/rust2rpm, automates many of these steps. Try rust2rpm $crate first before trying to write a specfile by hand.

Naming

Dependencies

Packages MUST have BuildRequires: rust-packaging.

Automatic Requires/Provides

rust-packaging automatically creates Requires/Provides based on %cargo_registry/*/Cargo.toml files. Automatic provides create crate($name) = $version and crate($name/$feature) = $version for each "feature" crate provides. Automatic requirements take all this into account and create For example, syn = { version = "0.11", features = ["visit"] } becomes Requires: ((crate(syn) >= 0.11.0 with crate(syn) < 0.12.0) with crate(syn/visit)).

BuildRequires

Packagers MUST specify all BuildRequires according to the definition in Cargo.toml, for example:

[dependencies]
atty = "0.2.2"
[build-dependencies]
clap = "2.24.1"

should become to

# [dependencies]
BuildRequires:  (crate(atty) >= 0.2.2 with crate(atty) < 0.3.0)
# [build-dependencies]
BuildRequires:  (crate(clap) >= 2.24.1 with crate(clap) < 3.0.0)

Versions

Packagers SHOULD try to use latest version of dependent crates even if it requires patching of crate (along with sending Pull Request to upstream) to reduce maintenance burden.

ExclusiveArch

All rust packages MUST have ExclusiveArch: %{rust_arches}.

Others

Packagers MUST run %cargo_prep to prepare configuration for further cargo invocations (sets up RUSTFLAGS and all other stuff).

Nightly, Other Platforms, etc. crates

Packagers MUST NOT package crates which do not work with distribution. Packagers MUST patch packages which use such dependencies, for example:

--- cryptovec-0.3.4/Cargo.toml	2017-05-20T16:48:34+02:00
+++ cryptovec-0.3.4/Cargo.toml	2017-06-20T16:02:18.204182+02:00
@@ -10,5 +10,3 @@
 
 [dependencies]
 libc = "0.2"
-winapi = "0.2"
-kernel32-sys = "0.2"
--- cryptovec-0.3.4/src/lib.rs	2017-05-20 16:48:10.000000000 +0200
+++ cryptovec-0.3.4/src/lib.rs	2017-06-20 16:04:31.530991420 +0200
@@ -13,7 +13,9 @@
 // limitations under the License.
 //
 extern crate libc;
+#[cfg(windows)]
 extern crate winapi;
+#[cfg(windows)]
 extern crate kernel32;
 use libc::{malloc, free, c_void};
 #[cfg(not(windows))]

==

Examples

Library

# Generated by rust2rpm
%bcond_without check
%global debug_package %{nil}

%global crate clap

Name:           rust-%{crate}
Version:        2.25.0
Release:        1%{?dist}
Summary:        Simple to use, efficient, and full featured  Command Line Argument Parser

License:        MIT
URL:            https://crates.io/crates/clap
Source0:        https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
# Initial patched metadata
# * clippy is nightly
# * Loose unicode-segmentation requirements, it was done to support old Rust
Patch0:         clap-2.25.0-fix-metadata.diff

ExclusiveArch:  %{rust_arches}

BuildRequires:  rust-packaging
# [dependencies]
BuildRequires:  (crate(ansi_term) >= 0.9.0 with crate(ansi_term) < 0.10.0)
BuildRequires:  (crate(atty) >= 0.2.2 with crate(atty) < 0.3.0)
BuildRequires:  (crate(bitflags) >= 0.9.0 with crate(bitflags) < 0.10.0)
BuildRequires:  (crate(strsim) >= 0.6.0 with crate(strsim) < 0.7.0)
BuildRequires:  (crate(term_size) >= 0.3.0 with crate(term_size) < 0.4.0)
BuildRequires:  (crate(textwrap) >= 0.6.0 with crate(textwrap) < 0.7.0)
BuildRequires:  (crate(unicode-segmentation) >= 1.1.0 with crate(unicode-segmentation) < 2.0.0)
BuildRequires:  (crate(unicode-width) >= 0.1.4 with crate(unicode-width) < 0.2.0)
BuildRequires:  (crate(vec_map) >= 0.8.0 with crate(vec_map) < 0.9.0)
BuildRequires:  (crate(yaml-rust) >= 0.3.5 with crate(yaml-rust) < 0.4.0)
%if %{with check}
# [dev-dependencies]
BuildRequires:  (crate(lazy_static) >= 0.2.0 with crate(lazy_static) < 0.3.0)
BuildRequires:  (crate(regex) >= 0.2.0 with crate(regex) < 0.3.0)
%endif

%description
%{summary}.

%package        devel
Summary:        %{summary}
BuildArch:      noarch

%description    devel
A simple to use, efficient, and full featured  Command Line Argument Parser.

This package contains library source intended for building other packages
which use %{crate} from crates.io.

%prep
%autosetup -n %{crate}-%{version} -p1
%cargo_prep

%build
%cargo_build

%install
%cargo_install

%if %{with check}
%check
%cargo_test
%endif

%files          devel
%license LICENSE-MIT
%doc README.md CHANGELOG.md CONTRIBUTORS.md
%{cargo_registry}/%{crate}-%{version}/

Binary

# Generated by rust2rpm
%bcond_without check

%global crate ripgrep

Name:           rust-%{crate}
Version:        0.5.2
Release:        3%{?dist}
Summary:        Line oriented search tool using Rust's regex library

License:        Unlicense or MIT
URL:            https://crates.io/crates/ripgrep
Source0:        https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
# Initial patched metadata
# * No simd
# * No paths
# * Bump encoding_rs to 0.6, https://github.com/BurntSushi/ripgrep/pull/518
Patch0:         ripgrep-0.5.2-fix-metadata.diff

ExclusiveArch:  %{rust_arches}

BuildRequires:  rust-packaging
# [dependencies]
BuildRequires:  (crate(atty) >= 0.2.2 with crate(atty) < 0.3.0)
BuildRequires:  (crate(bytecount) >= 0.1.4 with crate(bytecount) < 0.2.0)
BuildRequires:  (crate(clap) >= 2.24.1 with crate(clap) < 3.0.0)
BuildRequires:  (crate(encoding_rs) >= 0.6.0 with crate(encoding_rs) < 0.7.0)
BuildRequires:  (crate(env_logger) >= 0.4.0 with crate(env_logger) < 0.5.0)
BuildRequires:  (crate(grep) >= 0.1.5 with crate(grep) < 0.2.0)
BuildRequires:  (crate(ignore) >= 0.2.0 with crate(ignore) < 0.3.0)
BuildRequires:  (crate(lazy_static) >= 0.2.0 with crate(lazy_static) < 0.3.0)
BuildRequires:  (crate(libc) >= 0.2.0 with crate(libc) < 0.3.0)
BuildRequires:  (crate(log) >= 0.3.0 with crate(log) < 0.4.0)
BuildRequires:  (crate(memchr) >= 1.0.0 with crate(memchr) < 2.0.0)
BuildRequires:  (crate(memmap) >= 0.5.0 with crate(memmap) < 0.6.0)
BuildRequires:  (crate(num_cpus) >= 1.0.0 with crate(num_cpus) < 2.0.0)
BuildRequires:  (crate(regex) >= 0.2.1 with crate(regex) < 0.3.0)
BuildRequires:  (crate(same-file) >= 0.1.1 with crate(same-file) < 0.2.0)
BuildRequires:  (crate(termcolor) >= 0.3.0 with crate(termcolor) < 0.4.0)
# [build-dependencies]
BuildRequires:  (crate(clap) >= 2.24.1 with crate(clap) < 3.0.0)
BuildRequires:  (crate(lazy_static) >= 0.2.0 with crate(lazy_static) < 0.3.0)

%description
%{summary}.

%package     -n %{crate}
Summary:        %{summary}

%description -n %{crate}
Line oriented search tool using Rust's regex library. Combines
the raw performance of grep with the usability of the silver searcher.

%prep
%autosetup -n %{crate}-%{version} -p1
%cargo_prep

%build
%cargo_build

%install
%cargo_install
install -D -p -m0644 doc/rg.1 %{buildroot}%{_mandir}/man1/rg.1

%if %{with check}
%check
%cargo_test
%endif

%files       -n %{crate}
%license LICENSE-MIT UNLICENSE COPYING
%doc README.md CHANGELOG.md
%{_bindir}/rg
%{_mandir}/man1/rg.1*

Library + Binary

# Generated by rust2rpm
%bcond_without check

%global crate rustfmt

Name:           rust-%{crate}
Version:        0.9.0
Release:        1%{?dist}
Summary:        Tool to find and fix Rust formatting issues

License:        ASL 2.0 or MIT
URL:            https://crates.io/crates/rustfmt
Source0:        https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate
# Initial patched metadata
# * No windows
Patch0:         rustfmt-0.9.0-fix-metadata.diff

ExclusiveArch:  %{rust_arches}

BuildRequires:  rust-packaging
# [dependencies]
BuildRequires:  (crate(diff) >= 0.1.0 with crate(diff) < 0.2.0)
BuildRequires:  (crate(env_logger) >= 0.4.0 with crate(env_logger) < 0.5.0)
BuildRequires:  (crate(getopts) >= 0.2.0 with crate(getopts) < 0.3.0)
BuildRequires:  (crate(libc) >= 0.2.11 with crate(libc) < 0.3.0)
BuildRequires:  (crate(log) >= 0.3.0 with crate(log) < 0.4.0)
BuildRequires:  (crate(regex) >= 0.2.0 with crate(regex) < 0.3.0)
BuildRequires:  (crate(serde) >= 1.0.0 with crate(serde) < 2.0.0)
BuildRequires:  (crate(serde_derive) >= 1.0.0 with crate(serde_derive) < 2.0.0)
BuildRequires:  (crate(serde_json) >= 1.0.0 with crate(serde_json) < 2.0.0)
BuildRequires:  (crate(strings) >= 0.1.0 with crate(strings) < 0.2.0)
BuildRequires:  (crate(syntex_errors) >= 0.59.0 with crate(syntex_errors) < 0.60.0)
BuildRequires:  (crate(syntex_syntax) >= 0.59.0 with crate(syntex_syntax) < 0.60.0)
BuildRequires:  (crate(term) >= 0.4.0 with crate(term) < 0.5.0)
BuildRequires:  (crate(toml) >= 0.4.0 with crate(toml) < 0.5.0)
BuildRequires:  (crate(unicode-segmentation) >= 1.0.0 with crate(unicode-segmentation) < 2.0.0)

%description
%{summary}.

%package     -n %{crate}
Summary:        %{summary}

%description -n %{crate}
%{summary}.

%package        devel
Summary:        %{summary}
BuildArch:      noarch

%description    devel
Tool to find and fix Rust formatting issues.

This package contains library source intended for building other packages
which use %{crate} from crates.io.

%prep
%autosetup -n %{crate}-%{version} -p1
%cargo_prep

%build
%cargo_build

%install
%cargo_install

%if %{with check}
%check
%cargo_test
%endif

%files       -n %{crate}
%{_bindir}/rustfmt
%{_bindir}/cargo-fmt

%files          devel
%license LICENSE-APACHE LICENSE-MIT
%{cargo_registry}/%{crate}-%{version}/