[packages/maturin] new

atler atler at pld-linux.org
Wed Apr 14 17:15:47 CEST 2021


commit 531002c854608f6ca1eff91932ba95928203a323
Author: Jan Palus <atler at pld-linux.org>
Date:   Wed Apr 14 17:13:21 2021 +0200

    new

 create-crates.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 maturin.spec     | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 131 insertions(+)
---
diff --git a/maturin.spec b/maturin.spec
new file mode 100644
index 0000000..c9995e5
--- /dev/null
+++ b/maturin.spec
@@ -0,0 +1,62 @@
+%define		crates_ver	0.10.3
+
+Summary:	Build and publish rust crates as python packages
+Name:		maturin
+Version:	0.10.3
+Release:	1
+License:	MIT or Apache v2.0
+Group:		Applications
+Source0:	https://github.com/PyO3/maturin/archive/v%{version}/%{name}-%{version}.tar.gz
+# Source0-md5:	b1d821f86a97dc10648f38aa2c6a8540
+# ./create-crates.sh
+Source1:	%{name}-crates-%{crates_ver}.tar.xz
+# Source1-md5:	1b5a724601e35752b98b5ad8afc2a2b1
+URL:		https://github.com/PyO3/maturin
+BuildRequires:	cargo
+BuildRequires:	rpmbuild(macros) >= 2.004
+BuildRequires:	rust
+ExclusiveArch:	%{rust_arches}
+BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%description
+Build and publish crates with pyo3, rust-cpython and cffi bindings as
+well as rust binaries as python packages.
+
+%prep
+%setup -q -a1
+
+%{__mv} maturin-%{crates_ver}/* .
+sed -i -e 's/@@VERSION@@/%{version}/' Cargo.lock
+
+# use our offline registry
+export CARGO_HOME="$(pwd)/.cargo"
+
+mkdir -p "$CARGO_HOME"
+cat >.cargo/config <<EOF
+[source.crates-io]
+registry = 'https://github.com/rust-lang/crates.io-index'
+replace-with = 'vendored-sources'
+
+[source.vendored-sources]
+directory = '$PWD/vendor'
+EOF
+
+%build
+export CARGO_HOME="$(pwd)/.cargo"
+
+%cargo_build --frozen
+
+%install
+rm -rf $RPM_BUILD_ROOT
+export CARGO_HOME="$(pwd)/.cargo"
+
+%cargo_install --frozen --root $RPM_BUILD_ROOT%{_prefix} --path $(pwd)
+%{__rm} $RPM_BUILD_ROOT%{_prefix}/.crates*
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(644,root,root,755)
+%doc Changelog.md Readme.md
+%attr(755,root,root) %{_bindir}/maturin
diff --git a/create-crates.sh b/create-crates.sh
new file mode 100755
index 0000000..297913a
--- /dev/null
+++ b/create-crates.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+for cmd in bsdtar rpm-specdump cargo perl; do
+  if ! command -v $cmd > /dev/null 2> /dev/null; then
+    not_installed="$not_installed$cmd "
+  fi
+done
+
+if [ -n "$not_installed" ]; then
+  echo "ERROR: required commands not found: $not_installed" >&2
+  exit 1
+fi
+
+pkg_dir=$(readlink -f $(dirname "$0"))
+pkg_name=$(basename "$pkg_dir")
+
+if [ ! -f "$pkg_dir/$pkg_name.spec" ]; then
+  echo "ERROR: unable to determine package name" >&2
+  exit 1
+fi
+
+spec_dump=$(rpm-specdump "$pkg_dir/$pkg_name.spec")
+pkg_version=$(echo "$spec_dump" | grep PACKAGE_VERSION | cut -f3 -d' ')
+pkg_src=$(basename $(echo "$spec_dump" | grep SOURCEURL0 | cut -f3- -d' '))
+crates_file="$pkg_name-crates-$pkg_version.tar.xz"
+cargo_package=${force_cargo_package:-$pkg_name}
+
+if [ -e "$pkg_dir/$crates_file" ]; then
+  echo "ERROR: crates file $crates_file already exists" >&2
+  exit 1
+fi
+
+if [ ! -f "$pkg_dir/$pkg_src" ]; then
+  echo "ERROR: source file $pkg_src not found" >&2
+  exit 1
+fi
+
+tmpdir=$(mktemp -d)
+
+rm_tmpdir() {
+  if [ -n "$tmpdir" -a -d "$tmpdir" ]; then
+    rm -rf "$tmpdir"
+  fi
+}
+
+trap rm_tmpdir EXIT INT HUP
+
+cd "$tmpdir"
+bsdtar xf "$pkg_dir/$pkg_src"
+src_dir=$(ls)
+if [ $(echo "$src_dir" | wc -l) -ne 1 ]; then
+  echo "ERROR: unexpected source structure:\n$src_dir" >&2
+  exit 1
+fi
+
+cd "$src_dir"
+cargo vendor
+if [ $? -ne 0 ]; then
+  echo "ERROR: cargo vendor failed" >&2
+  exit 1
+fi
+
+# replace cargo package version with @@VERSION@@
+perl -pi -e 'BEGIN { undef $/;} s/(\[\[package\]\]\nname\s*=\s*"'"$cargo_package"'"\nversion\s*=\s*")[^"]+/$1\@\@VERSION\@\@/m' Cargo.lock
+
+cd ..
+tar cJf "$pkg_dir/$crates_file" "$src_dir"/{Cargo.lock,vendor}
+
+# vim: expandtab shiftwidth=2 tabstop=2
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/maturin.git/commitdiff/531002c854608f6ca1eff91932ba95928203a323



More information about the pld-cvs-commit mailing list