Giter VIP home page Giter VIP logo

python-wasm's Introduction

CPython on WASM

Build scripts and configuration for building CPython for Emscripten.

Check out Christian Heimes' talk about the effort at PyConDE: https://www.youtube.com/watch?v=oa2LllRZUlU

Pretty straight forward. First, install emscripten. Then, run the following commands:

# get the Python sources
./fetch-python.sh
# build Python for the machine we are building on, needed before cross compiling for emscripten
./build-python-build.sh
# build Python cross-compiling to emscripten
./build-python-emscripten-browser.sh

There will probably be errors, but that's just part of the fun of experimental platforms.

Assuming things compiled correctly, you can have emscripten serve the Python executable and then open http://localhost:8000/python.html in your browser:

./run-python-browser.sh

The CLI input is done via an input modal which is rather annoying. Also to get output you need to click Cancel on the modal...

Developing

Once you've built the Emscripten'd Python, you can rebuild it via

./clean-host.sh
./build-python-emscripten-browser.sh

which will rebuild Python targeting emscripten and re-generate the python.{html, wasm, js}

Test build artifacts

You can also download builds from our CI workflow and test WASM builds locally.

Emscripten browser build

  • download and unzip the emscripten-browser-main.zip build artifact
  • run a local webserver in the same directory as python.html, e.g. python3 -m http.server
  • open http://localhost:8000/python.html
  • enter commands into the browser modal window and check the web developer console (F12) for output. You may need to hit "Cancel" on the modal after sending input for output to appear.

Emscripten NodeJS build

  • download and unzip the emscripten-node-main.zip build artifact
  • run node python.js (older versions may need --experimental-wasm-bigint)

WASI

  • download and unzip the wasi-main.zip build artifact
  • install wasmtime
  • run wasmtime run --dir . -- python.wasm

python-wasm's People

Contributors

ethanhs avatar tiran avatar pmp-p avatar brettcannon avatar katharosada avatar almogbaku avatar kumaraditya303 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.