bytecodealliance / wasmtime-py

Python WebAssembly runtime powered by Wasmtime
https://bytecodealliance.github.io/wasmtime-py/
Apache License 2.0
390 stars 52 forks source link

PyPI package does not work on Alpine #237

Closed whitequark closed 3 months ago

whitequark commented 4 months ago

To reproduce:

$ docker run --network=host -it alpine:latest
/ # apk add py3-pip
/ # cd /root
~ # python -m venv venv
~ # . venv/bin/activate
(venv) ~ # pip install wasmtime
Collecting wasmtime
  Downloading wasmtime-21.0.0-py3-none-any.whl.metadata (7.4 kB)
Collecting importlib-resources>=5.10 (from wasmtime)
  Downloading importlib_resources-6.4.0-py3-none-any.whl.metadata (3.9 kB)
Downloading wasmtime-21.0.0-py3-none-any.whl (4.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.4/4.4 MB 8.8 MB/s eta 0:00:00
Downloading importlib_resources-6.4.0-py3-none-any.whl (38 kB)
Installing collected packages: importlib-resources, wasmtime
Successfully installed importlib-resources-6.4.0 wasmtime-21.0.0
(venv) ~ # python
Python 3.11.9 (main, Apr 14 2024, 13:40:00) [GCC 13.2.1 20231014] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wasmtime
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/venv/lib/python3.11/site-packages/wasmtime/__init__.py", line 17, in <module>
    from ._error import WasmtimeError, ExitTrap
  File "/root/venv/lib/python3.11/site-packages/wasmtime/_error.py", line 2, in <module>
    from . import _ffi as ffi
  File "/root/venv/lib/python3.11/site-packages/wasmtime/_ffi.py", line 30, in <module>
    raise RuntimeError("precompiled wasmtime binary not found at `{}`".format(filename))
RuntimeError: precompiled wasmtime binary not found at `/root/venv/lib/python3.11/site-packages/wasmtime/linux-x86_64/_libwasmtime.so`

The root cause is that the manylinux wheels that are currently published are based on glibc, but Alpine is based on musl libc. There is a separate musllinux platform tag that can be used in that case.

Do you think musl-compatible builds could be added? This would improve compatibility with certain distributions like Alphine Linux, Void Linux, and others focusing on size and speed.

alexcrichton commented 4 months ago

Is there a python target which is "not glibc" and/or "only musl libc"? Or would all linux users need to switch over to a musl-based version?

I'll also note that we haven't yet added musl/alpine releases for Wasmtime itself and this repo pulls from the artifacts produced in Wasmtime itself so that might be a prerequisite here too

sdomi commented 4 months ago

It's musllinux, as per https://peps.python.org/pep-0656/ - this can be a separate build from manylinux, especially since you already ship different wheels per architecture and system.

alexcrichton commented 4 months ago

Nice! I believe with that there'd be a new addition of musllinux_1_2_x86_64 here. I added building of Wasmtime binaries to https://github.com/bytecodealliance/wasmtime/pull/8668.

@whitequark do you need any other platforms other than x86_64? It'll be significantly more difficult getting other musl-based architectures working since we'd have to build our own toolchain which is generally not an easy thing to architect for CI

whitequark commented 4 months ago

do you need any other platforms other than x86_64?

That should cover the vast majority of use cases. I can see someone wanting arm64 for Alpine on Apple M1 eventually, but that's a niche of a niche and I don't think we need to care about this now. Thanks!

alexcrichton commented 4 months ago

@whitequark can you test this release and see if it works for you?

sdomi commented 4 months ago

@alexcrichton tested, can verify that it works for me :)

alexcrichton commented 4 months ago

Awesome, thanks! Is this something where you'd like to see that as a 21.0.1 release? Or is waiting until April June 20 for the Wasmtime 22 release ok?

whitequark commented 4 months ago

(Do you mean June?)

alexcrichton commented 4 months ago

Oops sorry, yes, I mean June.

whitequark commented 4 months ago

I think that's fine--we get folks on musl-based distros occasionally but it's not a lot and you don't need to go through the trouble of making a release. Thanks for offering!

(I guess this issue could be closed once there's a release?)