From 66ccbf0e256f5ce808e35fdb9b194dc9ccbe2420 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 21 Apr 2025 09:56:31 -0500 Subject: [PATCH 1/5] Attempting to add testing for RiscV64 --- .github/workflows/tests.yml | 21 +++++++++++++++- ubuntu-test | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100755 ubuntu-test diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7dbb4fdd..d9b3e326 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -145,8 +145,27 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 - manylinux: + riscv64: + runs-on: ubuntu-latest + name: RiscV 64 + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + - name: Build and test greenlet + env: + DOCKER_IMAGE: riscv64/ubuntu:latest + run: bash ./ubuntu-test + + manylinux: runs-on: ubuntu-latest # We use a regular Python matrix entry to share as much code as possible. strategy: diff --git a/ubuntu-test b/ubuntu-test new file mode 100755 index 00000000..f039f3f9 --- /dev/null +++ b/ubuntu-test @@ -0,0 +1,50 @@ +#!/bin/bash + +# This needs to be run from the root of the project. +# To update: docker pull quay.io/pypa/manylinux2010_x86_64 +set -e +export PYTHONUNBUFFERED=1 +export PYTHONDONTWRITEBYTECODE=1 +# Use a fixed hash seed for reproducibility +export PYTHONHASHSEED=8675309 +export CI=1 +export TRAVIS=true +export PIP_NO_WARN_SCRIPT_LOCATION=1 + + +if [ -d /greenlet ]; then + # Running inside docker + export GREENLET_MANYLINUX=1 + # Build for speed (we're going to test this anyway) and without assertions. + # Note: -Ofast includes -ffast-math which affects process-wide floating-point flags (e.g. can affect numpy). + # It may also violate standards compliance in a few ways. Rather than opt-out with -fno-fast-math, + # we use O3, which has neither of those problems. + export CFLAGS="-O3 -DNDEBUG -Wall" + + apt-get update + apt-get install -y python3.12 python3.12-dev python3.12-venv gcc git g++ + update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 + + # Build in an isolated directory + mkdir /tmp/build + cd /tmp/build + git config --global --add safe.directory /greenlet/.git + git clone /greenlet greenlet + cd greenlet + + python -m venv /tmp/venv + . /tmp/venv/bin/activate + echo "Python" + python --version + + python -mpip install -U pip + python -mpip install -U setuptools wheel + python -mpip wheel -v --wheel-dir ./dist . + python -mpip install -U .[test] + python -m unittest discover -v greenlet.tests + + exit 0 +fi + +# Mount the current directory as /greenlet +docker run --rm -v "$(pwd):/greenlet" ${DOCKER_IMAGE:-riscv64/ubuntu:latest} /greenlet/$(basename $0) From 9ccad5be0842aa3f31c8c3b3458d43b35fee8a9f Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 21 Apr 2025 10:11:16 -0500 Subject: [PATCH 2/5] ubuntu-test: Explicitly set the platform that we're going to emulate. This is to avoid 'docker: no matching manifest for linux/amd64 in the manifest list entries.' Unclear why I don't have to do this for the manylinux images. --- ubuntu-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ubuntu-test b/ubuntu-test index f039f3f9..c31e5fa4 100755 --- a/ubuntu-test +++ b/ubuntu-test @@ -47,4 +47,4 @@ if [ -d /greenlet ]; then fi # Mount the current directory as /greenlet -docker run --rm -v "$(pwd):/greenlet" ${DOCKER_IMAGE:-riscv64/ubuntu:latest} /greenlet/$(basename $0) +docker run --rm --platform linux/riscv64 -v "$(pwd):/greenlet" ${DOCKER_IMAGE:-riscv64/ubuntu:latest} /greenlet/$(basename $0) From 6ddbda318a8951335b9a5a4f3409f1c1d4384201 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 21 Apr 2025 12:20:59 -0500 Subject: [PATCH 3/5] switch_riscv_unix.h: Go back to 'long' instead of 'int' on 64-bit platforms Fixes #443 --- src/greenlet/platform/switch_riscv_unix.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/greenlet/platform/switch_riscv_unix.h b/src/greenlet/platform/switch_riscv_unix.h index 32ca78c8..87611222 100644 --- a/src/greenlet/platform/switch_riscv_unix.h +++ b/src/greenlet/platform/switch_riscv_unix.h @@ -12,13 +12,9 @@ static int slp_switch(void) { int ret; -#if __riscv_xlen == 32 long fp; long *stackref, stsizediff; -#else - int fp; - int *stackref, stsizediff; -#endif + __asm__ volatile ("" : : : REGS_TO_SAVE); __asm__ volatile ("mv %0, fp" : "=r" (fp) : ); __asm__ volatile ("mv %0, sp" : "=r" (stackref) : ); From 4d9b27d00332062f603908c06637098fc40eb66b Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 21 Apr 2025 15:56:04 -0500 Subject: [PATCH 4/5] ubuntu-test: Remove some ancient/incorrect/useless comments. --- ubuntu-test | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ubuntu-test b/ubuntu-test index c31e5fa4..93854348 100755 --- a/ubuntu-test +++ b/ubuntu-test @@ -1,7 +1,7 @@ #!/bin/bash # This needs to be run from the root of the project. -# To update: docker pull quay.io/pypa/manylinux2010_x86_64 + set -e export PYTHONUNBUFFERED=1 export PYTHONDONTWRITEBYTECODE=1 @@ -15,10 +15,7 @@ export PIP_NO_WARN_SCRIPT_LOCATION=1 if [ -d /greenlet ]; then # Running inside docker export GREENLET_MANYLINUX=1 - # Build for speed (we're going to test this anyway) and without assertions. - # Note: -Ofast includes -ffast-math which affects process-wide floating-point flags (e.g. can affect numpy). - # It may also violate standards compliance in a few ways. Rather than opt-out with -fno-fast-math, - # we use O3, which has neither of those problems. + # Our setup.py overrides this with -Os; be sure it does. export CFLAGS="-O3 -DNDEBUG -Wall" apt-get update From d9eba21b04b36ad5c6cf5907702272a8e8792a33 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 21 Apr 2025 15:57:14 -0500 Subject: [PATCH 5/5] MANIFEST.in: Include the new script, per check-manifest. --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index f9b94e87..3c0c8ccf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -50,6 +50,7 @@ include LICENSE.PSF include MANIFEST.in include make-manylinux +include ubuntu-test global-exclude *.pyc global-exclude *.pyd