File conduit.spec of Package conduit

#
# spec file for package conduit
#
# 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/
#

%global home_dir /var/lib/matrix-conduit
%global services matrix-conduit.service

%if 0%{?suse_version} >= 1600
%bcond_without clang
%else
%bcond_with    clang
%endif

%if 0%{?suse_version} == 1500
%global force_gcc_version 13
%endif

Name:           conduit
Version:        0.10.8+git0.9bba85c7
Release:        0
Summary:        A simple, fast and reliable chat server powered by Matrix
# FIXME: Select a correct license from https://github.com/openSUSE/spec-cleaner#spdx-licenses
License:        Apache-2.0
URL:            https://gitlab.com/famedly/conduit
Source0:        %{name}-%{version}.tar.zst
Source1:        vendor.tar.zst
Source2:        conduit.sysusers
BuildRequires:  zstd
BuildRequires:  cargo-packaging
BuildRequires:  cargo
BuildRequires:  rust
# TODO: figure out how to use the system copy
#BuildRequires:  pkgconfig(rocksdb)
BuildRequires:  clang-devel
%if %{without clang}
BuildRequires:  gcc%{?force_gcc_version}-c++ >= %{force_gcc_version}
%endif
BuildRequires:  sysuser-shadow
BuildRequires:  sysuser-tools
%{?systemd_ordering}
%{?sysusers_requires}

%description
A Matrix homeserver written in Rust

%prep
%autosetup -p1 -a1

%build
%if %{with clang}
export CC=clang
export CXX=clang++
%else
%if 0%{?force_gcc_version}
export CC="gcc-%{?force_gcc_version}"
export CXX="g++-%{?force_gcc_version}"
%endif
%endif
%{cargo_build}
%sysusers_generate_pre %{SOURCE2} %{name} %{name}.conf

%install
install -D -m 0755 target/release/conduit      %{buildroot}%{_sbindir}/matrix-conduit
install -D -m 0640 conduit-example.toml        %{buildroot}%{_sysconfdir}/matrix-conduit/conduit.toml
install -D -m 0750 -d                          %{buildroot}%{home_dir}
install -D -m 0644 %{SOURCE2}                  %{buildroot}%{_sysusersdir}/%{name}.conf
install -D -m 0644                          -t %{buildroot}%{_unitdir}/ debian/matrix-conduit.service



%pre -f %{name}.pre
%service_add_pre %{services}

%preun
%service_del_preun %{services}

%post
%service_add_post %{services}

%postun
%service_del_postun %{services}

%files
%license LICENSE
%doc *.md docs/
%{_sbindir}/matrix-conduit
%config(noreplace) %attr(-,root,matrix-conduit) %{_sysconfdir}/matrix-conduit/
%dir %attr(-,matrix-conduit,matrix-conduit) %{home_dir}
%{_sysusersdir}/%{name}.conf
%{_unitdir}/%{services}

%changelog
openSUSE Build Service is sponsored by