|
25 | 25 | LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" |
26 | 26 | LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8") |
27 | 27 |
|
| 28 | +WASI_SDK_VERSION = 24 |
| 29 | + |
28 | 30 | WASMTIME_VAR_NAME = "WASMTIME" |
29 | 31 | WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}" |
30 | 32 |
|
@@ -169,10 +171,22 @@ def make_build_python(context, working_dir): |
169 | 171 |
|
170 | 172 |
|
171 | 173 | def find_wasi_sdk(): |
172 | | - """Find the path to wasi-sdk.""" |
| 174 | + """Find the path to the WASI SDK.""" |
173 | 175 | if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"): |
174 | 176 | return pathlib.Path(wasi_sdk_path) |
175 | | - elif (default_path := pathlib.Path("/opt/wasi-sdk")).exists(): |
| 177 | + |
| 178 | + opt_path = pathlib.Path("/opt") |
| 179 | + # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team |
| 180 | + # has said they don't plan to ever do a point release and all of their Git tags |
| 181 | + # lack the ``.0`` suffix. |
| 182 | + # Starting with WASI SDK 23, the tarballs went from containing a directory named |
| 183 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g. |
| 184 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``. |
| 185 | + potential_sdks = [path for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*") |
| 186 | + if path.is_dir()] |
| 187 | + if len(potential_sdks) == 1: |
| 188 | + return potential_sdks[0] |
| 189 | + elif (default_path := opt_path / "wasi-sdk").is_dir(): |
176 | 190 | return default_path |
177 | 191 |
|
178 | 192 |
|
@@ -303,6 +317,8 @@ def clean_contents(context): |
303 | 317 |
|
304 | 318 |
|
305 | 319 | def main(): |
| 320 | + default_host_triple = "wasm32-wasip1" |
| 321 | + default_wasi_sdk = find_wasi_sdk() |
306 | 322 | default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run " |
307 | 323 | # Make sure the stack size will work for a pydebug |
308 | 324 | # build. |
@@ -346,17 +362,17 @@ def main(): |
346 | 362 | for subcommand in build, configure_host: |
347 | 363 | subcommand.add_argument("--wasi-sdk", type=pathlib.Path, |
348 | 364 | dest="wasi_sdk_path", |
349 | | - default=find_wasi_sdk(), |
350 | | - help="Path to wasi-sdk; defaults to " |
351 | | - "$WASI_SDK_PATH or /opt/wasi-sdk") |
| 365 | + default=default_wasi_sdk, |
| 366 | + help=f"Path to the WASI SDK; defaults to {default_wasi_sdk}") |
352 | 367 | subcommand.add_argument("--host-runner", action="store", |
353 | 368 | default=default_host_runner, dest="host_runner", |
354 | | - help="Command template for running the WASI host " |
355 | | - "(default designed for wasmtime 14 or newer: " |
356 | | - f"`{default_host_runner}`)") |
| 369 | + help="Command template for running the WASI host; defaults to " |
| 370 | + f"`{default_host_runner}`") |
357 | 371 | for subcommand in build, configure_host, make_host: |
358 | | - subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1", |
359 | | - help="The target triple for the WASI host build") |
| 372 | + subcommand.add_argument("--host-triple", action="store", |
| 373 | + default=default_host_triple, |
| 374 | + help="The target triple for the WASI host build; " |
| 375 | + f"defaults to {default_host_triple}") |
360 | 376 |
|
361 | 377 | context = parser.parse_args() |
362 | 378 | context.init_dir = pathlib.Path().absolute() |
|
0 commit comments