Skip to content

Commit

Permalink
pythonGH-115978: Disable *readv() and *writev() on WASI
Browse files Browse the repository at this point in the history
Wasmtime doesn't implement them in a way to pass test_posix (bytecodealliance/wasmtime#7830).

This fix allows running under WASI 0.2 primitives for wasmtime.
  • Loading branch information
brettcannon committed Mar 1, 2024
1 parent 90a1e98 commit 6694d23
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Expand Up @@ -6,7 +6,7 @@ ENV WASI_SDK_VERSION=20
ENV WASI_SDK_PATH=/opt/wasi-sdk

ENV WASMTIME_HOME=/opt/wasmtime
ENV WASMTIME_VERSION=14.0.4
ENV WASMTIME_VERSION=18.0.2
ENV WASMTIME_CPU_ARCH=x86_64

RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,clang,curl,git,ln,tar,xz} 'dnf-command(builddep)' && \
Expand Down
@@ -0,0 +1,4 @@
Disable preadv(), readv(), pwritev(), and writev() on WASI.

Under wasmtime for WASI 0.2, these functions don't pass test_posix
(https://github.com/bytecodealliance/wasmtime/issues/7830).
9 changes: 9 additions & 0 deletions Tools/wasm/config.site-wasm32-wasi
Expand Up @@ -40,3 +40,12 @@ ac_cv_header_netpacket_packet_h=no

# Disable int-conversion for wask-sdk as it triggers an error from version 17.
ac_cv_disable_int_conversion=yes

# preadv(), readv(), pwritev(), and writev() under wasmtime's WASI 0.2 support
# do not use more than the first buffer provided, failing under test_posix.
# Since wasmtime will not be changing this behaviour, disable the functions.
# https://github.com/bytecodealliance/wasmtime/issues/7830
ac_cv_func_preadv=no
ac_cv_func_readv=no
ac_cv_func_pwritev=no
ac_cv_func_writev=no
29 changes: 17 additions & 12 deletions Tools/wasm/wasi.py
Expand Up @@ -277,18 +277,23 @@ def clean_contents(context):


def main():
default_host_runner = (f"{shutil.which('wasmtime')} run "
# Make sure the stack size will work for a pydebug
# build.
# The 8388608 value comes from `ulimit -s` under Linux
# which equates to 8291 KiB.
"--wasm max-wasm-stack=8388608 "
# Enable thread support.
"--wasm threads=y --wasi threads=y "
# Map the checkout to / to load the stdlib from /Lib.
"--dir {HOST_DIR}::{GUEST_DIR} "
# Set PYTHONPATH to the sysconfig data.
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}")
host_runner_parts = [
f"{shutil.which('wasmtime')} run",
# Make sure the stack size will work for a pydebug
# build.
# The 8388608 value comes from `ulimit -s` under Linux
# which equates to 8291 KiB.
"--wasm max-wasm-stack=8388608",
# Enable thread support.
#"--wasm threads=y --wasi threads=y "
# Use WASI 0.2 primitives
"--wasi preview2",
# Map the checkout to / to load the stdlib from /Lib.
"--dir {HOST_DIR}::{GUEST_DIR}",
# Set PYTHONPATH to the sysconfig data.
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}"
]
default_host_runner = " ".join(host_runner_parts)

parser = argparse.ArgumentParser()
subcommands = parser.add_subparsers(dest="subcommand")
Expand Down

0 comments on commit 6694d23

Please sign in to comment.