Skip to content

Commit 9fc6482

Browse files
committed
fix: properly handle runfiles paths in rust_wasm_component_test
- Replace runfiles library approach with direct path searching - Support common runfiles directory layouts in test scripts - Handle both local and CI execution environments - Fix wasm-tools binary path resolution issues
1 parent d54e025 commit 9fc6482

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/rust_wasm_component_test.bzl

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,81 @@ def _rust_wasm_component_test_impl(ctx):
1515
toolchain = ctx.toolchains["@rules_wasm_component//toolchains:wasm_tools_toolchain_type"]
1616
wasm_tools = toolchain.wasm_tools
1717

18-
# Generate test script
19-
ctx.actions.write(
20-
output = test_script,
21-
content = """#!/bin/bash
18+
# Generate test script that uses runfiles
19+
script_content = """#!/bin/bash
2220
set -e
2321
22+
# Get the runfiles directory
23+
if [[ -n "${{RUNFILES_DIR}}" ]]; then
24+
RUNFILES="${{RUNFILES_DIR}}"
25+
elif [[ -n "${{RUNFILES_MANIFEST_FILE}}" ]]; then
26+
RUNFILES="$(dirname "${{RUNFILES_MANIFEST_FILE}}")"
27+
else
28+
RUNFILES="${{BASH_SOURCE[0]}}.runfiles"
29+
fi
30+
31+
# Look for wasm-tools in common locations
32+
WASM_TOOLS=""
33+
for path in \\
34+
"${{RUNFILES}}/{wasm_tools_workspace}/{wasm_tools_path}" \\
35+
"${{RUNFILES}}/{wasm_tools_path}" \\
36+
"${{RUNFILES}}/_main/{wasm_tools_path}" \\
37+
"${{RUNFILES}}/../{wasm_tools_workspace}/{wasm_tools_path}" \\
38+
"${{RUNFILES}}/../{wasm_tools_path}"; do
39+
if [[ -f "${{path}}" ]]; then
40+
WASM_TOOLS="${{path}}"
41+
break
42+
fi
43+
done
44+
45+
if [[ -z "${{WASM_TOOLS}}" ]]; then
46+
echo "ERROR: Cannot find wasm-tools binary" >&2
47+
echo "Searched in:" >&2
48+
echo " ${{RUNFILES}}/{wasm_tools_workspace}/{wasm_tools_path}" >&2
49+
echo " ${{RUNFILES}}/{wasm_tools_path}" >&2
50+
echo " ${{RUNFILES}}/_main/{wasm_tools_path}" >&2
51+
echo " ${{RUNFILES}}/../{wasm_tools_workspace}/{wasm_tools_path}" >&2
52+
echo " ${{RUNFILES}}/../{wasm_tools_path}" >&2
53+
exit 1
54+
fi
55+
56+
# Look for component in common locations
57+
COMPONENT_WASM=""
58+
for path in \\
59+
"${{RUNFILES}}/{component_workspace}/{component_path}" \\
60+
"${{RUNFILES}}/{component_path}" \\
61+
"${{RUNFILES}}/_main/{component_path}"; do
62+
if [[ -f "${{path}}" ]]; then
63+
COMPONENT_WASM="${{path}}"
64+
break
65+
fi
66+
done
67+
68+
if [[ -z "${{COMPONENT_WASM}}" ]]; then
69+
echo "ERROR: Cannot find component WASM file" >&2
70+
echo "Searched in:" >&2
71+
echo " ${{RUNFILES}}/{component_workspace}/{component_path}" >&2
72+
echo " ${{RUNFILES}}/{component_path}" >&2
73+
echo " ${{RUNFILES}}/_main/{component_path}" >&2
74+
exit 1
75+
fi
76+
2477
# Validate component
2578
echo "Validating WASM component..."
26-
{wasm_tools} validate {component_wasm}
79+
"${{WASM_TOOLS}}" validate "${{COMPONENT_WASM}}"
2780
2881
# TODO: Run component with wasmtime if available
2982
echo "✅ Component validation passed"
3083
""".format(
31-
wasm_tools = wasm_tools.path,
32-
component_wasm = component_info.wasm_file.path,
33-
),
84+
wasm_tools_workspace = wasm_tools.owner.workspace_name if wasm_tools.owner else "_main",
85+
wasm_tools_path = wasm_tools.short_path,
86+
component_workspace = component_info.wasm_file.owner.workspace_name if component_info.wasm_file.owner else "_main",
87+
component_path = component_info.wasm_file.short_path,
88+
)
89+
90+
ctx.actions.write(
91+
output = test_script,
92+
content = script_content,
3493
is_executable = True,
3594
)
3695

0 commit comments

Comments
 (0)