Skip to content

Commit d1d83f1

Browse files
committed
feat: Add Python 3.11.4
1 parent 7be7939 commit d1d83f1

File tree

11 files changed

+345
-18
lines changed

11 files changed

+345
-18
lines changed

.github/workflows/build-python.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ jobs:
1515
include:
1616
- prefix: ""
1717
suffix: ""
18-
version: "3.11.3"
18+
version: "3.11.4"
1919
- prefix: "wasmedge-"
2020
suffix: "-wasmedge"
21-
version: "3.11.3"
21+
version: "3.11.4"
2222
- prefix: "aio-"
2323
suffix: "-aio"
24-
version: "3.11.3"
24+
version: "3.11.4"
2525
- prefix: "aio-wasmedge-"
2626
suffix: "-aio-wasmedge"
27-
version: "3.11.3"
27+
version: "3.11.4"
2828
runs-on: ubuntu-latest
2929
steps:
3030
- name: Checkout repository

Makefile

+14-14
Original file line numberDiff line numberDiff line change
@@ -67,42 +67,42 @@ oci-python-3.11.1-wasmedge: python/wasmedge-v3.11.1
6767
-f images/python/Dockerfile \
6868
build-output
6969

70-
.PHONY: python/wasmedge-v3.11.3
71-
python/wasmedge-v3.11.3:
70+
.PHONY: python/wasmedge-v3.11.4
71+
python/wasmedge-v3.11.4:
7272
WLR_BUILD_FLAVOR=wasmedge \
7373
make -C python $(subst python/wasmedge-,,$@)
7474

75-
.PHONY: python/aio-v3.11.3
76-
python/aio-v3.11.3:
75+
.PHONY: python/aio-v3.11.4
76+
python/aio-v3.11.4:
7777
WLR_BUILD_FLAVOR=aio \
7878
make -C python $(subst python/aio-,,$@)
7979

80-
.PHONY: python/aio-wasmedge-v3.11.3
81-
python/aio-wasmedge-v3.11.3:
80+
.PHONY: python/aio-wasmedge-v3.11.4
81+
python/aio-wasmedge-v3.11.4:
8282
WLR_BUILD_FLAVOR=aio-wasmedge \
8383
make -C python $(subst python/aio-wasmedge-,,$@)
8484

85-
.PHONY: oci-python-3.11.3
86-
oci-python-3.11.3: python/v3.11.3
85+
.PHONY: oci-python-3.11.4
86+
oci-python-3.11.4: python/v3.11.4
8787
docker build \
8888
--platform wasi/wasm32 \
8989
--build-arg NAME=python-wasm \
9090
--build-arg SUMMARY="CPython built for WASI, by Wasm Labs" \
91-
--build-arg ARTIFACTS_BASE_DIR=python/v3.11.3 \
91+
--build-arg ARTIFACTS_BASE_DIR=python/v3.11.4 \
9292
--build-arg PYTHON_BINARY=python.wasm \
93-
-t ghcr.io/vmware-labs/python-wasm:3.11.3 \
93+
-t ghcr.io/vmware-labs/python-wasm:3.11.4 \
9494
-f images/python/Dockerfile \
9595
build-output
9696

97-
.PHONY: oci-python-3.11.3-wasmedge
98-
oci-python-3.11.3-wasmedge: python/wasmedge-v3.11.3
97+
.PHONY: oci-python-3.11.4-wasmedge
98+
oci-python-3.11.3-wasmedge: python/wasmedge-v3.11.4
9999
docker build \
100100
--platform wasi/wasm32 \
101101
--build-arg NAME=python-wasm \
102102
--build-arg SUMMARY="CPython built for WASI+WasmEdge, by Wasm Labs" \
103-
--build-arg ARTIFACTS_BASE_DIR=python/v3.11.3-wasmedge \
103+
--build-arg ARTIFACTS_BASE_DIR=python/v3.11.4-wasmedge \
104104
--build-arg PYTHON_BINARY=python.wasm \
105-
-t ghcr.io/vmware-labs/python-wasm:3.11.3-wasmedge \
105+
-t ghcr.io/vmware-labs/python-wasm:3.11.4-wasmedge \
106106
-f images/python/Dockerfile \
107107
build-output
108108

python/test/run_me.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ "$(realpath $PWD)" != "$(realpath $(dirname $BASH_SOURCE))" ]]
4+
then
5+
echo "This script works only if called from its location as PWD"
6+
exit 1
7+
fi
8+
9+
TESTS=$(for t in */test.py; do echo $(dirname $t); done)
10+
11+
status=0
12+
13+
for test_dir in "$TESTS"; do
14+
echo "Running test in '${test_dir}'..."
15+
if diff ${test_dir}/test.stdout <($WLR_TEST_RUNTIME \
16+
--mapdir /usr::${WLR_OUTPUT}/usr \
17+
--mapdir /test::./${test_dir} \
18+
--mapdir .::./${test_dir} \
19+
${WLR_TESTED_MODULE} \
20+
/test/test.py); then
21+
echo "${test_dir}/test.py passed!"
22+
else
23+
echo "${test_dir}/test.py failed!"
24+
status=$(expr ${status} + 1)
25+
fi
26+
done
27+
28+
exit $status

python/test/sqlite/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.db

python/test/sqlite/test.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import traceback
2+
3+
import sqlite3
4+
import sys
5+
6+
DB_FILE_NAME = 'test.db'
7+
8+
def create_table(con, name, schema):
9+
cursorObj = con.cursor()
10+
cursorObj.execute(f"CREATE TABLE {name}{schema}")
11+
con.commit()
12+
13+
def populate_table(con, name):
14+
cursorObj = con.cursor()
15+
cursorObj.execute(f"INSERT INTO {name} VALUES(1, 'John', 700, 'TheDarkMaster')")
16+
cursorObj.execute(f"INSERT INTO {name} VALUES(2, 'Jane', 710, 'AngelOfBenevolence')")
17+
cursorObj.execute(f"INSERT INTO {name} VALUES(3, 'George', 623, 'MagiFromTheDeep')")
18+
con.commit()
19+
20+
def select_table(con, name):
21+
cursorObj = con.cursor()
22+
cursorObj.execute(f"SELECT * FROM {name}")
23+
rows = cursorObj.fetchall()
24+
for row in rows:
25+
print(row)
26+
27+
def sql_version(con):
28+
cursor = con.cursor()
29+
30+
sqlite_select_Query = "select sqlite_version();"
31+
cursor.execute(sqlite_select_Query)
32+
record = cursor.fetchall()
33+
print("SQLite Database Version is: ", record)
34+
cursor.close()
35+
36+
connection = None
37+
try:
38+
connection = sqlite3.connect(DB_FILE_NAME)
39+
print("Database created and Successfully Connected to SQLite")
40+
41+
sql_version(connection)
42+
43+
try:
44+
create_table(connection, "players", "(id integer PRIMARY KEY, name text, score real, nickname text)")
45+
except sqlite3.Error as e:
46+
print("Error while trying to create table: ", e)
47+
48+
try:
49+
populate_table(connection, "players")
50+
except sqlite3.Error as e:
51+
print("Error while trying to create table: ", e)
52+
53+
54+
try:
55+
select_table(connection, "players")
56+
57+
except sqlite3.Error as e:
58+
print("Error while trying to fetch table: ", e)
59+
60+
61+
except sqlite3.Error as error:
62+
print("Error while connecting to sqlite", error)
63+
64+
print(traceback.format_exc())
65+
66+
finally:
67+
if connection:
68+
connection.close()
69+
print("The SQLite connection is closed")
70+
import os
71+
if os.path.isfile(DB_FILE_NAME):
72+
os.remove(DB_FILE_NAME)
73+
print(f"File '{DB_FILE_NAME}' deleted!")
74+

python/test/sqlite/test.stdout

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Database created and Successfully Connected to SQLite
2+
SQLite Database Version is: [('3.42.0',)]
3+
(1, 'John', 700.0, 'TheDarkMaster')
4+
(2, 'Jane', 710.0, 'AngelOfBenevolence')
5+
(3, 'George', 623.0, 'MagiFromTheDeep')
6+
The SQLite connection is closed
7+
File 'test.db' deleted!

python/v3.11.4/wlr-build.sh

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ ! -v WLR_ENV ]]
4+
then
5+
echo "WLR build environment is not set"
6+
exit 1
7+
fi
8+
9+
cd "${WLR_SOURCE_PATH}"
10+
11+
if [[ "${WLR_BUILD_FLAVOR}" == *"aio"* ]]
12+
then
13+
source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_wasi_vfs.sh
14+
wlr_wasi_vfs_setup_dependencies || exit 1
15+
fi
16+
17+
source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh
18+
19+
export CFLAGS_CONFIG="-O0"
20+
21+
22+
# This fails with upgraded clang for wasi-sdk19 and later. Disabled on cpython main.
23+
#
24+
# PyModule_AddIntMacro(module, CLOCK_MONOTONIC) and the like cause this.
25+
# In all POSIX variants CLOCK_MONOTONIC is a numeric constant, so python imports it as int macro
26+
# However, in wasi-libc clockid_t is defined as a pointer to struct __clockid.
27+
28+
export CFLAGS_CONFIG="${CFLAGS_CONFIG} -Wno-int-conversion"
29+
30+
export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_DEPENDENCIES} ${CFLAGS}"
31+
export LDFLAGS="${LDFLAGS_DEPENDENCIES} ${LDFLAGS}"
32+
33+
export PYTHON_WASM_CONFIGURE="--with-build-python=python3"
34+
35+
if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]]
36+
then
37+
if [[ ! -v WABT_ROOT ]]
38+
then
39+
echo "WABT_ROOT is needed to patch imports for wasmedge"
40+
exit 1
41+
fi
42+
fi
43+
44+
# By exporting WLR_SKIP_WASM_OPT envvar during the build, the
45+
# wasm-opt wrapper in the wasm-base image will be a dummy wrapper that
46+
# is effectively a NOP.
47+
#
48+
# This is due to https://github.com/llvm/llvm-project/issues/55781, so
49+
# that we get to choose which optimization passes are executed after
50+
# the artifacts have been built.
51+
export WLR_SKIP_WASM_OPT=1
52+
53+
if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then
54+
logStatus "Configuring build with '${PYTHON_WASM_CONFIGURE}'... "
55+
CONFIG_SITE=./Tools/wasm/config.site-wasm32-wasi ./configure -C --host=wasm32-wasi --build=$(./config.guess) ${PYTHON_WASM_CONFIGURE} || exit 1
56+
else
57+
logStatus "Skipping configure..."
58+
fi
59+
60+
export MAKE_TARGETS='python.wasm wasm_stdlib'
61+
62+
logStatus "Building '${MAKE_TARGETS}'... "
63+
make -j ${MAKE_TARGETS} || exit 1
64+
65+
unset WLR_SKIP_WASM_OPT
66+
67+
if [[ "${WLR_BUILD_FLAVOR}" == *"aio"* ]]
68+
then
69+
logStatus "Packing with wasi-vfs"
70+
wlr_wasi_vfs_cli pack python.wasm --mapdir /usr::$PWD/usr -o python.wasm || exit 1
71+
fi
72+
73+
logStatus "Optimizing python binary..."
74+
wasm-opt -O2 -o python-optimized.wasm python.wasm || exit 1
75+
76+
if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]]
77+
then
78+
logStatus "Patching python binary for wasmedge..."
79+
${WLR_REPO_ROOT}/scripts/build-helpers/patch_wasmedge_wat_sock_accept.sh python-optimized.wasm || exit 1
80+
fi
81+
82+
logStatus "Preparing artifacts... "
83+
TARGET_PYTHON_BINARY=${WLR_OUTPUT}/bin/python.wasm
84+
85+
mkdir -p ${WLR_OUTPUT}/bin 2>/dev/null || exit 1
86+
87+
if [[ "${WLR_BUILD_FLAVOR}" == *"aio"* ]]
88+
then
89+
cp -v python-optimized.wasm ${TARGET_PYTHON_BINARY} || exit 1
90+
else
91+
mkdir -p ${WLR_OUTPUT}/usr 2>/dev/null || exit 1
92+
cp -v python-optimized.wasm ${TARGET_PYTHON_BINARY} || exit 1
93+
cp -TRv usr ${WLR_OUTPUT}/usr || exit 1
94+
fi
95+
96+
if [[ "${WLR_BUILD_FLAVOR}" != *"aio"* && "${WLR_BUILD_FLAVOR}" != *"wasmedge"* ]]
97+
then
98+
99+
logStatus "Install includes..."
100+
make inclinstall \
101+
prefix=${WLR_OUTPUT} \
102+
libdir=${WLR_OUTPUT}/lib/wasm32-wasi \
103+
pkgconfigdir=${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig || exit 1
104+
105+
logStatus "Create libpython3.11-aio.a"
106+
(${AR} -M <<EOF
107+
create libpython3.11-aio.a
108+
addlib libpython3.11.a
109+
addlib ${WLR_DEPS_ROOT}/build-output/lib/wasm32-wasi/libz.a
110+
addlib ${WLR_DEPS_ROOT}/build-output/lib/wasm32-wasi/libbz2.a
111+
addlib ${WLR_DEPS_ROOT}/build-output/lib/wasm32-wasi/libsqlite3.a
112+
addlib ${WLR_DEPS_ROOT}/build-output/lib/wasm32-wasi/libuuid.a
113+
addlib Modules/expat/libexpat.a
114+
addlib Modules/_decimal/libmpdec/libmpdec.a
115+
save
116+
end
117+
EOF
118+
) || echo exit 1
119+
120+
mkdir -p ${WLR_OUTPUT}/lib/wasm32-wasi/ 2>/dev/null || exit 1
121+
cp -v libpython3.11-aio.a ${WLR_OUTPUT}/lib/wasm32-wasi/libpython3.11.a || exit 1
122+
123+
logStatus "Generating pkg-config file for libpython3.11.a"
124+
DESCRIPTION="libpython3.11 allows embedding the CPython interpreter"
125+
EXTRA_LINK_FLAGS="-lpython3.11 -Wl,-z,stack-size=524288 -Wl,--stack-first -Wl,--initial-memory=10485760 -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks"
126+
127+
PC_INCLUDE_SUBDIR=python3.11 wlr_pkg_config_create_pc_file "libpython3.11" "${WLR_PACKAGE_VERSION}" "${DESCRIPTION}" "${EXTRA_LINK_FLAGS}" || exit 1
128+
129+
WLR_PACKAGE_LIB_EXTRA_DIRS=usr wlr_package_lib || exit 1
130+
fi
131+
132+
logStatus "DONE. Artifacts in ${WLR_OUTPUT}"

python/v3.11.4/wlr-env-repo.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 == "--unset" ]]
4+
then
5+
unset WLR_REPO
6+
unset WLR_REPO_BRANCH
7+
unset WLR_ENV_NAME
8+
unset WLR_PACKAGE_VERSION
9+
unset WLR_PACKAGE_NAME
10+
return
11+
fi
12+
13+
export WLR_REPO=https://github.com/python/cpython
14+
export WLR_REPO_BRANCH=v3.11.4
15+
export WLR_ENV_NAME=python/v3.11.4
16+
export WLR_PACKAGE_VERSION=3.11.4
17+
export WLR_PACKAGE_NAME=python

python/v3.11.4/wlr-info.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"deps": {
3+
"libuuid": {
4+
"build_target": "libs/libuuid/v1.0.3",
5+
"required_file": "lib/wasm32-wasi/libuuid.a"
6+
},
7+
"zlib": {
8+
"build_target": "libs/zlib/v1.2.13",
9+
"required_file": "lib/wasm32-wasi/libz.a"
10+
},
11+
"SQLite": {
12+
"build_target": "libs/sqlite/v3.42.0",
13+
"required_file": "lib/wasm32-wasi/libsqlite3.a"
14+
},
15+
"bzip2": {
16+
"build_target": "libs/bzip2/v1.0.8",
17+
"required_file": "lib/wasm32-wasi/libbz2.a"
18+
}
19+
}
20+
}

python/v3.11.4/wlr-tag.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export WLR_TAG="python/3.11.4"

0 commit comments

Comments
 (0)