Create release #49
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Create release" | |
env: | |
WASI_SDK_PATH: /opt/wasi-sdk | |
on: | |
workflow_dispatch: | |
inputs: | |
python_version: | |
required: true | |
description: "Version of CPython to build" | |
wasi_sdk_version: | |
required: true | |
default: 20 | |
type: number | |
description: "WASI SDK version" | |
threads: | |
required: true | |
default: true | |
type: boolean | |
description: "Build threaded version?" | |
permissions: | |
contents: write | |
jobs: | |
draft-release: | |
name: "Draft release" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Create draft release" | |
run: | | |
gh release create v${{ inputs.python_version }} --title "CPython ${{ inputs.python_version}} w/ WASI SDK ${{ inputs.wasi_sdk_version}}" --repo "brettcannon/cpython-wasi-build" --draft | |
env: | |
GH_TOKEN: ${{ github.token }} | |
build: | |
needs: draft-release | |
name: "Build CPython ${{ inputs.python_version }} using WASI SDK ${{ inputs.wasi_sdk_version }}" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Install WASI SDK ${{ inputs.wasi_sdk_version }}" | |
run: | | |
mkdir ${{ env.WASI_SDK_PATH }} && \ | |
curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ inputs.wasi_sdk_version }}/wasi-sdk-${{ inputs.wasi_sdk_version }}.0-linux.tar.gz | \ | |
tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip | |
$WASI_SDK_PATH/bin/clang --version | |
- name: "Install wasmtime" | |
# wasmtime version hard-coded due to https://github.com/bytecodealliance/wasmtime/issues/6107 . | |
# Also doesn't really matter as it exists just to make `wasm_build.py` happy. | |
run: | | |
curl https://wasmtime.dev/install.sh -sSf | bash | |
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH | |
$HOME/.wasmtime/bin/wasmtime --version | |
- name: "Install build dependencies" | |
# https://devguide.python.org/getting-started/setup-building/#linux | |
# Removed: gdb lcov libncurses5-dev libreadline6-dev tk-dev | |
run: | | |
sudo apt-get install build-essential pkg-config \ | |
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev \ | |
liblzma-dev libsqlite3-dev libssl-dev \ | |
lzma lzma-dev uuid-dev zlib1g-dev | |
- name: "Install Python" | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: "Checkout CPython" | |
uses: actions/checkout@v3 | |
with: | |
repository: "python/cpython" | |
ref: "v${{ inputs.python_version }}" | |
- name: "Build" | |
run: python3 Tools/wasm/wasm_build.py wasi build | |
- name: "Create lib directory" | |
shell: bash | |
run: | | |
export PYTHON_BIN_NAME=`builddir/build/python -c "import sys; print(f'python{sys.version_info.major}.{sys.version_info.minor}')"` | |
export ZIP_LIB_DIR=zip-file/lib/$PYTHON_BIN_NAME | |
mkdir --parents $ZIP_LIB_DIR | |
echo "ZIP_LIB_DIR=$ZIP_LIB_DIR" >> $GITHUB_ENV | |
- name: "Copy python.wasm" | |
run: cp builddir/wasi/python.wasm zip-file | |
- name: "Copy stdlib" | |
# Adding lib-dynload to silence the error message: | |
# "Could not find platform dependent libraries <exec_prefix>". | |
run: | | |
cp -r Lib/* ${{ env.ZIP_LIB_DIR }} | |
mkdir ${{ env.ZIP_LIB_DIR }}/lib-dynload | |
- name: "Strip stdlib" | |
# Based on preexisting practice; could probably strip out more. | |
run: | | |
pushd ${{ env.ZIP_LIB_DIR }} | |
rm -rf curses/ ctypes/test/ ensurepip/ distutils/ \ | |
lib2to3/ idlelib/ test/ multiprocessing/ \ | |
tkinter/ turtledemo/ venv/ unittest/test/ | |
find -name __pycache__ | xargs rm -rf | |
popd | |
- name: "Copy over _sysconfigdata_*.py" | |
run: cp builddir/wasi/build/lib.wasi-wasm32-*/_sysconfigdata_*.py ${{ env.ZIP_LIB_DIR }} | |
- name: "Calculate zip file names" | |
run: | | |
export ZIP_FILE_NAME=python-${{ inputs.python_version }}-wasi_sdk-${{ inputs.wasi_sdk_version }}.zip | |
echo "EXECUTABLE_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV | |
echo "BUILD_ARTIFACTS_FILE_NAME=_build-$ZIP_FILE_NAME" >> $GITHUB_ENV | |
- name: "Create executable zip" | |
run: | | |
pushd zip-file | |
zip -r ${{ env.EXECUTABLE_FILE_NAME }} * | |
popd | |
- name: "Create build artifact zip" | |
run: | | |
pushd builddir/wasi | |
zip ${{ env.BUILD_ARTIFACTS_FILE_NAME }} \ | |
config.log config.cache Makefile pyconfig.h libpython*.a \ | |
Modules/Setup.local Modules/Setup.stdlib Modules/config.c \ | |
Modules/_decimal/libmpdec/libmpdec.a \ | |
Modules/expat/libexpat.a \ | |
Programs/python.o | |
popd | |
- name: "Attach files to the release" | |
run: | | |
gh release upload v${{ inputs.python_version }} zip-file/${{ env.EXECUTABLE_FILE_NAME }} builddir/wasi/${{ env.BUILD_ARTIFACTS_FILE_NAME }} --repo "brettcannon/cpython-wasi-build" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
threads-build: | |
if: ${{ inputs.threads }} | |
needs: draft-release | |
name: "Build threaded CPython ${{ inputs.python_version }} using WASI SDK ${{ inputs.wasi_sdk_version }}" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Install WASI SDK ${{ inputs.wasi_sdk_version }}" | |
run: | | |
mkdir ${{ env.WASI_SDK_PATH }} && \ | |
curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ inputs.wasi_sdk_version }}/wasi-sdk-${{ inputs.wasi_sdk_version }}.0-linux.tar.gz | \ | |
tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip | |
$WASI_SDK_PATH/bin/clang --version | |
- name: "Install wasmtime" | |
# wasmtime version hard-coded due to https://github.com/bytecodealliance/wasmtime/issues/6107 . | |
# Also doesn't really matter as it exists just to make `wasm_build.py` happy. | |
run: | | |
curl https://wasmtime.dev/install.sh -sSf | bash | |
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH | |
$HOME/.wasmtime/bin/wasmtime --version | |
- name: "Install build dependencies" | |
# https://devguide.python.org/getting-started/setup-building/#linux | |
# Removed: gdb lcov libncurses5-dev libreadline6-dev tk-dev | |
run: | | |
sudo apt-get install build-essential pkg-config \ | |
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev \ | |
liblzma-dev libsqlite3-dev libssl-dev \ | |
lzma lzma-dev uuid-dev zlib1g-dev | |
- name: "Install Python" | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.x" | |
- name: "Checkout CPython" | |
uses: actions/checkout@v3 | |
with: | |
repository: "python/cpython" | |
ref: "v${{ inputs.python_version }}" | |
- name: "Build" | |
run: python3 Tools/wasm/wasm_build.py wasi-threads build | |
- name: "Create lib directory" | |
shell: bash | |
run: | | |
export PYTHON_BIN_NAME=`builddir/build/python -c "import sys; print(f'python{sys.version_info.major}.{sys.version_info.minor}')"` | |
export ZIP_LIB_DIR=zip-file/lib/$PYTHON_BIN_NAME | |
mkdir --parents $ZIP_LIB_DIR | |
echo "ZIP_LIB_DIR=$ZIP_LIB_DIR" >> $GITHUB_ENV | |
- name: "Copy python.wasm" | |
run: cp builddir/wasi-threads/python.wasm zip-file | |
- name: "Copy stdlib" | |
# Adding lib-dynload to silence the error message: | |
# "Could not find platform dependent libraries <exec_prefix>". | |
run: | | |
cp -r Lib/* ${{ env.ZIP_LIB_DIR }} | |
mkdir ${{ env.ZIP_LIB_DIR }}/lib-dynload | |
- name: "Strip stdlib" | |
# Based on preexisting practice; could probably strip out more. | |
run: | | |
pushd ${{ env.ZIP_LIB_DIR }} | |
rm -rf curses/ ctypes/test/ ensurepip/ distutils/ \ | |
lib2to3/ idlelib/ test/ multiprocessing/ \ | |
tkinter/ turtledemo/ venv/ unittest/test/ | |
find -name __pycache__ | xargs rm -rf | |
popd | |
- name: "Copy over _sysconfigdata_*.py" | |
run: cp builddir/wasi-threads/build/lib.wasi-wasm32-*/_sysconfigdata_*.py ${{ env.ZIP_LIB_DIR }} | |
- name: "Calculate zip file names" | |
run: | | |
export ZIP_FILE_NAME=python-${{ inputs.python_version }}-wasi_sdk-${{ inputs.wasi_sdk_version }}-threads.zip | |
echo "EXECUTABLE_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV | |
echo "BUILD_ARTIFACTS_FILE_NAME=_build-$ZIP_FILE_NAME" >> $GITHUB_ENV | |
- name: "Create executable zip" | |
run: | | |
pushd zip-file | |
zip -r ${{ env.EXECUTABLE_FILE_NAME }} * | |
popd | |
- name: "Create build artifact zip" | |
run: | | |
pushd builddir/wasi-threads | |
zip ${{ env.BUILD_ARTIFACTS_FILE_NAME }} \ | |
config.log config.cache Makefile pyconfig.h libpython*.a \ | |
Modules/Setup.local Modules/Setup.stdlib Modules/config.c \ | |
Modules/_decimal/libmpdec/libmpdec.a \ | |
Modules/expat/libexpat.a \ | |
Programs/python.o | |
popd | |
- name: "Attach files to the release" | |
run: | | |
gh release upload v${{ inputs.python_version }} zip-file/${{ env.EXECUTABLE_FILE_NAME }} builddir/wasi-threads/${{ env.BUILD_ARTIFACTS_FILE_NAME }} --repo "brettcannon/cpython-wasi-build" | |
env: | |
GH_TOKEN: ${{ github.token }} |