Day 22 — WASM + Python = ❤️

Today I attended the "Intro to WebAssembly" session by Ezzeri. He talked about some useful performance benchmarks that he's been working on.

I went on to play with wasmer-python which is a WebAssembly runtime for Python! It lets you execute WASM binaries with an API similar to how you'd execute them in Javascript. In the coming days, I'll try to compile Rust crates (or C libs) to WASM and try to execute them using wasmer-python.

I couldn't install the wasmer_compiler_cranelift package (like shown in the README) as it is no longer available on PyPI. I guess they've updated the API so that a compiler is no longer explicitly required. I'll investigate more and try to work on a PR to update the README.

Since I couldn't get wasmer-python to work with the usual install instructions, I followed the steps in the development section and learned about some cool new things!

wasmer-python uses a justfile (similar to a Makefile) to help you get set up for development. The just syntax is inspired from make, but it looks much simpler! A just prelude set up everything I needed to build wasmer-python, though it didn't pick up the Python virtual environment I had created using virtualfish, and created a new one in a .env directory which I had to activate using source .env/bin/activate.fish.

I also found the WASM extension for VS Code which shows you the WAT for any WASM binary that you open.

wasmer-python already has pre-compiled WASM binaries for all examples. So I was puzzled when I compiled the simple.rs example using rustc and it generated a binary that was way bigger than the one they already had! To give you an idea of the bigness, this newly generated binary had 6000 WAT lines compared to just 15 WAT lines in the binary that was already present! WAT just happened?!

I looked at the docs to see if they had any steps on compiling the examples, but finally found them in the justfile! They use wasm-gc and wasm-opt to optimize the WASM binary generated by rustc. After that I also found the mention of these tools in this cool Rust and WebAssembly book. I love these docs that the Rust community has going on!


Today I also added a .pypirc to my $HOME directory so I don't have to enter my username and password every time I make a release. I generated a token scoped to just one project, but I guess I could have a token with the "all projects" scope since I'd be using it on my local machine. What are the best practices?


  [distutils]
  index-servers =
      pypi-present

  [pypi-present]
  repository = https://upload.pypi.org/legacy/
  username = __token__
  password = <api_token>