%global debug_package %{nil} %bcond check 0 Name: rs-edit Version: 0.2.0 Release: %autorelease Summary: Rust structural search-and-replace CLI. License: GPL-2.0-only URL: https://src00.lsme.ca/devops/rs-edit Source0: %{name}-v%{version}.tar.gz BuildRequires: cargo BuildRequires: rust Requires: cargo Requires: rust Requires: rust-src %if !0%{?fedora} BuildRequires: curl %endif %description %{summary}. %prep %autosetup -n %{name} %if !0%{?fedora} __SYSTEM_RUST_VERSION="$(rustc --version | sed -E 's/^rustc ([0-9]+(\.[0-9]+){1,2}).*/\1/')" __REQUIRED_RUST_VERSION="$(sed -nE 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"([0-9]+(\.[0-9]+){1,2})".*/\1/p' rust-toolchain.toml)" __REQUIRED_RUST_VERSION="$(printf '%s\n' "$__REQUIRED_RUST_VERSION" | awk -F. ' NF == 2 { print $0 ".0" } NF == 3 { print $0 } ')" if [ -z "$__SYSTEM_RUST_VERSION" ] || [ -z "$__REQUIRED_RUST_VERSION" ]; then echo "Unable to determine the Rust versions" exit 1 fi if [ "$(printf '%s\n%s\n' "$__SYSTEM_RUST_VERSION" "$__REQUIRED_RUST_VERSION" | sort -V | tail -n1)" = "$__SYSTEM_RUST_VERSION" ]; then echo "Skipping Rust download. Required ${__REQUIRED_RUST_VERSION}, installed: ${__SYSTEM_RUST_VERSION}" else echo "Downloading Rust ${__REQUIRED_RUST_VERSION} ..." curl --fail --location --output rustup-init \ "https://static.rust-lang.org/rustup/dist/$(uname --machine)-unknown-linux-gnu/rustup-init" chmod +x rustup-init ./rustup-init --verbose --profile minimal --component rust-src --default-toolchain "$__REQUIRED_RUST_VERSION" -y rm -f rustup-init fi %endif %build %if !0%{?fedora} if [ -x "${HOME}/.cargo/bin/rustc" ]; then export PATH="${HOME}/.cargo/bin:${PATH}" fi rustc --version cargo --version %endif cargo build --release --locked %if %{with check} %check cargo test --locked %endif %install install -D -m 0755 target/release/rs-edit %{buildroot}%{_bindir}/rs-edit %files %license LICENSE %{_bindir}/rs-edit %changelog %autochangelog