Skip to content

Commit 3fbe8b5

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

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 = 1,
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 5d1d297f30a6fe08afe393ac7a4eb8f4a80c62e9
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 0be48f9d..55cbb94c 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 = 1,
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/bcr_tests/MODULE.bazel b/bcr_tests/MODULE.bazel
34+
index 0387095f..61394e8c 100644
35+
--- a/bcr_tests/MODULE.bazel
36+
+++ b/bcr_tests/MODULE.bazel
37+
@@ -3,9 +3,9 @@ module(
38+
# Test that the default SDK is registered by not registering one from the test module.
39+
)
40+
41+
-bazel_dep(name = "io_bazel_rules_go", version = "", repo_name = "rules_go")
42+
+bazel_dep(name = "rules_go", version = "")
43+
local_path_override(
44+
- module_name = "io_bazel_rules_go",
45+
+ module_name = "rules_go",
46+
path = "..",
47+
)
48+
49+
diff --git a/extras/embed_data.bzl b/extras/embed_data.bzl
50+
index bfa30878..9c99eb5a 100644
51+
--- a/extras/embed_data.bzl
52+
+++ b/extras/embed_data.bzl
53+
@@ -131,7 +131,7 @@ go_embed_data = rule(
54+
doc = "If `True`, the embedded data will be stored as `string` instead of `[]byte`.",
55+
),
56+
"_embed": attr.label(
57+
- default = "@io_bazel_rules_go//go/tools/builders:embed",
58+
+ default = "@rules_go//go/tools/builders:embed",
59+
executable = True,
60+
cfg = "host",
61+
),
62+
diff --git a/go/platform/crosstool.bzl b/go/platform/crosstool.bzl
63+
index 2e758720..0528048c 100644
64+
--- a/go/platform/crosstool.bzl
65+
+++ b/go/platform/crosstool.bzl
66+
@@ -54,5 +54,5 @@ def platform_from_crosstool(crosstool_top, cpu):
67+
for matcher in matchers:
68+
platform = matcher(crosstool_top, cpu)
69+
if platform:
70+
- return "@io_bazel_rules_go//go/toolchain:{}".format(platform)
71+
+ return "@rules_go//go/toolchain:{}".format(platform)
72+
return None
73+
diff --git a/go/private/go_toolchain.bzl b/go/private/go_toolchain.bzl
74+
index 9a364815..2eb6349d 100644
75+
--- a/go/private/go_toolchain.bzl
76+
+++ b/go/private/go_toolchain.bzl
77+
@@ -25,7 +25,7 @@ load("//go/private/actions:link.bzl", "emit_link")
78+
load("//go/private/actions:pack.bzl", "emit_pack")
79+
load("//go/private/actions:stdlib.bzl", "emit_stdlib")
80+
81+
-GO_TOOLCHAIN = "@io_bazel_rules_go//go:toolchain"
82+
+GO_TOOLCHAIN = "@rules_go//go:toolchain"
83+
84+
def _go_toolchain_impl(ctx):
85+
sdk = ctx.attr.sdk[GoSDK]
86+
@@ -115,8 +115,8 @@ def declare_toolchains(host, sdk, builder):
87+
impl_name = toolchain_name + "-impl"
88+
89+
cgo_constraints = (
90+
- "@io_bazel_rules_go//go/toolchain:cgo_off",
91+
- "@io_bazel_rules_go//go/toolchain:cgo_on",
92+
+ "@rules_go//go/toolchain:cgo_off",
93+
+ "@rules_go//go/toolchain:cgo_on",
94+
)
95+
constraints = [c for c in p.constraints if c not in cgo_constraints]
96+
97+
@@ -135,8 +135,8 @@ def declare_toolchains(host, sdk, builder):
98+
name = toolchain_name,
99+
toolchain_type = GO_TOOLCHAIN,
100+
exec_compatible_with = [
101+
- "@io_bazel_rules_go//go/toolchain:" + host_goos,
102+
- "@io_bazel_rules_go//go/toolchain:" + host_goarch,
103+
+ "@rules_go//go/toolchain:" + host_goos,
104+
+ "@rules_go//go/toolchain:" + host_goarch,
105+
],
106+
target_compatible_with = constraints,
107+
toolchain = ":" + impl_name,
108+
diff --git a/go/private/nogo.bzl b/go/private/nogo.bzl
109+
index 1d3491bb..efb4594f 100644
110+
--- a/go/private/nogo.bzl
111+
+++ b/go/private/nogo.bzl
112+
@@ -12,7 +12,7 @@
113+
# See the License for the specific language governing permissions and
114+
# limitations under the License.
115+
116+
-DEFAULT_NOGO = "@io_bazel_rules_go//:default_nogo"
117+
+DEFAULT_NOGO = "@rules_go//:default_nogo"
118+
119+
def _go_register_nogo_impl(ctx):
120+
ctx.template(
121+
diff --git a/go/private/platforms.bzl b/go/private/platforms.bzl
122+
index 21a62e90..b31cae1a 100644
123+
--- a/go/private/platforms.bzl
124+
+++ b/go/private/platforms.bzl
125+
@@ -141,7 +141,7 @@ CGO_GOOS_GOARCH = {
126+
127+
def _generate_constraints(names, bazel_constraints):
128+
return {
129+
- name: bazel_constraints.get(name, "@io_bazel_rules_go//go/toolchain:" + name)
130+
+ name: bazel_constraints.get(name, "@rules_go//go/toolchain:" + name)
131+
for name in names
132+
}
133+
134+
@@ -159,7 +159,7 @@ def _generate_platforms():
135+
name = goos + "_" + goarch,
136+
goos = goos,
137+
goarch = goarch,
138+
- constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_off"],
139+
+ constraints = constraints + ["@rules_go//go/toolchain:cgo_off"],
140+
cgo = False,
141+
))
142+
if (goos, goarch) in CGO_GOOS_GOARCH:
143+
@@ -170,7 +170,7 @@ def _generate_platforms():
144+
name = goos + "_" + goarch + "_cgo",
145+
goos = goos,
146+
goarch = goarch,
147+
- constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_on"] + mingw,
148+
+ constraints = constraints + ["@rules_go//go/toolchain:cgo_on"] + mingw,
149+
cgo = True,
150+
))
151+
152+
diff --git a/go/private/rules/nogo.bzl b/go/private/rules/nogo.bzl
153+
index 638d067f..d71ad18b 100644
154+
--- a/go/private/rules/nogo.bzl
155+
+++ b/go/private/rules/nogo.bzl
156+
@@ -115,7 +115,7 @@ def nogo(name, visibility = None, **kwargs):
157+
native.alias(
158+
name = name,
159+
actual = select({
160+
- "@io_bazel_rules_go//go/private:nogo_active": actual_name,
161+
+ "@rules_go//go/private:nogo_active": actual_name,
162+
"//conditions:default": Label("//:default_nogo"),
163+
}),
164+
visibility = visibility,
165+
diff --git a/go/private/rules/transition.bzl b/go/private/rules/transition.bzl
166+
index 6499caec..b978be25 100644
167+
--- a/go/private/rules/transition.bzl
168+
+++ b/go/private/rules/transition.bzl
169+
@@ -44,6 +44,7 @@ def filter_transition_label(label):
170+
way to refer to this repository (@io_bazel_rules_go from another workspace,
171+
but only repo-relative labels if this repository is the main workspace).
172+
"""
173+
+ label = label.replace("@io_bazel_rules_go", "@rules_go")
174+
if label.startswith("//command_line_option:"):
175+
# This is a special prefix that allows transitions to access the values
176+
# of native command-line flags. It is not a valid package, but just a
177+
diff --git a/go/private/sdk.bzl b/go/private/sdk.bzl
178+
index ee53cb0b..768b174d 100644
179+
--- a/go/private/sdk.bzl
180+
+++ b/go/private/sdk.bzl
181+
@@ -237,7 +237,7 @@ def _sdk_build_file(ctx, platform):
182+
"{goos}": goos,
183+
"{goarch}": goarch,
184+
"{exe}": ".exe" if goos == "windows" else "",
185+
- "{rules_go_repo_name}": "io_bazel_rules_go",
186+
+ "{rules_go_repo_name}": "rules_go",
187+
},
188+
)
189+
190+
diff --git a/go/toolchain/toolchains.bzl b/go/toolchain/toolchains.bzl
191+
index b4e070cf..6a342da7 100644
192+
--- a/go/toolchain/toolchains.bzl
193+
+++ b/go/toolchain/toolchains.bzl
194+
@@ -34,7 +34,7 @@ def declare_constraints():
195+
@bazel_tools//platforms:default_platform will be used most of the time).
196+
"""
197+
for goos, constraint in GOOS_CONSTRAINTS.items():
198+
- if constraint.startswith("@io_bazel_rules_go//go/toolchain:"):
199+
+ if constraint.startswith("@rules_go//go/toolchain:"):
200+
native.constraint_value(
201+
name = goos,
202+
constraint_setting = "@platforms//os:os",
203+
@@ -46,7 +46,7 @@ def declare_constraints():
204+
)
205+
206+
for goarch, constraint in GOARCH_CONSTRAINTS.items():
207+
- if constraint.startswith("@io_bazel_rules_go//go/toolchain:"):
208+
+ if constraint.startswith("@rules_go//go/toolchain:"):
209+
native.constraint_value(
210+
name = goarch,
211+
constraint_setting = "@platforms//cpu:cpu",
212+
diff --git a/go/tools/bazel_testing/def.bzl b/go/tools/bazel_testing/def.bzl
213+
index d097027b..366fb4b1 100644
214+
--- a/go/tools/bazel_testing/def.bzl
215+
+++ b/go/tools/bazel_testing/def.bzl
216+
@@ -26,7 +26,7 @@ def go_bazel_test(rule_files = None, **kwargs):
217+
# Add dependency on bazel_testing library.
218+
kwargs.setdefault("deps", [])
219+
220+
- bazel_testing_library = "@io_bazel_rules_go//go/tools/bazel_testing"
221+
+ bazel_testing_library = Label("//go/tools/bazel_testing")
222+
if bazel_testing_library not in kwargs["deps"]:
223+
kwargs["deps"].append(bazel_testing_library)
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: bcr_tests
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-eHdAzhuM5AXcBJ0nxqT9oDzP5W0fbGugf0D7rBSK4Kw=",
3+
"patch_strip": 1,
4+
"patches": {
5+
"bcr.patch": "sha256-9qvDraT/4Z+RSXlZNBWoi2nkFRXDmDDe9ULVZ5dUkeI="
6+
},
7+
"strip_prefix": "rules_go-40b563af1496634e5cda3b325dbb4fcdd10ff8f8",
8+
"url": "https://github.com/bazelbuild/rules_go/archive/40b563af1496634e5cda3b325dbb4fcdd10ff8f8.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)