Skip to content

Commit 8f2d0ae

Browse files
brettcannonmiss-islington
authored andcommitted
GH-137243: Have Tools/wasm/wasi detect WASI SDK installs in /opt when the release tarball is extracted (GH-137244)
(cherry picked from commit 2f1a9f2) Co-authored-by: Brett Cannon <brett@python.org>
1 parent 38a42fe commit 8f2d0ae

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
@@ -25,6 +25,8 @@
2525
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
2626
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
2727

28+
WASI_SDK_VERSION = 24
29+
2830
WASMTIME_VAR_NAME = "WASMTIME"
2931
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
3032

@@ -169,10 +171,22 @@ def make_build_python(context, working_dir):
169171

170172

171173
def find_wasi_sdk():
172-
"""Find the path to wasi-sdk."""
174+
"""Find the path to the WASI SDK."""
173175
if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"):
174176
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():
176190
return default_path
177191

178192

@@ -303,6 +317,8 @@ def clean_contents(context):
303317

304318

305319
def main():
320+
default_host_triple = "wasm32-wasip1"
321+
default_wasi_sdk = find_wasi_sdk()
306322
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
307323
# Make sure the stack size will work for a pydebug
308324
# build.
@@ -346,17 +362,17 @@ def main():
346362
for subcommand in build, configure_host:
347363
subcommand.add_argument("--wasi-sdk", type=pathlib.Path,
348364
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}")
352367
subcommand.add_argument("--host-runner", action="store",
353368
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}`")
357371
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}")
360376

361377
context = parser.parse_args()
362378
context.init_dir = pathlib.Path().absolute()

0 commit comments

Comments
 (0)