GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-40280: Add wasm cross build targets (GH-29771) by tiran · Pull Request #29771 · python/cpython

Conversation

@tiran

@tiran tiran commented Nov 25, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

CPython uses the same target triplet convention as Rust:

$ rustc --print target-list | grep wasm
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm64-unknown-unknown

Signed-off-by: Christian Heimes [email protected]

https://bugs.python.org/issue40280

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

emmatyping reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Nov 25, 2021
@bedevere-bot bedevere-bot added the awaiting core review label Nov 25, 2021
@tiran
tiran requested a review from brettcannon November 25, 2021 14:33
emmatyping
emmatyping reviewed Nov 25, 2021
View reviewed changes
Comment thread configure.ac Resolved

Uh oh!

There was an error while loading. Please reload this page.

@tiran
tiran force-pushed the bpo-40280-wasm branch from 0afc925 to aa16619 Compare November 25, 2021 16:32
@emmatyping

emmatyping commented Nov 25, 2021

Copy link
Copy Markdown
Member

FWIW, this is enough to allow me to compile CPython with emscripten with the following settings:

# assuming emsdk, llvm, etc is installed...
READELF=llvm-readelf-12 emconfigure ./configure ac_cv_func_memfd_create=no ac_cv_func_eventfd=no ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no cross_compiling=yes --with-pydebug --with-suffix=.wasm --with-ensurepip=no --disable-ipv6 --host=wasm32-unknown-emscripten --build=x86_64-unknown-linux-gnu

emmake make FREEZE_MODULE=../cpython-build/Programs/_freeze_module

However it seems the built python.wasm won't run with any of the webassembly runtimes I tried, I think the finall emcc call would need to be tweaked...

tiran reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tiran

tiran commented Nov 25, 2021

Copy link
Copy Markdown
Member Author

I'm facing the same issue, e.g. wasmtime complaints about missing clock_gettime.

I fixed the sigset_t issue in GH-29770 and the wrong CC for cross compilation in GH-29752. Pyodide and similar projects have more downstream patches.

Did you know that you can put all custom autoconf overrides into a config.site file? I'm using this config.site file

# config.site-wasm
ac_cv_buggy_getaddrinfo=no
ac_cv_file__dev_ptmx=yes
ac_cv_file__dev_ptc=no
# undefined symbols in wasm:
ac_cv_func_posix_spawn=no
ac_cv_func_posix_spawnp=no
ac_cv_func_eventfd=no

to run CONFIG_SITE=config.site-wasm emconfigure ./configure ....

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brettcannon
brettcannon requested changes Nov 25, 2021
View reviewed changes

@brettcannon brettcannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I don't know if the current solution will work with wasm32-wasi. We should also make sure to support wasm32-unknown-wasi.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread configure.ac Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Build/2021-11-25-10-55-03.bpo-40280.E9-gsQ.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread configure.ac Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting core review label Nov 25, 2021
@bedevere-bot

bedevere-bot commented Nov 25, 2021

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Nov 25, 2021
@brettcannon

brettcannon commented Nov 25, 2021

Copy link
Copy Markdown
Member

Do we want to record all the incantations we are trying to make builds work somewhere? E.g. https://bugs.python.org/issue40280 or somewhere else like a GitHub org/repo (I'm happy to create a cpython-wasm repo and give you both write access to write down what does and doesn't work)?

@ethanhs while I think --with-suffix .wasm should trigger STANDALONE_WASM=1, I'm not sure, so you may need to set that environment variable to force emscripten to do a WASI build over an emscripten/browser/JS build.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tiran

tiran commented Nov 25, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

configure runs the host and build strings through config.sub, which converts any short forms into long canonical form:

$ emconfigure ../../configure -C --host=wasm32-wasi --build=x86_64-unknown-linux-gnu
configure: ../../configure -C --host=wasm32-wasi --build=x86_64-unknown-linux-gnu
configure: loading site script /usr/local/etc/config.site
configure: loading cache config.cache
checking for git... found
checking build system type... x86_64-unknown-linux-gnu
checking host system type... wasm32-unknown-wasi

--host=wasm32-wasi -> wasm32-unknown-wasi

For more information see:

  • https://wiki.osdev.org/Target_Triplet
  • https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Specifying-Target-Triplets.html
brettcannon reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tiran added 3 commits November 25, 2021 20:48
@tiran
bpo-40280: Add wasm cross build targets
a04c64c
CPython uses the same target triplet convention as Rust:

```
$ rustc --print target-list | grep wasm
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm64-unknown-unknown
```

Signed-off-by: Christian Heimes <[email protected]>
@tiran
Upper case WASI
05cb9f2
@tiran
Include wasm32-unknown-wasi triple
d4fba93
@tiran
tiran force-pushed the bpo-40280-wasm branch from aa16619 to d4fba93 Compare November 25, 2021 19:48
brettcannon
brettcannon approved these changes Nov 25, 2021
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting changes labels Nov 25, 2021
@tiran tiran changed the title bpo-40280: Add wasm cross build targets bpo-40280: Add wasm cross build targets (GH-29771) Nov 25, 2021
@tiran
tiran merged commit 1052a39 into python:main Nov 25, 2021
@tiran
tiran deleted the bpo-40280-wasm branch November 25, 2021 20:24
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 25, 2021
@emmatyping

emmatyping commented Nov 25, 2021

Copy link
Copy Markdown
Member

Do we want to record all the incantations we are trying to make builds work somewhere? E.g. https://bugs.python.org/issue40280 or somewhere else like a GitHub org/repo (I'm happy to create a cpython-wasm repo and give you both write access to write down what does and doesn't work)?

This seems like a great idea! Plus there will definitely need to be more patches for WASI, and probably Emscripten as well, so we can coordinate there if needed.

while I think --with-suffix .wasm should trigger STANDALONE_WASM=1, I'm not sure, so you may need to set that environment variable to force emscripten to do a WASI build over an emscripten/browser/JS build.

Certainly could! I was mostly seeing if I could get things to build at all before I went to bed. I'll probably play with things more tomorrow (and hopefully have something to show for it).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tiran

tiran commented Nov 25, 2021

Copy link
Copy Markdown
Member Author

+1 for Brett's proposal.

Progress! I'm now getting a different error from wasmtime. My emscripten version may not support pthread.

# wasmtime ./python.wasm
Error: failed to run main module `./python.wasm`

Caused by:
    0: failed to instantiate "./python.wasm"
    1: unknown import: `env::pthread_create` has not been defined
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@emmatyping

emmatyping commented Nov 26, 2021

Copy link
Copy Markdown
Member

Progress! I'm now getting a different error from wasmtime. My emscripten version may not support pthread.

Great! Unfortunately I don't think wasmtime supports pthreads. The only WASM runtime that I could find that did was https://github.com/bytecodealliance/wasm-micro-runtime

Wasmer seems to stub pthread out https://github.com/wasmerio/wasmer/blob/master/lib/emscripten/src/pthread.rs, but maybe it just passes those through?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

remykarem pushed a commit to remykarem/cpython that referenced this pull request Dec 7, 2021
@tiran remykarem
bpo-40280: Add wasm cross build targets (pythonGH-29771)
de3a352
@SimonBiggs SimonBiggs mannequin mentioned this pull request Jun 7, 2022
Consider supporting emscripten/webassembly as a build target #84461
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@emmatyping emmatyping emmatyping left review comments
@brettcannon brettcannon brettcannon approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@tiran @emmatyping @bedevere-bot @brettcannon @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.