55import functools
66import os
77
8+ import tomllib
9+
810try :
911 from os import process_cpu_count as cpu_count
1012except ImportError :
1820
1921HERE = pathlib .Path (__file__ ).parent
2022
23+ # Path is: cpython/Tools/wasm/wasi
2124CHECKOUT = HERE .parent .parent .parent
2225assert (CHECKOUT / "configure" ).is_file (), (
2326 "Please update the location of the file"
@@ -213,9 +216,10 @@ def make_build_python(context, working_dir):
213216 log ("🎉" , f"{ binary } { version } " )
214217
215218
216- def find_wasi_sdk ():
219+ def find_wasi_sdk (config ):
217220 """Find the path to the WASI SDK."""
218221 wasi_sdk_path = None
222+ wasi_sdk_version = config ["targets" ]["wasi-sdk" ]
219223
220224 if wasi_sdk_path_env_var := os .environ .get ("WASI_SDK_PATH" ):
221225 wasi_sdk_path = pathlib .Path (wasi_sdk_path_env_var )
@@ -229,7 +233,7 @@ def find_wasi_sdk():
229233 # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
230234 potential_sdks = [
231235 path
232- for path in opt_path .glob (f"wasi-sdk-{ WASI_SDK_VERSION } .0*" )
236+ for path in opt_path .glob (f"wasi-sdk-{ wasi_sdk_version } .0*" )
233237 if path .is_dir ()
234238 ]
235239 if len (potential_sdks ) == 1 :
@@ -245,12 +249,12 @@ def find_wasi_sdk():
245249 found_version = version_details .splitlines ()[0 ]
246250 # Make sure there's a trailing dot to avoid false positives if somehow the
247251 # supported version is a prefix of the found version (e.g. `25` and `2567`).
248- if not found_version .startswith (f"{ WASI_SDK_VERSION } ." ):
252+ if not found_version .startswith (f"{ wasi_sdk_version } ." ):
249253 major_version = found_version .partition ("." )[0 ]
250254 log (
251255 "⚠️" ,
252256 f" Found WASI SDK { major_version } , "
253- f"but WASI SDK { WASI_SDK_VERSION } is the supported version" ,
257+ f"but WASI SDK { wasi_sdk_version } is the supported version" ,
254258 )
255259
256260 return wasi_sdk_path
@@ -408,8 +412,10 @@ def builder(context):
408412
409413
410414def main ():
411- default_host_triple = "wasm32-wasip1"
412- default_wasi_sdk = find_wasi_sdk ()
415+ with (HERE / "config.toml" ).open ("rb" ) as file :
416+ config = tomllib .load (file )
417+ default_wasi_sdk = find_wasi_sdk (config )
418+ default_host_triple = config ["targets" ]["host-triple" ]
413419 default_host_runner = (
414420 f"{ WASMTIME_HOST_RUNNER_VAR } run "
415421 # For setting PYTHONPATH to the sysconfig data directory.
0 commit comments