-
Notifications
You must be signed in to change notification settings - Fork 7
214 lines (208 loc) · 9.68 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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 }}