|
26 | 26 | LOCAL_SETUP_MARKER = ("# Generated by Tools/wasm/wasi .\n" |
27 | 27 | "# Required to statically build extension modules.").encode("utf-8") |
28 | 28 |
|
| 29 | +WASI_SDK_VERSION = 24 |
| 30 | + |
29 | 31 | WASMTIME_VAR_NAME = "WASMTIME" |
30 | 32 | WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}" |
31 | 33 |
|
@@ -180,10 +182,22 @@ def make_build_python(context, working_dir): |
180 | 182 |
|
181 | 183 |
|
182 | 184 | def find_wasi_sdk(): |
183 | | - """Find the path to wasi-sdk.""" |
| 185 | + """Find the path to the WASI SDK.""" |
184 | 186 | if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"): |
185 | 187 | return pathlib.Path(wasi_sdk_path) |
186 | | - elif (default_path := pathlib.Path("/opt/wasi-sdk")).exists(): |
| 188 | + |
| 189 | + opt_path = pathlib.Path("/opt") |
| 190 | + # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team |
| 191 | + # has said they don't plan to ever do a point release and all of their Git tags |
| 192 | + # lack the ``.0`` suffix. |
| 193 | + # Starting with WASI SDK 23, the tarballs went from containing a directory named |
| 194 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g. |
| 195 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``. |
| 196 | + potential_sdks = [path for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*") |
| 197 | + if path.is_dir()] |
| 198 | + if len(potential_sdks) == 1: |
| 199 | + return potential_sdks[0] |
| 200 | + elif (default_path := opt_path / "wasi-sdk").is_dir(): |
187 | 201 | return default_path |
188 | 202 |
|
189 | 203 |
|
@@ -313,6 +327,8 @@ def clean_contents(context): |
313 | 327 |
|
314 | 328 |
|
315 | 329 | def main(): |
| 330 | + default_host_triple = "wasm32-wasip1" |
| 331 | + default_wasi_sdk = find_wasi_sdk() |
316 | 332 | default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run " |
317 | 333 | # Make sure the stack size will work for a pydebug |
318 | 334 | # build. |
@@ -360,17 +376,17 @@ def main(): |
360 | 376 | for subcommand in build, configure_host: |
361 | 377 | subcommand.add_argument("--wasi-sdk", type=pathlib.Path, |
362 | 378 | dest="wasi_sdk_path", |
363 | | - default=find_wasi_sdk(), |
364 | | - help="Path to wasi-sdk; defaults to " |
365 | | - "$WASI_SDK_PATH or /opt/wasi-sdk") |
| 379 | + default=default_wasi_sdk, |
| 380 | + help=f"Path to the WASI SDK; defaults to {default_wasi_sdk}") |
366 | 381 | subcommand.add_argument("--host-runner", action="store", |
367 | 382 | default=default_host_runner, dest="host_runner", |
368 | | - help="Command template for running the WASI host " |
369 | | - "(default designed for wasmtime 14 or newer: " |
370 | | - f"`{default_host_runner}`)") |
| 383 | + help="Command template for running the WASI host; defaults to " |
| 384 | + f"`{default_host_runner}`") |
371 | 385 | for subcommand in build, configure_host, make_host: |
372 | | - subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1", |
373 | | - help="The target triple for the WASI host build") |
| 386 | + subcommand.add_argument("--host-triple", action="store", |
| 387 | + default=default_host_triple, |
| 388 | + help="The target triple for the WASI host build; " |
| 389 | + f"defaults to {default_host_triple}") |
374 | 390 |
|
375 | 391 | context = parser.parse_args() |
376 | 392 | context.init_dir = pathlib.Path().absolute() |
|
0 commit comments