feat(xtask): bring wasi-sdk treatment up to par with the loader

The loader package's `ensure_wasi_sdk_exists` private method checks for
the wasi-sdk, fetching it if it can't be found. This logic was
re-implemented in xtask for `build-wasm-stdlib`, but without the
fetching functionality. We can have nice things in xtask too! Rather
than make this function a public member of `tree-sitter-loader`, we
just re-implement and leave a nice comment asking people to keep the
two in sync.
This commit is contained in:
WillLillis 2025-11-26 02:40:19 -05:00 committed by Will Lillis
parent 14b4708018
commit df8b62fc50
5 changed files with 144 additions and 19 deletions

View file

@ -41,6 +41,8 @@ use tree_sitter_tags::{Error as TagsError, TagsConfiguration};
static GRAMMAR_NAME_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#""name":\s*"(.*?)""#).unwrap());
const WASI_SDK_VERSION: &str = include_str!("../wasi-sdk-version").trim_ascii();
pub type LoaderResult<T> = Result<T, LoaderError>;
#[derive(Debug, Error)]
@ -223,7 +225,7 @@ impl std::fmt::Display for ScannerSymbolError {
pub struct WasiSDKClangError {
pub wasi_sdk_dir: String,
pub possible_executables: Vec<&'static str>,
download: bool,
pub download: bool,
}
impl std::fmt::Display for WasiSDKClangError {
@ -1436,9 +1438,12 @@ impl Loader {
return Err(LoaderError::WasiSDKPlatform);
};
let sdk_filename = format!("wasi-sdk-29.0-{arch_os}.tar.gz");
let sdk_filename = format!("wasi-sdk-{WASI_SDK_VERSION}-{arch_os}.tar.gz");
let wasi_sdk_major_version = WASI_SDK_VERSION
.trim_end_matches(char::is_numeric) // trim minor version...
.trim_end_matches('.'); // ...and '.' separator
let sdk_url = format!(
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-29/{sdk_filename}",
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-{wasi_sdk_major_version}/{sdk_filename}",
);
info!("Downloading wasi-sdk from {sdk_url}...");