@@ -196,25 +196,44 @@ def make_build_python(context, working_dir):
196196
197197def find_wasi_sdk ():
198198 """Find the path to the WASI SDK."""
199- if wasi_sdk_path := os .environ .get ("WASI_SDK_PATH" ):
200- return pathlib .Path (wasi_sdk_path )
201-
202- opt_path = pathlib .Path ("/opt" )
203- # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team
204- # has said they don't plan to ever do a point release and all of their Git tags
205- # lack the ``.0`` suffix.
206- # Starting with WASI SDK 23, the tarballs went from containing a directory named
207- # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g.
208- # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
209- potential_sdks = [
210- path
211- for path in opt_path .glob (f"wasi-sdk-{ WASI_SDK_VERSION } .0*" )
212- if path .is_dir ()
213- ]
214- if len (potential_sdks ) == 1 :
215- return potential_sdks [0 ]
216- elif (default_path := opt_path / "wasi-sdk" ).is_dir ():
217- return default_path
199+ wasi_sdk_path = None
200+
201+ if wasi_sdk_path_env_var := os .environ .get ("WASI_SDK_PATH" ):
202+ wasi_sdk_path = pathlib .Path (wasi_sdk_path_env_var )
203+ else :
204+ opt_path = pathlib .Path ("/opt" )
205+ # WASI SDK versions have a ``.0`` suffix, but it's a constant; the WASI SDK team
206+ # has said they don't plan to ever do a point release and all of their Git tags
207+ # lack the ``.0`` suffix.
208+ # Starting with WASI SDK 23, the tarballs went from containing a directory named
209+ # ``wasi-sdk-{WASI_SDK_VERSION}.0`` to e.g.
210+ # ``wasi-sdk-{WASI_SDK_VERSION}.0-x86_64-linux``.
211+ potential_sdks = [
212+ path
213+ for path in opt_path .glob (f"wasi-sdk-{ WASI_SDK_VERSION } .0*" )
214+ if path .is_dir ()
215+ ]
216+ if len (potential_sdks ) == 1 :
217+ wasi_sdk_path = potential_sdks [0 ]
218+ elif (default_path := opt_path / "wasi-sdk" ).is_dir ():
219+ wasi_sdk_path = default_path
220+
221+ # Starting with WASI SDK 25, a VERSION file is included in the root
222+ # of the SDK directory that we can read to warn folks when they are using
223+ # an unsupported version.
224+ if wasi_sdk_path and (version_file := wasi_sdk_path / "VERSION" ).is_file ():
225+ version_details = version_file .read_text (encoding = "utf-8" )
226+ found_version = version_details .splitlines ()[0 ]
227+ # Make sure there's a trailing dot to avoid false positives if somehow the
228+ # supported version is a prefix of the found version (e.g. `25` and `2567`).
229+ if not found_version .startswith (f"{ WASI_SDK_VERSION } ." ):
230+ major_version = found_version .partition ("." )[0 ]
231+ print (
232+ f"⚠️ Found WASI SDK { major_version } , "
233+ f"but WASI SDK { WASI_SDK_VERSION } is the supported version"
234+ )
235+
236+ return wasi_sdk_path
218237
219238
220239def wasi_sdk_env (context ):
0 commit comments