@@ -63,132 +63,22 @@ func main() {
6363 log .Fatalf ("Failed to parse config file: %v" , err )
6464 }
6565
66- // Get wasmtime path from config (provided by Bazel)
67- // The path may be relative to the sandbox root, try to resolve it
68- wasmtimeBinary := config .WasmtimePath
69- if wasmtimeBinary == "" {
70- log .Fatalf ("wasmtime_path not specified in config" )
71- }
72-
73- // Try to find wasmtime - may need to resolve relative path
74- wasmtimeResolved := wasmtimeBinary
75- if _ , err := os .Stat (wasmtimeResolved ); err != nil {
76- // Try looking in common locations
77- alternativePaths := []string {
78- "wasmtime" ,
79- "./wasmtime" ,
80- filepath .Join (filepath .Dir (os .Args [0 ]), "wasmtime" ),
81- }
82- found := false
83- for _ , path := range alternativePaths {
84- if _ , err := os .Stat (path ); err == nil {
85- wasmtimeResolved = path
86- found = true
87- break
88- }
89- }
90- if ! found {
91- log .Fatalf ("Wasmtime binary not found at %s or alternative locations: %v" , wasmtimeBinary , err )
92- }
93- }
94-
95- wasmtimeBinary = wasmtimeResolved
96-
97- // Get WASM component path from config (provided by Bazel)
98- wasmComponentPath := config .WasmComponentPath
99- if wasmComponentPath == "" {
100- log .Fatalf ("wasm_component_path not specified in config" )
101- }
102-
103- // Try to find component - may need to resolve relative path
104- componentResolved := wasmComponentPath
105- if _ , err := os .Stat (componentResolved ); err != nil {
106- // Try looking in common locations
107- alternativePaths := []string {
108- "file_ops_component.wasm" ,
109- "./file_ops_component.wasm" ,
110- filepath .Join (filepath .Dir (os .Args [0 ]), "file_ops_component.wasm" ),
111- }
112- found := false
113- for _ , path := range alternativePaths {
114- if _ , err := os .Stat (path ); err == nil {
115- componentResolved = path
116- found = true
117- break
118- }
119- }
120- if ! found {
121- log .Fatalf ("WASM component not found at %s or alternative locations: %v" , wasmComponentPath , err )
122- }
123- }
124-
125- wasmComponentPath = componentResolved
66+ // Note: wasmtime_path and wasm_component_path are optional - they're only needed
67+ // if the config uses WASM component execution. File-only operations don't need them.
68+ // This file_ops wrapper now handles pure file operations directly in Go.
12669
127- // Build wasmtime command - map current working directory (Bazel sandbox root) to /
128- // This gives the WASM component access to all Bazel-provided inputs
129- var args []string
130- args = append (args , "run" )
131-
132- // Map current directory to / in WASI sandbox
133- // This way, all paths in the Bazel sandbox are accessible with the same relative paths
13470 cwd , err := os .Getwd ()
13571 if err != nil {
13672 log .Fatalf ("Failed to get current working directory: %v" , err )
13773 }
13874
139- // Map the entire Bazel sandbox with read/write permissions
140- args = append (args , "--dir" , cwd + "::/" )
141-
142- // Convert workspace_dir to absolute path for WASI
75+ // Convert workspace_dir to absolute path
14376 workspaceFullPath := filepath .Join (cwd , config .WorkspaceDir )
14477 if err := os .MkdirAll (workspaceFullPath , 0755 ); err != nil {
14578 log .Fatalf ("Failed to create workspace directory: %v" , err )
14679 }
147- log .Printf ("DEBUG: Created workspace directory: %s" , workspaceFullPath )
148-
149- // Copy config file to a simple location in /tmp that we can pass to WASM component
150- // This avoids symlink issues in Bazel's complex sandbox
151- tmpConfigPath := "/tmp/file_ops_config.json"
152- if err := ioutil .WriteFile (tmpConfigPath , configData , 0644 ); err != nil {
153- log .Fatalf ("Failed to write temporary config file: %v" , err )
154- }
155- log .Printf ("DEBUG: Wrote config to temp file: %s" , tmpConfigPath )
156-
157- // Map /tmp directory for config access
158- args = append (args , "--dir" , "/tmp::/" + "tmp" )
159-
160- // Explicitly map the workspace directory with write permissions
161- args = append (args , "--dir" , workspaceFullPath + "::" + "/workspace" )
162-
163- // Execute WASM component via wasmtime
164- log .Printf ("DEBUG: Executing file_ops WASM component" )
165- log .Printf ("DEBUG: Wasmtime: %s" , wasmtimeBinary )
166- log .Printf ("DEBUG: Component: %s" , wasmComponentPath )
167- log .Printf ("DEBUG: Workspace dir: %s" , config .WorkspaceDir )
168- log .Printf ("DEBUG: Operations count: %d" , len (config .Operations ))
169-
170- // Use the explicitly mapped workspace directory in WASI
171- // We mapped workspaceFullPath to /workspace
172- // The directory already exists from the Go wrapper, so the WASM component just needs to use it
173- wasiWorkspaceDir := "/workspace"
174- log .Printf ("DEBUG: WASI workspace dir: %s (already created in Go wrapper)" , wasiWorkspaceDir )
175-
176- // Update config to use the mapped workspace directory
177- // The WASM component should treat this as already-existing
178- config .WorkspaceDir = wasiWorkspaceDir
179-
180- // Write updated config to temp file
181- updatedConfigData , err := json .Marshal (config )
182- if err != nil {
183- log .Fatalf ("Failed to marshal updated config: %v" , err )
184- }
185- if err := ioutil .WriteFile ("/tmp/file_ops_config.json" , updatedConfigData , 0644 ); err != nil {
186- log .Fatalf ("Failed to write updated config file: %v" , err )
187- }
188- log .Printf ("DEBUG: Updated config with absolute workspace path" )
18980
19081 // Process file operations directly in Go
191- // This is more reliable than trying to use the WASM component for now
19282 log .Printf ("DEBUG: Processing %d file operations" , len (config .Operations ))
19383
19484 for i , op := range config .Operations {
0 commit comments