Metadata-Version: 2.5
Name: smol-emscripten
Version: 0.0.1
Summary: Smol Emscripten for building Python extensions Pyodide imports
Project-URL: Homepage, https://github.com/justindujardin/smol_emscripten
Author-email: Justin DuJardin <justin@dujardinconsulting.com>
License-Expression: Apache-2.0 AND Apache-2.0 WITH LLVM-exception AND NCSA AND (MIT OR NCSA) AND MIT AND MPL-2.0 AND PSF-2.0 AND BSD-2-Clause AND BSD-3-Clause AND ISC AND Spencer-94 AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND Zlib AND bzip2-1.0.6
License-File: LICENSE
License-File: licenses/binaryen.txt
License-File: licenses/bzip2.txt
License-File: licenses/clang.txt
License-File: licenses/compiler-rt.txt
License-File: licenses/cpython-incorporated.txt
License-File: licenses/cpython.txt
License-File: licenses/emscripten.txt
License-File: licenses/fp16.txt
License-File: licenses/hacl.txt
License-File: licenses/libcxx.txt
License-File: licenses/libcxxabi.txt
License-File: licenses/libffi.txt
License-File: licenses/libunwind.txt
License-File: licenses/lld.txt
License-File: licenses/llvm-third-party.txt
License-File: licenses/llvm.txt
License-File: licenses/mimalloc.txt
License-File: licenses/musl.txt
License-File: licenses/node.txt
License-File: licenses/pyodide.txt
License-File: licenses/stackframe.txt
License-File: licenses/zlib.txt
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Compilers
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# 🦔 smol-emscripten

`pip install smol-emscripten` and build Python extensions that Pyodide imports, with nothing else installed.

Each wheel holds one archive for its platform:

- Emscripten 4.0.9 as Pyodide 0.29.4 patches it: clang, wasm-ld, llvm-objcopy, wasm-opt and emcc, with the headers its cache installs, frozen in place
- CPython 3.13's headers for wasm32
- the Pyodide runtime: `pyodide.js`, `pyodide.asm.js`, `pyodide.asm.wasm`, `python_stdlib.zip` and `pyodide-lock.json`
- node 24.22.1, to run that runtime outside a browser

Unpack it anywhere, and `toolchain()` says where everything is and how to call it:

```python
import os, subprocess, tarfile
import smol_emscripten

with tarfile.open(smol_emscripten.get_archive_path()) as archive:
    archive.extractall(cache, filter="data")
tc = smol_emscripten.toolchain(cache / smol_emscripten.ROOT)
env = tc.environment(os.environ)

subprocess.run(tc.emcc_command(*tc.cflags, "-c", "fast.c", "-o", "fast.o"), env=env, check=True)
subprocess.run(
    tc.emcc_command("fast.o", "-o", "fast.cpython-313-wasm32-emscripten.so", *tc.ldflags,
                    "-sSIDE_MODULE=2", "-sEXPORTED_FUNCTIONS=_PyInit_fast"),
    env=env, check=True,
)
```

emcc runs on the Python you call it from. `cflags` and `ldflags` are the ones Pyodide builds its own side modules with, and `cflags` maps the toolchain's paths to `/smol-emscripten`, so what it compiles is the same bytes wherever it was unpacked, on every platform. `environment()` leaves out any Emscripten or node settings the caller has, so the archive is all a build sees. The cache is frozen: nothing writes to the toolchain, and builds can run side by side.

## Platforms

| Platform | Wheel tag |
|---|---|
| linux-x86_64 | `manylinux_2_28_x86_64` |
| linux-aarch64 | `manylinux_2_28_aarch64` |
| macos-arm64 | `macosx_13_0_arm64` |
| windows-x86_64 | `win_amd64` |

## What it covers

A side module's compile and link: what a build of a C or C++ extension (Cython's included) needs, and a runtime to import it in. It doesn't ship `em++`, `emar`, the libraries a main module links, or a Rust toolchain.

## Building it

```bash
uv sync
uv run python tools/build_archive.py              # this machine's platform, or --platform <name>
uv run python tools/verify.py                     # on the archive's own platform
uv run python tools/build_wheel.py
```

Every input is pinned by URL and sha256 in `tools/pins.py`: Emscripten's release build, node, Pyodide's cross-build environment, and on Linux libatomic and zlib from Debian 12, which wasm-opt and clang load and a system may not have. Building runs none of them, so any machine builds any platform's archive. `verify.py` proves one on its own platform: it compiles a C and a C++ extension in release and debug, imports them in Pyodide under the archive's node, and checks that nothing wrote into the toolchain and that none of its paths reached the output. CI does that on all four platforms and checks that each compiled the same bytes.

## Licenses

The packaging is Apache-2.0 (`LICENSE`). What the archive carries keeps its own license, each in `licenses/` (in the repository, the wheel and the archive):

| What | License | File |
|---|---|---|
| clang, its headers, wasm-ld, llvm-objcopy | Apache-2.0 WITH LLVM-exception, and LLVM's legacy NCSA terms | `llvm.txt`, `clang.txt`, `lld.txt` |
| What LLVM incorporates, in those binaries: its regex engine, xxHash, Unicode's tables, a Microsoft header on Windows | Spencer-94, BSD-3-Clause, ISC, BSD-2-Clause, Unicode-DFS-2015, Unicode-DFS-2016, MIT | `llvm-third-party.txt` |
| libc++, libc++abi, libunwind, compiler-rt: their headers, and compiled into `pyodide.asm.wasm` | Apache-2.0 WITH LLVM-exception, and the legacy NCSA and MIT terms | `libcxx.txt`, `libcxxabi.txt`, `libunwind.txt`, `compiler-rt.txt` |
| Emscripten | MIT or NCSA | `emscripten.txt` |
| musl, Emscripten's libc: its headers, and compiled into `pyodide.asm.wasm` | MIT | `musl.txt` |
| mimalloc: its headers, and compiled into wasm-opt on Linux | MIT | `mimalloc.txt` |
| wasm-opt (Binaryen), with its copy of LLVM's DWARF code | Apache-2.0, and LLVM's terms above | `binaryen.txt`, `llvm.txt`, `llvm-third-party.txt` |
| FP16, compiled into wasm-opt | MIT | `fp16.txt` |
| node | MIT, with the licenses of what it bundles | `node.txt` |
| The Pyodide runtime, and its patches to Emscripten | MPL-2.0 | `pyodide.txt` |
| stackframe and error-stack-parser, in `pyodide.js` | MIT | `stackframe.txt` |
| libffi, in `pyodide.asm.wasm` | MIT | `libffi.txt` |
| CPython: its headers, its standard library, and the interpreter in `pyodide.asm.wasm` | PSF-2.0 | `cpython.txt` |
| What CPython's interpreter incorporates (libmpdec, expat, mimalloc, dtoa, SipHash and more), as CPython's own license page lists it | each its own | `cpython-incorporated.txt` |
| HACL*, CPython's hashes | MIT | `hacl.txt` |
| bzip2, in `pyodide.asm.wasm` | bzip2-1.0.6 | `bzip2.txt` |
| zlib, in `pyodide.asm.wasm`, and on Linux as `lib/libz.so.1` | Zlib | `zlib.txt` |
| libatomic (Linux) | GPL-3.0-or-later WITH GCC-exception-3.1 | `gcc-runtime-exception.txt`, `gpl-3.0.txt` |

The rest of Emscripten's headers (Khronos, X11, GLFW and the like) carry their notices in the files themselves, SDL's in `SDL/COPYING`, and `emscripten/third_party/leb128/` has its own `LICENSE`.

The archive's `licenses/sources.txt` says where the source of its compiled code is, for the licenses that ask: the Pyodide release for the runtime and the patches (MPL-2.0), and on Linux the Debian source packages libatomic and zlib were built from (`gcc-12` 12.2.0-14+deb12u1 is libatomic's Corresponding Source under GPL-3.0). A web build that ships the runtime redistributes what's compiled into it, so it carries `toolchain().runtime_licenses` (the files `RUNTIME_LICENSES` names) and says where Pyodide's source is, `PYODIDE_SOURCE`.
