{"id":17930316,"url":"https://github.com/pmp-p/micropython-ports-wasm","last_synced_at":"2025-03-24T04:31:14.249Z","repository":{"id":109580247,"uuid":"168343871","full_name":"pmp-p/micropython-ports-wasm","owner":"pmp-p","description":"*experimental* wasm micropython port *not a fork* for Pythons Everywhere","archived":false,"fork":false,"pushed_at":"2020-08-10T11:26:26.000Z","size":6896,"stargazers_count":38,"open_issues_count":3,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-29T13:46:13.269Z","etag":null,"topics":["emscripten","micropython","wasm","wip-do-not-use"],"latest_commit_sha":null,"homepage":"http://pmp-p.github.io/layout.html","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmp-p.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"custom":["https://www.paypal.me/pmpp"],"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null}},"created_at":"2019-01-30T13:01:40.000Z","updated_at":"2024-10-25T16:24:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a6b6300-577b-4105-8298-6bb550ade619","html_url":"https://github.com/pmp-p/micropython-ports-wasm","commit_stats":{"total_commits":74,"total_committers":2,"mean_commits":37.0,"dds":0.05405405405405406,"last_synced_commit":"8bfc32f57b2d575352db2296e364d39b8f700dd6"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmp-p%2Fmicropython-ports-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmp-p%2Fmicropython-ports-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmp-p%2Fmicropython-ports-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmp-p%2Fmicropython-ports-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmp-p","download_url":"https://codeload.github.com/pmp-p/micropython-ports-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245211036,"owners_count":20578331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["emscripten","micropython","wasm","wip-do-not-use"],"created_at":"2024-10-28T21:12:48.882Z","updated_at":"2025-03-24T04:31:13.633Z","avatar_url":"https://github.com/pmp-p.png","language":"C","funding_links":["https://www.paypal.me/pmpp"],"categories":[],"sub_categories":[],"readme":"# MicroPython and Web Assembly (wasm)\n\n### NEWS:\n\n[![Gitter](https://badges.gitter.im/Wasm-Python/community.svg)](https://gitter.im/Wasm-Python/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n10 August 2020 : now WaPy can load as an es6 module, it also feature step-debugging for synchronous code.\n\n3 June 2020 : https://github.com/pmp-p/wapy/tree/wapy-wipdonotuse is quite stable and can run 2x to 5x slower than cpython native\n\n5x slower means full preemption like micropython.schedule can do on MCU except there it returns to js coroutines.\n\nso time.sleep, open(file \u0026 sockets), import are going to be implemented with \"aio\" functions (POSIX.1-2001, POSIX.1-2008)\n\nthe ffi/ctypes support seems enough to run some  PySDL2 samples ( ctypes wrapper for CPython and SDL2 )\n\n\ndemo: https://pmp-p.github.io/wapy/minide/\n\nto build : apply https://patch-diff.githubusercontent.com/raw/pmp-p/wapy/pull/3.diff on a micropython-master tree named build-no_nlr\n\n\nNeither micropython/micropython or pfalcon/pycopy seem actually attracted to have a bare metal preemptible VM :\n\nhttps://github.com/micropython/micropython/pull/4131#issuecomment-629597963\n\nhttps://github.com/pfalcon/pycopy/issues/18\n\n\nI don't see much point to bother integrate in upstream \"ports\" folder :\nso future of wapy could well be wasi-header-only or an arduino lib tied to Wasm3\nwhich should allow to write wapy drivers directly with bare-metal C or arduino.\n\n\n\n\n\n1 May 2020 : Project lives again, but is not compatible with either micropython or pycopy because of adoption of a no nlr, registers and a heavily customized vm.c\ni'll se how to integrate again when time comes. Meanwhile i'll try to maintain prebuilt and testsuite here  https://github.com/pmp-p/wapy\n\n\n20 august 2019 : blocked again https://bugs.llvm.org/show_bug.cgi?id=43060\n\n16 august 2019 : retrying stackless with clang CI intregration\n this is using emsdk tot-upstream (tip of tree) not latest-upstream (yet)\n\n\n10 august 2019 : currently paused because reached somehow limit of emscripten compiler by abusing jump tables\n   meanwhile trying new upstream clang with micropython no nlr branch which is better for stackless\nhttps://github.com/pmp-p/micropython/tree/wasm-nonlr/ports/wasm-no-nlr\n\n\nold working versions always stored in branches.\n\n\n\n## What ?\n\nwasm is a virtual machine for internet browsers which run bytecode closer to native speeds\nsee https://webassembly.org/\n\nbut we want to run python virtual machine and its own bytecode ;) so thanks to micropython\nwe'll be able to by compiling micropython core to wasm bytecode first.\n\n\n\n## Requirements\n\n - Linux OS with gcc/clang, a decent build environnement and libltdl-dev\n\n - have python3 in your path 3.6 should do it but 3.7 / 3.8 are safer.\n\n - Follow the instructions for getting started with Emscripten [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).\n\n\n\n## Getting started ( wapy, only basic js skill required )\n\nGet the content of  https://github.com/pmp-p/pmp-p.github.io/tree/master/wapy.es6 and hack it to your liking.\n\n\n\n\n## Getting started (this port)\n\n( does not apply to wapy, involves compilation )\n\nBeware this is not a micropython fork :\n it's a port folder to add support to official micropython for a new \"machine\"\n\n\nYou first need to get easy building your own official micropython and its javascript port\n\n\nFollow the instructions for getting started with micropython unix build\n\nhttps://github.com/micropython/micropython/\n\n\nto check if your emscripten build works ( facultative, FYI last test on emscripten 1.38.31 was ok )\n\nhttps://github.com/micropython/micropython/tree/master/ports/javascript\n\nbut i suggest using ```emmake make -C ports/javascript PYTHON=python2``` instead of just make\n\n\n\nWhat are the differences between this repo and the official javascript port?\n\nsee https://github.com/pmp-p/micropython-ports-wasm/issues/4\n\n\n## Dive in !\n\nnow you're ready to build the port, you can run\n\n```\n# micropython-ports-wasm will go in micropython/ports/wasm\n# as it's not a fork but a drop in target port we need to checkout a full microPython\n\n# get the micropython core.\n\n# official ( should always work ! )\ngit clone --recursive --recurse-submodules https://github.com/micropython/micropython\ncd micropython\n\n\n# or lvgl enabled ( wip could not work )\n# git clone --recursive --recurse-submodules https://github.com/littlevgl/lv_micropython.git\n# cd lv_micropython\n# git checkout lvgl_javascript\n# git submodule update --recursive --init\n# if you want to use asyncio with lvgl just add the patch https://patch-diff.githubusercontent.com/raw/littlevgl/lv_binding_micropython/pull/30.diff\n# that allows you to service with SDL.run_once()\n\n#build host tools\nmake -C mpy-cross\nmake -C ports/unix\n\n#add the target port\ncd micropython/ports\ngit clone https://github.com/pmp-p/micropython-ports-wasm.git wasm\n\n\ncd wasm\n\n#transpile the mixed python/C module to pure C\n#use a python3 version with annotations support !\n# . modgen.sh\n\n. /path/to/emsdk/emsdk_set_env.sh\n\n# for LVGL support use \"./rebuild.sh LVGL=1\" instead\n# test will be run automatically.\n# emmake make USER_C_MODULES=cmod \u0026\u0026 . runtest.sh\n\n# modgen and make have been merged in rebuild-upsteam.sh script\nchmod +x *sh\n\n# avoid using ./rebuild-fastcom.sh\n# only there for testing clang 8-10 and binaryen discrepancy\n\n./rebuild-upstream.sh\n\n# fast rebuild\n# ./rebuild-upstream.sh fast=1\n\n# using asyncfy (bad perf even on upstream) avoid fast=1 when changing\n# mode\n# ./rebuild-upstream.sh ASYNCIFY=1\n\n```\n\nnow you can navigate http://127.0.0.1:8000/index.html\n\nto edit code samples look in micropython/*.html\n\n\n## Usage\n\n\ncopy the 4 files located in micropython folder found inside the build folder\n ``pythons.js micropython.js micropython.data micropython.wasm``\nand drop them where your main let's say myupython.html file will be\n\nnow you have 3 options to run code :\n\n 1) from the web via arguments ( sys.argv ) with a call myupython.html?full_url_to_the_script.py\n\n 2) from a \u003cscript type=\"text/µpython\u003e tag\n\n 3) interactively from repl with xterm.js\n\n\nfor 1\u00262 you will need to provide a javascript term_impl(text) function that output stdout stream where you want it to go\n\n\n\n![Preview1](./docs/runtest.png)\n\n\n\n## History:\n\ncodebase\nhttps://github.com/matthewelse/micropython\n\nMicropython webassembly target\nhttps://github.com/micropython/micropython/issues/3313\n\nSupport for Emscripten\nhttps://github.com/micropython/micropython/pull/2618\n\nRFC: emscripten: Got something to compile and link.\nhttps://github.com/micropython/micropython/pull/1561\n\nJavascript Port - MicroPython transmuted into Javascript by Emscripten.\nhttps://github.com/micropython/micropython/pull/3575\n\nEmscripten\n\nhttps://github.com/micropython/micropython/issues/888\n\n\nMicroPython and emscripten\n\nhttps://www.bountysource.com/issues/5037165-emscripten\n\nhttps://github.com/micropython/micropython/issues/3474\n\nhttps://github.com/kkimdev/epsilon\n\n\n\n## Experimental Features (current or future):\n\nExplicit exceptions :\nhttps://github.com/dpgeorge/micropython/tree/py-remove-nlr\n\n\nUsing requestIdleCallback :\nhttps://developers.google.com/web/updates/2015/08/using-requestidlecallback\n\n\nmulti core interpreters :\nhttps://github.com/ericsnowcurrently/multi-core-python/wiki\n\n\nMultiplexed rpc :\nhttps://brionv.com/log/2019/05/10/wasm-rpc-thoughts/\n\n\nA C api for pythons ?\nhttps://github.com/pyhandle/hpy\n\n\nnative code compiler ?\nhttps://github.com/windelbouwman/ppci-mirror\n\nintegrated gui\nhttps://github.com/littlevgl/lv_binding_micropython\n\n\nvarious shared/distributed memory objects related subjects.\nhttps://github.com/apache/arrow\nhttps://capnproto.org/\nhttp://doc.pypy.org/en/latest/stm.html#python-3-cpython-and-others\n\nmesh network\nhttps://github.com/chr15m/bugout\nhttps://chr15m.github.io/bep44-for-decentralized-applications.html\n\n\n\n\n## goal ( far far away ):\n\n\nThis is a research project aimed toward a cooperative multitasking multicore/multinode python solution.\nThough still keeping some level of preemption over coroutines at byte code level for soft-rt purpose.\n\n\ntesting on browser+wasm makes it easier than baremetal.\n\n\n\n\nmeet me on  #microPython or #micropython-fr on freenode\n\nhttps://kiwi.freenode.net/?nick=upy-wasm-guest\u0026channel=#micropython-fr\n\n\n\n#\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmp-p%2Fmicropython-ports-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmp-p%2Fmicropython-ports-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmp-p%2Fmicropython-ports-wasm/lists"}