Skip to content

Commit cef738e

Browse files
committed
fix(windows): use proper rules_rust settings path for rustc flags in transition
Changed from @rules_rust//:extra_rustc_flags to the correct build setting: @rules_rust//rust/settings:extra_rustc_flags Also improved Windows detection to check multiple indicators: - host_platform string - cpu string (looks for 'x64_windows') And updated flag format to use -Clinker= (no space) which is the standard rustc syntax.
1 parent 8df9edb commit cef738e

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

rust/transitions.bzl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,44 @@ def _wasm_transition_impl(settings, attr):
1919

2020
# Detect Windows execution platform for wasm-component-ld.exe workaround
2121
# On Windows, the linker needs .exe extension but Rust's wasm32-wasip2 target spec doesn't add it
22-
host_platform = str(settings["//command_line_option:host_platform"])
23-
is_windows = "windows" in host_platform
22+
#
23+
# Check multiple possible indicators of Windows:
24+
# 1. host_platform label might contain "windows"
25+
# 2. cpu setting might be x86_64 or x64_windows
26+
# 3. Default to adding .exe suffix on any platform with "windows" in cpu string
27+
host_platform = str(settings.get("//command_line_option:host_platform", ""))
28+
cpu = str(settings.get("//command_line_option:cpu", ""))
2429

25-
# Get current rustc flags
26-
rustc_flags = list(settings.get("@rules_rust//:extra_rustc_flags", []))
30+
# Windows detection: check both platform and CPU strings
31+
is_windows = "windows" in host_platform.lower() or "windows" in cpu.lower() or "x64_windows" in cpu
32+
33+
# Get current rustc flags from the rules_rust extra_rustc_flags setting
34+
# Note: This is a list of strings
35+
current_flags = list(settings.get("@rules_rust//rust/settings:extra_rustc_flags", []))
2736

2837
# Add Windows-specific linker configuration
38+
# IMPORTANT: This must happen for wasm32-wasip2 builds on Windows hosts
2939
if is_windows:
3040
# Override the linker for wasm32-wasip2 on Windows hosts
31-
rustc_flags.extend(["-C", "linker=wasm-component-ld.exe"])
41+
# The Rust target spec hardcodes "wasm-component-ld" but Windows needs .exe
42+
# The -C linker= flag should override the target spec's linker setting
43+
current_flags.extend(["-Clinker=wasm-component-ld.exe"])
3244

3345
return {
3446
"//command_line_option:platforms": "//platforms:wasm32-wasip2",
35-
"@rules_rust//:extra_rustc_flags": rustc_flags,
47+
"@rules_rust//rust/settings:extra_rustc_flags": current_flags,
3648
}
3749

3850
wasm_transition = transition(
3951
implementation = _wasm_transition_impl,
4052
inputs = [
4153
"//command_line_option:host_platform",
42-
"@rules_rust//:extra_rustc_flags",
54+
"//command_line_option:cpu",
55+
"@rules_rust//rust/settings:extra_rustc_flags",
4356
],
4457
outputs = [
4558
"//command_line_option:platforms",
46-
"@rules_rust//:extra_rustc_flags",
59+
"@rules_rust//rust/settings:extra_rustc_flags",
4760
],
4861
)
4962

0 commit comments

Comments
 (0)