Skip to content

Commit 6b9d409

Browse files
committed
Add rules_go 0.33.0
This is highly experimental and thus carries a `print` warning.
1 parent ff21b36 commit 6b9d409

File tree

5 files changed

+301
-0
lines changed

5 files changed

+301
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module(
2+
name = "rules_go",
3+
version = "0.33.0",
4+
compatibility_level = 0,
5+
toolchains_to_register = [
6+
"@go_default_sdk//:all",
7+
],
8+
)
9+
10+
print("WARNING: The rules_go Bazel module is still highly experimental and subject to change at any time. Only use it to try out bzlmod for now.")
11+
12+
bazel_dep(name = "bazel_skylib", version = "1.2.0")
13+
bazel_dep(name = "platforms", version = "0.0.4")
14+
15+
non_module_dependencies = use_extension("@rules_go//go/private:extensions.bzl", "non_module_dependencies")
16+
use_repo(
17+
non_module_dependencies,
18+
"io_bazel_rules_nogo",
19+
)
20+
21+
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
22+
go_sdk.download(name = "go_default_sdk", version = "1.18.3")
23+
use_repo(go_sdk, "go_default_sdk")
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
commit 46e763254208487d300827a8e4979718d53e6a88
2+
Author: Fabian Meumertzheim <[email protected]>
3+
Date: Tue Jun 7 23:41:52 2022 +0200
4+
5+
Rename to rules_go
6+
7+
diff --git a/MODULE.bazel b/MODULE.bazel
8+
index 820be22d..312e58e2 100644
9+
--- a/MODULE.bazel
10+
+++ b/MODULE.bazel
11+
@@ -1,5 +1,5 @@
12+
module(
13+
- name = "io_bazel_rules_go",
14+
+ name = "rules_go",
15+
version = "0.33.0",
16+
compatibility_level = 0,
17+
toolchains_to_register = [
18+
@@ -12,12 +12,12 @@ print("WARNING: The rules_go Bazel module is still highly experimental and subje
19+
bazel_dep(name = "bazel_skylib", version = "1.2.0")
20+
bazel_dep(name = "platforms", version = "0.0.4")
21+
22+
-non_module_dependencies = use_extension("@io_bazel_rules_go//go/private:extensions.bzl", "non_module_dependencies")
23+
+non_module_dependencies = use_extension("@rules_go//go/private:extensions.bzl", "non_module_dependencies")
24+
use_repo(
25+
non_module_dependencies,
26+
"io_bazel_rules_nogo",
27+
)
28+
29+
-go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
30+
+go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
31+
go_sdk.download(name = "go_default_sdk", version = "1.18.3")
32+
use_repo(go_sdk, "go_default_sdk")
33+
diff --git a/extras/embed_data.bzl b/extras/embed_data.bzl
34+
index bfa30878..9c99eb5a 100644
35+
--- a/extras/embed_data.bzl
36+
+++ b/extras/embed_data.bzl
37+
@@ -131,7 +131,7 @@ go_embed_data = rule(
38+
doc = "If `True`, the embedded data will be stored as `string` instead of `[]byte`.",
39+
),
40+
"_embed": attr.label(
41+
- default = "@io_bazel_rules_go//go/tools/builders:embed",
42+
+ default = "@rules_go//go/tools/builders:embed",
43+
executable = True,
44+
cfg = "host",
45+
),
46+
diff --git a/go/platform/crosstool.bzl b/go/platform/crosstool.bzl
47+
index 2e758720..0528048c 100644
48+
--- a/go/platform/crosstool.bzl
49+
+++ b/go/platform/crosstool.bzl
50+
@@ -54,5 +54,5 @@ def platform_from_crosstool(crosstool_top, cpu):
51+
for matcher in matchers:
52+
platform = matcher(crosstool_top, cpu)
53+
if platform:
54+
- return "@io_bazel_rules_go//go/toolchain:{}".format(platform)
55+
+ return "@rules_go//go/toolchain:{}".format(platform)
56+
return None
57+
diff --git a/go/private/go_toolchain.bzl b/go/private/go_toolchain.bzl
58+
index 9a364815..2eb6349d 100644
59+
--- a/go/private/go_toolchain.bzl
60+
+++ b/go/private/go_toolchain.bzl
61+
@@ -25,7 +25,7 @@ load("//go/private/actions:link.bzl", "emit_link")
62+
load("//go/private/actions:pack.bzl", "emit_pack")
63+
load("//go/private/actions:stdlib.bzl", "emit_stdlib")
64+
65+
-GO_TOOLCHAIN = "@io_bazel_rules_go//go:toolchain"
66+
+GO_TOOLCHAIN = "@rules_go//go:toolchain"
67+
68+
def _go_toolchain_impl(ctx):
69+
sdk = ctx.attr.sdk[GoSDK]
70+
@@ -115,8 +115,8 @@ def declare_toolchains(host, sdk, builder):
71+
impl_name = toolchain_name + "-impl"
72+
73+
cgo_constraints = (
74+
- "@io_bazel_rules_go//go/toolchain:cgo_off",
75+
- "@io_bazel_rules_go//go/toolchain:cgo_on",
76+
+ "@rules_go//go/toolchain:cgo_off",
77+
+ "@rules_go//go/toolchain:cgo_on",
78+
)
79+
constraints = [c for c in p.constraints if c not in cgo_constraints]
80+
81+
@@ -135,8 +135,8 @@ def declare_toolchains(host, sdk, builder):
82+
name = toolchain_name,
83+
toolchain_type = GO_TOOLCHAIN,
84+
exec_compatible_with = [
85+
- "@io_bazel_rules_go//go/toolchain:" + host_goos,
86+
- "@io_bazel_rules_go//go/toolchain:" + host_goarch,
87+
+ "@rules_go//go/toolchain:" + host_goos,
88+
+ "@rules_go//go/toolchain:" + host_goarch,
89+
],
90+
target_compatible_with = constraints,
91+
toolchain = ":" + impl_name,
92+
diff --git a/go/private/nogo.bzl b/go/private/nogo.bzl
93+
index 1d3491bb..efb4594f 100644
94+
--- a/go/private/nogo.bzl
95+
+++ b/go/private/nogo.bzl
96+
@@ -12,7 +12,7 @@
97+
# See the License for the specific language governing permissions and
98+
# limitations under the License.
99+
100+
-DEFAULT_NOGO = "@io_bazel_rules_go//:default_nogo"
101+
+DEFAULT_NOGO = "@rules_go//:default_nogo"
102+
103+
def _go_register_nogo_impl(ctx):
104+
ctx.template(
105+
diff --git a/go/private/platforms.bzl b/go/private/platforms.bzl
106+
index 21a62e90..b31cae1a 100644
107+
--- a/go/private/platforms.bzl
108+
+++ b/go/private/platforms.bzl
109+
@@ -141,7 +141,7 @@ CGO_GOOS_GOARCH = {
110+
111+
def _generate_constraints(names, bazel_constraints):
112+
return {
113+
- name: bazel_constraints.get(name, "@io_bazel_rules_go//go/toolchain:" + name)
114+
+ name: bazel_constraints.get(name, "@rules_go//go/toolchain:" + name)
115+
for name in names
116+
}
117+
118+
@@ -159,7 +159,7 @@ def _generate_platforms():
119+
name = goos + "_" + goarch,
120+
goos = goos,
121+
goarch = goarch,
122+
- constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_off"],
123+
+ constraints = constraints + ["@rules_go//go/toolchain:cgo_off"],
124+
cgo = False,
125+
))
126+
if (goos, goarch) in CGO_GOOS_GOARCH:
127+
@@ -170,7 +170,7 @@ def _generate_platforms():
128+
name = goos + "_" + goarch + "_cgo",
129+
goos = goos,
130+
goarch = goarch,
131+
- constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_on"] + mingw,
132+
+ constraints = constraints + ["@rules_go//go/toolchain:cgo_on"] + mingw,
133+
cgo = True,
134+
))
135+
136+
diff --git a/go/private/rules/nogo.bzl b/go/private/rules/nogo.bzl
137+
index 638d067f..d71ad18b 100644
138+
--- a/go/private/rules/nogo.bzl
139+
+++ b/go/private/rules/nogo.bzl
140+
@@ -115,7 +115,7 @@ def nogo(name, visibility = None, **kwargs):
141+
native.alias(
142+
name = name,
143+
actual = select({
144+
- "@io_bazel_rules_go//go/private:nogo_active": actual_name,
145+
+ "@rules_go//go/private:nogo_active": actual_name,
146+
"//conditions:default": Label("//:default_nogo"),
147+
}),
148+
visibility = visibility,
149+
diff --git a/go/private/rules/transition.bzl b/go/private/rules/transition.bzl
150+
index 6499caec..b978be25 100644
151+
--- a/go/private/rules/transition.bzl
152+
+++ b/go/private/rules/transition.bzl
153+
@@ -44,6 +44,7 @@ def filter_transition_label(label):
154+
way to refer to this repository (@io_bazel_rules_go from another workspace,
155+
but only repo-relative labels if this repository is the main workspace).
156+
"""
157+
+ label = label.replace("@io_bazel_rules_go", "@rules_go")
158+
if label.startswith("//command_line_option:"):
159+
# This is a special prefix that allows transitions to access the values
160+
# of native command-line flags. It is not a valid package, but just a
161+
diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl
162+
index ee53cb0b..768b174d 100644
163+
--- a/go/private/sdk.bzl
164+
+++ b/go/private/sdk.bzl
165+
@@ -237,7 +237,7 @@ def _sdk_build_file(ctx, platform):
166+
"{goos}": goos,
167+
"{goarch}": goarch,
168+
"{exe}": ".exe" if goos == "windows" else "",
169+
- "{rules_go_repo_name}": "io_bazel_rules_go",
170+
+ "{rules_go_repo_name}": "rules_go",
171+
},
172+
)
173+
174+
diff --git a/go/toolchain/toolchains.bzl b/go/toolchain/toolchains.bzl
175+
index b4e070cf..6a342da7 100644
176+
--- a/go/toolchain/toolchains.bzl
177+
+++ b/go/toolchain/toolchains.bzl
178+
@@ -34,7 +34,7 @@ def declare_constraints():
179+
@bazel_tools//platforms:default_platform will be used most of the time).
180+
"""
181+
for goos, constraint in GOOS_CONSTRAINTS.items():
182+
- if constraint.startswith("@io_bazel_rules_go//go/toolchain:"):
183+
+ if constraint.startswith("@rules_go//go/toolchain:"):
184+
native.constraint_value(
185+
name = goos,
186+
constraint_setting = "@platforms//os:os",
187+
@@ -46,7 +46,7 @@ def declare_constraints():
188+
)
189+
190+
for goarch, constraint in GOARCH_CONSTRAINTS.items():
191+
- if constraint.startswith("@io_bazel_rules_go//go/toolchain:"):
192+
+ if constraint.startswith("@rules_go//go/toolchain:"):
193+
native.constraint_value(
194+
name = goarch,
195+
constraint_setting = "@platforms//cpu:cpu",
196+
diff --git a/go/tools/bazel_testing/def.bzl b/go/tools/bazel_testing/def.bzl
197+
index d097027b..366fb4b1 100644
198+
--- a/go/tools/bazel_testing/def.bzl
199+
+++ b/go/tools/bazel_testing/def.bzl
200+
@@ -26,7 +26,7 @@ def go_bazel_test(rule_files = None, **kwargs):
201+
# Add dependency on bazel_testing library.
202+
kwargs.setdefault("deps", [])
203+
204+
- bazel_testing_library = "@io_bazel_rules_go//go/tools/bazel_testing"
205+
+ bazel_testing_library = Label("//go/tools/bazel_testing")
206+
if bazel_testing_library not in kwargs["deps"]:
207+
kwargs["deps"].append(bazel_testing_library)
208+
209+
diff --git a/tests/bcr/MODULE.bazel b/tests/bcr/MODULE.bazel
210+
index 9d7a1bd8..8c4b5353 100644
211+
--- a/tests/bcr/MODULE.bazel
212+
+++ b/tests/bcr/MODULE.bazel
213+
@@ -3,9 +3,9 @@ module(
214+
# Test that the default SDK is registered by not registering one from the test module.
215+
)
216+
217+
-bazel_dep(name = "io_bazel_rules_go", version = "", repo_name = "my_rules_go")
218+
+bazel_dep(name = "rules_go", version = "", repo_name = "my_rules_go")
219+
local_path_override(
220+
- module_name = "io_bazel_rules_go",
221+
+ module_name = "rules_go",
222+
path = "../..",
223+
)
224+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
matrix:
2+
platform:
3+
- centos7
4+
- debian10
5+
- ubuntu2004
6+
- macos
7+
- windows
8+
tasks:
9+
verify_targets:
10+
name: Verify build targets
11+
platform: ${{ platform }}
12+
build_targets:
13+
- '@rules_go//go/tools/bzltestutil/...'
14+
bcr_test_module:
15+
module_path: tests/bcr
16+
matrix:
17+
platform:
18+
- centos7
19+
- debian10
20+
- ubuntu2004
21+
- macos
22+
- windows
23+
tasks:
24+
run_test_module:
25+
name: Run test module
26+
platform: ${{ platform }}
27+
build_targets:
28+
- //...
29+
- '@go_sdk//...'
30+
test_targets:
31+
- //...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"integrity": "sha256-Be67qgs3sPXNHdZdfdn2+l55xmDpmoxLwXAeoHrs/4Y=",
3+
"patch_strip": 1,
4+
"patches": {
5+
"bcr.patch": "sha256-FfynuYQO7lAOvJ3Fnx7PYx7mDjLbjS2hjYUlhg5MYgs="
6+
},
7+
"strip_prefix": "rules_go-bcr-commit-e80bb2c02752a71042b9898cac470980cfcc7016",
8+
"url": "https://github.com/bazelbuild/rules_go/archive/refs/tags/bcr-commit-e80bb2c02752a71042b9898cac470980cfcc7016.tar.gz"
9+
}

modules/rules_go/metadata.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"homepage": "https://github.com/bazelbuild/rules_go",
3+
"maintainers": [
4+
{
5+
"email": "[email protected]",
6+
"github": "fmeum",
7+
"name": "Fabian Meumertzheim"
8+
}
9+
],
10+
"versions": [
11+
"0.33.0"
12+
],
13+
"yanked_versions": {}
14+
}

0 commit comments

Comments
 (0)