Skip to content

Commit

Permalink
chore: add support for bzlmod (#232)
Browse files Browse the repository at this point in the history
- Clean house:
  - Remove all conditional dependency code.
- Remove the ability to build buildtools from source. Just use
`keith/buildifier-prebuilt`.
  - Remove unused `binary_pkg`.
- Add `MODULE.bazel` with all dependencies.
- Update all example workspaces to include a `MODULE.bazel`.
- Add `--noenable_bzlmod` to `shared.bazelrc` until
bazelbuild/bazel#14140 is fixed.

Related to #195.
  • Loading branch information
cgrindel authored Mar 8, 2023
1 parent 58c788b commit c3fde70
Show file tree
Hide file tree
Showing 43 changed files with 162 additions and 815 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This lets us glob() up all the files inside the examples to make them inputs to tests
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, run `bazel run @contrib_rules_bazel_integration_test//tools:update_deleted_packages`.
build --deleted_packages=examples/bzlformat/build_buildtools,examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
query --deleted_packages=examples/bzlformat/build_buildtools,examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
build --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters
query --deleted_packages=examples/bzlformat/simple,examples/bzlformat/simple/mockascript,examples/bzlformat/simple/mockascript/internal,examples/markdown/simple,examples/markdown/simple/bar,examples/updatesrc/simple,examples/updatesrc/simple/header,examples/updatesrc/simple/srcs/Bar,examples/updatesrc/simple/srcs/Foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo,tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/foo/bar,tests/updatesrc_tests/workspace/diff_and_update_test,tests/updatesrc_tests/workspace/diff_and_update_test/with_custom_values,tests/updatesrc_tests/workspace/diff_and_update_test/with_defaults,tests/updatesrc_tests/workspace/letters

# Import Shared settings
import %workspace%/shared.bazelrc
Expand Down
14 changes: 4 additions & 10 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ gazelle(

bzlformat_pkg(name = "bzlformat")

bzlformat_missing_pkgs(
name = "bzlformat_missing_pkgs",
)
bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs")

# MARK: - Update Source Files

Expand All @@ -51,6 +49,9 @@ updatesrc_update_all(name = "update_all")
tidy(
name = "tidy",
targets = [
# Remove the child workspace symlinks before doing some of the other
# operations that my experience infinite symlink expansion errors.
"@contrib_rules_bazel_integration_test//tools:remove_child_wksp_bazel_symlinks",
"@contrib_rules_bazel_integration_test//tools:update_deleted_packages",
":bzlformat_missing_pkgs_fix",
":update_all",
Expand Down Expand Up @@ -209,7 +210,6 @@ bzl_library(
srcs = ["deps.bzl"],
visibility = ["//visibility:public"],
deps = [
":bazel_starlib_buildtools",
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
Expand All @@ -222,12 +222,6 @@ bzl_library(
deps = ["@bazel_gazelle//:deps"],
)

bzl_library(
name = "bazel_starlib_buildtools",
srcs = ["bazel_starlib_buildtools.bzl"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "bazel_versions",
srcs = ["bazel_versions.bzl"],
Expand Down
110 changes: 110 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
module(
name = "cgrindel_bazel_starlib",
version = "0.13.1",
)

bazel_dep(
name = "bazel_skylib_gazelle_plugin",
version = "1.4.1",
dev_dependency = True,
)

bazel_dep(
name = "rules_go",
version = "0.38.1",
repo_name = "io_bazel_rules_go",
)
bazel_dep(
name = "gazelle",
version = "0.29.0",
)
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(
name = "stardoc",
version = "0.5.3",
repo_name = "io_bazel_stardoc",
)
bazel_dep(
name = "buildifier_prebuilt",
version = "6.0.0.1",
)

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")

# NOTE: We are not loading the Go modules from go.mod, because we are doing
# something a little weird in that we are building an executable from another
# repository. The `go mod tidy` operation does not fill in the indirect deps.
# Instead, we declare the same repos listed in `go_deps.bzl`.
# go_deps.from_file(go_mod = "//:go.mod")
go_deps.module(
path = "github.com/alecthomas/assert",
sum = "h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=",
version = "v0.0.0-20170929043011-405dbfeb8e38",
)
go_deps.module(
path = "github.com/alecthomas/colour",
sum = "h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=",
version = "v0.1.0",
)
go_deps.module(
path = "github.com/alecthomas/repr",
sum = "h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=",
version = "v0.0.0-20210801044451-80ca428c5142",
)
go_deps.module(
path = "github.com/alecthomas/template",
sum = "h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=",
version = "v0.0.0-20160405071501-a0175ee3bccc",
)
go_deps.module(
path = "github.com/alecthomas/units",
sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=",
version = "v0.0.0-20151022065526-2efee857e7cf",
)
go_deps.module(
path = "github.com/davecgh/go-spew",
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
version = "v1.1.1",
)
go_deps.module(
path = "github.com/ekalinin/github-markdown-toc.go",
sum = "h1:6jRFt5qg61XfXZbP3SDaeTX+1OC1EgbHvRceYDmPAUE=",
version = "v1.2.1",
)
go_deps.module(
path = "github.com/mattn/go-isatty",
sum = "h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=",
version = "v0.0.14",
)
go_deps.module(
path = "github.com/sergi/go-diff",
sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=",
version = "v1.2.0",
)
go_deps.module(
path = "github.com/stretchr/testify",
sum = "h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=",
version = "v1.7.0",
)
go_deps.module(
path = "gopkg.in/alecthomas/kingpin.v2",
sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=",
version = "v2.2.4",
)

# Declare all of the go modules that we are going to use to build the ekalinin
# github markdown toc.
use_repo(
go_deps,
"com_github_alecthomas_assert",
"com_github_alecthomas_colour",
"com_github_alecthomas_repr",
"com_github_alecthomas_template",
"com_github_alecthomas_units",
"com_github_davecgh_go_spew",
"com_github_ekalinin_github_markdown_toc_go",
"com_github_mattn_go_isatty",
"com_github_sergi_go_diff",
"com_github_stretchr_testify",
"in_gopkg_alecthomas_kingpin_v2",
)
86 changes: 0 additions & 86 deletions bazel_starlib_buildtools.bzl

This file was deleted.

4 changes: 3 additions & 1 deletion bazel_versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
CURRENT_BAZEL_VERSION = "//:.bazelversion"

OTHER_BAZEL_VERSIONS = [
"5.4.0",
# GH195: Enable once we can use the default enable_bzlmod values (i.e., do
# not need to specify).
# "5.4.0",
]

SUPPORTED_BAZEL_VERSIONS = [
Expand Down
4 changes: 1 addition & 3 deletions bzlformat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ information.

In addition to the [workspace snippet for the repository](/README.md#workspace-configuration), add
the following to your `WORKSPACE` file. This is the initialization logic for the [prebuilt
buildtools](/~https://github.com/keith/buildifier-prebuilt). If you would prefer to build the
[buildtools](/~https://github.com/bazelbuild/buildtools) from source, check out the [build_buildtools
example](/examples/bzlformat/build_buildtools)
buildtools](/~https://github.com/keith/buildifier-prebuilt).

```python
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
Expand Down
2 changes: 1 addition & 1 deletion bzlformat/tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("//bzlformat:defs.bzl", "bzlformat_pkg")
sh_binary(
name = "buildifier",
srcs = ["buildifier.sh"],
data = ["@bazel_starlib_buildtools//:buildifier"],
data = ["@buildifier_prebuilt//buildifier"],
visibility = ["//visibility:public"],
deps = [
"//shlib/lib:arrays",
Expand Down
2 changes: 1 addition & 1 deletion bzlformat/tools/buildifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ arrays_sh="$(rlocation "${arrays_sh_location}")" || \
(echo >&2 "Failed to locate ${arrays_sh_location}" && exit 1)
source "${arrays_sh}"

buildifier_location=bazel_starlib_buildtools/buildifier
buildifier_location=buildifier_prebuilt/buildifier/buildifier
buildifier="$(rlocation "${buildifier_location}")" || \
(echo >&2 "Failed to locate ${buildifier_location}" && exit 1)

Expand Down
2 changes: 1 addition & 1 deletion bzlformat/tools/missing_pkgs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sh_binary(
srcs = ["fix.sh"],
data = [
":find",
"@bazel_starlib_buildtools//:buildozer",
"@buildifier_prebuilt//buildozer",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
2 changes: 1 addition & 1 deletion bzlformat/tools/missing_pkgs/fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source "${common_sh}"

find_missing_pkgs_bin="$(rlocation cgrindel_bazel_starlib/bzlformat/tools/missing_pkgs/find.sh)"

buildozer_location=bazel_starlib_buildtools/buildozer
buildozer_location=buildifier_prebuilt/buildozer/buildozer
buildozer="$(rlocation "${buildozer_location}")" || \
(echo >&2 "Failed to locate ${buildozer_location}" && exit 1)

Expand Down
57 changes: 3 additions & 54 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(":bazel_starlib_buildtools.bzl", "bazel_starlib_buildtools")

def _bazeldoc_dependencies():
maybe(
Expand All @@ -26,53 +25,8 @@ def _prebuilt_buildtools_dependencies():
],
)

bazel_starlib_buildtools(
name = "bazel_starlib_buildtools",
buildozer_target = "@buildifier_prebuilt//buildozer",
buildozer_location = "buildifier_prebuilt/buildozer/buildozer",
buildifier_target = "@buildifier_prebuilt//buildifier",
buildifier_location = "buildifier_prebuilt/buildifier/buildifier",
)

def _compile_from_source_buildtools_dependencies():
maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "930c2c3b5ecc6c9c12615cf5ad93f1cd6e12d0aba862b572e076259970ac3a53",
strip_prefix = "protobuf-3.21.12",
urls = [
"/~https://github.com/protocolbuffers/protobuf/archive/v3.21.12.tar.gz",
],
)

maybe(
http_archive,
name = "com_github_bazelbuild_buildtools",
sha256 = "ca524d4df8c91838b9e80543832cf54d945e8045f6a2b9db1a1d02eec20e8b8c",
strip_prefix = "buildtools-6.0.1",
urls = [
"/~https://github.com/bazelbuild/buildtools/archive/refs/tags/6.0.1.tar.gz",
],
)

bazel_starlib_buildtools(
name = "bazel_starlib_buildtools",
buildozer_target = "@com_github_bazelbuild_buildtools//buildozer",
buildozer_location = "com_github_bazelbuild_buildtools/buildozer/buildozer_/buildozer",
buildifier_target = "@com_github_bazelbuild_buildtools//buildifier",
buildifier_location = "com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier",
)

def bazel_starlib_dependencies(
use_prebuilt_buildtools = True,
use_bazeldoc = True):
def bazel_starlib_dependencies():
"""Declares the dependencies for bazel-starlib.
Args:
use_prebuilt_buildtools: A `bool` specifying whether to use a prebuilt
version of `bazelbuild/buildtools`.
use_bazeldoc: A `bool` specifying whether the `bazeldoc` dependencies
should be loaded.
"""

maybe(
Expand Down Expand Up @@ -105,10 +59,5 @@ def bazel_starlib_dependencies(
],
)

if use_bazeldoc:
_bazeldoc_dependencies()

if use_prebuilt_buildtools:
_prebuilt_buildtools_dependencies()
else:
_compile_from_source_buildtools_dependencies()
_bazeldoc_dependencies()
_prebuilt_buildtools_dependencies()
1 change: 0 additions & 1 deletion doc/shlib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ filegroup(
# MARK: - Documentation Providers

_RULE_NAMES = [
"binary_pkg",
"execute_binary",
]

Expand Down
Loading

0 comments on commit c3fde70

Please sign in to comment.