8000 gh-95853: Add script to automate WASM build (GH-95828) by tiran · Pull Request #95828 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

gh-95853: Add script to automate WASM build (GH-95828) #95828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add script to automate WASM build
Automate WASM build with a new Python script. The script provides
several build profiles with configure flags for Emscripten flavors
and WASI. The script can detect and use Emscripten SDK and WASI SDK from
default locations or env vars.

``configure`` now detects Node arguments and creates HOSTRUNNER
arguments for Node 16. It also sets correct arguments for
``wasm64-emscripten``.
  • Loading branch information
tiran committed Aug 11, 2022
commit 13c3be595e907b816b21b735c32a20bebb3ebd03
10 changes: 7 additions & 3 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2789,14 +2789,18 @@ EM_JS(char *, _Py_emscripten_runtime, (void), {
if (typeof navigator == 'object') {
info = navigator.userAgent;
} else if (typeof process == 'object') {
info = "Node.js ".concat(process.version)
info = "Node.js ".concat(process.version);
} else {
info = "UNKNOWN"
info = "UNKNOWN";
}
var len = lengthBytesUTF8(info) + 1;
var res = _malloc(len);
stringToUTF8(info, res, len);
if (res) stringToUTF8(info, res, len);
#if __wasm64__
return BigInt(res);
#else
return res;
#endif
});

static PyObject *
Expand Down
33 changes: 26 additions & 7 deletions Tools/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ docker run --rm -ti -v $(pwd):/python-wasm/cpython -w /python-wasm/cpython quay.

### Compile a build Python interpreter

From within the container, run the following commands:
From within the container, run the following command:

```shell
./Tools/wasm/wasm_build.py build
```

The command is roughly equivalent to:

```shell
mkdir -p builddir/build
Expand All @@ -45,13 +51,13 @@ make -j$(nproc)
popd
```

### Fetch and build additional emscripten ports
### Cross compile to wasm32-emscripten for browser

```shell
embuilder build zlib bzip2
./Tools/wasm/wasm_build.py emscripten-browser
```

### Cross compile to wasm32-emscripten for browser
The command is roughly equivalent to:

```shell
mkdir -p builddir/emscripten-browser
Expand Down Expand Up @@ -85,22 +91,29 @@ and header files with debug builds.
### Cross compile to wasm32-emscripten for node

```shell
mkdir -p builddir/emscripten-node
pushd builddir/emscripten-node
./Tools/wasm/wasm_build.py emscripten-browser-dl
```

The command is roughly equivalent to:

```shell
mkdir -p builddir/emscripten-node-dl
pushd builddir/emscripten-node-dl

CONFIG_SITE=../../Tools/wasm/config.site-wasm32-emscripten \
emconfigure ../../configure -C \
--host=wasm32-unknown-emscripten \
--build=$(../../config.guess) \
--with-emscripten-target=node \
--enable-wasm-dynamic-linking \
--with-build-python=$(pwd)/../build/python

emmake make -j$(nproc)
popd
```

```shell
node --experimental-wasm-threads --experimental-wasm-bulk-memory --experimental-wasm-bigint builddir/emscripten-node/python.js
node --experimental-wasm-threads --experimental-wasm-bulk-memory --experimental-wasm-bigint builddir/emscripten-node-dl/python.js
```

(``--experimental-wasm-bigint`` is not needed with recent NodeJS versions)
Expand Down Expand Up @@ -234,6 +247,12 @@ The script ``wasi-env`` sets necessary compiler and linker flags as well as
``pkg-config`` overrides. The script assumes that WASI-SDK is installed in
``/opt/wasi-sdk`` or ``$WASI_SDK_PATH``.

```shell
./Tools/wasm/wasm_build.py wasi
```

The command is roughly equivalent to:

```shell
mkdir -p builddir/wasi
pushd builddir/wasi
Expand Down
Loading
0