Skip to content

Commit ab797fc

Browse files
committed
Extract data from Tools/wasm/wasi that varies between Python versions into a config file
This should allow for easier backporting of code.
1 parent b3bf212 commit ab797fc

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

Tools/wasm/wasi/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import contextlib
55
import functools
66
import os
7+
import tomllib
78

89
try:
910
from os import process_cpu_count as cpu_count
@@ -18,6 +19,7 @@
1819

1920
HERE = pathlib.Path(__file__).parent
2021

22+
# Path is: wasi wasm Tools cpython
2123
CHECKOUT = HERE.parent.parent.parent
2224
assert (CHECKOUT / "configure").is_file(), (
2325
"Please update the location of the file"
@@ -213,9 +215,10 @@ def make_build_python(context, working_dir):
213215
log("🎉", f"{binary} {version}")
214216

215217

216-
def find_wasi_sdk():
218+
def find_wasi_sdk(config):
217219
"""Find the path to the WASI SDK."""
218220
wasi_sdk_path = None
221+
wasi_sdk_version = config["targets"]["wasi-sdk"]
219222

220223
if wasi_sdk_path_env_var := os.environ.get("WASI_SDK_PATH"):
221224
wasi_sdk_path = pathlib.Path(wasi_sdk_path_env_var)
@@ -229,7 +232,7 @@ def find_wasi_sdk():
229232
# ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
230233
potential_sdks = [
231234
path
232-
for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*")
235+
for path in opt_path.glob(f"wasi-sdk-{wasi_sdk_version}.0*")
233236
if path.is_dir()
234237
]
235238
if len(potential_sdks) == 1:
@@ -245,12 +248,12 @@ def find_wasi_sdk():
245248
found_version = version_details.splitlines()[0]
246249
# Make sure there's a trailing dot to avoid false positives if somehow the
247250
# supported version is a prefix of the found version (e.g. `25` and `2567`).
248-
if not found_version.startswith(f"{WASI_SDK_VERSION}."):
251+
if not found_version.startswith(f"{wasi_sdk_version}."):
249252
major_version = found_version.partition(".")[0]
250253
log(
251254
"⚠️",
252255
f" Found WASI SDK {major_version}, "
253-
f"but WASI SDK {WASI_SDK_VERSION} is the supported version",
256+
f"but WASI SDK {wasi_sdk_version} is the supported version",
254257
)
255258

256259
return wasi_sdk_path
@@ -410,8 +413,10 @@ def clean_contents(context):
410413

411414

412415
def main():
413-
default_host_triple = "wasm32-wasip1"
414-
default_wasi_sdk = find_wasi_sdk()
416+
with (HERE / "config.toml").open("rb") as file:
417+
config = tomllib.load(file)
418+
default_wasi_sdk = find_wasi_sdk(config)
419+
default_host_triple = config["targets"]["host-triple"]
415420
default_host_runner = (
416421
f"{WASMTIME_HOST_RUNNER_VAR} run "
417422
# For setting PYTHONPATH to the sysconfig data directory.

Tools/wasm/wasi/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Any data that can vary between Python versions is to be kept in this file.
2+
# This allows for blanket copying of the WASI build code between supported
3+
# Python versions.
4+
[targets]
5+
wasi-sdk = 29
6+
host-triple = "wasm32-wasip1"

0 commit comments

Comments
 (0)