Skip to content

Commit b8a526d

Browse files
authored
Upgrade Go, use Gazelle (#246)
This will be needed shortly for a wrapper tool in an upcoming PR. It's a good example anyway. - In WORKSPACE, add dependency on bazel_gazelle. - Add deps.bzl with a go_dependencies macro, tracking dependenices from this workspace. Empty for now. - Add go.mod, go.sum tracking Go dependencies. Empty for now. - Add root BUILD file, declaring a Gazelle target. - Run gazelle. This cleans up go/BUILD and perl/BUILD.
1 parent 0285172 commit b8a526d

File tree

7 files changed

+57
-13
lines changed

7 files changed

+57
-13
lines changed

BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("@bazel_gazelle//:def.bzl", "gazelle")
2+
3+
gazelle(name = "gazelle")
4+
5+
# gazelle:exclude java

WORKSPACE

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ http_archive(
5151
urls = [
5252
"https://github.com/googleapis/googleapis/archive/522f79ca64f61da52731d51f7ead8696a2a3c61a.tar.gz",
5353
],
54-
)
54+
)
5555

5656
http_archive(
5757
name = "com_engflow_engflowapis",
@@ -60,7 +60,7 @@ http_archive(
6060
urls = [
6161
"https://github.com/EngFlow/engflowapis/archive/0300f7885c4404d26ff494a329a5f2a3fcf67342.zip",
6262
],
63-
)
63+
)
6464

6565
http_archive(
6666
name = "io_grpc_grpc_java",
@@ -77,15 +77,24 @@ http_archive(
7777
urls = [
7878
"https://github.com/bazelbuild/rules_kotlin/releases/download/v1.8.1/rules_kotlin_release.tgz",
7979
],
80-
)
80+
)
8181

8282
http_archive(
8383
name = "io_bazel_rules_go",
8484
sha256 = "91585017debb61982f7054c9688857a2ad1fd823fc3f9cb05048b0025c47d023",
8585
urls = [
8686
"https://github.com/bazelbuild/rules_go/releases/download/v0.42.0/rules_go-v0.42.0.zip",
8787
],
88-
)
88+
)
89+
90+
http_archive(
91+
name = "bazel_gazelle",
92+
sha256 = "d3fa66a39028e97d76f9e2db8f1b0c11c099e8e01bf363a923074784e451f809",
93+
urls = [
94+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
95+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
96+
],
97+
)
8998

9099
http_archive(
91100
name = "rules_proto",
@@ -112,7 +121,7 @@ http_archive(
112121
urls = [
113122
"https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.5.0.tar.gz",
114123
],
115-
)
124+
)
116125

117126
load("@rules_proto_grpc//java:repositories.bzl", rules_proto_grpc_java_repos = "java_repos")
118127

@@ -132,7 +141,7 @@ http_archive(
132141
urls = [
133142
"https://github.com/protocolbuffers/protobuf/archive/376ba2f8bc5273e3c461f39a73bcc6504d70e2f4.tar.gz",
134143
],
135-
)
144+
)
136145

137146
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
138147

@@ -194,10 +203,17 @@ scalatest_repositories()
194203
scalatest_toolchain()
195204

196205
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
206+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
207+
load(":deps.bzl", "go_dependencies")
208+
209+
# gazelle:repository_macro deps.bzl%go_dependencies
210+
go_dependencies()
197211

198212
go_rules_dependencies()
199213

200-
go_register_toolchains(version = "1.20.5")
214+
go_register_toolchains(version = "1.21.2")
215+
216+
gazelle_dependencies()
201217

202218
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
203219

@@ -263,7 +279,7 @@ http_archive(
263279
urls = [
264280
"https://github.com/bazelbuild/rules_perl/archive/366b6aa76b12056a9e0cc23364686f25dcc41702.zip",
265281
],
266-
)
282+
)
267283

268284
load("@rules_perl//perl:deps.bzl", "perl_register_toolchains", "perl_rules_dependencies")
269285

@@ -297,7 +313,7 @@ http_archive(
297313
sha256 = "2ab7ce101db02d7a1de48f8157cbd978f00a19bad44828fd213aa69fe352497d",
298314
strip_prefix = "abseil-py-2.0.0",
299315
url = "https://github.com/abseil/abseil-py/archive/refs/tags/v2.0.0.tar.gz",
300-
)
316+
)
301317

302318
http_archive(
303319
name = "build_bazel_rules_swift",

deps.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
deps.bzl contains macros that declare dependencies for each langauge
3+
that needs them.
4+
"""
5+
6+
def go_dependencies():
7+
"""Declares Go dependencies needed by this workspace.
8+
9+
Managed with 'bazel run //:gazelle -- update-repos -from-file=go.mod.
10+
11+
Keep in sync with go.mod.
12+
"""
13+
pass

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/EngFlow/example
2+
3+
go 1.21.2

go.sum

Whitespace-only changes.

go/BUILD

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
22

33
go_binary(
44
name = "go",
5-
srcs = ["main.go"],
5+
embed = [":go_lib"],
66
visibility = ["//visibility:public"],
77
)
8+
9+
go_library(
10+
name = "go_lib",
11+
srcs = ["main.go"],
12+
importpath = "github.com/EngFlow/example/go",
13+
visibility = ["//visibility:private"],
14+
)

perl/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ load("@rules_perl//perl:perl.bzl", "perl_binary")
22

33
perl_binary(
44
name = "perl",
5-
srcs = ["hello_world.pl"]
6-
)
5+
srcs = ["hello_world.pl"],
6+
)

0 commit comments

Comments
 (0)