Skip to content

[mypyc] Add support for building mypyc code on WASM #13446

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

Merged
merged 13 commits into from
Sep 16, 2022
Merged

[mypyc] Add support for building mypyc code on WASM #13446

merged 13 commits into from
Sep 16, 2022

Conversation

emmatyping
Copy link
Member

@emmatyping emmatyping commented Aug 18, 2022

Description

This PR tweaks two things about how mypyc generates and builds C code to better support WebAssembly. First, we search sysconfig for the size of size_t, which works much better for cross-compiling. Second, newer versions of clang have -Wno-unused-but-set-variable and so it is added to the default list of arguments (this should probably land regardless the decision on merging this PR).

Test Plan

This PR depends on #13445. To test this PR, you can do the following:

assuming mypy checkout with both PRs applied, must be on Python 3.10(!)

$ pip install pyodide-build
$ pyodide build --exports pyinit backend-args --global-option=--use-mypyc

Note: you will get a warning about using --global-option, you can ignore it for now. I'm trying to find out why --build-option isn't working...

@emmatyping
Copy link
Member Author

Blocked on python/typeshed#8572

@emmatyping emmatyping mentioned this pull request Aug 20, 2022
@emmatyping
Copy link
Member Author

Hmm I'm unsure why things disagree. It seems like sys.maxsize != sysconfig.get_config_var("SIZEOF_SIZE_T") on 32 bit Python on 64bit windows??

@emmatyping
Copy link
Member Author

Ah yeah I messed up my math so it was setting SIZEOF_SIZE_T to 3 not 4 😅

This should be ready review now!

@emmatyping
Copy link
Member Author

emmatyping commented Sep 16, 2022

The latest commit 4ec39a8 enables outputting VT100 color codes for use in the web via things like https://www.npmjs.com/package/ansi-to-html. I guess I could directly output HTML but I figure that this is a bit more portable in case someone wants to run mypy under node or do something else. This is only enabled if you pass MYPY_FORCE_COLOR anyway.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with the big caveat that I'm not sure I understand the exact circumstances when sysconfig's sizeof_size_t differs from sys.maxsize

@emmatyping
Copy link
Member Author

@hauntsaninja

I'm not sure I understand the exact circumstances when sysconfig's sizeof_size_t differs from sys.maxsize

SIZE_OF_SIZE_T is only defined in UNIX environments, so we still rely on sys.maxsize on Windows. They only differ when you are cross compiling (like we would be for WASM)

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja hauntsaninja merged commit 11be378 into master Sep 16, 2022
@hauntsaninja hauntsaninja deleted the wasm branch September 16, 2022 23:58
@emmatyping
Copy link
Member Author

Oh this also needs #13445 to actually work (pyodide build uses the PEP 517 interface)

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

Successfully merging this pull request may close these issues.

3 participants