File bat.spec of Package bat

#
# spec file for package bat
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           bat
Version:        0.25.0
Release:        0
Summary:        A cat(1) clone with syntax highlighting and Git integration
License:        Apache-2.0 OR MIT
Group:          Productivity/Text/Utilities
URL:            https://github.com/sharkdp/bat
Source0:        %{name}-%{version}.tar.xz
Source1:        vendor.tar.xz
BuildRequires:  cargo-packaging
# weak-dep-features introduced in 1.60 and already used by libgit2-sys
# https://github.com/rust-lang/git2-rs/commit/d8ee105a8f3ce4d5c57cd091b67943aab86b176a
BuildRequires:  rust >= 1.60
# Use system libonig to avoid compiling bundled oniguruma C sources
BuildRequires:  libonig-devel
ExclusiveArch:  %{rust_arches}

%description
A cat(1) clone which supports syntax highlighting for a large number of
programming and markup languages. It has git integration and automatic paging.

%package bash-completion
Summary:        Bash completion for %{name}
Requires:       %{name} = %{version}
Supplements:    (%{name} and bash-completion)
BuildArch:      noarch

%description bash-completion
Bash command line completion support for %{name}.

%package fish-completion
Summary:        Fish completion for %{name}
Requires:       %{name} = %{version}
Supplements:    (%{name} and fish)
BuildArch:      noarch

%description fish-completion
Fish command line completion support for %{name}.

%package zsh-completion
Summary:        Zsh completion for %{name}
Requires:       %{name} = %{version}
Supplements:    (%{name} and zsh)
BuildArch:      noarch

%description zsh-completion
Zsh command line completion support for %{name}.

%prep
%setup -qa1

%build
# Prefer linking against the system libonig instead of building vendored oniguruma
# Ensure onig_sys uses the system libonig by unsetting the feature flag that
# is injected by the cargo packaging macro in the build environment.
# Provide the same environment variables used previously but make sure
# CARGO_FEATURE_VENDORED is removed from the environment for the cargo invocation.
export RUSTONIG_SYSTEM_LIBONIG=1
export RUSTONIG_DYNAMIC_LIBONIG=1
export RUSTONIG_STATIC_LIBONIG=0
# Unset any CARGO_FEATURE_VENDORED injected into the RPM build environment so
# that onig_sys will link against the system libonig instead of compiling
# the vendored oniguruma C sources.
unset CARGO_FEATURE_VENDORED
# Workaround: some bundled oniguruma C sources emit incompatible-pointer-types
# and old-style definition diagnostics with modern system headers/compilers.
# Pass additional CFLAGS to the C compiler to suppress these warnings so the
# vendored build does not fail in cases where it might still be chosen.
export CC=cc
export CFLAGS="$CFLAGS -Wno-incompatible-pointer-types -Wno-old-style-definition"
export CARGO_AUDITABLE=auditable
export CARGO_INCREMENTAL=0
export CARGO_TARGET_DIR=target
export RUSTFLAGS=' -Clink-arg=-Wl,-z,relro,-z,now -C debuginfo=2 -C strip=none'
# Run cargo with CARGO_FEATURE_VENDORED unset to avoid enabling the vendored oniguruma C sources
env -u CARGO_FEATURE_VENDORED RUSTONIG_SYSTEM_LIBONIG=1 RUSTONIG_DYNAMIC_LIBONIG=1 RUSTONIG_STATIC_LIBONIG=0 CC="$CC" CFLAGS="$CFLAGS" /usr/bin/cargo auditable build -j4 --offline --locked --release

%install
install -D -m 0755 target/release/%{name} %{buildroot}%{_bindir}/%{name}

install -D -m 0644 $(find target/release/build -name "%{name}.1") "%{buildroot}/%{_mandir}/man1/%{name}.1"

install -D -m 0644 $(find target/release/build -name "%{name}.bash") "%{buildroot}/%{_datadir}/bash-completion/completions/%{name}"
install -D -m 0644 $(find target/release/build -name "%{name}.fish") "%{buildroot}/%{_datadir}/fish/vendor_completions.d/%{name}.fish"
install -D -m 0644 $(find target/release/build -name "%{name}.zsh")  "%{buildroot}/%{_datadir}/zsh/site-functions/_%{name}"

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

%files
%doc README.md CONTRIBUTING.md CHANGELOG.md
%license LICENSE-MIT LICENSE-APACHE
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1%{ext_man}

%files bash-completion
%{_datadir}/bash-completion/completions/%{name}

%files fish-completion
%dir %{_datadir}/fish
%dir %{_datadir}/fish/vendor_completions.d
%{_datadir}/fish/vendor_completions.d/%{name}.fish

%files zsh-completion
%dir %{_datadir}/zsh
%dir %{_datadir}/zsh/site-functions
%{_datadir}/zsh/site-functions/_%{name}

%changelog
openSUSE Build Service is sponsored by