File stalwart.spec of Package stalwart

#
# spec file for package stalwart
#
# Copyright (c) 2025 SUSE LLC and contributors
#
# 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/
#

%define pkg_home %{_localstatedir}/lib/%{name}
%global rust_version 1.93

%if 0%{?suse_version} >= 1600 && 0%{?is_opensuse}
%bcond_without mold
%else
%bcond_with    mold
%endif

%if %{with mold}
%global build_rustflags "-C" "linker=clang++" "-C" "link-arg='-fuse-ld=/usr/bin/mold -latomic -Wl,-z,relro,-z,now,-zstack-size=8388608'" "-C" "debuginfo=2" "-C" "incremental=false" "-C" "strip=none" "-A" "warnings"
%else
%global build_rustflags "-C" "linker=clang++" "-C" "link-arg='-fuse-ld=/usr/bin/ld.lld -latomic -Wl,-z,relro,-z,now,-zstack-size=8388608'" "-C" "debuginfo=2" "-C" "incremental=false" "-C" "strip=none" "-A" "warnings"
%endif

Name:           stalwart
Version:        0.15.5
Release:        0
Summary:        Secure, scalable mail & collaboration server
License:        AGPL-3.0-only
URL:            https://stalw.art/
Source0:        https://github.com/stalwartlabs/stalwart/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        vendor.tar.zst
Source2:        system-user-stalwart.conf
Source3:        stalwart.default
# https://github.com/stalwartlabs/stalwart/discussions/2851
# https://github.com/cryptomilk/stalwart/tree/asn-tls
# PATCH-FIX-OPENSUSE stalwart-fix-tls-pem-combinded-files.patch
Patch0:         stalwart-fix-tls-pem-combinded-files.patch
%if %{with mold}
BuildRequires:  mold
%else
BuildRequires:  lld
%endif
BuildRequires:  cargo-packaging
#BuildRequires:  libclang13
#BuildRequires:  libstdc++-devel
BuildRequires:  clang
BuildRequires:  gcc-c++
BuildRequires:  python3
%if "%{?rust_version}" != ""
# workaround for:
# zypper in cargo1.79 cargo cargo-packaging
# Problem: 1: the to be installed cargo-1.81.0-150500.27.21.1.x86_64 obsoletes 'cargo1.79' provided by the to be installed cargo1.79-1.79.0-150500.11.3.1.x86_64
#   Solution 1: do not install cargo1.79-1.79.0-150500.11.3.1.x86_64
#   Solution 2: do not install cargo-1.81.0-150500.27.21.1.x86_64
#
#!BuildIgnore: cargo
BuildRequires:  cargo%{rust_version}
BuildRequires:  rust%{rust_version}
%else
BuildRequires:  cargo
BuildRequires:  rust
%endif
BuildRequires:  systemd-rpm-macros
%if %{__isa_bits} < 64
BuildRequires: do_not_build
%endif

%description
All-in-one Mail & Collaboration server.
It supports a number of protocols, including
IMAP, JMAP, SMTP, CalDAV, CardDAV, WebDAV.

%package -n system-user-%{name}
Summary:        System user and group %{name}
BuildArch:      noarch
BuildRequires:  sysuser-tools
%sysusers_requires

%description -n system-user-%{name}
System user for use by Stalwart.

%prep
%autosetup -a1 -p1

%build
# this removes all proprietary code that is not under AGPL-3.0-only
python3 resources/scripts/ossify.py crates
sed -i -e 's|__PATH__%{_sysconfdir}/config|%{_sysconfdir}/stalwart/config|g' -e 's|__PATH__|/usr|g' resources/systemd/stalwart-mail.service
sed -i -e 's|\(\[Service\]\)|\1\nEnvironmentFile=/etc/default/stalwart|' resources/systemd/stalwart-mail.service
%{cargo_build} -p stalwart --no-default-features --features 'sqlite postgres mysql rocks s3 redis azure nats'
%{cargo_build} -p stalwart-cli

%sysusers_generate_pre %{SOURCE2} stalwart system-user-stalwart.conf

%install
install -Dm755 -t %{buildroot}%{_bindir} target/release/stalwart
install -Dm755 -t %{buildroot}%{_bindir} target/release/stalwart-cli
install -Dm644 -t %{buildroot}%{_sysconfdir}/stalwart resources/config/config.toml
install -Dm644 -t %{buildroot}%{_unitdir} resources/systemd/stalwart-mail.service
install -Dm644 %{SOURCE2} %{buildroot}%{_sysusersdir}/system-user-stalwart.conf
install -Dm644 %{SOURCE3} %{buildroot}%{_sysconfdir}/default/stalwart

%pre -f stalwart.pre
%service_add_pre stalwart-mail.service

%post
%service_add_post stalwart-mail.service

%preun
%service_del_preun stalwart-mail.service

%postun
%service_del_postun stalwart-mail.service

%files
%license LICENSES/AGPL-3.0-only.txt
%doc README.md CHANGELOG.md
%{_bindir}/stalwart
%{_bindir}/stalwart-cli
%{_unitdir}/stalwart-mail.service
%dir %{_sysconfdir}/stalwart
%attr(0640,root,stalwart) %config(noreplace) %{_sysconfdir}/stalwart/config.toml
%dir %{_sysconfdir}/default
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/default/stalwart

%files -n system-user-%{name}
%{_sysusersdir}/system-user-%{name}.conf

%changelog
openSUSE Build Service is sponsored by