Skip to content

Commit 48a1305

Browse files
committed
debug: identify JavaScript component symlink issue in sandbox
- Add debugging to JavaScript component rule to identify file access issue - Discovered that workspace setup creates symlinks instead of copying files - Symlinks point to absolute paths that don't exist in sandbox context - Files like index.js are symlinks to execroot paths that are inaccessible - Need to fix workspace setup to copy actual file contents, not create symlinks
1 parent 2df9539 commit 48a1305

File tree

3 files changed

+67
-32
lines changed

3 files changed

+67
-32
lines changed

MODULE.bazel.lock

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

js/defs.bzl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,33 @@ def _js_component_impl(ctx):
6969
if ctx.attr.compat:
7070
jco_args.add("--compat")
7171

72+
# Debug the issue by adding debugging
73+
debug_script = ctx.actions.declare_file(ctx.attr.name + "_debug.sh")
74+
ctx.actions.write(
75+
output = debug_script,
76+
content = """#!/bin/bash
77+
echo "=== JCO DEBUG INFO ==="
78+
echo "Entry point file: {}"
79+
echo "File exists check:"
80+
ls -la "{}"
81+
echo "Working directory contents:"
82+
ls -la "{}"
83+
echo "Running jco with: $@"
84+
exec "$@"
85+
""".format(
86+
paths.join(work_dir.path, ctx.attr.entry_point),
87+
paths.join(work_dir.path, ctx.attr.entry_point),
88+
work_dir.path
89+
),
90+
is_executable = True,
91+
)
92+
7293
ctx.actions.run(
73-
executable = jco,
74-
arguments = [jco_args],
94+
executable = debug_script,
95+
arguments = [jco.path] + [jco_args],
7596
inputs = [work_dir, wit_dest],
7697
outputs = [component_wasm],
98+
tools = [jco],
7799
mnemonic = "JCOBuild",
78100
progress_message = "Building JavaScript component %s with jco" % ctx.label,
79101
)

tools/bazel_helpers/file_ops_actions.bzl

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,26 +305,39 @@ def setup_js_workspace_action(ctx, sources, package_json = None, npm_deps = None
305305
Prepared JavaScript workspace directory
306306
"""
307307

308-
config = {
309-
"work_dir": ctx.label.name + "_jswork",
310-
"workspace_type": "javascript",
311-
"sources": [{"source": src, "destination": None, "preserve_permissions": False} for src in sources],
312-
"headers": [],
313-
"dependencies": [],
314-
}
315-
308+
# Create workspace directory
309+
workspace_dir = ctx.actions.declare_directory(ctx.label.name + "_jswork")
310+
311+
# Prepare inputs
312+
all_inputs = list(sources)
316313
if package_json:
317-
config["dependencies"].append({
318-
"source": package_json,
319-
"destination": "package.json",
320-
"preserve_permissions": False,
321-
})
322-
314+
all_inputs.append(package_json)
323315
if npm_deps:
324-
config["dependencies"].append({
325-
"source": npm_deps,
326-
"destination": "node_modules",
327-
"preserve_permissions": False,
328-
})
329-
330-
return prepare_workspace_action(ctx, config)
316+
all_inputs.append(npm_deps)
317+
318+
# Use a simpler direct shell approach
319+
cp_commands = ["mkdir -p {}".format(workspace_dir.path)]
320+
321+
# Copy source files to workspace root (flatten structure)
322+
for src in sources:
323+
cp_commands.append("cp {} {}/{}".format(src.path, workspace_dir.path, src.basename))
324+
325+
if package_json:
326+
cp_commands.append("cp {} {}/package.json".format(package_json.path, workspace_dir.path))
327+
328+
if npm_deps:
329+
cp_commands.append("cp -r {} {}/node_modules".format(npm_deps.path, workspace_dir.path))
330+
331+
# Add debugging
332+
cp_commands.append("echo 'JavaScript workspace files:'")
333+
cp_commands.append("ls -la {}".format(workspace_dir.path))
334+
335+
ctx.actions.run_shell(
336+
command = " && ".join(cp_commands),
337+
inputs = all_inputs,
338+
outputs = [workspace_dir],
339+
mnemonic = "SetupJSWorkspace",
340+
progress_message = "Setting up JavaScript workspace for %s" % ctx.label,
341+
)
342+
343+
return workspace_dir

0 commit comments

Comments
 (0)