Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Artox committed Sep 19, 2021
1 parent dff552d commit 55594cd
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 0001-strndupa.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
implement strndupa which musl does not provide.
copied from a patchset at the openembedded project:
https://git.openembedded.org/openembedded-core/plain/meta/recipes-core/systemd/systemd/0005-src-basic-missing.h-check-for-missing-strndupa.patch

--- python-systemd-234/systemd/util.c.orig
+++ python-systemd-234/systemd/util.c
@@ -32,6 +32,15 @@
#include <unistd.h>
#include <net/if.h>

+#define strndupa(s, n) \
+ ({ \
+ const char *__old = (s); \
+ size_t __len = strnlen(__old, (n)); \
+ char *__new = (char *)alloca(__len + 1); \
+ __new[__len] = '\0'; \
+ (char *)memcpy(__new, __old, __len); \
+ })
+
#include "util.h"

int safe_atou(const char *s, unsigned *ret_u) {
10 changes: 10 additions & 0 deletions 0002-endian.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- python-systemd-234/systemd/util.c.orig
+++ python-systemd-234/systemd/util.c
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <net/if.h>
+#include <endian.h>

#define strndupa(s, n) \
({ \
41 changes: 41 additions & 0 deletions APKBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributor: Josua Mayer <josua.mayer@jm0.eu>
# Maintainer:
pkgname=py3-systemd
pkgver=234
pkgrel=0
pkgdesc="python bindings for systemd"
url="https://github.com/systemd/python-systemd"
arch="all"
license="LGPL-2.1"
depends=""
makedepends="gcc libsystemd-dev musl-dev python3-dev py3-setuptools"
checkdepends="py3-pytest"
install=""
subpackages=""
source="python-systemd-$pkgver.tar.gz::https://github.com/systemd/python-systemd/archive/refs/tags/v$pkgver.tar.gz
0001-strndupa.patch
0002-endian.patch"
builddir="$srcdir/python-systemd-$pkgver"
options="!check" # tests fail for no good reason

build() {
python3 setup.py build
:
}

check() {
pytest
}

package() {
python3 setup.py install --prefix=/usr --root="$pkgdir"

# Remove installed tests
rm -rf "$pkgdir"/usr/lib/python3*/site-packages/systemd/test
}

sha512sums="
164e34ba46827711e9c6ff9ed58b2706d9a22abfc7001de030ed7d463d8ddf783eb5fee93b207c29950a3c566018cc3f1a21a549421cf3e05c1287b433367eb2 python-systemd-234.tar.gz
9e7f34804b69190a19ddcb2a2712ad93b079cb34d3ccae771d4bde729a74ba7a14e2f4ff44d24feba189bb4aea07df6d29bf869849c03c08560c3502ef4829e8 0001-strndupa.patch
0b83d21f343c61b425013e13d42bad434d398d05c72859bebac8b45e3dd4554bcb21af31aa8128de80ae08931af8d1276462293a2ac220155f62ee1bcc811da2 0002-endian.patch
"
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Alpine python-systemd Package

This is an experimental build of systemd python bindings for Alpine Linux. **ONLY bindings** has been packaged, and proper functioning of systemd is untested.

Use this package to satisfy build-time dependencies for other software projects, **when you don't care if the systemd part works right**!

## Compile Package

Full compile instructions are provided on the ["Creating an Alpine package" page on the alpine wiki](https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package), the tldr is as follows:

#### On a system running The target Alpine release, install build tools:

apk add alpine-sdk git
adduser -G abuild abuild
mkdir -p /var/cache/distfiles
chown abuild:abuild /var/cache/distfiles
su - abuild
abuild-keygen -a -i

#### Clone the package sources:

git clone https://github.com/Artox/alpine-python-systemd.git
cd alpine-python-systemd

#### Execute alpine package builder

abuild -r

#### Find binary packages in *~/packages/<username>/*:

find ~/packages -type f
/home/user/packages/user/aarch64/py3-systemd-234-r0.apk
/home/user/packages/user/aarch64/APKINDEX.tar.gz

## Compile for all Architectures

#### On a system where qemu user-mode emulation has been set up, download rootfs's:

export basedir=~

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
wget https://dl-cdn.alpinelinux.org/alpine/v3.14/releases/$arch/alpine-minirootfs-3.14.2-$arch.tar.gz
sudo mkdir -p $basedir/build-$arch
sudo tar -C $basedir/build-$arch -xf alpine-minirootfs-3.14.2-$arch.tar.gz
sudo cp -L /etc/resolv.conf $basedir/build-$arch/etc/resolv.conf
done

#### Copy QEMU binaries to each rootfs:

sudo cp /usr/bin/qemu-aarch64{,-binfmt} $basedir/build-aarch64/usr/bin/
sudo cp /usr/bin/qemu-arm{,-binfmt} $basedir/build-armhf/usr/bin/
sudo cp /usr/bin/qemu-arm{,-binfmt} $basedir/build-armv7/usr/bin/
sudo cp /usr/bin/qemu-ppc64le{,-binfmt} $basedir/build-ppc64le/usr/bin/
sudo cp /usr/bin/qemu-s390x{,-binfmt} $basedir/build-s390x/usr/bin/
sudo cp /usr/bin/qemu-i386{,-binfmt} $basedir/build-x86/usr/bin/
sudo cp /usr/bin/qemu-x86_64{,-binfmt} $basedir/build-x86_64/usr/bin/

#### Install alpine build tools:

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
sudo chroot $basedir/build-$arch /sbin/apk add alpine-sdk
done


#### Execute Builds:

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
sudo mount --bind /dev $basedir/build-$arch/dev
sudo mount -t proc proc $basedir/build-$arch/proc
done

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
sudo rm -rf $basedir/build-$arch/root/.abuild $basedir/build-$arch/root/source
sudo cp -R $basedir/alpine-python-systemd $basedir/build-$arch/root/source
sudo cp -R $basedir/.abuild $basedir/build-$arch/root/
sudo chroot $basedir/build-$arch /bin/sh -c 'arch=$(cat /etc/apk/arch); wget https://github.com/Artox/alpine-systemd/releases/download/1/libsystemd-249-r0.$arch.apk; wget https://github.com/Artox/alpine-systemd/releases/download/1/libsystemd-dev-249-r0.$arch.apk; apk --allow-untrusted add libcap *.apk; rm -f *.apk'
sudo chroot $basedir/build-$arch /bin/sh -c 'cd ~/source; abuild -F -r'
sudo chroot $basedir/build-$arch /bin/sh -c 'apk del libsystemd-dev libsystemd libcap'
done

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
sudo umount $basedir/build-$arch/dev
sudo umount $basedir/build-$arch/proc
done

#### Collect Results:

mkdir -p packages
for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
sudo cp -R $basedir/build-$arch/root/packages/root/$arch ./packages/
done
sudo chown -R $(id -u):$(id -g) packages

for arch in aarch64 armhf armv7 ppc64le s390x x86 x86_64; do
cp -v packages/$arch/py3-systemd-234-r0.apk py3-systemd-234-r0.$arch.apk
done

0 comments on commit 55594cd

Please sign in to comment.