Skip to content

Commit

Permalink
Enable Bzlmod
Browse files Browse the repository at this point in the history
All but finishes bazelbuild#1482, barring the release and publication to the Bazel
Central Registry. Closes bazelbuild#1625.

New `MODULE.bazel` files mirroring existing `WORKSPACE` configurations
and copies of the `protobuf` toolchainization patch comprise the bulk of
the commit. The empty `WORKSPACE.bzlmod` files ensure that Bzlmod won't
evaluate the existing `WORKSPACE` files.

Reenables the `last_green` Bazel build in CI. Other than that, these new
files comprise the most significant part of the change:

- `.bazelignore`
- `.bcr/*`
- `scala/extensions/config.bzl`
- `scala/extensions/deps.bzl`
- `scala/private/extensions/dev_deps.bzl`
- `scala/private/macros/bzlmod.bzl`

`config.bzl`, `deps.bzl`, and `dev_deps.bzl` are thoroughly tested by
existing tests. These new test files thoroughly test the helpers from
`scala/private/macros/bzlmod.bzl` specifically:

- scala/private/macros/test/...
- test/shell/test_bzlmod_macros.sh

The pattern employed throughout the new module extensions is explained
in the `scala/private/macros/bzlmod.bzl` docstring.

Adding `test/shell/test_bzlmod_macros.sh` also precipitated adding a new
`assert_matches` helper to `test/shell/test_helper.sh`.
`test/shell/test_helper.sh` also introduces a mechanism for
automatically finding and skipping tests, documented in the comment at
the bottom of the file.

"Publish to BCR" configuration in the `.bcr` directory comes from:

- https://github.com/bazel-contrib/publish-to-bcr/tree/main/templates

The bazel-contrib/publish-to-bcr README contains further guidance on
configuring the app.

---

This change enables Bazel 7 and 8 users to migrate their `rules_scala`
dependency from `WORKSPACE` to `MODULE.bazel` whenever they're ready.

Once the Publish to BCR GitHub app is ready, we can use it to publish a
new version to https://registry.bazel.build/. At that point, we can
close bazelbuild#1482.
  • Loading branch information
mbland committed Mar 5, 2025
1 parent 3615365 commit 53a9c26
Show file tree
Hide file tree
Showing 79 changed files with 3,547 additions and 31 deletions.
10 changes: 4 additions & 6 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ tasks:
# Install xmllint
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
- "./test_rules_scala.sh"
# Switch `last_rc` to `last_green` once Bzlmod lands.
# https://github.com/bazelbuild/rules_scala/issues/1482
test_rules_scala_linux_last_rc:
name: "./test_rules_scala (last_rc Bazel)"
test_rules_scala_linux_last_green:
name: "./test_rules_scala (last_green Bazel)"
platform: ubuntu2004
bazel: last_rc
bazel: last_green
shell_commands:
# Install xmllint
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
- echo "build --enable_workspace" >> .bazelrc
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_rc Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_green Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
test_rules_scala_macos:
name: "./test_rules_scala"
platform: macos
Expand Down
19 changes: 19 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Remove once the following is fixed:
# - bazelbuild/bazel: Loading top-level targets in local_path_override modules
# in child directory breaks the build #22208
# https://github.com/bazelbuild/bazel/issues/22208
dt_patches/compiler_sources
dt_patches/test_dt_patches
dt_patches/test_dt_patches_user_srcjar
examples/crossbuild
examples/overridden_artifacts
examples/scala3
examples/semanticdb
examples/testing/multi_frameworks_toolchain
examples/testing/scalatest_repositories
examples/testing/specs2_junit_repositories
test/proto_cross_repo_boundary/repo
test_cross_build
third_party/test/example_external_workspace
third_party/test/new_local_repo
third_party/test/proto
5 changes: 2 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Switch to --noenable_workspace when Bzlmod lands.
# https://github.com/bazelbuild/rules_scala/issues/1482
common --enable_workspace --noenable_bzlmod
# Remove once Bazel 8 becomes the default supported version.
common --noenable_workspace

# Remove once proto toolchainization becomes the default
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
Expand Down
Empty file added .bcr/config.yml
Empty file.
20 changes: 20 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"homepage": "https://github.com/bazelbuild/rules_scala",
"maintainers": [
{
"name": "Simonas Pinevičius",
"email": "simonas.pinevicius@gmail.com",
"github": "simuons"
},
{
"name": "Vaidas Pilkauskas",
"email": "vaidas.pilkauskas@gmail.com",
"github": "liucijus"
}
],
"repository": [
"github:bazelbuild/rules_scala"
],
"versions": [],
"yanked_versions": {}
}
14 changes: 14 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# We recommend included a bcr test workspace that exercises your ruleset with bzlmod.
# For an example, see https://github.com/aspect-build/bazel-lib/tree/main/e2e/bzlmod.
bcr_test_module:
module_path: "examples/crossbuild"
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel: [6.x, 7.x]
tasks:
run_tests:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
test_targets:
- "//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
}
14 changes: 12 additions & 2 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ set -o errexit -o nounset -o pipefail

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
PREFIX="rules_scala-${TAG:1}"
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG:1}"
PREFIX="rules_scala-${VERSION}"
ARCHIVE="rules_scala-$TAG.tar.gz"
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

cat << EOF
## Using Bzlmod
Paste this snippet into your \`MODULE.bazel\` file:
\`\`\`starlark
# Set \`repo_name = "io_bazel_rules_scala"\` if you still need it.
bazel_dep(name = "rules_scala", version = "${VERSION}")
\`\`\`
## Using WORKSPACE
Paste this snippet into your \`WORKSPACE\` file:
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ test/semanticdb/tempsrc

# From scripts/create_repository.py
repository-artifacts.json

# Until it settles down
**/MODULE.bazel.lock

# Used by some tests, but can also be used for local experimentation.
tmp/
Loading

0 comments on commit 53a9c26

Please sign in to comment.