Skip to content

Commit 09ea5d7

Browse files
committed
feat(phase2): Implement single source of truth for tool versions
Phase 2 complete - Created centralized version management system: New File: toolchains/tool_versions.bzl - TOOL_VERSIONS constant with all tool versions - get_tool_version() function for accessing versions - TOOL_COMPATIBILITY_MATRIX for cross-tool compatibility - validate_tool_versions() for compatibility checking - Comprehensive documentation Tool Versions Defined: - wasm-tools: 1.240.0 - wasmtime: 28.0.0 - wit-bindgen: 0.46.0 ⭐ - wac: 0.8.0 - wkg: 0.11.0 - wizer: 8.1.0 - wasmsign2: 0.2.6 - wasi-sdk: 26 - tinygo: 0.39.0 - nodejs: 20.18.0 Updated Files: 1. toolchains/wasm_toolchain.bzl - Load get_tool_version() from tool_versions.bzl - Replace hardcoded wit-bindgen version: "0.46.0" → get_tool_version("wit-bindgen") - Replace hardcoded wac version: "0.8.0" → get_tool_version("wac") 2. rust/rust_wasm_component_bindgen.bzl - Load get_tool_version() from tool_versions.bzl - Add runtime compatibility validation - Fail build if CLI version incompatible with embedded runtime - Compatible versions: 0.44.0, 0.45.0, 0.46.0 Benefits: ✅ Single source of truth - all versions in ONE location ✅ Type-safe access - Bazel fails if tool undefined ✅ Automatic validation - incompatible versions caught at build time ✅ Easy updates - change version in one place ✅ Documentation - compatibility matrix documents known-good combinations Next Steps (Phase 3): - Template Cargo.toml to derive from TOOL_VERSIONS - Automate version sync between Bazel and Cargo - Add CI check to prevent version drift
1 parent 566111e commit 09ea5d7

File tree

3 files changed

+176
-2
lines changed

3 files changed

+176
-2
lines changed

rust/rust_wasm_component_bindgen.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load("@rules_rust//rust:defs.bzl", "rust_common", "rust_library")
44
load("//wit:wit_bindgen.bzl", "wit_bindgen")
55
load("//wit:symmetric_wit_bindgen.bzl", "symmetric_wit_bindgen")
6+
load("//toolchains:tool_versions.bzl", "get_tool_version")
67
load(":rust_wasm_component.bzl", "rust_wasm_component")
78
load(":transitions.bzl", "wasm_transition")
89

@@ -67,6 +68,20 @@ def _generate_wrapper_impl(ctx):
6768
# IMPORTANT: When updating wit-bindgen CLI version (in wasm_toolchain.bzl),
6869
# verify this embedded runtime still provides the required API.
6970
# Check generated bindings for any new runtime requirements.
71+
72+
# Validate CLI version compatibility
73+
COMPATIBLE_CLI_VERSIONS = ["0.44.0", "0.45.0", "0.46.0"]
74+
cli_version = get_tool_version("wit-bindgen")
75+
if cli_version not in COMPATIBLE_CLI_VERSIONS:
76+
fail(
77+
"Embedded runtime incompatible with wit-bindgen CLI {}. " +
78+
"Compatible versions: {}. " +
79+
"Update the embedded runtime in rust_wasm_component_bindgen.bzl or downgrade CLI version.".format(
80+
cli_version,
81+
", ".join(COMPATIBLE_CLI_VERSIONS)
82+
)
83+
)
84+
7085
wrapper_content = """// Generated wrapper for WIT bindings
7186
//
7287
// COMPATIBILITY: wit-bindgen CLI 0.44.0 - 0.46.0

toolchains/tool_versions.bzl

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
"""Single source of truth for tool versions
2+
3+
This file defines the canonical versions for all WebAssembly toolchain components.
4+
All toolchain setup code MUST reference these constants to ensure version consistency.
5+
6+
IMPORTANT: When updating versions here:
7+
1. Update corresponding JSON registry in checksums/tools/<tool>.json
8+
2. Verify compatibility using validate_tool_compatibility() in checksums/registry.bzl
9+
3. Check embedded runtimes (rust_wasm_component_bindgen.bzl) for API compatibility
10+
4. Update Cargo.toml dependencies if using the tool as a crate
11+
5. Test the full build pipeline
12+
"""
13+
14+
# Tool versions - single source of truth
15+
TOOL_VERSIONS = {
16+
# Core WebAssembly toolchain
17+
"wasm-tools": "1.240.0", # Component model tools (validate, parse, compose, etc.)
18+
"wasmtime": "28.0.0", # WebAssembly runtime for testing/execution
19+
20+
# WIT and binding generation
21+
"wit-bindgen": "0.46.0", # WIT binding generator (MUST match Cargo.toml if used as crate)
22+
"wac": "0.8.0", # WebAssembly Composition tool
23+
"wkg": "0.11.0", # WebAssembly package manager
24+
25+
# Optimization and initialization
26+
"wizer": "8.1.0", # WebAssembly pre-initialization tool
27+
28+
# Signatures and security
29+
"wasmsign2": "0.2.6", # WebAssembly signing tool
30+
31+
# Platform SDKs
32+
"wasi-sdk": "26", # WASI SDK for C/C++ compilation
33+
"tinygo": "0.39.0", # TinyGo compiler for Go→WASM
34+
35+
# Node.js ecosystem
36+
"nodejs": "20.18.0", # Node.js runtime for jco toolchain
37+
}
38+
39+
# Compatibility matrix - defines which versions work together
40+
# Key: wasm-tools version
41+
# Value: Dict of compatible tool versions
42+
TOOL_COMPATIBILITY_MATRIX = {
43+
"1.240.0": {
44+
"wit-bindgen": ["0.46.0"],
45+
"wac": ["0.7.0", "0.8.0"],
46+
"wkg": ["0.11.0"],
47+
"wasmsign2": ["0.2.6"],
48+
"wasmtime": ["27.0.0", "28.0.0"],
49+
},
50+
"1.239.0": {
51+
"wit-bindgen": ["0.43.0", "0.46.0"],
52+
"wac": ["0.7.0", "0.8.0"],
53+
"wkg": ["0.11.0"],
54+
"wasmsign2": ["0.2.6"],
55+
"wasmtime": ["27.0.0", "28.0.0"],
56+
},
57+
"1.235.0": {
58+
"wit-bindgen": ["0.43.0", "0.46.0"],
59+
"wac": ["0.7.0", "0.8.0"],
60+
"wkg": ["0.11.0"],
61+
"wasmsign2": ["0.2.6"],
62+
"wasmtime": ["27.0.0"],
63+
},
64+
}
65+
66+
def get_tool_version(tool_name):
67+
"""Get the canonical version for a tool
68+
69+
Args:
70+
tool_name: Name of the tool (e.g., "wasm-tools", "wit-bindgen")
71+
72+
Returns:
73+
String: Version number
74+
75+
Fails:
76+
If tool_name is not defined in TOOL_VERSIONS
77+
"""
78+
if tool_name not in TOOL_VERSIONS:
79+
fail("Unknown tool: {}. Available tools: {}".format(
80+
tool_name,
81+
", ".join(TOOL_VERSIONS.keys())
82+
))
83+
return TOOL_VERSIONS[tool_name]
84+
85+
def get_compatible_versions(base_tool, base_version):
86+
"""Get compatible versions for other tools based on a base tool version
87+
88+
Args:
89+
base_tool: Name of the base tool (usually "wasm-tools")
90+
base_version: Version of the base tool
91+
92+
Returns:
93+
Dict: Mapping of tool names to list of compatible versions
94+
Empty dict if no compatibility info available
95+
"""
96+
if base_tool == "wasm-tools" and base_version in TOOL_COMPATIBILITY_MATRIX:
97+
return TOOL_COMPATIBILITY_MATRIX[base_version]
98+
return {}
99+
100+
def validate_tool_versions(tools_config):
101+
"""Validate that a set of tool versions are compatible
102+
103+
Args:
104+
tools_config: Dict mapping tool names to versions
105+
106+
Returns:
107+
List: List of warning messages (empty if all compatible)
108+
"""
109+
warnings = []
110+
111+
# Check if wasm-tools is in the config
112+
if "wasm-tools" not in tools_config:
113+
return warnings
114+
115+
wasm_tools_version = tools_config["wasm-tools"]
116+
compat_info = get_compatible_versions("wasm-tools", wasm_tools_version)
117+
118+
if not compat_info:
119+
warnings.append(
120+
"Warning: No compatibility information for wasm-tools {}".format(wasm_tools_version)
121+
)
122+
return warnings
123+
124+
# Check each tool against compatibility matrix
125+
for tool, version in tools_config.items():
126+
if tool == "wasm-tools":
127+
continue
128+
129+
if tool in compat_info:
130+
if version not in compat_info[tool]:
131+
warnings.append(
132+
"Warning: {} version {} may not be compatible with wasm-tools {}. " +
133+
"Recommended versions: {}".format(
134+
tool,
135+
version,
136+
wasm_tools_version,
137+
", ".join(compat_info[tool]),
138+
)
139+
)
140+
141+
return warnings
142+
143+
def get_all_tool_versions():
144+
"""Get all tool versions as a dict
145+
146+
Returns:
147+
Dict: Copy of TOOL_VERSIONS
148+
"""
149+
return dict(TOOL_VERSIONS)
150+
151+
# Export compatibility matrix for external use
152+
def get_compatibility_matrix():
153+
"""Get the full compatibility matrix
154+
155+
Returns:
156+
Dict: Copy of TOOL_COMPATIBILITY_MATRIX
157+
"""
158+
return dict(TOOL_COMPATIBILITY_MATRIX)

toolchains/wasm_toolchain.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("//checksums:registry.bzl", "get_tool_info", "validate_tool_compatibility")
44
load("//toolchains:diagnostics.bzl", "create_retry_wrapper", "format_diagnostic_error", "log_diagnostic_info", "validate_system_tool")
55
load("//toolchains:monitoring.bzl", "add_build_telemetry", "create_health_check")
66
load("//toolchains:tool_cache.bzl", "cache_tool", "clean_expired_cache", "retrieve_cached_tool", "validate_tool_functionality")
7+
load("//toolchains:tool_versions.bzl", "get_tool_version", "validate_tool_versions")
78

89
def _get_rust_toolchain_info(repository_ctx):
910
"""Get Rust toolchain info from the registered hermetic toolchain"""
@@ -497,7 +498,7 @@ def _download_wasm_tools(repository_ctx):
497498
def _download_wac(repository_ctx):
498499
"""Download wac only"""
499500
platform = _detect_host_platform(repository_ctx)
500-
wac_version = "0.8.0"
501+
wac_version = get_tool_version("wac") # From tool_versions.bzl
501502

502503
# Get checksum and platform info from tool_versions.bzl
503504
tool_info = get_tool_info("wac", wac_version, platform)
@@ -519,7 +520,7 @@ def _download_wac(repository_ctx):
519520
def _download_wit_bindgen(repository_ctx):
520521
"""Download wit-bindgen only"""
521522
platform = _detect_host_platform(repository_ctx)
522-
wit_bindgen_version = "0.46.0"
523+
wit_bindgen_version = get_tool_version("wit-bindgen") # From tool_versions.bzl
523524

524525
# Get checksum and platform info from tool_versions.bzl
525526
tool_info = get_tool_info("wit-bindgen", wit_bindgen_version, platform)

0 commit comments

Comments
 (0)