Skip to content

Commit cafae74

Browse files
committed
fix: add go_sum support to resolve Go module dependency errors
- Added go_sum attribute to go_wasm_component rule - Updated setup_go_module_action to include go.sum files in workspace - Fixed all go_component targets to specify go_sum parameter - Removed unused cm import from calculator_main.go This resolves the CI failures: - main.go:4:2: go.bytecodealliance.org/[email protected]: missing go.sum entry - calculator_main.go:4:2: missing go.sum entry for module Note: WIT dependency issues with wasi:io/streams still need to be addressed
1 parent 06c2d76 commit cafae74

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

examples/go_component/BUILD.bazel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ go_wasm_component(
5151
name = "calculator_component",
5252
srcs = [
5353
"calculator.go",
54-
"main.go",
54+
"calculator_main.go",
5555
"utils.go",
5656
],
5757
adapter = "//wasm/adapters:wasi_snapshot_preview1",
5858
go_mod = "go.mod",
59+
go_sum = "go.sum",
5960
optimization = "release",
6061
wit = ":calculator_wit",
6162
world = "calculator-world",
@@ -66,6 +67,7 @@ go_wasm_component(
6667
name = "calculator_simple",
6768
srcs = ["calculator_main.go"],
6869
go_mod = "go.mod",
70+
go_sum = "go.sum",
6971
optimization = "release",
7072
wit = ":calculator_wit",
7173
world = "calculator-world",
@@ -76,6 +78,7 @@ go_wasm_component(
7678
name = "calculator_with_bindings",
7779
srcs = ["calculator_with_bindings.go"],
7880
go_mod = "go.mod",
81+
go_sum = "go.sum",
7982
optimization = "release",
8083
wit = ":calculator_wit",
8184
world = "calculator-world",
@@ -86,6 +89,7 @@ go_wasm_component(
8689
name = "calculator_simple_binding",
8790
srcs = ["calculator_simple_binding.go"],
8891
go_mod = "go.mod",
92+
go_sum = "go.sum",
8993
optimization = "release",
9094
wit = ":simple_calculator_wit",
9195
world = "calculator-world",
@@ -96,6 +100,7 @@ go_wasm_component(
96100
name = "calculator_manual",
97101
srcs = ["calculator_manual.go"],
98102
go_mod = "go.mod",
103+
go_sum = "go.sum",
99104
optimization = "release",
100105
# Remove WIT temporarily to test basic build
101106
# wit = ":simple_calculator_wit",
@@ -113,6 +118,7 @@ go_wasm_component(
113118
],
114119
adapter = "//wasm/adapters:wasi_snapshot_preview1",
115120
go_mod = "go.mod",
121+
go_sum = "go.sum",
116122
optimization = "release",
117123
world = "wasi:cli/command",
118124
)
@@ -127,6 +133,7 @@ go_wasm_component(
127133
],
128134
adapter = "//wasm/adapters:wasi_snapshot_preview1",
129135
go_mod = "go.mod",
136+
go_sum = "go.sum",
130137
optimization = "debug",
131138
world = "wasi:cli/command",
132139
)
@@ -140,6 +147,7 @@ go_wasm_component(
140147
], # Include simple_wasi.go (no WIT deps) and utils.go
141148
adapter = "//wasm/adapters:wasi_snapshot_preview1",
142149
go_mod = "go.mod",
150+
go_sum = "go.sum",
143151
optimization = "debug",
144152
world = "wasi:cli/command",
145153
)
@@ -150,6 +158,7 @@ go_wasm_component(
150158
name = "simple_wasi",
151159
srcs = ["simple_wasi.go"],
152160
go_mod = "go.mod",
161+
go_sum = "go.sum",
153162
optimization = "release",
154163
# No WIT or world specified - just basic WASI support
155164
)
@@ -163,6 +172,7 @@ go_wasm_component(
163172
],
164173
adapter = "//wasm/adapters:wasi_snapshot_preview1",
165174
go_mod = "go.mod",
175+
go_sum = "go.sum",
166176
optimization = "debug",
167177
world = "wasi:cli/command",
168178
)

examples/go_component/calculator_main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package main
22

3-
import (
4-
"go.bytecodealliance.org/cm"
5-
)
6-
73
// This will be replaced with proper generated bindings from wit-bindgen-go
84
// For now, we'll use a simplified approach that works with TinyGo's WIT support
95

go/defs.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ def _prepare_go_module(ctx, tinygo_toolchain):
346346
ctx,
347347
sources = ctx.files.srcs, # Use original sources, bindings handled separately
348348
go_mod = ctx.file.go_mod,
349+
go_sum = ctx.file.go_sum,
349350
wit_file = wit_file,
350351
bindings_dir = bindings_dir_file,
351352
go_binary = go_binary, # Pass Go binary for dependency resolution
@@ -609,6 +610,10 @@ go_wasm_component = rule(
609610
allow_single_file = ["go.mod"],
610611
doc = "Go module file",
611612
),
613+
"go_sum": attr.label(
614+
allow_single_file = ["go.sum"],
615+
doc = "Go module checksum file",
616+
),
612617
"wit": attr.label(
613618
providers = [WitInfo],
614619
doc = "WIT library for binding generation",

tools/bazel_helpers/file_ops_actions.bzl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,14 @@ def prepare_workspace_action(ctx, config):
272272

273273
return workspace_dir
274274

275-
def setup_go_module_action(ctx, sources, go_mod = None, wit_file = None, bindings_dir = None, go_binary = None):
275+
def setup_go_module_action(ctx, sources, go_mod = None, go_sum = None, wit_file = None, bindings_dir = None, go_binary = None):
276276
"""Set up a Go module workspace for TinyGo compilation
277277
278278
Args:
279279
ctx: Bazel rule context
280280
sources: List of Go source files
281281
go_mod: Optional go.mod file
282+
go_sum: Optional go.sum file
282283
wit_file: Optional WIT file for binding generation
283284
bindings_dir: Optional generated WIT bindings directory
284285
go_binary: Optional hermetic Go binary for dependency resolution
@@ -303,6 +304,13 @@ def setup_go_module_action(ctx, sources, go_mod = None, wit_file = None, binding
303304
"preserve_permissions": False,
304305
})
305306

307+
if go_sum:
308+
config["dependencies"].append({
309+
"source": go_sum,
310+
"destination": "go.sum",
311+
"preserve_permissions": False,
312+
})
313+
306314
if wit_file:
307315
# CRITICAL FIX: TinyGo and wasm-tools expect WIT file in wit/ subdirectory
308316
# with the original filename (preserve the actual file name)

0 commit comments

Comments
 (0)