Skip to content

Instantly share code, notes, and snippets.

@felixonmars
Forked from hack3ric/README.md
Created July 6, 2023 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixonmars/06e72852ce9a053aa53f61fa52613654 to your computer and use it in GitHub Desktop.
Save felixonmars/06e72852ce9a053aa53f61fa52613654 to your computer and use it in GitHub Desktop.
PyPy bootstrap for Arch Linux riscv64
  • Since Arch Linux removed Python 2 from its official repository, we need to use AUR scripts. Build python2 from AUR. Note that there's one failed test (test_gdbm), but it should be fine with --nocheck.

  • Build python2-cffi, python2-setuptools, python2-pycparser, python2-ply from AUR.

  • Use pypy-bootstrap-riscv64.patch below to build first version of pypy on riscv64 with something like:

    $ pwd
    .../archriscv/pypy/repos/community-x86_64
    $ extra-riscv64-build -- -d "/tmp/pkgcache:/var/cache/pacman/pkg/" \
      -I ../../../python2/python2-2.7.18-8-riscv64.pkg.tar.zst \
      -I ../../../python2-cffi/python2-cffi-1.15.0-3-riscv64.pkg.tar.zst \
      -I ../../../python2-pycparser/python2-pycparser-2.21-1-any.pkg.tar.zst \
      -I ../../../python2-ply/python2-ply-3.11-1-any.pkg.tar.zst \
      -I ../../../python2-setuptools/python2-setuptools-2:44.1.1-2-any.pkg.tar.zst
    
  • From now on, PyPy can now build itself. Use pypy-riscv64.patch below for future versions.

Newly added build flags are taken from Debian's pypy3 translating script. Without those, PyPy refuses to build.

I've also tried building pypy3 from pypy. It builds fine with original Arch tweaks disabled (see pypy3-riscv64.patch below). I wonder if it is building with its vendored dependencies? (I didn't find that matching string in pypy/goal/targetpypystandalone.py)

diff --git a/repos/community-x86_64/PKGBUILD b/repos/community-x86_64/PKGBUILD
index 22c599d7..2461dc3a 100644
--- PKGBUILD
+++ PKGBUILD
@@ -8,7 +8,7 @@ pkgdesc="A Python implementation written in Python, JIT enabled"
url="https://pypy.org"
arch=('x86_64')
depends=('expat' 'bzip2' 'gdbm' 'openssl' 'libffi' 'zlib' 'ncurses')
-makedepends=('pypy' 'tk' 'sqlite' 'mercurial')
+makedepends=('python2' 'python2-cffi' 'tk' 'sqlite' 'mercurial')
optdepends=('sqlite: sqlite module'
'tk: tk module')
options=(!buildflags)
@@ -19,10 +19,12 @@ sha512sums=('2a8a0b88b42b090954ebec9eadeaab9ac269075c124631b454798e71b3558464be3
build() {
cd pypy2.7-v${pkgver}-src/pypy/goal
+ export PYPY_MULTIARCH=riscv64-linux-gnu
+
# For some reason, PyPy wants to use their vendored dependencies when detecting linux.
# Weird, we'll patch it out.
sed -i "s/, 'linux', 'linux2'//" targetpypystandalone.py
- pypy ../../rpython/bin/rpython -Ojit --shared targetpypystandalone
+ python2 -u ../../rpython/bin/rpython -O3 --shared --no-profopt targetpypystandalone --withoutmod-_continuation
# Compile binary modules
PYTHONPATH=../.. ./pypy-c ../../lib_pypy/pypy_tools/build_cffi_imports.py
@@ -32,7 +34,7 @@ package() {
cd pypy2.7-v${pkgver}-src
# Prepare installation
- pypy pypy/tool/release/package.py --archive-name pypy --targetdir .
+ python2 pypy/tool/release/package.py --archive-name pypy --targetdir .
mkdir unpacked
tar xf pypy.tar.bz2 -C unpacked
diff --git a/repos/community-x86_64/PKGBUILD b/repos/community-x86_64/PKGBUILD
index 22c599d7..f57ec6ee 100644
--- PKGBUILD
+++ PKGBUILD
@@ -3,7 +3,7 @@
pkgname=pypy
pkgver=7.3.11
-pkgrel=1
+pkgrel=1.1
pkgdesc="A Python implementation written in Python, JIT enabled"
url="https://pypy.org"
arch=('x86_64')
@@ -19,10 +19,12 @@ sha512sums=('2a8a0b88b42b090954ebec9eadeaab9ac269075c124631b454798e71b3558464be3
build() {
cd pypy2.7-v${pkgver}-src/pypy/goal
+ export PYPY_MULTIARCH=riscv64-linux-gnu
+
# For some reason, PyPy wants to use their vendored dependencies when detecting linux.
# Weird, we'll patch it out.
sed -i "s/, 'linux', 'linux2'//" targetpypystandalone.py
- pypy ../../rpython/bin/rpython -Ojit --shared targetpypystandalone
+ pypy -u ../../rpython/bin/rpython -O3 --shared --no-profopt targetpypystandalone --withoutmod-_continuation
# Compile binary modules
PYTHONPATH=../.. ./pypy-c ../../lib_pypy/pypy_tools/build_cffi_imports.py
diff --git a/repos/community-x86_64/PKGBUILD b/repos/community-x86_64/PKGBUILD
index e2733483..e2656470 100644
--- PKGBUILD
+++ PKGBUILD
@@ -19,10 +19,12 @@ sha512sums=('96432c03ab7f69b39cd6be073e80d4ed3ac2d1a1cec66724f11964ad453f9c3511b
build() {
cd pypy${_pyversion}-v${pkgver}-src/pypy/goal
+ export PYPY_MULTIARCH=riscv64-linux-gnu
+
# For some reason, PyPy wants to use their vendored dependencies when detecting linux.
# Weird, we'll patch it out.
- sed -i "s/, 'linux', 'linux2'//" targetpypystandalone.py
- pypy ../../rpython/bin/rpython -Ojit --shared targetpypystandalone
+ #sed -i "s/, 'linux', 'linux2'//" targetpypystandalone.py
+ pypy -u ../../rpython/bin/rpython -O3 --shared --no-profopt targetpypystandalone --withoutmod-_continuation
# Compile binary modules
PYTHONPATH=../.. ./pypy3.9-c ../../lib_pypy/pypy_tools/build_cffi_imports.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment