## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# EL8 and EL9 require `gcc-toolset-13` as build dependency.
# * On EL8, Binutils 2.30 do not support the `vmovdqu` AVX-512 instruction.
# * On EL8 and EL9, GCC 8.5.0/11.4.1 generates ultra-slow test code for aarch64.
# * When building with `gcc-toolset-12`, the `gcc-annobin` plugin is not found.
%global needs_gcc_toolset 0%{?el8} || 0%{?el9}

Name:           blake3
Version:        1.5.5
Release:        %autorelease
Summary:        Official C implementation of the BLAKE3 cryptographic hash function

License:        Apache-2.0
URL:            https://github.com/BLAKE3-team/BLAKE3/
Source0:        %{url}/archive/%{version}/%{name}-%{version}.tar.gz

BuildRequires:  cmake
%if %{needs_gcc_toolset}
BuildRequires:  gcc-toolset-13
BuildRequires:  gcc-toolset-13-libasan-devel
BuildRequires:  gcc-toolset-13-libubsan-devel
%else
BuildRequires:  gcc
BuildRequires:  libasan
BuildRequires:  libubsan
%endif
BuildRequires:  python3

%description
BLAKE3 is a cryptographic hash function that is:
- Much faster than MD5, SHA-1, SHA-2, SHA-3, and BLAKE2.
- Secure, unlike MD5 and SHA-1. And secure against length extension, unlike
  SHA-2.
- Highly parallelizable across any number of threads and SIMD lanes, because
  it's a Merkle tree on the inside.
- Capable of verified streaming and incremental updates, again because it's a
  Merkle tree.
- A PRF, MAC, KDF, and XOF, as well as a regular hash.
- One algorithm with no variants, which is fast on x86-64 and also on smaller
  architectures.


%package devel
Summary: %{summary} - development files
Requires: %{name}%{?_isa} = %{version}-%{release}

%description devel
Development files for the %{name} library.


%prep
%autosetup -p1 -n BLAKE3-%{version}


%build
%if %{needs_gcc_toolset}
. /opt/rh/gcc-toolset-13/enable
%endif
cd c
%cmake
%cmake_build


%check
# These make-flag definitions are only used locally
%ifnarch x86_64
%define non_x86_64_flags BLAKE3_NO_SSE2=1 BLAKE3_NO_SSE41=1 BLAKE3_NO_AVX2=1 BLAKE3_NO_AVX512=1
%else
%if %{needs_gcc_toolset}
# Do not run the AVX-512 test because it segfaults when instrumented with ASAN
# (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110027 - fixed upstream, but
# `gcc-toolset-13` does not include the fix)
%define non_x86_64_flags BLAKE3_NO_AVX512=1
%endif
%endif
%ifarch %{arm32} aarch64
%define arm_flags %{?flags} BLAKE3_USE_NEON=1
%endif

%if %{needs_gcc_toolset}
. /opt/rh/gcc-toolset-13/enable
%endif
cd c
%make_build %{?non_x86_64_flags} %{?arm_flags} -f Makefile.testing test

# There is no NEON assembly implementation
%make_build %{?non_x86_64_flags} BLAKE3_NO_NEON=1 -f Makefile.testing test_asm


%install
cd c
%cmake_install


%files
%license LICENSE_A2
%doc c/README.md
%{_libdir}/lib%{name}.so.0
%{_libdir}/lib%{name}.so.%{version}

%files devel
%doc c/example.c
%{_includedir}/%{name}.h
%{_libdir}/lib%{name}.so
%{_libdir}/cmake/%{name}/
%{_libdir}/pkgconfig/lib%{name}.pc


%changelog
## START: Generated by rpmautospec
* Wed Nov 27 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.5-1
- Update to 1.5.5 (fedora#2329086)

* Wed Aug 21 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.4-1
- Update to 1.5.4 (fedora#2306018)

* Wed Jul 17 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.3-3
- Build with GCC instead of Clang

* Wed Jul 17 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Mon Jul 15 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.3-1
- Update to 1.5.3 (fedora#2297810)

* Sat Mar 16 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.1-2
- Use %%autorelease and remove non-%%autochangelog entries

* Sat Mar 16 2024 Christoph Erhardt <fedora@sicherha.de> - 1.5.1-1
- Update to 1.5.1 (fedora#2269330)

* Tue Jan 23 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jan 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Nov 10 2023 Christoph Erhardt <fedora@sicherha.de> - 1.5.0-2
- Exclude i686 on Fedora >= 39

* Fri Nov 10 2023 Christoph Erhardt <fedora@sicherha.de> - 1.5.0-1
- Initial import (fedora#2241062)
## END: Generated by rpmautospec