LOCAL_SETUP_MARKER = ("# Generated by Tools/wasm/wasi .\n"
"# Required to statically build extension modules.").encode("utf-8")
+WASI_SDK_VERSION = 24
+
WASMTIME_VAR_NAME = "WASMTIME"
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
def find_wasi_sdk():
- """Find the path to wasi-sdk."""
+ """Find the path to the WASI SDK."""
if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"):
return pathlib.Path(wasi_sdk_path)
- elif (default_path := pathlib.Path("/opt/wasi-sdk")).exists():
+
+ opt_path = pathlib.Path("/opt")
+ # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team
+ # has said they don't plan to ever do a point release and all of their Git tags
+ # lack the ``.0`` suffix.
+ # Starting with WASI SDK 23, the tarballs went from containing a directory named
+ # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g.
+ # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
+ potential_sdks = [path for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*")
+ if path.is_dir()]
+ if len(potential_sdks) == 1:
+ return potential_sdks[0]
+ elif (default_path := opt_path / "wasi-sdk").is_dir():
return default_path
def main():
+ default_host_triple = "wasm32-wasip1"
+ default_wasi_sdk = find_wasi_sdk()
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
# Make sure the stack size will work for a pydebug
# build.
for subcommand in build, configure_host:
subcommand.add_argument("--wasi-sdk", type=pathlib.Path,
dest="wasi_sdk_path",
- default=find_wasi_sdk(),
- help="Path to wasi-sdk; defaults to "
- "$WASI_SDK_PATH or /opt/wasi-sdk")
+ default=default_wasi_sdk,
+ help=f"Path to the WASI SDK; defaults to {default_wasi_sdk}")
subcommand.add_argument("--host-runner", action="store",
default=default_host_runner, dest="host_runner",
- help="Command template for running the WASI host "
- "(default designed for wasmtime 14 or newer: "
- f"`{default_host_runner}`)")
+ help="Command template for running the WASI host; defaults to "
+ f"`{default_host_runner}`")
for subcommand in build, configure_host, make_host:
- subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1",
- help="The target triple for the WASI host build")
+ subcommand.add_argument("--host-triple", action="store",
+ default=default_host_triple,
+ help="The target triple for the WASI host build; "
+ f"defaults to {default_host_triple}")
context = parser.parse_args()
context.init_dir = pathlib.Path().absolute()