Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] zlib support required by widely used python modules #96

Open
c-x opened this issue Jun 27, 2024 · 4 comments
Open

[bug] zlib support required by widely used python modules #96

c-x opened this issue Jun 27, 2024 · 4 comments

Comments

@c-x
Copy link

c-x commented Jun 27, 2024

Hi!

Apparently cpython was compiled without zlib support, which is required by the requests library (probably the most used/famous http library in python).

% poetry run componentize-py --wit-path myapp/wit --world plugins componentize -p myapp main -o my-app.wasm
Traceback (most recent call last):
  File "/myapp/python/.venv/bin/componentize-py", line 8, in <module>
    sys.exit(script())
             ^^^^^^^^
AssertionError: Traceback (most recent call last):
  File "/0/main.py", line 2, in <module>
    import requests
  File "/1/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/1/urllib3/__init__.py", line 18, in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
  File "/1/urllib3/connectionpool.py", line 15, in <module>
    from ._request_methods import RequestMethods
  File "/1/urllib3/_request_methods.py", line 10, in <module>
    from .response import BaseHTTPResponse
  File "/1/urllib3/response.py", line 11, in <module>
    import zlib
ModuleNotFoundError: No module named 'zlib'


Caused by:
    ModuleNotFoundError: No module named 'zlib'

Issue probably linked to #64

@dicej
Copy link
Collaborator

dicej commented Jun 27, 2024

I believe @brettcannon is planning to add zlib to the WASI build of CPython, along with other native modules such as bzip2, etc.

Regarding requests: I agree that this would be a great library to support, but it's going to take more than adding zlib to support it. I assume it also uses the ssl module, which is going to be way tougher to support given that Wasm doesn't currently have constant time operations, which means OpenSSL is vulnerable to timing attacks when compiled to Wasm. I think the most practical way to support requests is to port it to use wasi:http instead of sockets on WASIp2, which someone would need to volunteer to do.

@brettcannon
Copy link

I believe @brettcannon is planning to add zlib to the WASI build of CPython, along with other native modules such as bzip2, etc.

Correct, it's planned: https://opensource.snarky.ca/Python/WASI#Plans .

@c-x
Copy link
Author

c-x commented Jun 28, 2024

@brettcannon @dicej do you have any ETA/objective for this fix?

@brettcannon
Copy link

@c-x No ETA from me. The objective is to get zlib statically compiled into the binary I build for CPython via https://github.com/python/cpython/blob/main/Tools/wasm/wasi.py .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants