|
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 |
|
@@ -173,10 +175,22 @@ def make_build_python(context, working_dir):
|
173 | 175 |
|
174 | 176 |
|
175 | 177 | def find_wasi_sdk():
|
176 |
| - """Find the path to wasi-sdk.""" |
| 178 | + """Find the path to the WASI SDK.""" |
177 | 179 | if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"):
|
178 | 180 | return pathlib.Path(wasi_sdk_path)
|
179 |
| - elif (default_path := pathlib.Path("/opt/wasi-sdk")).exists(): |
| 181 | + |
| 182 | + opt_path = pathlib.Path("/opt") |
| 183 | + # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team |
| 184 | + # has said they don't plan to ever do a point release and all of their Git tags |
| 185 | + # lack the ``.0`` suffix. |
| 186 | + # Starting with WASI SDK 23, the tarballs went from containing a directory named |
| 187 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g. |
| 188 | + # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``. |
| 189 | + potential_sdks = [path for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*") |
| 190 | + if path.is_dir()] |
| 191 | + if len(potential_sdks) == 1: |
| 192 | + return potential_sdks[0] |
| 193 | + elif (default_path := opt_path / "wasi-sdk").is_dir(): |
180 | 194 | return default_path
|
181 | 195 |
|
182 | 196 |
|
@@ -306,6 +320,8 @@ def clean_contents(context):
|
306 | 320 |
|
307 | 321 |
|
308 | 322 | def main():
|
| 323 | + default_host_triple = "wasm32-wasip1" |
| 324 | + default_wasi_sdk = find_wasi_sdk() |
309 | 325 | default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
|
310 | 326 | # Make sure the stack size will work for a pydebug
|
311 | 327 | # build.
|
@@ -349,17 +365,17 @@ def main():
|
349 | 365 | for subcommand in build, configure_host:
|
350 | 366 | subcommand.add_argument("--wasi-sdk", type=pathlib.Path,
|
351 | 367 | dest="wasi_sdk_path",
|
352 |
| - default=find_wasi_sdk(), |
353 |
| - help="Path to wasi-sdk; defaults to " |
354 |
| - "$WASI_SDK_PATH or /opt/wasi-sdk") |
| 368 | + default=default_wasi_sdk, |
| 369 | + help=f"Path to the WASI SDK; defaults to {default_wasi_sdk}") |
355 | 370 | subcommand.add_argument("--host-runner", action="store",
|
356 | 371 | default=default_host_runner, dest="host_runner",
|
357 |
| - help="Command template for running the WASI host " |
358 |
| - "(default designed for wasmtime 14 or newer: " |
359 |
| - f"`{default_host_runner}`)") |
| 372 | + help="Command template for running the WASI host; defaults to " |
| 373 | + f"`{default_host_runner}`") |
360 | 374 | for subcommand in build, configure_host, make_host:
|
361 |
| - subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1", |
362 |
| - help="The target triple for the WASI host build") |
| 375 | + subcommand.add_argument("--host-triple", action="store", |
| 376 | + default=default_host_triple, |
| 377 | + help="The target triple for the WASI host build; " |
| 378 | + f"defaults to {default_host_triple}") |
363 | 379 |
|
364 | 380 | context = parser.parse_args()
|
365 | 381 | context.init_dir = pathlib.Path().absolute()
|
|
0 commit comments