Skip to content

Commit 2f1a9f2

Browse files
authored
GH-137243: Have Tools/wasm/wasi detect WASI SDK installs in /opt when the release tarball is extracted (GH-137244)
1 parent e3ea861 commit 2f1a9f2

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Have Tools/wasm/wasi detect a WASI SDK install in /opt when it was directly
2+
extracted from a release tarball.

Tools/wasm/wasi/__main__.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
LOCAL_SETUP_MARKER = ("# Generated by Tools/wasm/wasi .\n"
2727
"# Required to statically build extension modules.").encode("utf-8")
2828

29+
WASI_SDK_VERSION = 24
30+
2931
WASMTIME_VAR_NAME = "WASMTIME"
3032
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
3133

@@ -173,10 +175,22 @@ def make_build_python(context, working_dir):
173175

174176

175177
def find_wasi_sdk():
176-
"""Find the path to wasi-sdk."""
178+
"""Find the path to the WASI SDK."""
177179
if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"):
178180
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():
180194
return default_path
181195

182196

@@ -306,6 +320,8 @@ def clean_contents(context):
306320

307321

308322
def main():
323+
default_host_triple = "wasm32-wasip1"
324+
default_wasi_sdk = find_wasi_sdk()
309325
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
310326
# Make sure the stack size will work for a pydebug
311327
# build.
@@ -349,17 +365,17 @@ def main():
349365
for subcommand in build, configure_host:
350366
subcommand.add_argument("--wasi-sdk", type=pathlib.Path,
351367
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}")
355370
subcommand.add_argument("--host-runner", action="store",
356371
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}`")
360374
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}")
363379

364380
context = parser.parse_args()
365381
context.init_dir = pathlib.Path().absolute()

0 commit comments

Comments
 (0)