11
11
import re
12
12
import subprocess
13
13
import sys
14
+ import sysconfig
14
15
from enum import Enum
15
16
from pathlib import Path
16
17
from typing import Any , Union
35
36
# We assume this script works with any pip version above this.
36
37
PIP_MIN_VERSION = "23.1"
37
38
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
+
38
52
39
53
class Colors (Enum ):
40
54
RESET = "\033 [0m"
@@ -189,7 +203,11 @@ def check_module_in_constraint(mod: str, constraint: str):
189
203
190
204
class Dev :
191
205
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
+ )
193
211
self .args : dict [str , Any ] = {}
194
212
195
213
self .deps : dict [str , set [str ]] = {
@@ -233,6 +251,14 @@ def cmd_build(self):
233
251
]
234
252
235
253
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
+
236
262
# editable install
237
263
if not quiet :
238
264
install_args .append ("-Ceditable-verbose=true" )
@@ -259,6 +285,9 @@ def cmd_build(self):
259
285
if sanitize :
260
286
install_args .append (f"-Csetup-args=-Db_sanitize={ sanitize } " )
261
287
288
+ if wasm :
289
+ install_args .extend (wasm_args )
290
+
262
291
info_str = (
263
292
f"with { debug = } , { lax = } , { sdl3 = } , { stripped = } , { coverage = } and { sanitize = } "
264
293
)
@@ -484,6 +513,12 @@ def prep_env(self):
484
513
# set PATH to give high priority to executables in the python bin folder
485
514
# this is where the binaries for meson/ninja/cython/sphinx/etc are installed
486
515
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' ]} "
487
522
488
523
pprint ("Checking pip version" )
489
524
pip_v = cmd_run ([self .py , "-m" , "pip" , "-V" ], capture_output = True )
@@ -497,6 +532,10 @@ def prep_env(self):
497
532
pprint ("pip version is too old or unknown, attempting pip upgrade" )
498
533
pip_install (self .py , ["-U" , "pip" ])
499
534
535
+ if wasm :
536
+ # dont try to install any deps on WASM
537
+ return
538
+
500
539
deps = self .deps .get (self .args ["command" ], set ())
501
540
ignored_deps = self .args ["ignore_dep" ]
502
541
deps_filtered = deps .copy ()
0 commit comments