Skip to content

Commit 31ab4c8

Browse files
feat: bzlmod setup (#385)
Creates MODULE.bazel and WORKSPACE.bzlmod files to enable bazel-skylib to work with the `--experimental_enable_bzlmod` flag. rules_go has been updated as the previously used version is not available in the BCR. stardoc has been updated due to a strange issue with Bzlmod enabled that caused the `diff_test` and `unittest` docs to be generated without any contents that was magically fixed upon updating. bazelbuild/bazel-central-registry#124 Co-authored-by: Alexandre Rostovtsev <[email protected]>
1 parent 1bbb388 commit 31ab4c8

29 files changed

+171
-107
lines changed

.bazelci/presubmit.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ tasks:
9696
- "--test_env=LOCALAPPDATA"
9797
- "--test_tag_filters=-no_windows"
9898

99+
ubuntu1804_last_green_bzlmod:
100+
name: "Last Green Bazel (with bzlmod)"
101+
platform: ubuntu1804
102+
bazel: last_green
103+
build_targets:
104+
- "//..."
105+
test_targets:
106+
- "//..."
107+
build_flags:
108+
- "--experimental_enable_bzlmod"
109+
test_flags:
110+
- "--experimental_enable_bzlmod"
111+
- "--test_env=PATH"
112+
99113
buildifier: latest

BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ package(default_visibility = ["//visibility:public"])
77
# buildifier: disable=skylark-comment
88
# gazelle:exclude skylark_library.bzl
99

10-
exports_files(["LICENSE"])
10+
exports_files([
11+
"LICENSE",
12+
"MODULE.bazel",
13+
])
1114

1215
filegroup(
1316
name = "test_deps",
@@ -69,6 +72,7 @@ filegroup(
6972
"BUILD",
7073
"CODEOWNERS",
7174
"CONTRIBUTORS",
75+
"WORKSPACE.bzlmod",
7276
"//lib:distribution",
7377
"//rules:distribution",
7478
"//rules/private:distribution",

MODULE.bazel

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module(
2+
name = "bazel_skylib",
3+
compatibility_level = 1,
4+
version = "1.2.1",
5+
)
6+
7+
register_toolchains(
8+
"//toolchains/unittest:cmd_toolchain",
9+
"//toolchains/unittest:bash_toolchain",
10+
)
11+
12+
bazel_dep(name = "platforms", version = "0.0.4")
13+
14+
### INTERNAL ONLY - lines after this are not included in the release packaging.
15+
16+
# Gazelle extension is experimental
17+
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.33.0")
18+
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.26.0")
19+
20+
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
21+
22+
go_deps.module(
23+
path = "github.com/bazelbuild/buildtools",
24+
sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=",
25+
version = "v0.0.0-20220531122519-a43aed7014c8",
26+
)
27+
28+
use_repo(go_deps, "com_github_bazelbuild_buildtools")
29+
30+
# Build-only / test-only dependencies
31+
bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.1")
32+
bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.5.1")
33+
bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.1")

WORKSPACE

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
66
maybe(
77
name = "io_bazel_rules_go",
88
repo_rule = http_archive,
9-
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
9+
sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369",
1010
urls = [
11-
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
12-
"https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
11+
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
12+
"https://github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
1313
],
1414
)
1515

@@ -26,10 +26,10 @@ go_register_toolchains(version = "1.17.1")
2626
maybe(
2727
http_archive,
2828
name = "io_bazel_stardoc",
29-
sha256 = "c9794dcc8026a30ff67cf7cf91ebe245ca294b20b071845d12c192afe243ad72",
29+
sha256 = "aa814dae0ac400bbab2e8881f9915c6f47c49664bf087c409a15f90438d2c23e",
3030
urls = [
31-
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
32-
"https://github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
31+
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.1/stardoc-0.5.1.tar.gz",
32+
"https://github.com/bazelbuild/stardoc/releases/download/0.5.1/stardoc-0.5.1.tar.gz",
3333
],
3434
)
3535

WORKSPACE.bzlmod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Workaround so that targets prefixed with @bazel_skylib still work
2+
workspace(name = "bazel_skylib")

distribution/BUILD

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ package(
66
default_visibility = ["//visibility:private"],
77
)
88

9+
genrule(
10+
name = "distro_module_bazel",
11+
srcs = ["//:MODULE.bazel"],
12+
outs = ["MODULE.bazel"],
13+
cmd = "sed -e '/### INTERNAL ONLY/,$$d' $(location //:MODULE.bazel) >$@",
14+
)
15+
916
# Build the artifact to put on the github release page.
1017
pkg_tar(
1118
name = "bazel-skylib-%s" % version,
12-
srcs = ["//:distribution"],
19+
srcs = [
20+
"distro_module_bazel",
21+
"//:distribution",
22+
],
1323
extension = "tar.gz",
1424
mode = "0644",
1525
# Make it owned by root so it does not have the uid of the CI robot.

docs/analysis_test_doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A test verifying other targets can be successfully analyzed as part of a `bazel test`
44

5-
<a id="#analysis_test"></a>
5+
<a id="analysis_test"></a>
66

77
## analysis_test
88

docs/build_test_doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A test verifying other targets build as part of a `bazel test`
44

5-
<a id="#build_test"></a>
5+
<a id="build_test"></a>
66

77
## build_test
88

docs/collections_doc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Skylib module containing functions that operate on collections.
44

5-
<a id="#collections.after_each"></a>
5+
<a id="collections.after_each"></a>
66

77
## collections.after_each
88

@@ -25,7 +25,7 @@ Inserts `separator` after each item in `iterable`.
2525
A new list with `separator` after each item in `iterable`.
2626

2727

28-
<a id="#collections.before_each"></a>
28+
<a id="collections.before_each"></a>
2929

3030
## collections.before_each
3131

@@ -48,7 +48,7 @@ Inserts `separator` before each item in `iterable`.
4848
A new list with `separator` before each item in `iterable`.
4949

5050

51-
<a id="#collections.uniq"></a>
51+
<a id="collections.uniq"></a>
5252

5353
## collections.uniq
5454

docs/common_settings_doc.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ More documentation on how to use build settings at
99
https://docs.bazel.build/versions/main/skylark/config.html#user-defined-build-settings
1010

1111

12-
<a id="#bool_flag"></a>
12+
<a id="bool_flag"></a>
1313

1414
## bool_flag
1515

@@ -27,7 +27,7 @@ A bool-typed build setting that can be set on the command line
2727
| <a id="bool_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
2828

2929

30-
<a id="#bool_setting"></a>
30+
<a id="bool_setting"></a>
3131

3232
## bool_setting
3333

@@ -45,7 +45,7 @@ A bool-typed build setting that cannot be set on the command line
4545
| <a id="bool_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
4646

4747

48-
<a id="#int_flag"></a>
48+
<a id="int_flag"></a>
4949

5050
## int_flag
5151

@@ -63,7 +63,7 @@ An int-typed build setting that can be set on the command line
6363
| <a id="int_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
6464

6565

66-
<a id="#int_setting"></a>
66+
<a id="int_setting"></a>
6767

6868
## int_setting
6969

@@ -81,7 +81,7 @@ An int-typed build setting that cannot be set on the command line
8181
| <a id="int_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
8282

8383

84-
<a id="#string_flag"></a>
84+
<a id="string_flag"></a>
8585

8686
## string_flag
8787

@@ -100,7 +100,7 @@ A string-typed build setting that can be set on the command line
100100
| <a id="string_flag-values"></a>values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] |
101101

102102

103-
<a id="#string_list_flag"></a>
103+
<a id="string_list_flag"></a>
104104

105105
## string_list_flag
106106

@@ -118,7 +118,7 @@ A string list-typed build setting that can be set on the command line
118118
| <a id="string_list_flag-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
119119

120120

121-
<a id="#string_list_setting"></a>
121+
<a id="string_list_setting"></a>
122122

123123
## string_list_setting
124124

@@ -136,7 +136,7 @@ A string list-typed build setting that cannot be set on the command line
136136
| <a id="string_list_setting-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
137137

138138

139-
<a id="#string_setting"></a>
139+
<a id="string_setting"></a>
140140

141141
## string_setting
142142

@@ -155,7 +155,7 @@ A string-typed build setting that cannot be set on the command line
155155
| <a id="string_setting-values"></a>values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] |
156156

157157

158-
<a id="#BuildSettingInfo"></a>
158+
<a id="BuildSettingInfo"></a>
159159

160160
## BuildSettingInfo
161161

0 commit comments

Comments
 (0)