Skip to content

Commit ca1e86f

Browse files
authored
Simplify setting CLI options for WASI builds (GH-141769)
This introduces a Wasmtime configuration file to get some CLI options out of the code for easier manipulation. It also allows for easier tweaking after the Makefile is generated. As well, cut back on the flexibility of specifying HOSTRUNNER for simpler code. The flexibility was never used and so it didn't make sense to keep it around.
1 parent b4344f7 commit ca1e86f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Tools/wasm/wasi/__main__.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import sysconfig
1717
import tempfile
1818

19-
CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent
19+
HERE = pathlib.Path(__file__).parent
20+
21+
CHECKOUT = HERE.parent.parent.parent
2022
assert (CHECKOUT / "configure").is_file(), (
2123
"Please update the location of the file"
2224
)
@@ -304,9 +306,7 @@ def configure_wasi_python(context, working_dir):
304306
"specify via $WASI_SDK_PATH or --wasi-sdk"
305307
)
306308

307-
config_site = os.fsdecode(
308-
CHECKOUT / "Tools" / "wasm" / "wasi" / "config.site-wasm32-wasi"
309-
)
309+
config_site = os.fsdecode(HERE / "config.site-wasm32-wasi")
310310

311311
wasi_build_dir = working_dir.relative_to(CHECKOUT)
312312

@@ -324,10 +324,7 @@ def configure_wasi_python(context, working_dir):
324324
# Use PYTHONPATH to include sysconfig data which must be anchored to the
325325
# WASI guest's `/` directory.
326326
args = {
327-
"GUEST_DIR": "/",
328-
"HOST_DIR": CHECKOUT,
329-
"ENV_VAR_NAME": "PYTHONPATH",
330-
"ENV_VAR_VALUE": f"/{sysconfig_data_dir}",
327+
"PYTHONPATH": f"/{sysconfig_data_dir}",
331328
"PYTHON_WASM": working_dir / "python.wasm",
332329
}
333330
# Check dynamically for wasmtime in case it was specified manually via
@@ -417,16 +414,18 @@ def main():
417414
default_wasi_sdk = find_wasi_sdk()
418415
default_host_runner = (
419416
f"{WASMTIME_HOST_RUNNER_VAR} run "
420-
# Make sure the stack size will work for a pydebug
421-
# build.
422-
# Use 32 MiB stack.
423-
"--wasm max-wasm-stack=33554432 "
424-
# Enable thread support; causes use of preview1.
425-
# "--wasm threads=y --wasi threads=y "
417+
# For setting PYTHONPATH to the sysconfig data directory.
418+
"--env PYTHONPATH={PYTHONPATH} "
426419
# Map the checkout to / to load the stdlib from /Lib.
427-
"--dir {HOST_DIR}::{GUEST_DIR} "
428-
# Set PYTHONPATH to the sysconfig data.
429-
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}"
420+
f"--dir {os.fsdecode(CHECKOUT)}::/ "
421+
# Flags involving --optimize, --codegen, --debug, --wasm, and --wasi can be kept
422+
# in a config file.
423+
# We are using such a file to act as defaults in case a user wants to override
424+
# only some of the settings themselves, make it easy to modify settings
425+
# post-build so that they immediately apply to the Makefile instead of having to
426+
# regenerate it, and allow for easy copying of the settings for anyone else who
427+
# may want to use them.
428+
f"--config {os.fsdecode(HERE / 'wasmtime.toml')}"
430429
)
431430
default_logdir = pathlib.Path(tempfile.gettempdir())
432431

Tools/wasm/wasi/wasmtime.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://docs.wasmtime.dev/cli-options.html#cli-options-using-toml-file
2+
3+
[wasm]
4+
# 32 MiB; big enough for the test suite to pass under a debug build.
5+
max-wasm-stack = 33_554_432

0 commit comments

Comments
 (0)