Skip to content

Commit

Permalink
chore: introduce strict bzlmod by adding WORKSPACE.bzlmod (#238)
Browse files Browse the repository at this point in the history
- Add `WORKSPACE.bzlmod` to all workspaces to ensure that the strict
bzlmod support was enabled.
- Disable all documentation generation and tests until
bazelbuild/bazel#14140 is fixed.
- Update CI to execute tidy and test with and without bzlmod.
- Fix warning in `sorted_genquery.bzl`.

Related to #195.
  • Loading branch information
cgrindel authored Mar 9, 2023
1 parent 93cfa28 commit 56de025
Show file tree
Hide file tree
Showing 22 changed files with 828 additions and 726 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ jobs:
fail-fast: false
matrix:
runner: [macos-12, ubuntu-22.04]
enable_bzlmod: [true, false]
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v3
- uses: cgrindel/gha_set_up_bazel@v1
with:
repo_name: bazel-starlib
- uses: ./.github/actions/configure_bzlmod
with:
enabled: ${{ matrix.enable_bzlmod }}
- uses: ./.github/actions/tidy_and_test
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 7 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bazel_dep(
bazel_dep(
name = "gazelle",
version = "0.29.0",
repo_name = "bazel_gazelle",
)
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(
Expand All @@ -28,8 +29,13 @@ bazel_dep(
name = "buildifier_prebuilt",
version = "6.0.0.1",
)
bazel_dep(name = "platforms", version = "0.0.6")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(name = "go_sdk")
use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@bazel_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
Expand Down
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file marks the root of the Bazel workspace.
# See MODULE.bazel for dependencies and setup.

workspace(name = "cgrindel_bazel_starlib")

load("//:deps.bzl", "bazel_starlib_dependencies")
Expand Down
23 changes: 23 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# workspace(name = "cgrindel_bazel_starlib")

# MARK: - Integration Testing

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

http_archive(
name = "contrib_rules_bazel_integration_test",
sha256 = "6263b8d85a125e1877c463bf4d692bebc2b6479c924f64a3d45c81fbfbc495df",
strip_prefix = "rules_bazel_integration_test-0.10.3",
urls = [
"http://github.com/bazel-contrib/rules_bazel_integration_test/archive/v0.10.3.tar.gz",
],
)

load("@contrib_rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")

bazel_integration_test_rules_dependencies()

load("@contrib_rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries")
load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS")

bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS)
232 changes: 117 additions & 115 deletions doc/bazeldoc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,115 +1,117 @@
load(
"//bazeldoc:defs.bzl",
"doc_for_provs",
"write_file_list",
"write_header",
doc_providers = "providers",
)
load("//bzlformat:defs.bzl", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

filegroup(
name = "doc_files",
srcs = glob(["*.md"]) + [
# A doc file has a reference to this file.
"BUILD.bazel",
],
visibility = ["//:markdown_test_visibility"],
)

# Lovingly inspired by
# https://github.com/bazelbuild/rules_swift/blob/021c11b1d578ffba547140eb24854cdfe74c794f/doc/BUILD.bazel#L3

# MARK: - Documentation Declarations

_API_SRCS = [
"doc_utilities",
"providers",
]

_STARDOC_INPUT = "//bazeldoc:defs.bzl"

_DOC_DEPS = [
"//bazeldoc:defs",
]

_API_DOC_PROVIDERS = [
doc_providers.create(
name = name,
stardoc_input = _STARDOC_INPUT,
symbols = [name],
deps = _DOC_DEPS,
)
for name in _API_SRCS
]

_BUILD_RULES_PROV = doc_providers.create(
name = "build_rules_overview",
stardoc_input = _STARDOC_INPUT,
symbols = [
"doc_for_provs",
"stardoc_for_prov",
"stardoc_for_provs",
"write_doc",
"write_file_list",
"write_header",
],
deps = _DOC_DEPS,
)

_ALL_DOC_PROVIDERS = [
_BUILD_RULES_PROV,
doc_providers.create(
name = "api",
is_stardoc = False,
stardoc_input = _STARDOC_INPUT,
deps = _DOC_DEPS,
),
] + _API_DOC_PROVIDERS

# MARK: - Special Case api.md

write_file_list(
name = "api_doc",
out = "api.md_",
doc_provs = _API_DOC_PROVIDERS,
header_content = [
"# Documentation API",
"",
"The APIs described below are used by ",
"[the build rules](build_rules_overview.md) to facilitate the ",
"generation of the Starlark documentation.",
"",
],
)

# MARK: - Headers

write_header(
name = "build_rules_overview_header",
header_content = [
"# Build Rules",
"",
"The macros described below are used to generate, test and copy ",
"Starlark documentation.",
],
symbols = _BUILD_RULES_PROV.symbols,
)

# Write the API headers
[
write_header(
name = doc_prov.header_label,
out = doc_prov.header_basename,
header_content = [
"# `{name}` API".format(name = doc_prov.name),
],
)
for doc_prov in _API_DOC_PROVIDERS
if doc_prov.is_stardoc
]

doc_for_provs(
doc_provs = _ALL_DOC_PROVIDERS,
)
# GH195: Enable once stardoc supports repo mapping.

# load(
# "//bazeldoc:defs.bzl",
# "doc_for_provs",
# "write_file_list",
# "write_header",
# doc_providers = "providers",
# )
# load("//bzlformat:defs.bzl", "bzlformat_pkg")

# bzlformat_pkg(name = "bzlformat")

# filegroup(
# name = "doc_files",
# srcs = glob(["*.md"]) + [
# # A doc file has a reference to this file.
# "BUILD.bazel",
# ],
# visibility = ["//:markdown_test_visibility"],
# )

# # Lovingly inspired by
# # https://github.com/bazelbuild/rules_swift/blob/021c11b1d578ffba547140eb24854cdfe74c794f/doc/BUILD.bazel#L3

# # MARK: - Documentation Declarations

# _API_SRCS = [
# "doc_utilities",
# "providers",
# ]

# _STARDOC_INPUT = "//bazeldoc:defs.bzl"

# _DOC_DEPS = [
# "//bazeldoc:defs",
# ]

# _API_DOC_PROVIDERS = [
# doc_providers.create(
# name = name,
# stardoc_input = _STARDOC_INPUT,
# symbols = [name],
# deps = _DOC_DEPS,
# )
# for name in _API_SRCS
# ]

# _BUILD_RULES_PROV = doc_providers.create(
# name = "build_rules_overview",
# stardoc_input = _STARDOC_INPUT,
# symbols = [
# "doc_for_provs",
# "stardoc_for_prov",
# "stardoc_for_provs",
# "write_doc",
# "write_file_list",
# "write_header",
# ],
# deps = _DOC_DEPS,
# )

# _ALL_DOC_PROVIDERS = [
# _BUILD_RULES_PROV,
# doc_providers.create(
# name = "api",
# is_stardoc = False,
# stardoc_input = _STARDOC_INPUT,
# deps = _DOC_DEPS,
# ),
# ] + _API_DOC_PROVIDERS

# # MARK: - Special Case api.md

# write_file_list(
# name = "api_doc",
# out = "api.md_",
# doc_provs = _API_DOC_PROVIDERS,
# header_content = [
# "# Documentation API",
# "",
# "The APIs described below are used by ",
# "[the build rules](build_rules_overview.md) to facilitate the ",
# "generation of the Starlark documentation.",
# "",
# ],
# )

# # MARK: - Headers

# write_header(
# name = "build_rules_overview_header",
# header_content = [
# "# Build Rules",
# "",
# "The macros described below are used to generate, test and copy ",
# "Starlark documentation.",
# ],
# symbols = _BUILD_RULES_PROV.symbols,
# )

# # Write the API headers
# [
# write_header(
# name = doc_prov.header_label,
# out = doc_prov.header_basename,
# header_content = [
# "# `{name}` API".format(name = doc_prov.name),
# ],
# )
# for doc_prov in _API_DOC_PROVIDERS
# if doc_prov.is_stardoc
# ]

# doc_for_provs(
# doc_provs = _ALL_DOC_PROVIDERS,
# )
Loading

0 comments on commit 56de025

Please sign in to comment.