Skip to content

Commit 4fe8147

Browse files
committed
fix: restore conditional Go compilation logic to fix module directory errors
- Revert to compiling main.go instead of module directory path - TinyGo was interpreting directory paths as package imports, not local dirs - Now compiles main.go directly and TinyGo auto-discovers other .go files - Fixes calculator_component, http_service_component, simple_test, multi_file_test - All Go components have main.go so will use file path compilation
1 parent d7762b1 commit 4fe8147

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

go/defs.bzl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,21 @@ def _compile_tinygo_module(ctx, tinygo, go_binary, wasm_opt_binary, wasm_tools,
232232
ctx.attr.world,
233233
])
234234

235-
# Always compile the entire Go module directory to include all source files
236-
# This ensures TinyGo can see all Go files in the same package, not just main.go
237-
tinygo_args.append(go_module_files.path)
235+
# Find main Go file path within the module directory
236+
main_go_found = False
237+
main_go_path = None
238+
for src in ctx.files.srcs:
239+
if src.basename == "main.go":
240+
main_go_path = go_module_files.path + "/main.go"
241+
main_go_found = True
242+
break
243+
244+
if main_go_found:
245+
tinygo_args.append(main_go_path)
246+
else:
247+
# If no main.go, compile the entire module directory
248+
# This allows TinyGo to see all Go files in the package
249+
tinygo_args.append(go_module_files.path)
238250

239251
# Validate that we have Go source files
240252
go_files = [src for src in ctx.files.srcs if src.extension == "go"]

0 commit comments

Comments
 (0)