File pgrx.spec of Package pgrx

##
# Copyright (c) 2023 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/
#

%define         pg_name  @BUILD_FLAVOR@%{nil}
%define         ext_name   pgrx

%{pg_version_from_name}
# keep in sync with postgresql
%{!?product_libs_llvm_ver: %global product_libs_llvm_ver 15}

Version:        0.16.1
Release:        0

%if "%{pg_name}" == ""
Name:           %{ext_name}
BuildRequires:  postgresql-server-devel
BuildRequires:  cargo >= 1.70
BuildRequires:  rust >= 1.70
BuildRequires:  cargo-packaging
BuildRequires:  pkgconfig(openssl)
BuildRequires:  clang%{product_libs_llvm_ver}-devel
BuildRequires:  llvm%{product_libs_llvm_ver}-devel
BuildRequires:  rust-bindgen
BuildRequires:  rust-cbindgen
Requires:       cargo
Requires:       cargo-packaging
Requires:       rust-bindgen
Requires:       rust-cbindgen
Requires:       clang%{product_libs_llvm_ver}-devel
Requires:       llvm%{product_libs_llvm_ver}-devel
%global main_package 1

%else
Name:           %{pg_name}-%{ext_name}
BuildRequires:  %{pg_name}-server-devel
Requires:       %{pg_name}-server-devel
Requires:       pgrx = %{version}
%global main_package 0
BuildArch:      noarch
%endif
Summary:        Build Postgres Extensions with Rust!
License:        MIT
URL:            https://github.com/pgcentralfoundation/pgrx
Source:         %{ext_name}-%{version}.tar.zst
Source1:        vendor.tar.zst
Source2:        macros.pgrx
BuildRequires:  zstd

%description
pgrx is a framework for developing PostgreSQL extensions in Rust and strives to be as idiomatic and safe as possible.

%prep
%autosetup -p 1 -a 1 -n %{ext_name}-%{version}

%if 0%{?main_package}
%build
export PGRX_PG_CONFIG_PATH=%{_bindir}/pg_config
export pg_version=$(%{_bindir}/pg_config --version | awk '{print $2}' | awk -F '.' '{print $1}')
%{cargo_build} --features=pg${pg_version}

%install
install -D -m 0755 -t %{buildroot}%{_bindir}/ target/release/cargo-pgrx target/release/pgrx-version-updater
install -D -m 0644 %{SOURCE2} %{buildroot}%{_rpmmacrodir}/macros.%{name}

%files
%license LICENSE
%doc *.md
%{_bindir}/cargo-pgrx
%{_bindir}/pgrx-version-updater
%{_rpmmacrodir}/macros.%{name}

%else

%files
%license LICENSE

%endif

%changelog
openSUSE Build Service is sponsored by