Stream: wasmtime

Topic: Missing import for cpython


view this post on Zulip Ben Brandt (Jan 21 2025 at 14:24):

Hi all, I am trying to compile cpython for wasip2 and am getting the following issue when I try and run it with wasmtime:

Command:

wasmtime run --wasm max-wasm-stack=8388608 --wasi preview2 --dir {HOST_DIR}::{GUEST_DIR}

Output

Error: failed to run main module `/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/cross-build/wasm32-wasip2/python.wasm`

Caused by:
    0: failed to instantiate "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/cross-build/wasm32-wasip2/python.wasm"
    1: unknown import: `wasi_snapshot_preview1::adapter_open_badfd` has not been defined
Traceback (most recent call last):
  File "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/./Tools/wasm/wasi.py", line 365, in <module>
    main()
    ~~~~^^
  File "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/./Tools/wasm/wasi.py", line 361, in main
    dispatch[context.subcommand](context)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/./Tools/wasm/wasi.py", line 85, in wrapper
    return func(context, working_dir)
  File "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/./Tools/wasm/wasi.py", line 272, in make_wasi_python
    subprocess.check_call([exec_script, "--version"])
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.13/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 419, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '[PosixPath('/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/cross-build/wasm32-wasip2/python.sh'), '--version']' returned non-zero exit status 1.

The weird thing is it seems like it should be available based on this: https://github.com/bytecodealliance/wasmtime/blob/cd67a6090d515189a9c286bec2d993a591da3739/crates/wasi-preview1-component-adapter/src/lib.rs#L171

I built with wasi-sdk v25 (which might be the issue) and using wasmtime v28 and v29 caused the issue.

If anyone has any ideas, I'd appreciate it, otherwise I'll keep trying different combinations of wasmtime and wasi-sdk. Thanks!

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Victor Adossi (Jan 21 2025 at 14:53):

Is this issue possibly linked/relevant?

Hi There, I'm trying to build a component that could be used by wasmtime serve. The code is in Rust, but for various reasons I cannot rely on Cargo and have to work in Bazel. I can build core Wasm ...

view this post on Zulip Ben Brandt (Jan 21 2025 at 14:54):

Hmm maybe... I will take a look. Thanks

view this post on Zulip Victor Adossi (Jan 21 2025 at 14:56):

Yeah it seems unlikely since the tooling probably isn't doing anything funny with the adapter name/does this properly... but I wonder if this is something that tripped people up somewhat recently, and specifying an adapter name (via --adapt name=<path> might be necessary now where it wasn't before...

view this post on Zulip Ben Brandt (Jan 21 2025 at 15:03):

it is also possible that while I am telling cpython to compile with the target wasip2 that it is still doing it for p1 and that is also causing an issue...

view this post on Zulip Joel Dice (Jan 21 2025 at 15:08):

Is the python.wasm file a module or a component (use e.g. wasm-tools print and look at the first line of the output)? If it's a module, then presumably wasm-component-ld is not being run and the adapter isn't being used. Keep in mind that wasm32-wasip2 is not yet a supported target for CPython, so hacks may be required to get it working.

view this post on Zulip Ben Brandt (Jan 21 2025 at 15:14):

ah it is just a module... Ok this likely explains the issue thanks. I was just trying to check out Brett's flag to try a different target , which doesn't work yet. All good. thanks everyone!

view this post on Zulip Notification Bot (Jan 21 2025 at 15:14):

Ben Brandt has marked this topic as resolved.

view this post on Zulip Notification Bot (Jan 21 2025 at 15:25):

Ben Brandt has marked this topic as unresolved.

view this post on Zulip Ben Brandt (Jan 21 2025 at 15:25):

OK nevermind, even if I build for wasip1 I still have the same issue:

Checked 112 modules (69 built-in, 0 shared, 26 n/a on wasi-wasm32, 9 disabled, 8 missing, 0 failed on import)
Error: failed to run main module `/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/cross-build/wasm32-wasip1/python.wasm`

Caused by:
    0: failed to instantiate "/Users/benjamin.brandt/github/wasi-wheels/cpython-3.13.1/cross-build/wasm32-wasip1/python.wasm"
    1: unknown import: `wasi_snapshot_preview1::adapter_open_badfd` has not been defined

view this post on Zulip Ben Brandt (Jan 21 2025 at 15:31):

It also doesn't work with wasi-sdk 24... it is possible there's something wrong with my wasmtime or I messed something up in the build... I'll keep digging

view this post on Zulip Joel Dice (Jan 21 2025 at 15:45):

Hmm, that definitely shouldn't happen. The only part of wasi-libc that references adapter_open_badfd is descriptor_table.c, which is explicitly excluded from the WASIp1 build. I wonder if files got accidentally cached across the p2 and p1 builds? Maybe try doing a clean build if you haven't already.

WASI libc implementation for WebAssembly. Contribute to WebAssembly/wasi-libc development by creating an account on GitHub.

view this post on Zulip Ben Brandt (Jan 21 2025 at 15:58):

I'm running into the same issue just running the basic command listed here: https://devguide.python.org/getting-started/setup-building/index.html#wasi

I can ask @Brett Cannon again... for some reason it works for him, but I am having issues which leads me to believe I have something weird in my setup. But I guess this is more of a Cpython issue than a wasmtime issue...

These instructions cover how to get a working copy of the source code and a compiled version of the CPython interpreter (CPython is the version of Python available from https://www.python.org/). It...

view this post on Zulip Ben Brandt (Jan 21 2025 at 16:12):

I've also cleaned the entire cpython dir and replaced it multiple times but nothing seems to help...

view this post on Zulip Ralph (Jan 21 2025 at 16:42):

everything works for Brett

view this post on Zulip Ben Brandt (Jan 21 2025 at 16:48):

Yeah maybe it is because I am on 3.13.1 and there are changes on main I
need to backport... I'll take a look

view this post on Zulip Ben Brandt (Jan 21 2025 at 17:08):

@Joel Dice I actually have the same problem with the build from the script in componentize-py... so maybe it has more to do with how we are invoking wasmtime (or my wasmtime is wrong)

view this post on Zulip Joel Dice (Jan 21 2025 at 17:11):

componentize-py only cares about libpython312.so and simply ignores python.wasm, so the latter could be broken in various ways without me noticing. What's your goal here? Are you planning to use python.wasm for some specific purpose?

view this post on Zulip Ben Brandt (Jan 21 2025 at 17:25):

It was for building the wheels. And Brett's script does this validation.
But maybe I also only need the .so file and can just ignore it as well.


Last updated: Jan 24 2025 at 00:11 UTC