Skip to content

Commit b31ebc1

Browse files
committed
debug: add verbose logging and toolchain inspection for Windows
Added comprehensive debugging to understand why rustc can't find wasm-component-ld.exe: 1. Transition changes: - Added -vv flag for verbose rustc output on Windows - Will show search paths and command lines 2. New debug_rust_toolchain rule: - Inspects rustc location and sysroot - Lists files in rustlib directories - Checks if wasm-component-ld.exe is visible - Uses no-sandbox execution to see actual filesystem Usage in CI: bazel build //rust/debug:windows_toolchain_debug This will produce a _debug.txt file showing exactly what files are accessible to rustc in the Bazel sandbox on Windows.
1 parent ba1cf38 commit b31ebc1

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

rust/debug/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Debug targets for investigating Windows issues"""
2+
3+
load("//rust:debug_windows.bzl", "debug_rust_toolchain")
4+
5+
# Debug target that will show us what's visible in the Bazel sandbox on Windows
6+
debug_rust_toolchain(
7+
name = "windows_toolchain_debug",
8+
is_windows = select({
9+
"@platforms//os:windows": True,
10+
"//conditions:default": False,
11+
}),
12+
visibility = ["//visibility:public"],
13+
)

rust/debug_windows.bzl

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""Debug rules for investigating Windows Rust toolchain issues"""
2+
3+
def _debug_rust_toolchain_impl(ctx):
4+
"""Debug rule that dumps information about the Rust toolchain on Windows"""
5+
6+
output = ctx.actions.declare_file(ctx.label.name + "_debug.txt")
7+
8+
# Get rustc from the toolchain
9+
rust_toolchain = ctx.toolchains["@rules_rust//rust:toolchain_type"]
10+
rustc = rust_toolchain.rustc
11+
12+
# Create a debug script
13+
if ctx.attr.is_windows:
14+
# Windows PowerShell script
15+
script = """
16+
@echo off
17+
echo === Rust Toolchain Debug Info === > {output}
18+
echo. >> {output}
19+
echo Rustc path: {rustc} >> {output}
20+
echo. >> {output}
21+
22+
REM Get rustc's sysroot
23+
{rustc} --print sysroot >> {output} 2>&1
24+
25+
REM Check if lib directory exists relative to rustc
26+
FOR %%I IN ("{rustc}") DO SET "rustc_dir=%%~dpI"
27+
echo. >> {output}
28+
echo Rustc directory: %rustc_dir% >> {output}
29+
echo. >> {output}
30+
31+
REM Try to find wasm-component-ld.exe
32+
echo Searching for wasm-component-ld.exe: >> {output}
33+
where wasm-component-ld.exe >> {output} 2>&1 || echo Not found in PATH >> {output}
34+
echo. >> {output}
35+
36+
REM List what's in the rustc bin directory
37+
echo Contents of rustc bin directory: >> {output}
38+
dir /B "%rustc_dir%" >> {output} 2>&1
39+
40+
REM Check if lib/rustlib exists
41+
echo. >> {output}
42+
echo Checking lib/rustlib structure: >> {output}
43+
dir /B "%rustc_dir%..\\lib\\rustlib" >> {output} 2>&1
44+
45+
REM Check x86_64-pc-windows-msvc bin directory
46+
echo. >> {output}
47+
echo Checking x86_64-pc-windows-msvc bin directory: >> {output}
48+
dir /B "%rustc_dir%..\\lib\\rustlib\\x86_64-pc-windows-msvc\\bin" >> {output} 2>&1
49+
""".format(
50+
output = output.path,
51+
rustc = rustc.path,
52+
)
53+
54+
ctx.actions.run_shell(
55+
outputs = [output],
56+
inputs = [rustc],
57+
command = script,
58+
mnemonic = "DebugRustToolchain",
59+
execution_requirements = {
60+
"no-sandbox": "1", # Disable sandbox to see actual file system
61+
},
62+
)
63+
else:
64+
# Linux/Mac bash script
65+
script = """
66+
#!/bin/bash
67+
{{
68+
echo "=== Rust Toolchain Debug Info ==="
69+
echo
70+
echo "Rustc path: {rustc}"
71+
echo
72+
73+
# Get rustc's sysroot
74+
{rustc} --print sysroot
75+
76+
# Get rustc directory
77+
rustc_dir=$(dirname "{rustc}")
78+
echo
79+
echo "Rustc directory: $rustc_dir"
80+
echo
81+
82+
# Try to find wasm-component-ld
83+
echo "Searching for wasm-component-ld:"
84+
which wasm-component-ld || echo "Not found in PATH"
85+
echo
86+
87+
# List what's in the rustc bin directory
88+
echo "Contents of rustc bin directory:"
89+
ls -la "$rustc_dir" || echo "Directory not accessible"
90+
91+
# Check if lib/rustlib exists
92+
echo
93+
echo "Checking lib/rustlib structure:"
94+
ls -la "$rustc_dir/../lib/rustlib" || echo "Directory not accessible"
95+
96+
}} > {output} 2>&1
97+
""".format(
98+
output = output.path,
99+
rustc = rustc.path,
100+
)
101+
102+
ctx.actions.run_shell(
103+
outputs = [output],
104+
inputs = [rustc],
105+
command = script,
106+
mnemonic = "DebugRustToolchain",
107+
)
108+
109+
return [DefaultInfo(files = depset([output]))]
110+
111+
debug_rust_toolchain = rule(
112+
implementation = _debug_rust_toolchain_impl,
113+
attrs = {
114+
"is_windows": attr.bool(
115+
default = False,
116+
doc = "Whether this is running on Windows",
117+
),
118+
},
119+
toolchains = [
120+
"@rules_rust//rust:toolchain_type",
121+
],
122+
doc = """
123+
Debug rule that dumps information about the Rust toolchain.
124+
125+
On Windows, this will show:
126+
- Where rustc is located
127+
- What rustc's sysroot is
128+
- Whether wasm-component-ld.exe can be found
129+
- What files are visible in the rustlib directory
130+
131+
Example:
132+
debug_rust_toolchain(
133+
name = "debug_windows",
134+
is_windows = select({
135+
"@platforms//os:windows": True,
136+
"//conditions:default": False,
137+
}),
138+
)
139+
""",
140+
)

rust/transitions.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def _wasm_transition_impl(settings, attr):
3939
# rustc/lib/rustlib/x86_64-pc-windows-msvc/bin/wasm-component-ld.exe
4040
# But rustc can't find it by name alone. We need to help it.
4141
if is_windows:
42+
# DEBUG: Add verbose output to see what rustc is doing
43+
# -vv shows command lines and search paths
44+
current_flags.extend(["-vv"])
45+
4246
# Try using -Clink-self-contained=yes to force rustc to use its own linker tools
4347
# This should make it search in lib/rustlib/{target}/bin/
4448
current_flags.extend(["-Clink-self-contained=yes"])

0 commit comments

Comments
 (0)