Blob Blame History Raw
%bcond_without tests
# Disabled for now because protobuf-devel does not provide CMake files
%bcond_with grpctest
# Doxygen HTML help is not suitable for packaging due to a minified JavaScript
# bundle inserted by Doxygen itself. See discussion at
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555.
#
# We could potentially enable the Doxygen PDF documentation as a substitute,
# but currently Doxygen generates invalid LaTeX.
%bcond_with doc_pdf

Name:           flatbuffers
Version:        2.0.0
Release:        %autorelease
%global so_version 2
Summary:        Memory efficient serialization library

# The entire source code is ASL 2.0 except grpc/ which is BSD (3 clause)
License:        ASL 2.0 and BSD
URL:            https://google.github.io/flatbuffers
Source0:        https://github.com/google/flatbuffers/archive/v%{version}/%{name}-%{version}.tar.gz
# Hand-written for Fedora in groff_man(7) format based on --help output
Source1:        flatc.1

BuildRequires:  gcc-c++
BuildRequires:  cmake
# The ninja backend should be slightly faster than make, with no disadvantages.
BuildRequires:  ninja-build
%if %{with tests} && %{with grpctest}
BuildRequires:  grpc-devel
BuildRequires:  cmake(protobuf)
%endif

BuildRequires:  python3-devel

# The library contains pieces of gRPC project, with some additions.
# It is not easy to identify the version, which was used to take the code,
# but it should be something after version 1.3.2. See this discussion for
# details: https://github.com/google/flatbuffers/pull/4305
Provides:       bundled(grpc)

%global common_description %{expand: \
FlatBuffers is a cross platform serialization library architected for maximum
memory efficiency. It allows you to directly access serialized data without
parsing/unpacking it first, while still having great forwards/backwards
compatibility.}

%description
%{common_description}


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

%description    devel
%{common_description}

This package contains libraries and header files for developing applications
that use FlatBuffers.


%package        compiler
Summary:        FlatBuffers compiler (flatc)
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    compiler
%{common_description}

This package contains flatc, the FlatBuffers compiler.


%package        doc
Summary:        Documentation and examples for FlatBuffers

BuildArch:      noarch

%if %{with doc_pdf}
BuildRequires:  doxygen
BuildRequires:  doxygen-latex
# Required to format Python comments appropriately. Not yet packaged.
# BuildRequires: python3dist(doxypypy)
%endif

%description    doc
%{common_description}

This package contains documentation and examples for FlatBuffers.


%package -n     python3-flatbuffers
Summary:        FlatBuffers serialization format for Python

BuildArch:      noarch

Recommends:     python3dist(numpy)

Provides:       flatbuffers-python3 = %{version}-%{release}
Obsoletes:      flatbuffers-python3 < 2.0.0-6

%description -n python3-flatbuffers
%{common_description}

This package contains the Python runtime library for use with the Flatbuffers
serialization format.


%prep
%autosetup
# Remove unused directories that contain pre-compiled .jar files:
rm -rvf android/ kotlin/

%if %{with doc_pdf}
# We enable the Doxygen PDF documentation as a substitute for HTML. We must
# enable GENERATE_LATEX and LATEX_BATCHMODE; the rest are precautionary and
# should already be set as we like them. We also disable GENERATE_HTML, since
# we will not use it.
sed -r -i \
    -e "s/^([[:blank:]]*(GENERATE_LATEX|LATEX_BATCHMODE|USE_PDFLATEX|\
PDF_HYPERLINKS)[[:blank:]]*=[[:blank:]]*)NO[[:blank:]]*/\1YES/" \
    -e "s/^([[:blank:]]*(LATEX_TIMESTAMP|GENERATE_HTML)\
[[:blank:]]*=[[:blank:]]*)YES[[:blank:]]*/\1NO/" \
    ./docs/source/doxyfile
%endif

%py3_shebang_fix samples


%generate_buildrequires
pushd python >/dev/null
%pyproject_buildrequires
popd >/dev/null


%build
# Needed for correct Python wheel version
export VERSION='%{version}'
%set_build_flags
# Without this, building the tests fails.
export CXXFLAGS="${CXXFLAGS} -Wno-error=maybe-uninitialized"
%ifarch s390x
# Temporary workaround; report upstream if not fixed in a newer release
export CXXFLAGS="${CXXFLAGS} -Wno-error=stringop-overflow"
%endif
%cmake -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
%if %{with tests}
    -DFLATBUFFERS_BUILD_TESTS:BOOL=ON \
%if %{with grpctest}
    -DFLATBUFFERS_BUILD_GRPCTEST:BOOL=ON \
    -DGRPC_INSTALL_PATH:PATH=%{buildroot}%{_prefix} \
%endif
%else
    -DFLATBUFFERS_BUILD_TESTS:BOOL=OFF \
    -DFLATBUFFERS_BUILD_GRPCTEST:BOOL=OFF \
%endif
    -DFLATBUFFERS_BUILD_SHAREDLIB=ON \
    -DFLATBUFFERS_BUILD_FLATLIB=OFF \
    -DFLATBUFFERS_BUILD_FLATC=ON
%cmake_build

pushd python
%pyproject_wheel
popd

%if %{with doc_pdf}
pushd docs/source
doxygen
popd
%make_build -C docs/latex
%endif


%install
%cmake_install
pushd python
%pyproject_install
%pyproject_save_files flatbuffers
popd
mkdir -p %{buildroot}%{_mandir}/man1
cp -p %SOURCE1 %{buildroot}%{_mandir}/man1/flatc.1


%check
%if %{with tests}
%ctest
%endif
# Upstream does not appear to provide any dedicated Python tests.
%pyproject_check_import


%files
%license LICENSE.txt
%doc readme.md

%{_libdir}/libflatbuffers.so.%{so_version}{,.*}


%files devel
%{_includedir}/flatbuffers/

%{_libdir}/libflatbuffers.so

%{_libdir}/cmake/flatbuffers/
%{_libdir}/pkgconfig/flatbuffers.pc


%files compiler
%{_bindir}/flatc
%{_mandir}/man1/flatc.1*


%files doc
%license LICENSE.txt
%doc samples
%if %{with doc_pdf}
%doc docs/latex/refman.pdf
%endif


%files -n python3-flatbuffers -f %{pyproject_files}
%license LICENSE.txt


%changelog
%autochangelog