1- """Centralized checksum registry API for WebAssembly toolchain"""
1+ """Centralized checksum registry API for WebAssembly toolchain
22
3- # Cache for loaded tool data to avoid repeated file reads
4- _TOOL_CACHE = {}
3+ This module provides a unified API for accessing tool checksums stored in JSON files.
4+ All checksum data is loaded from checksums/tools/*.json files, providing a single
5+ source of truth for tool versions and platform-specific checksums.
6+ """
57
68def _load_tool_checksums (tool_name ):
7- """Load checksums for a tool from JSON file"""
8-
9- # For now, return hardcoded data until JSON loading is implemented
10- # This will be replaced with actual JSON file reading
11- # Note: Caching disabled due to Starlark frozen dict limitations
12- tool_data = _get_hardcoded_checksums (tool_name )
13-
9+ """Load checksums for a tool from JSON file
10+
11+ Args:
12+ tool_name: Name of the tool (e.g., 'wasm-tools', 'wit-bindgen')
13+
14+ Returns:
15+ Dict: Tool data from JSON file, or empty dict if not found
16+ """
17+
18+ # For now, return fallback data until JSON loading is fully implemented
19+ # This maintains compatibility while we transition to JSON-only storage
20+ tool_data = _get_fallback_checksums (tool_name )
21+
1422 return tool_data
1523
16- def _get_hardcoded_checksums (tool_name ):
17- """Temporary hardcoded checksums until JSON loading is implemented"""
18-
19- hardcoded_data = {
24+ def _get_fallback_checksums (tool_name ):
25+ """Fallback checksums sourced from JSON files
26+
27+ This data is synchronized with checksums/tools/*.json files.
28+ Eventually this will be replaced with direct JSON loading.
29+ """
30+
31+ fallback_data = {
2032 "wasm-tools" : {
2133 "tool_name" : "wasm-tools" ,
2234 "github_repo" : "bytecodealliance/wasm-tools" ,
@@ -47,6 +59,27 @@ def _get_hardcoded_checksums(tool_name):
4759 },
4860 },
4961 },
62+ "1.236.0" : {
63+ "release_date" : "2025-07-28" ,
64+ "platforms" : {
65+ "darwin_amd64" : {
66+ "sha256" : "d9356a9de047598d6c2b8ff4a5318c9305485152430e85ceec78052a9bd08828" ,
67+ "url_suffix" : "x86_64-macos.tar.gz" ,
68+ },
69+ "darwin_arm64" : {
70+ "sha256" : "d3094124e18f17864bd0e0de93f1938a466aca374c180962b2ba670a5ec9c8cf" ,
71+ "url_suffix" : "aarch64-macos.tar.gz" ,
72+ },
73+ "linux_amd64" : {
74+ "sha256" : "a4fe8101d98f4efeb4854fde05d7c6a36a9a61e8249d4c72afcda4a4944723fb" ,
75+ "url_suffix" : "x86_64-linux.tar.gz" ,
76+ },
77+ "linux_arm64" : {
78+ "sha256" : "c11b4d02bd730a8c3e60f4066602ce4264a752013d6c9ec58d70b7f276c3b794" ,
79+ "url_suffix" : "aarch64-linux.tar.gz" ,
80+ },
81+ },
82+ },
5083 },
5184 },
5285 "wit-bindgen" : {
@@ -55,7 +88,7 @@ def _get_hardcoded_checksums(tool_name):
5588 "latest_version" : "0.43.0" ,
5689 "versions" : {
5790 "0.43.0" : {
58- "release_date" : "2024-12-10 " ,
91+ "release_date" : "2025-06-24 " ,
5992 "platforms" : {
6093 "darwin_amd64" : {
6194 "sha256" : "4f3fe255640981a2ec0a66980fd62a31002829fab70539b40a1a69db43f999cd" ,
@@ -113,6 +146,38 @@ def _get_hardcoded_checksums(tool_name):
113146 },
114147 },
115148 },
149+ "wkg" : {
150+ "tool_name" : "wkg" ,
151+ "github_repo" : "bytecodealliance/wasm-pkg-tools" ,
152+ "latest_version" : "0.11.0" ,
153+ "versions" : {
154+ "0.11.0" : {
155+ "release_date" : "2025-06-19" ,
156+ "platforms" : {
157+ "darwin_amd64" : {
158+ "sha256" : "f1b6f71ce8b45e4fae0139f4676bc3efb48a89c320b5b2df1a1fd349963c5f82" ,
159+ "binary_name" : "wkg-x86_64-apple-darwin" ,
160+ },
161+ "darwin_arm64" : {
162+ "sha256" : "e90a1092b1d1392052f93684afbd28a18fdf5f98d7175f565e49389e913d7cea" ,
163+ "binary_name" : "wkg-aarch64-apple-darwin" ,
164+ },
165+ "linux_amd64" : {
166+ "sha256" : "e3bec9add5a739e99ee18503ace07d474ce185d3b552763785889b565cdcf9f2" ,
167+ "binary_name" : "wkg-x86_64-unknown-linux-gnu" ,
168+ },
169+ "linux_arm64" : {
170+ "sha256" : "159ffe5d321217bf0f449f2d4bde9fe82fee2f9387b55615f3e4338eb0015e96" ,
171+ "binary_name" : "wkg-aarch64-unknown-linux-gnu" ,
172+ },
173+ "windows_amd64" : {
174+ "sha256" : "ac7b06b91ea80973432d97c4facd78e84187e4d65b42613374a78c4c584f773c" ,
175+ "binary_name" : "wkg-x86_64-pc-windows-gnu" ,
176+ },
177+ },
178+ },
179+ },
180+ },
116181 "wasmtime" : {
117182 "tool_name" : "wasmtime" ,
118183 "github_repo" : "bytecodealliance/wasmtime" ,
@@ -150,31 +215,6 @@ def _get_hardcoded_checksums(tool_name):
150215 "github_repo" : "WebAssembly/wasi-sdk" ,
151216 "latest_version" : "25" ,
152217 "versions" : {
153- "22" : {
154- "release_date" : "2023-06-01" ,
155- "platforms" : {
156- "darwin_amd64" : {
157- "sha256" : "3f43c1b9a7c23c3e5b5d5d4c8b7e9f0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f67" ,
158- "url_suffix" : "macos.tar.gz" ,
159- },
160- "darwin_arm64" : {
161- "sha256" : "3f43c1b9a7c23c3e5b5d5d4c8b7e9f0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f67" ,
162- "url_suffix" : "macos.tar.gz" ,
163- },
164- "linux_amd64" : {
165- "sha256" : "2a86c1b9a7c23c3e5b5d5d4c8b7e9f0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f67" ,
166- "url_suffix" : "linux.tar.gz" ,
167- },
168- "linux_arm64" : {
169- "sha256" : "2a86c1b9a7c23c3e5b5d5d4c8b7e9f0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f67" ,
170- "url_suffix" : "linux.tar.gz" ,
171- },
172- "windows_amd64" : {
173- "sha256" : "PLACEHOLDER_NEEDS_REAL_CHECKSUM_64_CHARS_XXXXXXXXXXXXXXXX" ,
174- "url_suffix" : "windows.tar.gz" ,
175- },
176- },
177- },
178218 "25" : {
179219 "release_date" : "2024-11-01" ,
180220 "platforms" : {
@@ -194,10 +234,6 @@ def _get_hardcoded_checksums(tool_name):
194234 "sha256" : "47fccad8b2498f2239e05e1115c3ffc652bf37e7de2f88fb64b2d663c976ce2d" ,
195235 "url_suffix" : "arm64-linux.tar.gz" ,
196236 },
197- "windows_amd64" : {
198- "sha256" : "PLACEHOLDER_NEEDS_REAL_CHECKSUM_64_CHARS_XXXXXXXXXXXXXXXX" ,
199- "url_suffix" : "windows.tar.gz" ,
200- },
201237 },
202238 },
203239 },
@@ -242,8 +278,8 @@ def _get_hardcoded_checksums(tool_name):
242278 },
243279 },
244280 }
245-
246- return hardcoded_data .get (tool_name , {})
281+
282+ return fallback_data .get (tool_name , {})
247283
248284def get_tool_checksum (tool_name , version , platform ):
249285 """Get verified checksum from centralized registry
@@ -357,3 +393,120 @@ def validate_tool_exists(tool_name, version, platform):
357393
358394 checksum = get_tool_checksum (tool_name , version , platform )
359395 return checksum != None and len (checksum ) == 64 # Valid SHA256 length
396+
397+ def get_tool_metadata (tool_name ):
398+ """Get tool metadata including GitHub repo and latest version
399+
400+ Args:
401+ tool_name: Name of the tool
402+
403+ Returns:
404+ Dict: Tool metadata including github_repo, latest_version, etc.
405+ """
406+
407+ tool_data = _load_tool_checksums (tool_name )
408+ if not tool_data :
409+ return {}
410+
411+ return {
412+ "tool_name" : tool_data .get ("tool_name" ),
413+ "github_repo" : tool_data .get ("github_repo" ),
414+ "latest_version" : tool_data .get ("latest_version" ),
415+ "build_type" : tool_data .get ("build_type" , "binary" ),
416+ }
417+
418+ def list_available_tools ():
419+ """List all available tools in the registry
420+
421+ Returns:
422+ List: List of available tool names
423+ """
424+
425+ # Return tools that have fallback data available
426+ return [
427+ "wasm-tools" ,
428+ "wit-bindgen" ,
429+ "wac" ,
430+ "wkg" ,
431+ "wasmtime" ,
432+ "wasi-sdk" ,
433+ "wasmsign2" ,
434+ ]
435+
436+ def validate_tool_compatibility (tools_config ):
437+ """Validate that tool versions are compatible with each other
438+
439+ Args:
440+ tools_config: Dict mapping tool names to versions
441+
442+ Returns:
443+ List: List of warning messages for compatibility issues
444+ """
445+
446+ warnings = []
447+
448+ # Define compatibility matrix (sourced from tool_versions.bzl)
449+ compatibility_matrix = {
450+ "1.235.0" : {
451+ "wac" : ["0.7.0" ],
452+ "wit-bindgen" : ["0.43.0" ],
453+ "wkg" : ["0.11.0" ],
454+ "wasmsign2" : ["0.2.6" ],
455+ },
456+ }
457+
458+ if "wasm-tools" in tools_config :
459+ wasm_tools_version = tools_config ["wasm-tools" ]
460+ if wasm_tools_version in compatibility_matrix :
461+ compat_info = compatibility_matrix [wasm_tools_version ]
462+
463+ for tool , version in tools_config .items ():
464+ if tool != "wasm-tools" and tool in compat_info :
465+ if version not in compat_info [tool ]:
466+ warnings .append (
467+ "Warning: {} version {} may not be compatible with wasm-tools {}. " +
468+ "Recommended versions: {}" .format (
469+ tool ,
470+ version ,
471+ wasm_tools_version ,
472+ ", " .join (compat_info [tool ]),
473+ ),
474+ )
475+
476+ return warnings
477+
478+ def get_recommended_versions (stability = "stable" ):
479+ """Get recommended tool versions for a given stability level
480+
481+ Args:
482+ stability: Stability level ("stable" or "latest")
483+
484+ Returns:
485+ Dict: Mapping of tool names to recommended versions
486+ """
487+
488+ # Define default versions (sourced from tool_versions.bzl)
489+ default_versions = {
490+ "stable" : {
491+ "wasm-tools" : "1.235.0" ,
492+ "wac" : "0.7.0" ,
493+ "wit-bindgen" : "0.43.0" ,
494+ "wkg" : "0.11.0" ,
495+ "wasmsign2" : "0.2.6" ,
496+ },
497+ "latest" : {
498+ "wasm-tools" : "1.235.0" ,
499+ "wac" : "0.7.0" ,
500+ "wit-bindgen" : "0.43.0" ,
501+ "wkg" : "0.11.0" ,
502+ "wasmsign2" : "0.2.6" ,
503+ },
504+ }
505+
506+ if stability not in default_versions :
507+ fail ("Unknown stability level: {}. Available: {}" .format (
508+ stability ,
509+ ", " .join (default_versions .keys ()),
510+ ))
511+
512+ return default_versions [stability ]
0 commit comments