Skip to content

Commit d49e6f3

Browse files
authored
Extract data from Tools/wasm/wasi that varies between Python versions into a config file (GH-142273)
This should allow for easier backporting of code.
1 parent 58e1c7a commit d49e6f3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Tools/wasm/wasi/__main__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import functools
66
import os
77

8+
import tomllib
9+
810
try:
911
from os import process_cpu_count as cpu_count
1012
except ImportError:
@@ -18,6 +20,7 @@
1820

1921
HERE = pathlib.Path(__file__).parent
2022

23+
# Path is: cpython/Tools/wasm/wasi
2124
CHECKOUT = HERE.parent.parent.parent
2225
assert (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

410414
def 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.

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)