Skip to content

Commit 5f305c7

Browse files
committed
Simplify setting CLI options for WASI builds
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 3149d64 commit 5f305c7

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Tools/wasm/wasi/__main__.py

Lines changed: 16 additions & 15 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
)
@@ -305,7 +307,7 @@ def configure_wasi_python(context, working_dir):
305307
)
306308

307309
config_site = os.fsdecode(
308-
CHECKOUT / "Tools" / "wasm" / "wasi" / "config.site-wasm32-wasi"
310+
HERE / "config.site-wasm32-wasi"
309311
)
310312

311313
wasi_build_dir = working_dir.relative_to(CHECKOUT)
@@ -324,10 +326,7 @@ def configure_wasi_python(context, working_dir):
324326
# Use PYTHONPATH to include sysconfig data which must be anchored to the
325327
# WASI guest's `/` directory.
326328
args = {
327-
"GUEST_DIR": "/",
328-
"HOST_DIR": CHECKOUT,
329-
"ENV_VAR_NAME": "PYTHONPATH",
330-
"ENV_VAR_VALUE": f"/{sysconfig_data_dir}",
329+
"PYTHONPATH": f"/{sysconfig_data_dir}",
331330
"PYTHON_WASM": working_dir / "python.wasm",
332331
}
333332
# Check dynamically for wasmtime in case it was specified manually via
@@ -417,16 +416,18 @@ def main():
417416
default_wasi_sdk = find_wasi_sdk()
418417
default_host_runner = (
419418
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 "
419+
# For setting PYTHONPATH to the sysconfig data directory.
420+
"--env PYTHONPATH={PYTHONPATH} "
426421
# 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}"
422+
f"--dir {os.fsdecode(CHECKOUT)}::/ "
423+
# Flags involving --optimize, --codegen, --debug, --wasm, and --wasi can be kept
424+
# in a config file.
425+
# We are using such a file to act as defaults in case a user wants to override
426+
# only some of the settings themselves, make it easy to modify settings
427+
# post-build so that they immediately apply to the Makefile instead of having to
428+
# regenerate it, and allow for easy copying of the settings for anyone else who
429+
# may want to use them.
430+
f"--config {os.fsdecode(HERE / 'wasmtime.toml')}"
430431
)
431432
default_logdir = pathlib.Path(tempfile.gettempdir())
432433

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)