Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ set(CMAKE_EXECUTABLE_SUFFIX ".wasm")

add_compile_options(-Werror -Wall -Wextra -Wimplicit-fallthrough)

add_link_options(-Wl,--max-memory=67108864)
add_link_options(-Wl,--max-memory=67108864 -z stack-size=16777216 -Wl,--stack-first -Wl,--initial-memory=41943040)

add_executable(python-host pyhost.c)

find_package(Python COMPONENTS Development)

target_link_libraries(python-host PUBLIC Python::Python wasi_vfs)
target_link_libraries(python-host PUBLIC Python::Python wasi_vfs wasi-emulated-signal wasi-emulated-getpid wasi-emulated-process-clocks)
39 changes: 26 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV WASMTIME_VERSION=42.0.1
ENV WIZER_VERSION=10.0.0
ENV WASI_VFS_VERSION=0.6.2
ENV PYTHON_PATH=/opt/wasi-python
ENV PYTHON_PYLIB=${PYTHON_PATH}/lib/python3.13
ENV PYTHON_PYLIB=${PYTHON_PATH}/lib/python3.14
ENV PYTHON_SITE=${PYTHON_PYLIB}/site-packages

RUN <<EOF
Expand Down Expand Up @@ -67,32 +67,45 @@ EOF

RUN <<EOF
mkdir -p /build/cpython
curl -L https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz | \
curl -L https://www.python.org/ftp/python/3.14.3/Python-3.14.3.tgz | \
tar -xz --strip-components 1 -C /build/cpython
EOF

RUN <<'EOF'
cd /build/cpython
sed -i '/!_Py__has_attribute(preserve_none)/,/# endif/{
s/# if !_Py__has_attribute(preserve_none) || !_Py__has_attribute(musttail)/# if !_Py__has_attribute(musttail)/
}' Python/ceval_macros.h
sed -i 's/# define Py_PRESERVE_NONE_CC __attribute__((preserve_none))/# if _Py__has_attribute(preserve_none)\n# define Py_PRESERVE_NONE_CC __attribute__((preserve_none))\n# else\n# define Py_PRESERVE_NONE_CC\n# endif/' Python/ceval_macros.h
EOF

RUN <<EOF
cd /build/cpython
python3 Tools/wasm/wasi.py configure-build-python
python3 Tools/wasm/wasi.py make-build-python
python3 Tools/wasm/wasi configure-build-python
python3 Tools/wasm/wasi make-build-python
EOF

RUN <<EOF
cd /build/cpython
python3 Tools/wasm/wasi.py configure-host -- \
CFLAGS='-Os' --prefix=${PYTHON_PATH} --disable-test-modules
python3 Tools/wasm/wasi.py make-host
make -C cross-build/wasm32-wasi install COMPILEALL_OPTS='-j0 -b'
python3 Tools/wasm/wasi configure-host -- \
CFLAGS='-Os -mtail-call' --prefix=${PYTHON_PATH} --disable-test-modules --with-tail-call-interp
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the python_eval_frame smaller for chicory to compile

python3 Tools/wasm/wasi make-host
make -C cross-build/wasm32-wasip1 install COMPILEALL_OPTS='-j0 -b'
EOF

RUN <<EOF
cd /build/cpython/cross-build/wasm32-wasi
cd /build/cpython/cross-build/wasm32-wasip1
${WASI_SDK_PATH}/bin/ar -M <<AR
create ${PYTHON_PATH}/lib/libpython3.13.a
addlib libpython3.13.a
create ${PYTHON_PATH}/lib/libpython3.14.a
addlib libpython3.14.a
addlib Modules/expat/libexpat.a
addlib Modules/_decimal/libmpdec/libmpdec.a
addlib Modules/_hacl/libHacl_Hash_BLAKE2.a
addlib Modules/_hacl/libHacl_Hash_MD5.a
addlib Modules/_hacl/libHacl_Hash_SHA1.a
addlib Modules/_hacl/libHacl_Hash_SHA2.a
addlib Modules/_hacl/libHacl_Hash_SHA3.a
addlib Modules/_hacl/libHacl_HMAC.a
addlib ${WASI_SDK_LIBDIR}/libz.a
save
end
Expand All @@ -102,7 +115,7 @@ EOF
RUN <<EOF
cd ${PYTHON_PYLIB}
find . -name __pycache__ -exec rm -rf {} \;
rm -rf config-3.13-wasm32-wasi
rm -rf config-3.14-wasm32-wasi
rm -rf _*_support* _pyrepl bdb concurrent curses ensurepip doctest* idlelib
rm -rf multiprocessing pdb pydoc* socketserver* sqlite3 ssl* subprocess*
rm -rf tkinter turtle* unittest venv webbrowser* wsgiref xmlrpc
Expand All @@ -117,5 +130,5 @@ RUN <<EOF
cd ${PYTHON_SITE}
find . -name '*.dist-info' -exec rm -rf {} \;
rm -rf bin
/build/cpython/cross-build/build/python -m compileall -b .
$(find /build/cpython/cross-build -maxdepth 2 -name python -not -path '*/wasm32-*' -type f) -m compileall -b .
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems suspicious. It would be better to invoke this directly with the exact path.

EOF
8 changes: 5 additions & 3 deletions build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ export CMAKE_EXTRA_ARGS="
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DWASI_SDK_PREFIX=${WASI_SDK_PATH}
-DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake
-DCMAKE_PREFIX_PATH=/opt/wasi-python"
-DCMAKE_PREFIX_PATH=/opt/wasi-python
-DPython_INCLUDE_DIR=/opt/wasi-python/include/python3.14
-DPython_LIBRARY=/opt/wasi-python/lib/libpython3.14.a"

cmake -B ${TARGET_DIR} ${CMAKE_EXTRA_ARGS} .
cmake --build ${TARGET_DIR} --verbose

rm -rf "${TARGET_DIR}"/python

cp -a ${PYTHON_PATH}/lib/python3.13 ${TARGET_DIR}/python
cp -a ${PYTHON_PATH}/lib/python3.14 ${TARGET_DIR}/python
cp /work/trino.py ${TARGET_DIR}/python/site-packages/

wasi-vfs pack ${TARGET_DIR}/python-host.wasm \
--dir ${TARGET_DIR}/python::/opt/wasi-python/lib/python3.13 \
--dir ${TARGET_DIR}/python::/opt/wasi-python/lib/python3.14 \
--output ${TARGET_DIR}/python-host-packed.wasm

rm -rf "${TARGET_DIR}"/empty
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>io.trino</groupId>
<artifactId>trino-wasm-python</artifactId>
<version>3.13-6-SNAPSHOT</version>
<version>3.14-1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down Expand Up @@ -43,7 +43,7 @@
<air.javadoc.lint>all,-missing</air.javadoc.lint>
<air.release.preparation-goals>clean verify -DskipTests</air.release.preparation-goals>

<dep.chicory.version>1.7.2</dep.chicory.version>
<dep.chicory.version>1.7.5</dep.chicory.version>
</properties>

<dependencyManagement>
Expand Down
12 changes: 8 additions & 4 deletions pyhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static void skipType(const u8** const type)
case JSON:
case UUID:
case IPADDRESS:
case NUMBER:
break;
default:
FATAL("Unsupported Trino type %d", trinoType);
Expand Down Expand Up @@ -241,7 +242,8 @@ static PyObject* doBuildArgs(const u8** const type, const u8** const data)
*data += sizeof(f32);
return checked(PyFloat_FromDouble(value));
}
case DECIMAL: {
case DECIMAL:
case NUMBER: {
PyObject* number = readString(data);
PyObject* value = checked(PyObject_CallOneArg(decimalClass, number));
Py_DECREF(number);
Expand Down Expand Up @@ -643,15 +645,17 @@ static bool buildResult(const u8** const type, PyObject* input, Buffer* buffer)
bufferAppend(buffer, (u8*)&value, sizeof(f32));
return true;
}
case DECIMAL: {
case DECIMAL:
case NUMBER: {
const char* typeName = trinoType == DECIMAL ? "DECIMAL" : "NUMBER";
PyObject* string = PyObject_CallOneArg(decimalToStringFunction, input);
if (string == NULL) {
resultError(input, "DECIMAL");
resultError(input, typeName);
return false;
}
if (!bufferAppendString(buffer, string)) {
Py_DECREF(string);
resultError(input, "DECIMAL");
resultError(input, typeName);
return false;
}
Py_DECREF(string);
Expand Down
1 change: 1 addition & 0 deletions pyhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum
JSON = 20,
UUID = 21,
IPADDRESS = 22,
NUMBER = 23,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need to treat this as a separate type, if we're handling it identically to decimal on the Python side?

} TrinoType;

// WebAssembly types
Expand Down
Loading