GH-137243: Have Tools/wasm/wasi detect WASI SDK installs in /opt when the release tarball is extracted (GH-137244)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
Have Tools/wasm/wasi detect a WASI SDK install in /opt when it was directly
|
||||
extracted from a release tarball.
|
||||
@@ -26,6 +26,8 @@ LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
|
||||
LOCAL_SETUP_MARKER = ("# Generated by Tools/wasm/wasi .\n"
|
||||
"# Required to statically build extension modules.").encode("utf-8")
|
||||
|
||||
WASI_SDK_VERSION = 24
|
||||
|
||||
WASMTIME_VAR_NAME = "WASMTIME"
|
||||
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
|
||||
|
||||
@@ -173,10 +175,22 @@ def make_build_python(context, working_dir):
|
||||
|
||||
|
||||
def find_wasi_sdk():
|
||||
"""Find the path to wasi-sdk."""
|
||||
"""Find the path to the WASI SDK."""
|
||||
if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"):
|
||||
return pathlib.Path(wasi_sdk_path)
|
||||
elif (default_path := pathlib.Path("/opt/wasi-sdk")).exists():
|
||||
|
||||
opt_path = pathlib.Path("/opt")
|
||||
# WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team
|
||||
# has said they don't plan to ever do a point release and all of their Git tags
|
||||
# lack the ``.0`` suffix.
|
||||
# Starting with WASI SDK 23, the tarballs went from containing a directory named
|
||||
# ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g.
|
||||
# ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
|
||||
potential_sdks = [path for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*")
|
||||
if path.is_dir()]
|
||||
if len(potential_sdks) == 1:
|
||||
return potential_sdks[0]
|
||||
elif (default_path := opt_path / "wasi-sdk").is_dir():
|
||||
return default_path
|
||||
|
||||
|
||||
@@ -306,6 +320,8 @@ def clean_contents(context):
|
||||
|
||||
|
||||
def main():
|
||||
default_host_triple = "wasm32-wasip1"
|
||||
default_wasi_sdk = find_wasi_sdk()
|
||||
default_host_runner = (f"{WASMTIME_HOST_RUNNER_VAR} run "
|
||||
# Make sure the stack size will work for a pydebug
|
||||
# build.
|
||||
@@ -349,17 +365,17 @@ def main():
|
||||
for subcommand in build, configure_host:
|
||||
subcommand.add_argument("--wasi-sdk", type=pathlib.Path,
|
||||
dest="wasi_sdk_path",
|
||||
default=find_wasi_sdk(),
|
||||
help="Path to wasi-sdk; defaults to "
|
||||
"$WASI_SDK_PATH or /opt/wasi-sdk")
|
||||
default=default_wasi_sdk,
|
||||
help=f"Path to the WASI SDK; defaults to {default_wasi_sdk}")
|
||||
subcommand.add_argument("--host-runner", action="store",
|
||||
default=default_host_runner, dest="host_runner",
|
||||
help="Command template for running the WASI host "
|
||||
"(default designed for wasmtime 14 or newer: "
|
||||
f"`{default_host_runner}`)")
|
||||
help="Command template for running the WASI host; defaults to "
|
||||
f"`{default_host_runner}`")
|
||||
for subcommand in build, configure_host, make_host:
|
||||
subcommand.add_argument("--host-triple", action="store", default="wasm32-wasip1",
|
||||
help="The target triple for the WASI host build")
|
||||
subcommand.add_argument("--host-triple", action="store",
|
||||
default=default_host_triple,
|
||||
help="The target triple for the WASI host build; "
|
||||
f"defaults to {default_host_triple}")
|
||||
|
||||
context = parser.parse_args()
|
||||
context.init_dir = pathlib.Path().absolute()
|
||||
|
||||
Reference in New Issue
Block a user