|
| 1 | +name: Build Python |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + cpython_tag: |
| 7 | + description: "CPython git tag to build (e.g. v3.12.13, v3.15.0a7)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + freethreaded: |
| 11 | + description: "Also build a --disable-gil variant (3.13+)" |
| 12 | + required: false |
| 13 | + default: false |
| 14 | + type: boolean |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + |
| 19 | +defaults: |
| 20 | + run: |
| 21 | + shell: bash --noprofile --norc -exo pipefail {0} |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + runs-on: ubuntu-24.04-riscv |
| 26 | + env: |
| 27 | + CPYTHON_TAG: ${{ inputs.cpython_tag }} |
| 28 | + FREETHREADED: ${{ inputs.freethreaded }} |
| 29 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + steps: |
| 31 | + - name: Checkout this repo |
| 32 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 33 | + |
| 34 | + - name: Install build dependencies |
| 35 | + run: | |
| 36 | + sudo apt-get update -qq |
| 37 | + sudo apt-get install -qq -y --no-install-recommends \ |
| 38 | + build-essential \ |
| 39 | + ca-certificates \ |
| 40 | + g++-14 \ |
| 41 | + gcc-14 \ |
| 42 | + git \ |
| 43 | + libbz2-dev \ |
| 44 | + libexpat1-dev \ |
| 45 | + libffi-dev \ |
| 46 | + libgdbm-dev \ |
| 47 | + liblzma-dev \ |
| 48 | + libncursesw5-dev \ |
| 49 | + libreadline-dev \ |
| 50 | + libsqlite3-dev \ |
| 51 | + libssl-dev \ |
| 52 | + make \ |
| 53 | + patchelf \ |
| 54 | + pkg-config \ |
| 55 | + tk-dev \ |
| 56 | + uuid-dev \ |
| 57 | + wget \ |
| 58 | + xz-utils \ |
| 59 | + zlib1g-dev |
| 60 | +
|
| 61 | + # Make sure Python is built with gcc 14 |
| 62 | + echo "CC=gcc-14" >> $GITHUB_ENV |
| 63 | + echo "CXX=g++-14" >> $GITHUB_ENV |
| 64 | +
|
| 65 | + - name: Compute normalised version |
| 66 | + id: vars |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + tag="$CPYTHON_TAG" |
| 70 | + # Strip leading v, expand a/b/rc suffixes |
| 71 | + normalised="${tag#v}" |
| 72 | + normalised="$(echo "$normalised" | sed -E 's/a([0-9]+)$/-alpha.\1/; s/b([0-9]+)$/-beta.\1/; s/rc([0-9]+)$/-rc.\1/')" |
| 73 | + # X.Y |
| 74 | + minor_num="$(echo "$normalised" | cut -d. -f2)" |
| 75 | + minor="3.${minor_num}" |
| 76 | + echo "normalised=${normalised}" >> "$GITHUB_OUTPUT" |
| 77 | + echo "minor=${minor}" >> "$GITHUB_OUTPUT" |
| 78 | + echo "minor_num=${minor_num}" >> "$GITHUB_OUTPUT" |
| 79 | + echo "archive_base=python-${normalised}-linux-24.04-riscv64" >> "$GITHUB_OUTPUT" |
| 80 | + echo "Normalised version: ${normalised}" |
| 81 | + echo "Python X.Y: ${minor}" |
| 82 | + if [ "${FREETHREADED}" = "true" ] && [ "${minor_num}" -lt 13 ]; then |
| 83 | + echo "ERROR: freethreaded build requires CPython 3.13+" >&2 |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Checkout CPython |
| 88 | + run: git clone --depth 1 --branch "$CPYTHON_TAG" https://github.com/python/cpython.git src |
| 89 | + |
| 90 | + - name: Build standard CPython |
| 91 | + env: |
| 92 | + MINOR: ${{ steps.vars.outputs.minor }} |
| 93 | + ARCHIVE_BASE: ${{ steps.vars.outputs.archive_base }} |
| 94 | + NORMALISED: ${{ steps.vars.outputs.normalised }} |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | + mkdir -p output |
| 98 | + pushd src |
| 99 | + ./configure --with-ensurepip=install --enable-shared |
| 100 | + make -j"$(nproc)" 2>&1 | tee ../build_output.txt |
| 101 | + make install DESTDIR="$PWD/../staging-std" |
| 102 | + popd |
| 103 | +
|
| 104 | + mkdir -p "$ARCHIVE_BASE" |
| 105 | + cp -a staging-std/usr/local/bin "$ARCHIVE_BASE/" |
| 106 | + cp -a staging-std/usr/local/include "$ARCHIVE_BASE/" |
| 107 | + cp -a staging-std/usr/local/lib "$ARCHIVE_BASE/" |
| 108 | + cp -a staging-std/usr/local/share "$ARCHIVE_BASE/" |
| 109 | +
|
| 110 | + patchelf --set-rpath '$ORIGIN/../lib' "$ARCHIVE_BASE/bin/python${MINOR}" |
| 111 | +
|
| 112 | + sed -e "s|{{__VERSION_FULL__}}|${NORMALISED}|g" \ |
| 113 | + -e "s|{{__ARCH__}}|riscv64|g" \ |
| 114 | + installers/nix-setup-template.sh > "$ARCHIVE_BASE/setup.sh" |
| 115 | +
|
| 116 | + mv build_output.txt "$ARCHIVE_BASE/build_output.txt" |
| 117 | +
|
| 118 | + (cd "$ARCHIVE_BASE" && find . \( -type f -o -type l \) | sed 's|^\.|/|') > "$ARCHIVE_BASE/tools_structure.txt" |
| 119 | +
|
| 120 | + tar -czf "output/${ARCHIVE_BASE}.tar.gz" "$ARCHIVE_BASE" |
| 121 | + rm -rf "$ARCHIVE_BASE" staging-std |
| 122 | +
|
| 123 | + - name: Build free-threaded CPython |
| 124 | + if: ${{ inputs.freethreaded == true }} |
| 125 | + env: |
| 126 | + MINOR: ${{ steps.vars.outputs.minor }} |
| 127 | + ARCHIVE_BASE: ${{ steps.vars.outputs.archive_base }} |
| 128 | + NORMALISED: ${{ steps.vars.outputs.normalised }} |
| 129 | + run: | |
| 130 | + set -euo pipefail |
| 131 | + ft_base="${ARCHIVE_BASE}-freethreaded" |
| 132 | + pushd src |
| 133 | + git clean -fdx |
| 134 | + ./configure --with-ensurepip=install --enable-shared --disable-gil |
| 135 | + make -j"$(nproc)" 2>&1 | tee ../build_output.txt |
| 136 | + make install DESTDIR="$PWD/../staging-ft" |
| 137 | + popd |
| 138 | +
|
| 139 | + mkdir -p "$ft_base" |
| 140 | + cp -a staging-ft/usr/local/bin "$ft_base/" |
| 141 | + cp -a staging-ft/usr/local/include "$ft_base/" |
| 142 | + cp -a staging-ft/usr/local/lib "$ft_base/" |
| 143 | + cp -a staging-ft/usr/local/share "$ft_base/" |
| 144 | +
|
| 145 | + patchelf --set-rpath '$ORIGIN/../lib' "$ft_base/bin/python${MINOR}" |
| 146 | +
|
| 147 | + sed -e "s|{{__VERSION_FULL__}}|${NORMALISED}|g" \ |
| 148 | + -e "s|{{__ARCH__}}|riscv64|g" \ |
| 149 | + installers/nix-setup-template.sh > "$ft_base/setup.sh" |
| 150 | +
|
| 151 | + mv build_output.txt "$ft_base/build_output.txt" |
| 152 | +
|
| 153 | + (cd "$ft_base" && find . \( -type f -o -type l \) | sed 's|^\.|/|') > "$ft_base/tools_structure.txt" |
| 154 | +
|
| 155 | + tar -czf "output/${ft_base}.tar.gz" "$ft_base" |
| 156 | + rm -rf "$ft_base" staging-ft |
| 157 | +
|
| 158 | + - name: Print tarball hashes |
| 159 | + run: sha256sum output/*.tar.gz |
| 160 | + |
| 161 | + - name: Publish release |
| 162 | + env: |
| 163 | + NORMALISED: ${{ steps.vars.outputs.normalised }} |
| 164 | + run: | |
| 165 | + set -euo pipefail |
| 166 | + if gh release view "$NORMALISED" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then |
| 167 | + gh release upload "$NORMALISED" --repo "$GITHUB_REPOSITORY" --clobber ./output/*.tar.gz |
| 168 | + else |
| 169 | + gh release create "$NORMALISED" --repo "$GITHUB_REPOSITORY" \ |
| 170 | + --title "$NORMALISED" \ |
| 171 | + --notes "Python $NORMALISED" \ |
| 172 | + ./output/*.tar.gz |
| 173 | + fi |
0 commit comments