1111import re
1212import subprocess
1313import sys
14+ import sysconfig
1415from enum import Enum
1516from pathlib import Path
1617from typing import Any , Union
3536# We assume this script works with any pip version above this.
3637PIP_MIN_VERSION = "23.1"
3738
39+ # we will assume dev.py wasm builds are made for pygbag.
40+ host_gnu_type = sysconfig .get_config_var ("HOST_GNU_TYPE" )
41+ if isinstance (host_gnu_type , str ) and "wasm" in host_gnu_type :
42+ wasm = "wasi" if "wasi" in host_gnu_type else "emscripten"
43+ else :
44+ wasm = ""
45+
46+ wasm_cross_file = (source_tree / "buildconfig" / f"meson-cross-{ wasm } .ini" ).resolve ()
47+ wasm_args = [
48+ f"-Csetup-args=--cross-file={ wasm_cross_file } " ,
49+ "-Csetup-args=-Demscripten_type=pygbag" ,
50+ ]
51+
3852
3953class Colors (Enum ):
4054 RESET = "\033 [0m"
@@ -189,7 +203,11 @@ def check_module_in_constraint(mod: str, constraint: str):
189203
190204class Dev :
191205 def __init__ (self ) -> None :
192- self .py : Path = Path (sys .executable )
206+ self .py : Path = (
207+ Path (os .environ ["SDKROOT" ]) / "python3-wasm"
208+ if wasm
209+ else Path (sys .executable )
210+ )
193211 self .args : dict [str , Any ] = {}
194212
195213 self .deps : dict [str , set [str ]] = {
@@ -233,6 +251,14 @@ def cmd_build(self):
233251 ]
234252
235253 if not wheel_dir :
254+ if wasm :
255+ pprint (
256+ "Editable builds are not supported on WASM as of now. "
257+ "Pass --wheel to do a regular build" ,
258+ Colors .RED ,
259+ )
260+ sys .exit (1 )
261+
236262 # editable install
237263 if not quiet :
238264 install_args .append ("-Ceditable-verbose=true" )
@@ -259,6 +285,9 @@ def cmd_build(self):
259285 if sanitize :
260286 install_args .append (f"-Csetup-args=-Db_sanitize={ sanitize } " )
261287
288+ if wasm :
289+ install_args .extend (wasm_args )
290+
262291 info_str = (
263292 f"with { debug = } , { lax = } , { sdl3 = } , { stripped = } , { coverage = } and { sanitize = } "
264293 )
@@ -484,6 +513,12 @@ def prep_env(self):
484513 # set PATH to give high priority to executables in the python bin folder
485514 # this is where the binaries for meson/ninja/cython/sphinx/etc are installed
486515 os .environ ["PATH" ] = f"{ self .py .parent } { os .pathsep } { os .environ .get ('PATH' , '' )} "
516+ if wasm :
517+ for wasm_path in [
518+ self .py .parent / "emsdk" / "upstream" / "emscripten" ,
519+ self .py .parent / "devices" / "emsdk" / "usr" / "bin" ,
520+ ]:
521+ os .environ ["PATH" ] = f"{ wasm_path } { os .pathsep } { os .environ ['PATH' ]} "
487522
488523 pprint ("Checking pip version" )
489524 pip_v = cmd_run ([self .py , "-m" , "pip" , "-V" ], capture_output = True )
@@ -497,6 +532,10 @@ def prep_env(self):
497532 pprint ("pip version is too old or unknown, attempting pip upgrade" )
498533 pip_install (self .py , ["-U" , "pip" ])
499534
535+ if wasm :
536+ # dont try to install any deps on WASM
537+ return
538+
500539 deps = self .deps .get (self .args ["command" ], set ())
501540 ignored_deps = self .args ["ignore_dep" ]
502541 deps_filtered = deps .copy ()
0 commit comments