Skip to content

Commit ad0ab22

Browse files
avrabeclaude
andcommitted
feat(file_ops): Implement Branch 4 solution with JSON config and WASI sandbox mapping
Key improvements: - Eliminated runfiles dependency that was failing with 'no runfiles found' - Pass all paths (wasmtime, WASM component) via JSON config from Bazel - Expose WASM component file in file_ops_toolchain - Map entire Bazel sandbox root to / in WASI sandbox for file access - Convert operations to absolute paths compatible with WASI sandbox mapping - Add debug logging for sandbox environment troubleshooting - Add wasmtime_toolchain_type to go_wasm_component rule Architecture: - Bazel passes paths via JSON config to avoid runfiles fragility - file_ops Go binary locates wasmtime and WASM component from config - Maps sandbox root to WASI root for hermetic file operations - Operations are converted to absolute sandbox-root paths This is a solid Bazel-native foundation that eliminates the runfiles issue. The remaining work is final path resolution tuning in the WASI sandbox. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 846925e commit ad0ab22

File tree

6 files changed

+211
-116
lines changed

6 files changed

+211
-116
lines changed

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ go_wasm_component = rule(
831831
"@rules_wasm_component//toolchains:tinygo_toolchain_type",
832832
"@rules_wasm_component//toolchains:wasm_tools_toolchain_type",
833833
"@rules_wasm_component//toolchains:file_ops_toolchain_type",
834+
"@rules_wasm_component//toolchains:wasmtime_toolchain_type",
834835
],
835836
doc = """Builds a WebAssembly component from Go source using TinyGo + WASI Preview 2.
836837

toolchains/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ bzl_library(
211211
file_ops_toolchain(
212212
name = "file_ops_toolchain_impl",
213213
file_ops_component = "//tools/file_ops:file_ops",
214+
wasm_component = "@file_ops_component_external//file",
214215
wit_files = ["//tools/file_ops:wit_files"],
215216
)
216217

toolchains/file_ops_toolchain.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ def _file_ops_toolchain_impl(ctx):
99

1010
return [platform_common.ToolchainInfo(
1111
file_ops_component = ctx.executable.file_ops_component,
12+
file_ops_wasm_component = ctx.file.wasm_component,
1213
file_ops_info = struct(
1314
component = ctx.executable.file_ops_component,
1415
wit_files = ctx.files.wit_files,
16+
wasm_component = ctx.file.wasm_component,
1517
),
1618
)]
1719

@@ -24,6 +26,12 @@ file_ops_toolchain = rule(
2426
cfg = "exec",
2527
doc = "File Operations Component executable",
2628
),
29+
"wasm_component": attr.label(
30+
mandatory = True,
31+
allow_single_file = [".wasm"],
32+
cfg = "exec",
33+
doc = "WASM component file for file operations",
34+
),
2735
"wit_files": attr.label_list(
2836
allow_files = [".wit"],
2937
doc = "WIT interface files for the component",

tools/bazel_helpers/file_ops_actions.bzl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,14 @@ def prepare_workspace_action(ctx, config):
151151
file_ops_toolchain = ctx.toolchains["@rules_wasm_component//toolchains:file_ops_toolchain_type"]
152152
file_ops_tool = file_ops_toolchain.file_ops_component
153153

154+
# Get wasmtime and WASM component from toolchain
155+
wasmtime_toolchain = ctx.toolchains["@rules_wasm_component//toolchains:wasmtime_toolchain_type"]
156+
wasmtime_binary = wasmtime_toolchain.wasmtime
157+
158+
wasm_component = file_ops_toolchain.file_ops_wasm_component
159+
154160
# Collect all input files and build operations list
155-
all_inputs = []
161+
all_inputs = [wasmtime_binary, wasm_component]
156162
operations = []
157163

158164
# Process source files
@@ -208,9 +214,13 @@ def prepare_workspace_action(ctx, config):
208214
])
209215

210216
# Build JSON config for file operations tool
217+
# Use absolute paths in the sandbox - wasmtime_binary and wasm_component are Files
218+
# so we can get their paths relative to the execution root
211219
file_ops_config = {
212-
"workspace_dir": workspace_dir.path,
220+
"workspace_dir": workspace_dir.short_path,
213221
"operations": operations,
222+
"wasmtime_path": wasmtime_binary.path,
223+
"wasm_component_path": wasm_component.path,
214224
}
215225

216226
# Write config to a JSON file
@@ -457,6 +467,7 @@ def setup_js_workspace_action(ctx, sources, package_json = None, npm_deps = None
457467
outputs = [workspace_dir],
458468
mnemonic = "SetupJSWorkspace",
459469
progress_message = "Setting up JavaScript workspace for %s" % ctx.label,
470+
use_default_shell_env = True, # Allow access to environment for runfiles discovery
460471
)
461472

462473
return workspace_dir

0 commit comments

Comments
 (0)