File spirv-tools.spec of Package spirv-tools
%define realname SPIRV-Tools
%define realver 2025.1
%define srcext tar.gz
# See: DEPS
%define abseil_revision f004e6c0a9a25e16fd2a1ae671a9cacfa79625b4
%define effcee_revision 12241cbc30f20730b656db7fd5a3fa36cd420843
%define googletest_revision c00fd25b71a17e645e4567fcb465c3fa532827d2
%define protobuf_revision v21.12
%define re2_revision 6dcd83d60f7944926bfd308cc13979fc53dd69ca
%define spirv_headers_revision 09913f088a1197aba4aefd300a876b2ebbaa3391
### %define mimalloc_revision 09a27098aa6e9286518bd9c74e6ffa7199c3f04e
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
%if 0%{?rhel} >= 8
%define python3_pkg platform-python
%define python3 %{_libexecdir}/platform-python
%else
%define python3_pkg python3
%define python3 %{_bindir}/python3
%endif
# Common info
Name: spirv-tools
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: Apache-2.0
Group: Development/Tools/Other
URL: https://github.com/KhronosGroup/SPIRV-Tools
Summary: API and commands for processing SPIR-V modules
# Install-time parameters
Requires: lib%{realname} = %{version}-%{release}
Provides: %{realname} = %{version}-%{release}
Obsoletes: %{realname} < %{version}-%{release}
# Build-time parameters
BuildRequires: cmake >= 3.22.1
BuildRequires: pkg-config
BuildRequires: gcc-c++
BuildRequires: %{python3_pkg}
BuildRequires: ninja
Source0: https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/v%{realver}%{?extraver}.%{srcext}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# DEPS
Source11: https://github.com/abseil/abseil-cpp/archive/%{abseil_revision}.%{srcext}#/abseil-cpp.%{srcext}
Source12: https://github.com/google/effcee/archive/%{effcee_revision}.%{srcext}#/effcee.%{srcext}
Source13: https://github.com/google/googletest/archive/%{googletest_revision}.%{srcext}#/googletest.%{srcext}
Source14: https://github.com/protocolbuffers/protobuf/archive/refs/tags/%{protobuf_revision}.%{srcext}#/protobuf.%{srcext}
Source15: https://github.com/google/re2/archive/%{re2_revision}.%{srcext}#/re2.%{srcext}
Source16: https://github.com/KhronosGroup/SPIRV-Headers/archive/%{spirv_headers_revision}.%{srcext}#/spirv-headers.%{srcext}
### Source17: https://github.com/microsoft/mimalloc/archive/%{mimalloc_revision}.%{srcext}#/mimalloc.%{srcext}
%description
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.
The package includes an assembler, binary module parser, disassembler,
validator, and optimizer for SPIR-V. Except for the optimizer, all are based on
a common static library. The library contains all of the implementation details,
and is used in the standalone tools whilst also enabling integration into other
code bases directly. The optimizer implementation resides in its own library,
which depends on the core library.
%package -n lib%{realname}
Group: System/Libraries
Summary: Shared libraries for %{realname}
%description -n lib%{realname}
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.
This package provides shared libraries for %{realname}.
%package devel
Group: Development/Languages/C and C++
Summary: Development stuff for %{realname}
Requires: lib%{realname} = %{version}-%{release}
%description devel
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.
This package provides headers and libraries to build software
using %{realname}.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a11 -a12 -a13 -a14 -a15 -a16
for src in abseil-cpp effcee googletest protobuf re2; do
mv -f $src-* external/${src%-*}
done
mv -v SPIRV-Headers-* external/spirv-headers
%{__sed} -ri \
's|((\s*)add_library\(([^ ]*).+$)|\1\n\2set_target_properties(\3 PROPERTIES VERSION %{version} SOVERSION %{version})|' \
source/CMakeLists.txt
%{__sed} -ri \
's|((\s*)spvtools_default_compile_options\((.+)\))|\2set_target_properties(\3 PROPERTIES VERSION %{version} SOVERSION %{version})\n\1|' \
source/*/CMakeLists.txt
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags} %{?gcc_lto}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
_CMAKE_ARGS=(
-Wno-dev
-G Ninja
-DCMAKE_INSTALL_PREFIX=%{_prefix}
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_FLAGS_RELEASE="$_CFLAGS"
-DCMAKE_CXX_FLAGS_RELEASE="$_CFLAGS"
-DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS"
-DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS"
-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS"
-DCMAKE_VERBOSE_MAKEFILE=YES
)
cmake -S . -B tmp_build \
"${_CMAKE_ARGS[@]}" \
\
-DSPIRV_TOOLS_BUILD_STATIC=NO \
-DSPIRV_TOOLS_LIBRARY_TYPE=SHARED \
-DSPIRV_SKIP_TESTS=YES \
-DENABLE_SPIRV_TOOLS_INSTALL=YES
ninja -v -C tmp_build %{?_smp_mflags}
# Install built stuff
%install
DESTDIR=%{buildroot} ninja -v -C tmp_build install
# Fix shebang
%{__sed} -ri '1 s|^#!/usr/bin/env.+$|#!/bin/sh|' %{buildroot}%{_bindir}/spirv-lesspipe.sh
# Files list
%files
%defattr(-,root,root)
%license LICENSE
%doc CHANGES README.md
%{_bindir}/spirv-*
%files -n lib%{realname}
%defattr(-,root,root)
%{_libdir}/lib%{realname}*.so.%{version}
%files devel
%defattr(-,root,root)
%license LICENSE
%doc CODE_OF_CONDUCT.md CONTRIBUTING.md README.md
%{_includedir}/%{name}/
%{_libdir}/lib%{realname}*.so
%{_libdir}/pkgconfig/%{realname}-shared.pc
%{_libdir}/pkgconfig/%{realname}.pc
%dir %{_libdir}/cmake/%{realname}-diff
%dir %{_libdir}/cmake/%{realname}-link
%dir %{_libdir}/cmake/%{realname}-lint
%dir %{_libdir}/cmake/%{realname}-opt
%dir %{_libdir}/cmake/%{realname}-reduce
%dir %{_libdir}/cmake/%{realname}-tools
%dir %{_libdir}/cmake/%{realname}
%dir %{_libdir}/cmake
%{_libdir}/cmake/%{realname}-diff/*.cmake
%{_libdir}/cmake/%{realname}-link/*.cmake
%{_libdir}/cmake/%{realname}-lint/*.cmake
%{_libdir}/cmake/%{realname}-opt/*.cmake
%{_libdir}/cmake/%{realname}-reduce/*.cmake
%{_libdir}/cmake/%{realname}-tools/*.cmake
%{_libdir}/cmake/%{realname}/*.cmake
%post -n lib%{realname} -p /sbin/ldconfig
%postun -n lib%{realname} -p /sbin/ldconfig
%changelog