[3.14] GH-140768: Warn when the WASI SDK version doesn't match the supported version (GH-140769) (GH-140801)

GH-140768: Warn when the WASI SDK version doesn't match the supported version (GH-140769)
(cherry picked from commit 95a3564869)

Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
Miss Islington (bot) 2025-10-30 18:01:22 +01:00 committed by GitHub
parent 064e989de5
commit e595d995c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 18 deletions

View file

@ -0,0 +1 @@
Warn when the WASI SDK version doesn't match what's supported.

View file

@ -196,25 +196,44 @@ def make_build_python(context, working_dir):
def find_wasi_sdk(): def find_wasi_sdk():
"""Find the path to the WASI SDK.""" """Find the path to the WASI SDK."""
if wasi_sdk_path := os.environ.get("WASI_SDK_PATH"): wasi_sdk_path = None
return pathlib.Path(wasi_sdk_path)
opt_path = pathlib.Path("/opt") if wasi_sdk_path_env_var := os.environ.get("WASI_SDK_PATH"):
# WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team wasi_sdk_path = pathlib.Path(wasi_sdk_path_env_var)
# has said they don't plan to ever do a point release and all of their Git tags else:
# lack the ``.0`` suffix. opt_path = pathlib.Path("/opt")
# Starting with WASI SDK 23, the tarballs went from containing a directory named # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team
# ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g. # has said they don't plan to ever do a point release and all of their Git tags
# ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``. # lack the ``.0`` suffix.
potential_sdks = [ # Starting with WASI SDK 23, the tarballs went from containing a directory named
path # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g.
for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*") # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
if path.is_dir() potential_sdks = [
] path
if len(potential_sdks) == 1: for path in opt_path.glob(f"wasi-sdk-{WASI_SDK_VERSION}.0*")
return potential_sdks[0] if path.is_dir()
elif (default_path := opt_path / "wasi-sdk").is_dir(): ]
return default_path if len(potential_sdks) == 1:
wasi_sdk_path = potential_sdks[0]
elif (default_path := opt_path / "wasi-sdk").is_dir():
wasi_sdk_path = default_path
# Starting with WASI SDK 25, a VERSION file is included in the root
# of the SDK directory that we can read to warn folks when they are using
# an unsupported version.
if wasi_sdk_path and (version_file := wasi_sdk_path / "VERSION").is_file():
version_details = version_file.read_text(encoding="utf-8")
found_version = version_details.splitlines()[0]
# Make sure there's a trailing dot to avoid false positives if somehow the
# supported version is a prefix of the found version (e.g. `25` and `2567`).
if not found_version.startswith(f"{WASI_SDK_VERSION}."):
major_version = found_version.partition(".")[0]
print(
f"⚠️ Found WASI SDK {major_version}, "
f"but WASI SDK {WASI_SDK_VERSION} is the supported version"
)
return wasi_sdk_path
def wasi_sdk_env(context): def wasi_sdk_env(context):