From 6694d234cfdfc399f28d42d14b262288635232f1 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 1 Mar 2024 14:25:01 -0800 Subject: [PATCH 1/2] GH-115978: Disable `*readv()` and `*writev()` on WASI Wasmtime doesn't implement them in a way to pass test_posix (https://github.com/bytecodealliance/wasmtime/issues/7830). This fix allows running under WASI 0.2 primitives for wasmtime. --- .devcontainer/Dockerfile | 2 +- ...-03-01-14-22-08.gh-issue-115978.r2ePTo.rst | 4 +++ Tools/wasm/config.site-wasm32-wasi | 9 ++++++ Tools/wasm/wasi.py | 29 +++++++++++-------- 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-03-01-14-22-08.gh-issue-115978.r2ePTo.rst diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9f808af38e69df..365756458bba30 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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)' && \ diff --git a/Misc/NEWS.d/next/Library/2024-03-01-14-22-08.gh-issue-115978.r2ePTo.rst b/Misc/NEWS.d/next/Library/2024-03-01-14-22-08.gh-issue-115978.r2ePTo.rst new file mode 100644 index 00000000000000..2adac31ac6c21d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-01-14-22-08.gh-issue-115978.r2ePTo.rst @@ -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). diff --git a/Tools/wasm/config.site-wasm32-wasi b/Tools/wasm/config.site-wasm32-wasi index 5e98775400f6ea..4a1a466a4ab3f1 100644 --- a/Tools/wasm/config.site-wasm32-wasi +++ b/Tools/wasm/config.site-wasm32-wasi @@ -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 diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py index 1e75db5c7b8329..d3c249419438bc 100644 --- a/Tools/wasm/wasi.py +++ b/Tools/wasm/wasi.py @@ -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") From bdd3952218a63adecb722ad33575a50f8d2e19b2 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 1 Mar 2024 15:01:05 -0800 Subject: [PATCH 2/2] Revert jumping ahead to WASI 0.2 until it can be run successfully locally --- .devcontainer/Dockerfile | 2 +- Tools/wasm/wasi.py | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 365756458bba30..9f808af38e69df 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -6,7 +6,7 @@ ENV WASI_SDK_VERSION=20 ENV WASI_SDK_PATH=/opt/wasi-sdk ENV WASMTIME_HOME=/opt/wasmtime -ENV WASMTIME_VERSION=18.0.2 +ENV WASMTIME_VERSION=14.0.4 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)' && \ diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py index d3c249419438bc..1e75db5c7b8329 100644 --- a/Tools/wasm/wasi.py +++ b/Tools/wasm/wasi.py @@ -277,23 +277,18 @@ def clean_contents(context): def main(): - 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) + 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}") parser = argparse.ArgumentParser() subcommands = parser.add_subparsers(dest="subcommand")