MCPcopy Index your code
hub / github.com/python/cpython / configure_wasi_python

Function configure_wasi_python

Platforms/WASI/_build.py:334–384  ·  view source on GitHub ↗

Configure the WASI/host build.

(context, working_dir)

Source from the content-addressed store, hash-verified

332
333@subdir(lambda context: CROSS_BUILD_DIR / host_triple(context), clean_ok=True)
334def configure_wasi_python(context, working_dir):
335 """Configure the WASI/host build."""
336 config_site = os.fsdecode(HERE / "config.site-wasm32-wasi")
337
338 wasi_build_dir = working_dir.relative_to(CHECKOUT)
339
340 args = {
341 "WASMTIME": "wasmtime",
342 "ARGV0": f"/{wasi_build_dir}/python.wasm",
343 "CHECKOUT": os.fsdecode(CHECKOUT),
344 "WASMTIME_CONFIG_PATH": os.fsdecode(HERE / "wasmtime.toml"),
345 }
346 # Check dynamically for wasmtime in case it was specified manually via
347 # `--host-runner`.
348 if "{WASMTIME}" in context.host_runner:
349 if wasmtime := shutil.which("wasmtime"):
350 args["WASMTIME"] = wasmtime
351 else:
352 raise FileNotFoundError(
353 "wasmtime not found; download from "
354 "https://github.com/bytecodealliance/wasmtime"
355 )
356 host_runner = context.host_runner.format_map(args)
357 env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
358 build_python = os.fsdecode(build_python_path())
359 # The path to `configure` MUST be relative, else `python.wasm` is unable
360 # to find the stdlib due to Python not recognizing that it's being
361 # executed from within a checkout.
362 configure = [
363 os.path.relpath(CHECKOUT / "configure", working_dir),
364 f"--host={host_triple(context)}",
365 f"--build={BUILD_DIR.name}",
366 f"--with-build-python={build_python}",
367 ]
368 if build_python_is_pydebug():
369 configure.append("--with-pydebug")
370 if context.args:
371 configure.extend(context.args)
372 call(
373 configure,
374 env=updated_env(env_additions | wasi_sdk_env(context)),
375 context=context,
376 )
377
378 python_wasm = working_dir / "python.wasm"
379 exec_script = working_dir / "python.sh"
380 with exec_script.open("w", encoding="utf-8") as file:
381 file.write(f'#!/bin/sh\nexec {host_runner} {python_wasm} "$@"\n')
382 exec_script.chmod(0o755)
383 log("🏃", f"Created {exec_script} (--host-runner)... ")
384 sys.stdout.flush()
385
386
387@subdir(lambda context: CROSS_BUILD_DIR / host_triple(context))

Callers

nothing calls this directly

Calls 15

host_tripleFunction · 0.85
build_python_is_pydebugFunction · 0.85
wasi_sdk_envFunction · 0.85
format_mapMethod · 0.80
build_python_pathFunction · 0.70
callFunction · 0.70
updated_envFunction · 0.70
logFunction · 0.70
relative_toMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…