Skip to content

Support Bzlmod and add rules_scala to bazel-central-registry #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sfc-gh-pbennes opened this issue Mar 16, 2023 · 82 comments · Fixed by #1619 or #1722
Open

Support Bzlmod and add rules_scala to bazel-central-registry #1482

sfc-gh-pbennes opened this issue Mar 16, 2023 · 82 comments · Fixed by #1619 or #1722

Comments

@sfc-gh-pbennes
Copy link

sfc-gh-pbennes commented Mar 16, 2023

Greetings!

It looks like rules_scala isn't part of the Bzlmod effort or added to bazel-central-registry yet. I've opened an issue both here and in https://github.com/bazelbuild/bazel-central-registry to request it: bazelbuild/bazel-central-registry#522

@chrislovecnm
Copy link

Just a note to anyone that starts the work native.register_toolchains is not supported when using bzlmod.

@sluongng
Copy link

@chrislovecnm
Copy link

chrislovecnm commented Jul 11, 2023

@sluongng
Copy link

Yeah you would only want to prepare the toolchain (as a new repository) inside the extension I think. Registering it must be called from the MODULE.bazel file.

So native.register_toolchains call from the extension's starlark does not work, but having the extension create @pythons_hub//:all and then MODULE.bazel calling register_toolchains("@pythons_hub//:all") worked. 👍

@mateuszkuta256
Copy link
Contributor

I prepared a minimal bzlmod support here and gonna split it into a few PRs
TODOs after merging it:

  • write documentation on how to use rules_scala with bzlmod (some properties like SCALA_VERSION will probably be configurable via repo-env)
  • prepare release notes
  • contribute repo to the Bazel Central Registry
  • add tests that the project builds using both WORKSPACE and MODULE.bazel
  • migrate test/external workspaces to blzmod too

@pcj
Copy link
Member

pcj commented Jun 30, 2024

@mateuszkuta256 thanks for getting this started! Any progress updates or blockers?

@mateuszkuta256
Copy link
Contributor

@mateuszkuta256 thanks for getting this started! Any progress updates or blockers?

hi, unfortunately I'm working on other things now and won't continue with this PR in the foreseeable future
I remember this migration was on hold because interfered with 'cross compilation support'
It looks like great progress was done it this area, so maybe someone can already take over the PR

@mbland
Copy link
Contributor

mbland commented Oct 2, 2024

I'd like to take on the task of Bzlmodifying this repo through a series of pull requests.

I've already created a (mostly) working branch in my own fork. Though I saw a couple draft pull requests here, I ended up taking a different approach and got it mostly working. In fact, I did exactly what @sluongng suggested in #1482 (comment). (I didn't notice this comment before just now—I might've read it, but not understood it at the time—but I did study rules_python and rules_go, and ended up doing exactly that.)

There are still issues I need help to address (recorded in some of the commit messages), I didn't strictly maintain WORKSPACE compatibility (fixable), and I only tested against Scala 2.13. But I can start teasing chunks out of it in a methodical fashion, to ensure that I maintain WORKSPACE and cross-version compatibility.

For an example of what it looks like from a client perspective, here's what the MODULE.bazel stanza from my local EngFlow/example repo looks like (as opposed to the current stanza, explanatory comment notwithstanding):

bazel_dep(name = "rules_scala", repo_name = "io_bazel_rules_scala")
local_path_override(
    module_name = "rules_scala",
    path = "../../bazelbuild/rules_scala"
)   

scala_dev_deps = use_extension(
    "@io_bazel_rules_scala//scala/extensions:deps.bzl",
    "scala_deps",
    dev_dependency = True,
)   
scala_dev_deps.toolchains(
    scalatest = True,
)

So if folks are game for me to do this, I'll start carving off pieces as separate pull requests, and we can resolve any outstanding problems in the process.

cc: @BillyAutrey @jayconrod @benjaminp @TheGrizzlyDev

mbland added a commit to mbland/rules_scala that referenced this issue Oct 3, 2024
This begins the Bzlmod compatibility migration by updating Bazel to
version 7.3.2 and adding initial `MODULE.bazel` and `WORKSPACE.bzlmod`
files.

Part of: bazelbuild#1482

Though Bzlmod remains disabled, updating to Bazel 7.3.2 requred updating
or adding the following packages to maintain `WORKSPACE` compatibility.

In `rules_scala_setup()`:

- bazel_skylib: 1.4.1 => 1.7.1
- rules_cc: 0.0.6 => 0.0.10
- rules_java: 5.4.1 => 7.9.0
- rules_proto: 5.3.0-21.7 => 6.0.2

Dev dependencies in `WORKSPACE`:

- com_google_protobuf: 28.2
- rules_pkg: 1.0.1
- rules_jvm_external: 6.4
- com_google_absl: abseil-cpp-20240722.0
- zlib: 1.3.1

Of all of the new, explicit dev dependencies, only `com_google_protobuf`
will be necessary to include in `MODULE.bazel`. The Bzlmod mechanism
will discover these other transitive dev dependencies automatically.

Also removed the `rules_java_extra` repo from `WORKSPACE`, which
appeared unused.

---

Though the current `rules_java` version is 7.12.1, and largely works
with this repo, it requires a few temporary workarounds. Rather than
commit the workarounds, upgrading only to 7.9.0 now seems less crufty.

What follows is a very detailed explanation of what happens with 7.12.1
with Bazel 7.3.2, just to have it on the record.

---

The workaround is to change a few toolchain and macro file targets from
`@bazel_tools//tools/jdk:` to `@rules_java//toolchains:`. This isn't a
terribly bad or invasive workaround, but `@bazel_tools//tools/jdk:` is
clearly the canonical path. Best to keep it that way, lest we build up
technical debt.

Without the workaround, these targets would fail:

- //test/src/main/resources/java_sources:CompiledWithJava11
- //test/src/main/resources/java_sources:CompiledWithJava8
- //test/toolchains:java21_toolchain
- //test:JunitRuntimePlatform
- //test:JunitRuntimePlatform_test_runner
- //test:scala_binary_jdk_11

with this error:

```txt
ERROR: .../external/rules_java_builtin/toolchains/BUILD:254:14:

While resolving toolchains for target
@@rules_java_builtin//toolchains:platformclasspath (096dcc8):

No matching toolchains found for types
@@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type.
```

This appears to be a consequence of both upgrading the Bazel version
from 6.3.0 to 7.3.2 and updating `rules_java` to 7.12.1. The
`rules_java_builtin` repo is part of the `WORKSPACE` prefix that adds
implicit dependencies:

- https://bazel.build/external/migration#builtin-default-deps

This repo was added to 7.0.0-pre.20231011.2 in the following change,
mapped to `@rules_java` within the scope of the `@bazel_tools` repo:

- bazelbuild/bazel: Add rules_java_builtin to the users of Java modules
  bazelbuild/bazel@ff1abb2

This change tried to ensure `rules_java` remained compatible with
earlier Bazel versions. However, it changed all instances of
`@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` to
`//toolchains:bootstrap_runtime_toolchain_type`:

- bazelbuild/rules_java: Make rules_java backwards compatible with Bazel
  6.3.0
  bazelbuild/rules_java@30ecf3f

Bazel has bumped `rules_java` in its `workspace_deps.bzl` from 7.9.0 to
7.11.0, but it's only available as of 8.0.0-pre.20240911.1.

- bazelbuild/bazel: Update rules_java 7.11.1 / java_tools 13.8
  bazelbuild/bazel#23571
  bazelbuild/bazel@f92124a

---

What I believe is happening is, under Bazel 7.3.2 and `rules_java`
7.12.1:

- Bazel creates `rules_java` 7.9.0 as `@rules_java_builtin` in the
  `WORKSPACE` prefix.

- `@bazel_tools` has `@rules_java` mapped to `@rules_java_builtin` when
  initialized during the `WORKSPACE` prefix, during which
  `@bazel_tools//tools/jdk` registers `alias()` targets to
  `@rules_java` toolchain targets. These aliased toolchains specify
  `@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type` in their
  `toolchains` attribute.

- `WORKSPACE` loads `@rules_java` 7.12.1 and registers all its
  toolchains with type
  `@rules_java//toolchains:bootstrap_runtime_toolchain_type`.

- Some `@rules_java` rules explicitly specifying toolchains from
  `@bazel_tools//tools/jdk` can't find them, because the
  `@bazel_tools//tools/jdk` toolchain aliases expect toolchains of type
  `@bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type`.

This has broken other projects in the same way:

- bazelbuild/bazel: [Bazel CI] Downstream project broken by rules_java
  upgrade #23619
  bazelbuild/bazel#23619

These problems don't appear under Bzlmod, and `@rules_java_builtin` was
never required. This is because `WORKSPACE` executes its statements
sequentially, while Bzlmod builds the module dependency graph _before_
instantiating repositories (within module extensions).

It seems a fix is on the way that removes `@rules_java_builtin` from the
`WORKSPACE` prefix, and adds `@rules_java` to the suffix. At this
moment, though, it's not even in a prerelase:

- bazelbuild/bazel: Remove rules_java_builtin in WORKSPACE prefix
  bazelbuild/bazel@7506690

---

Note that the error message matches that from the following resolved
issue, but that issue was for non-Bzlmod child repos when `WORKSPACE`
was disabled.

- bazelbuild/bazel: Undefined @@rules_java_builtin repository with
  --noenable_workspace option
  bazelbuild/bazel#22754
mbland added a commit to mbland/rules_scala that referenced this issue Oct 5, 2024
Related to bazelbuild#1482, bazelbuild#1618, and bazelbuild#1619. Results from the investigation
documented at:

- bazelbuild#1619 (comment)

Updates `_import_paths()` in `scala_proto_aspect.bzl` to handle
differences `ProtoInfo.proto_source_root` and `ProtoInfo.direct_sources`
values between Bazel 6 and Bazel 7.

Without this change, `_import_paths()` emits incorrect values under
Bazel 7, causing targets containing generated `.proto` inputs to fail,
e.g.  `//test/proto3:test_generated_proto`.

See also:

- Fix paths for sibling repository setup and generated .proto files
  bazelbuild/bazel@6c6c196

- The docstring for `ProtoInfo.proto_source_root` in the Bazel sources:
  https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L155-L172

- Remove incompatible_generated_protos_in_virtual_imports
  bazelbuild/bazel@3efaa32

- Comment from: Generated Protos are no longer considered as
  virtual_imports in Bazel 7
  bazelbuild/bazel#21075 (comment)

---

I cherrypicked this commit into bazelbuild#1618. While it fixed the
`//test/proto3` build failure, it does _not_ fix the hanging
scalapb_workers from the ProtoScalaPBRule aspect.

I'll have to investiate further whether than hang is related to Bazel,
rules_proto, com_google_protobuf, or some mixture thereof. Still,
progress!
mbland added a commit to mbland/rules_scala that referenced this issue Oct 5, 2024
Related to bazelbuild#1482, bazelbuild#1618, and bazelbuild#1619. Results from the investigation
documented at:

- bazelbuild#1619 (comment)

Updates `_import_paths()` in `scala_proto_aspect.bzl` to handle
differences `ProtoInfo.proto_source_root` and `ProtoInfo.direct_sources`
values between Bazel 6 and Bazel 7.

Without this change, `_import_paths()` emits incorrect values under
Bazel 7, causing targets containing generated `.proto` inputs to fail,
e.g.  `//test/proto3:test_generated_proto`.

See also:

- Fix paths for sibling repository setup and generated .proto files
  bazelbuild/bazel@6c6c196

- The docstring for `ProtoInfo.proto_source_root` in the Bazel sources:
  https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L155-L172

- Remove incompatible_generated_protos_in_virtual_imports
  bazelbuild/bazel@3efaa32

- Comment from: Generated Protos are no longer considered as
  virtual_imports in Bazel 7
  bazelbuild/bazel#21075 (comment)

---

I cherrypicked this commit into bazelbuild#1618. While it fixed the
`//test/proto3` build failure, it does _not_ fix the hanging
scalapb_workers from the ProtoScalaPBRule aspect.

I'll have to investiate further whether than hang is related to Bazel,
rules_proto, com_google_protobuf, or some mixture thereof. Still,
progress!
mbland added a commit to mbland/rules_scala that referenced this issue Oct 6, 2024
Related to bazelbuild#1482, bazelbuild#1618, and bazelbuild#1619. Results from the investigation
documented at:

- bazelbuild#1619 (comment)

Updates `_import_paths()` in `scala_proto_aspect.bzl` to handle
differences `ProtoInfo.proto_source_root` and `ProtoInfo.direct_sources`
values between Bazel 6 and Bazel 7.

Without this change, `_import_paths()` emits incorrect values under
Bazel 7, causing targets containing generated `.proto` inputs to fail,
e.g.  `//test/proto3:test_generated_proto`.

See also:

- Fix paths for sibling repository setup and generated .proto files
  bazelbuild/bazel@6c6c196

- The docstring for `ProtoInfo.proto_source_root` in the Bazel sources:
  https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L155-L172

- Remove incompatible_generated_protos_in_virtual_imports
  bazelbuild/bazel@3efaa32

- Comment from: Generated Protos are no longer considered as
  virtual_imports in Bazel 7
  bazelbuild/bazel#21075 (comment)

---

I cherrypicked this commit into bazelbuild#1618. While it fixed the
`//test/proto3` build failure, it does _not_ fix the hanging
scalapb_workers from the ProtoScalaPBRule aspect.

I'll have to investiate further whether than hang is related to Bazel,
rules_proto, com_google_protobuf, or some mixture thereof. Still,
progress!
mbland added a commit to mbland/rules_scala that referenced this issue Oct 7, 2024
Related to bazelbuild#1482, bazelbuild#1618, and bazelbuild#1619. Results from the investigation
documented at:

- bazelbuild#1619 (comment)

Updates `_import_paths()` in `scala_proto_aspect.bzl` to handle
differences `ProtoInfo.proto_source_root` and `ProtoInfo.direct_sources`
values between Bazel 6 and Bazel 7.

Without this change, `_import_paths()` emits incorrect values under
Bazel 7, causing targets containing generated `.proto` inputs to fail,
e.g.  `//test/proto3:test_generated_proto`.

See also:

- Fix paths for sibling repository setup and generated .proto files
  bazelbuild/bazel@6c6c196

- The docstring for `ProtoInfo.proto_source_root` in the Bazel sources:
  https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L155-L172

- Remove incompatible_generated_protos_in_virtual_imports
  bazelbuild/bazel@3efaa32

- Comment from: Generated Protos are no longer considered as
  virtual_imports in Bazel 7
  bazelbuild/bazel#21075 (comment)

---

I cherrypicked this commit into bazelbuild#1618. While it fixed the
`//test/proto3` build failure, it does _not_ fix the hanging
scalapb_workers from the ProtoScalaPBRule aspect.

I'll have to investiate further whether than hang is related to Bazel,
rules_proto, com_google_protobuf, or some mixture thereof. Still,
progress!
mbland added a commit to mbland/rules_scala that referenced this issue Oct 7, 2024
Part of bazelbuild#1482.

Splits the last component off of canonical repo names to produce the
expected repo name.

Without Bzlmod, it returns the original name. With Bzlmod enabled, it
avoids generating output like:

    scala_import(
        name = "_main~scala_deps~io_bazel_rules_scala_scala_compiler",
        jars = ["scala-compiler-2.12.18.jar"],
    )

resulting in errors like:

```
ERROR: .../_main~_repo_rules~io_bazel_rules_scala/scala/BUILD:
no such target '@@_main~scala_deps~io_bazel_rules_scala_scala_compiler//:io_bazel_rules_scala_scala_compiler':
target 'io_bazel_rules_scala_scala_compiler' not declared in package ''
defined by .../_main~scala_deps~io_bazel_rules_scala_scala_compiler/BUILD
and referenced by '@@_main~_repo_rules~io_bazel_rules_scala//scala:default_toolchain_scala_compile_classpath_provider'
```

Also fixes the following error when attaching resources from custom repos to
targets under Bzlmod:

```txt
$ bazel test //test/src/main/scala/scalarules/test/resources:all

1) Scala library depending on resources from external resource-only
  jar::allow to load resources(scalarules.test.resources.ScalaLibResourcesFromExternalDepTest)
  java.lang.NullPointerException
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.get(ScalaLibResourcesFromExternalDepTest.scala:17)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$3(ScalaLibResourcesFromExternalDepTest.scala:11)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$2(ScalaLibResourcesFromExternalDepTest.scala:11)
```

Can be replaced with a future bazel-skylib implementation, if accepted
into that repo.

---

We can't rely on the specific canonical repository name format:

> Repos generated by extensions have canonical names in the form of
> `module_repo_canonical_name+extension_name+repo_name`. For extensions
> hosted in the root module, the `module_repo_canonical_name` part is
> replaced with the string `_main`. Note that the canonical name format is
> not an API you should depend on — it's subject to change at any time.
>
> - https://bazel.build/external/extension#repository_names_and_visibility

The change to no longer encode module versions in canonical repo names in
Bazel 7.1.0 is a recent example of Bazel maintainers altering the format:

- bazelbuild/bazel#21316

And the maintainers recently replaced the `~` delimiter with `+` in the
upcoming Bazel 8 release due to build performance issues on Windows:

- bazelbuild/bazel#22865

This function assumes the only valid `repo_name` characters are letters,
numbers, '_', '-', and '.'. It finds the last character not in this set, and
returns the contents of `name` following this character. This is valid so
long as this condition holds:

- https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryName.java#L159-L162
mbland added a commit to mbland/rules_scala that referenced this issue Oct 7, 2024
Part of bazelbuild#1482.

Splits the last component off of canonical repo names to produce the
expected repo name.

Without Bzlmod, it returns the original name. With Bzlmod enabled, it
avoids generating output like:

    scala_import(
        name = "_main~scala_deps~io_bazel_rules_scala_scala_compiler",
        jars = ["scala-compiler-2.12.18.jar"],
    )

resulting in errors like:

```
ERROR: .../_main~_repo_rules~io_bazel_rules_scala/scala/BUILD:
no such target '@@_main~scala_deps~io_bazel_rules_scala_scala_compiler//:io_bazel_rules_scala_scala_compiler':
target 'io_bazel_rules_scala_scala_compiler' not declared in package ''
defined by .../_main~scala_deps~io_bazel_rules_scala_scala_compiler/BUILD
and referenced by '@@_main~_repo_rules~io_bazel_rules_scala//scala:default_toolchain_scala_compile_classpath_provider'
```

Also fixes the following error when attaching resources from custom repos to
targets under Bzlmod:

```txt
$ bazel test //test/src/main/scala/scalarules/test/resources:all

1) Scala library depending on resources from external resource-only
  jar::allow to load resources(scalarules.test.resources.ScalaLibResourcesFromExternalDepTest)
  java.lang.NullPointerException
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.get(ScalaLibResourcesFromExternalDepTest.scala:17)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$3(ScalaLibResourcesFromExternalDepTest.scala:11)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$2(ScalaLibResourcesFromExternalDepTest.scala:11)
```

Can be replaced with a future bazel-skylib implementation, if accepted
into that repo.

---

We can't rely on the specific canonical repository name format:

> Repos generated by extensions have canonical names in the form of
> `module_repo_canonical_name+extension_name+repo_name`. For extensions
> hosted in the root module, the `module_repo_canonical_name` part is
> replaced with the string `_main`. Note that the canonical name format is
> not an API you should depend on — it's subject to change at any time.
>
> - https://bazel.build/external/extension#repository_names_and_visibility

The change to no longer encode module versions in canonical repo names in
Bazel 7.1.0 is a recent example of Bazel maintainers altering the format:

- bazelbuild/bazel#21316

And the maintainers recently replaced the `~` delimiter with `+` in the
upcoming Bazel 8 release due to build performance issues on Windows:

- bazelbuild/bazel#22865

This function assumes the only valid `repo_name` characters are letters,
numbers, '_', '-', and '.'. It finds the last character not in this set, and
returns the contents of `name` following this character. This is valid so
long as this condition holds:

- https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryName.java#L159-L162
liucijus pushed a commit that referenced this issue Oct 8, 2024
Related to #1482, #1618, and #1619. Results from the investigation
documented at:

- #1619 (comment)

Updates `_import_paths()` in `scala_proto_aspect.bzl` to handle
differences `ProtoInfo.proto_source_root` and `ProtoInfo.direct_sources`
values between Bazel 6 and Bazel 7.

Without this change, `_import_paths()` emits incorrect values under
Bazel 7, causing targets containing generated `.proto` inputs to fail,
e.g.  `//test/proto3:test_generated_proto`.

See also:

- Fix paths for sibling repository setup and generated .proto files
  bazelbuild/bazel@6c6c196

- The docstring for `ProtoInfo.proto_source_root` in the Bazel sources:
  https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/starlark/builtins_bzl/common/proto/proto_info.bzl#L155-L172

- Remove incompatible_generated_protos_in_virtual_imports
  bazelbuild/bazel@3efaa32

- Comment from: Generated Protos are no longer considered as
  virtual_imports in Bazel 7
  bazelbuild/bazel#21075 (comment)

---

I cherrypicked this commit into #1618. While it fixed the
`//test/proto3` build failure, it does _not_ fix the hanging
scalapb_workers from the ProtoScalaPBRule aspect.

I'll have to investiate further whether than hang is related to Bazel,
rules_proto, com_google_protobuf, or some mixture thereof. Still,
progress!
@simuons simuons reopened this Oct 8, 2024
mbland added a commit to mbland/rules_scala that referenced this issue Oct 8, 2024
Part of bazelbuild#1482.

Splits the last component off of canonical repo names to produce the
expected repo name.

Without Bzlmod, it returns the original name. With Bzlmod enabled, it
avoids generating output like:

    scala_import(
        name = "_main~scala_deps~io_bazel_rules_scala_scala_compiler",
        jars = ["scala-compiler-2.12.18.jar"],
    )

resulting in errors like:

```
ERROR: .../_main~_repo_rules~io_bazel_rules_scala/scala/BUILD:
no such target '@@_main~scala_deps~io_bazel_rules_scala_scala_compiler//:io_bazel_rules_scala_scala_compiler':
target 'io_bazel_rules_scala_scala_compiler' not declared in package ''
defined by .../_main~scala_deps~io_bazel_rules_scala_scala_compiler/BUILD
and referenced by '@@_main~_repo_rules~io_bazel_rules_scala//scala:default_toolchain_scala_compile_classpath_provider'
```

Also fixes the following error when attaching resources from custom repos to
targets under Bzlmod:

```txt
$ bazel test //test/src/main/scala/scalarules/test/resources:all

1) Scala library depending on resources from external resource-only
  jar::allow to load resources(scalarules.test.resources.ScalaLibResourcesFromExternalDepTest)
  java.lang.NullPointerException
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.get(ScalaLibResourcesFromExternalDepTest.scala:17)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$3(ScalaLibResourcesFromExternalDepTest.scala:11)
    at scalarules.test.resources.ScalaLibResourcesFromExternalDepTest.$anonfun$new$2(ScalaLibResourcesFromExternalDepTest.scala:11)
```

Can be replaced with a future bazel-skylib implementation, if accepted
into that repo.

---

We can't rely on the specific canonical repository name format:

> Repos generated by extensions have canonical names in the form of
> `module_repo_canonical_name+extension_name+repo_name`. For extensions
> hosted in the root module, the `module_repo_canonical_name` part is
> replaced with the string `_main`. Note that the canonical name format is
> not an API you should depend on — it's subject to change at any time.
>
> - https://bazel.build/external/extension#repository_names_and_visibility

The change to no longer encode module versions in canonical repo names in
Bazel 7.1.0 is a recent example of Bazel maintainers altering the format:

- bazelbuild/bazel#21316

And the maintainers recently replaced the `~` delimiter with `+` in the
upcoming Bazel 8 release due to build performance issues on Windows:

- bazelbuild/bazel#22865

This function assumes the only valid `repo_name` characters are letters,
numbers, '_', '-', and '.'. It finds the last character not in this set, and
returns the contents of `name` following this character. This is valid so
long as this condition holds:

- https://github.com/bazelbuild/bazel/blob/7.3.2/src/main/java/com/google/devtools/build/lib/cmdline/RepositoryName.java#L159-L162
@mbland
Copy link
Contributor

mbland commented Oct 11, 2024

A quick update for visibility: I'm very close to having the Bzlmodified rules_scala passing 100% of the tests, down to the last couple of failures:

  • I need to replace the bind() calls from twitter_scrooge with alias() or some such to get test_version.sh to pass.
  • I need to fix the Scala 3.1.2 and Scala 3.3.3 failures for the Scalafmt targets from test/shell/test_cross_build.sh (corresponding to the test3 and library3 test cases in test_scalafmt()).

I also need to get test_lint.sh working again, and update the dt_patches repos for Bzlmod. But the following all pass:

  • test_rules_scala.sh
  • test_reproducibility.sh
  • test_examples.sh
  • test_coverage.sh

Hopefully I can get these fixed up today, and I'll start peeling off the next pull request or two. And thanks to @simuons and @liucijus for reviewing and merging #1619 and #1620 already.

mbland added a commit to mbland/rules_scala that referenced this issue Apr 15, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
@mbland
Copy link
Contributor

mbland commented Apr 16, 2025

Weekly update!

Overview

#1722 hasn't changed...much.

I did just push a new commit this evening after building my #1722 branch with the last_green Bazel release. It updates _aspect_impl() in test/aspect/aspect.bzl to return a new VisitedInfo provider instead of a struct. This fixes //test/aspect:aspect_test when building with the last_green bazel:

  • bazel-a91a6a77171c008598bdee53d144792c95211890-darwin-arm64
$ USE_BAZEL_VERSION=last_green \
  bazel test --test_output=errors //test/aspect:aspect_test

ERROR: testing/toolchain/BUILD:10:27:
  in //test/aspect:aspect.bzl%test_aspect aspect
  on testing_toolchain_deps rule //testing/toolchain:junit_classpath:
  Returning a struct from an aspect implementation function is deprecated.

ERROR: Analysis of target '//testing/toolchain:junit_classpath' failed
ERROR: Analysis of target '//test/aspect:aspect_test' failed; build aborted: Analysis failed

This last_green Bazel build contains bazelbuild/bazel@07cddaf, summarized as "Remove support for returning struct providers from aspects".

That commit is related to:

At any rate, only test/aspect/aspect.bzl required changing, and ./test_all.sh now passes under the last_green Bazel.

Open

Pending branches

These are branches containing changes I'll submit as pull requests after #1722 lands. All of the following are orthogonal to one another and can land in any order:

  • bzlmod-bumps: Updates to Bazel 7.6.1, rules_python 1.3.0, Guava 33.4.6-jre, and Go 1.24.2 (so far).

  • test-src: Adds src/... to the bazel build and bazel test commands in test_rules_scala.sh to follow up on Add Java 24 compatibility #1719 and Cleanup WorkerTest after SecurityManager was removed #1721. Joins the contents lines in WorkerTest.testPersistentWorkerArgsfile using the line.separator system property to fix a test failure on Windows.

  • bzlmod-workflows: Uses the Publish to BCR reusable GitHub workflow. Updates .github/workflows/release.yml and adds publish-to-bcr.yml for publishing to the Bazel Central Registry.

  • replace-scalafmt-default-repo: Removes the scalafmt_config() macro and replaces it with the new @rules_scala_toolchains//scalafmt:config target. Fixes a bug discovered while writing test_dependency_versions.sh (added in the test-dependency-versions branch described below).

  • minimum-dependency-versions: Separates the latest dependency versions that we test against from the minimum required versions for users. Documents these minimum version requirements in README.md.

  • remove-label-wrappers: Removes Label wrappers around target string literals where they're not strictly necessary. See "More repo name insights, plus Label usage" below.

The following branch depends on #1722, replace-scalafmt-default-repo, and minimum-dependency-versions:

  • test-dependency-versions: Adds test_dependency_versions.sh to validate the minimum Bazel and dependency versions required by rules_scala, with and without the precompiled protocol compiler toolchain. Extracts setup, run, and teardown helpers from test/shell/test_bzlmod_helpers.sh into test_runner.sh for reuse by test_dependency_versions.sh. Adds a mechanism to skip tests by prefixing their name with _ to run_test_local and run_test_ci. Adds the RULES_SCALA_TEST_REGEX environment variable to test_runner.sh. Adds documentation for RULES_SCALA_TEST_{ONLY,REGEX,VERBOSE} to the header comment of test_runner.sh. Adds ./test_dependency_versions jobs to .bazelci/presubmit.yml.

Preview branches

As always, if you want to try the functionality before #1722 lands, please only use either my bzlmod or bzlmod-bazel-8 branches. I'll keep merging all of the Pending branches into them, so they remain stable even when the pending branches change. Both contain all the changes described above.

More repo name insights, plus Label usage

In drafting the upcoming post in the Bzlmod blog series, and reflecting on #1696, I gained more insight into:

  • the actual impact of internal references to a repository's own apparent name
  • when one must use a Label with target string literals and when it's optional

This led me to create the remove-label-wrappers branch to remove unnecessary Label instances introduced in #1696. It doesn't have to go in before the next release, or even at all, but it does reveal where Label wrappers are required or not.

The rest of the post will share insights and techniques for fixing canonical repo name related breakages from #1621, #1650, and #1694. Looking forward to publishing it this Thursday, 2025-04-17.

Publish to BCR is now a reusable GitHub Actions workflow

In other news, Publish to BCR has officially switched from a GitHub App to a reusable GitHub Actions workflow. That means I can open a pull request from bzlmod-workflows shortly after #1722 after all.

@rockpunk
Copy link

rockpunk commented Apr 20, 2025

Just wanted to take a moment and thank @mbland for the herculean efforts here. Seriously, this is incredible work. Not only is this a massive amount of work, but the regular comms and clear status updates have been a pleasure to keep up with. I remember suffering from a misplaced sense of self-confidence sometime last year and starting my own bzlmod branch to start hacking on this, only to quickly abandon my efforts. I'm sure I couldn't have been the only one. :) Thank you, Mike, for doing what others could not!

mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also fixes a bug in the failure message of `_default_platform()` in
`protoc_toolchains.bzl` by calling `string.join()` on the
`HOST_CONSTRAINTS` list. (Didn't notice this until building on Windows
ARM64, since there's no such binary `protobuf` release yet.)

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also fixes a bug in the failure message of `_default_platform()` in
`protoc_toolchains.bzl` by calling `string.join()` on the
`HOST_CONSTRAINTS` list. (Didn't notice this until building on Windows
ARM64, since there's no such binary `protobuf` release yet.)

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also fixes a bug in the failure message of `_default_platform()` in
`protoc_toolchains.bzl` by calling `string.join()` on the
`HOST_CONSTRAINTS` list. (Didn't notice this until building on Windows
ARM64, since there's no such binary `protobuf` release yet.)

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 21, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
@mbland
Copy link
Contributor

mbland commented Apr 22, 2025

Just wanted to take a moment and thank @mbland for the herculean efforts here. Seriously, this is incredible work. Not only is this a massive amount of work, but the regular comms and clear status updates have been a pleasure to keep up with. I remember suffering from a misplaced sense of self-confidence sometime last year and starting my own bzlmod branch to start hacking on this, only to quickly abandon my efforts. I'm sure I couldn't have been the only one. :) Thank you, Mike, for doing what others could not!

@rockpunk I appreciates the appreciation. I'm fortunate to have interest in the problem, my employer's encouragement to help solve it, and the support of the maintainers and everyone here. I'm certain others could've done the work, but I'm grateful to have had the support of my employer that perhaps others didn't.

Of course, the work, ever mysterious and important, isn't quite over yet, which brings me to the next...

Weekly update! (And I'm glad to hear someone other than me gets value out of my weekly brain dumps.)

Overview

#1722 has changed a little bit, as described in the sections below.

All pending change branches are up to date with the latest in #1722, as are the bzlmod and bzlmod-bazel-8 branches.

Open

Repo names blog post

As promised, I published Migrating to Bazel Modules (a.k.a. Bzlmod) - Repo Names, Again..., using pull requests from this effort as examples. I also posted an announcement of this post in my blog, which contains a suitable reference that I'd missed in the original post.

Removing unnecessary artifacts

@simuons asked in #1722 (comment) whether there was a better way to reuse protobuf.patch. I'd originally created copies due to paranoia over breaking Windows builds. But of course, after I switched them from copies to symlinks, everything was fine. (Plus, I'm not sure our only Windows CI job uses any of the nested modules anyway.)

While I was at it, I decided that empty WORKSPACE.bzlmod files weren't necessary anymore, given the --noenable_workspace flag in .bazelrc. After removing all of those, #1722 is now only 70 files, of which:

  • 13 are symlinks to protoc/0001-protobuf-19679-rm-protoc-dep.patch
  • 17 are MODULE.bazel files mirroring existing WORKSPACE files

Updated scala_deps module extension API

@simuons asked in #1722 (comment) to replace the boolean flags in scala_deps.toolchains() with individual tag classes. The thought being, each toolchain can potentially define its own set of attributes via its own tag class.

I've since changed the API from this (example from test_version/MODULE.bazel.template):

scala_deps.toolchains(
    scala_proto = True,
    scala_proto_options = ["grpc"],
    scalatest = True,
    specs2 = True,
)

to this:

scala_deps.scala()
scala_deps.scala_proto(
    options = ["grpc"],
)
scala_deps.scalatest()
scala_deps.specs2()

Note that:

  • The instantiation of a tag class, even without arguments, amounts to scala_deps.toolchains(toolchain = True) in the previous API.
  • The builtin Scala toolchain now requires scala_deps.scala(), whereas the previous API defaulted to scala_deps.toolchains(scala = True).
  • scala_deps.scala_proto(options = [...]) replaces scala_deps.toolchains(scala_proto_options = [...]).

All other tag class definitions remain the same, specifically:

  • settings
  • overridden_artifact
  • compiler_srcjar
  • scalafmt
  • twitter_scrooge

Fixing test_bzlmod_macros.sh on Linux and Windows

I noticed that the new test/shell/test_bzlmod_macros.sh tests from #1722 were only running on macOS in CI. I learned that one does not have to escape { in Bash regular expressions on macOS, but one must on Linux and Windows (i.e., \{).

The test then ran and failed under the test_rules_scala_jdk21 and test_rules_scala_win CI jobs. The test_rules_scala_jdk21 fix was trivial. I then updated _print_error_message from test/shell/test_helper.sh to fix the mangled error message on Windows.

That left the problem with local_path_override breaking on Windows. test_bzlmod_macros.sh generated test modules containing local_path_override calls with absolute paths. When Bazel tried to create a symlink from the MSYS2 encoded absolute path, the Windows API threw an error for want of a drive letter. The solution was to pass a relative path instead.

For more details, see the commit messages from #1722.

Reproducing and fixing Linux CI issues

In case this is useful to anyone: I develop on macOS. Until now, most of my changes have been compatible with the Linux CI build. But to really reproduce and validate the above breakage, I wanted to use the same Docker image as the CI build.

It's not available on Docker Hub, so here's how I built the image locally:

git clone [email protected]:bazelbuild/continuous-integration.git
cd continuous-integration/buildkite/docker/ubuntu2004
patch -p1 <ubuntu2004.patch
docker build --target ubuntu2004 -t bazelci/ubuntu2004 .

Here's ubuntu2004.patch:

diff --git i/buildkite/docker/ubuntu2004/Dockerfile w/buildkite/docker/ubuntu2004/Dockerfile
index da1f8845..a1a14b7d 100644
--- i/buildkite/docker/ubuntu2004/Dockerfile
+++ w/buildkite/docker/ubuntu2004/Dockerfile
@@ -55,13 +55,6 @@ RUN apt-get -y update && \
     apt-get -y purge apport && \
     rm -rf /var/lib/apt/lists/*
 
-# Workaround https://bugs.launchpad.net/ubuntu/+source/gcc-9/+bug/2029910
-# TODO: remove when the latest ubuntu:20.04 image has the fix.
-WORKDIR /tempdir
-RUN apt-get -y update && apt-get download libgcc-10-dev
-RUN dpkg -x libgcc-10-dev_10.5.0-1ubuntu1~20.04_amd64.deb .
-RUN cp usr/lib/gcc/x86_64-linux-gnu/10/libtsan_preinit.o /usr/lib/gcc/x86_64-linux-gnu/9/
-RUN rm -rf /tempdir
 WORKDIR /
 
 # Allow using sudo inside the container.
@@ -122,6 +115,11 @@ RUN apt-get -y update && \
     apt-get -y install openjdk-21-jdk-headless && \
     rm -rf /var/lib/apt/lists/*
 
+# https://www.docker.com/blog/understanding-the-docker-user-instruction/
+RUN useradd -m -u 501 -g 20 mbland
+USER mbland
+WORKDIR /home/mbland
+
 ENV JAVA_HOME /usr/lib/jvm/java-21-openjdk-${BUILDARCH}
 
 FROM ubuntu2004 AS ubuntu2004-kythe

Then I would run the following script within the rules_scala directory:

#!/usr/bin/env bash

exec docker run -it --rm --init \
  -v ".:/home/$USER/$(basename "$PWD")" \
  bazelci/ubuntu2004 /bin/bash

Within the container, I could then cd rules_scala and do my business.

BTW, if the rules_scala working directory was created with git-new-workdir, the .git directory will contain symlinks to absolute paths. These are valid on the host, but not inside the container, so git commands will then fail with:

mbland@bbc5d99432fc:~/rules_scala-bzlmod$ git ls-files
fatal: not a git repository (or any parent up to mount point /home/mbland)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

mbland@bbc5d99432fc:~/rules_scala-bzlmod$ ls -l .git/config
lrwxr-xr-x 1 mbland dialout 52 Oct  2  2024 .git/config -> /Users/mbland/src/bazelbuild/rules_scala/.git/config

(Hopefully this'll turn up in some poor, confused person's web searches one day.)

Reproducing and fixing Windows CI issues

I have Windows 11 installed on a personal machine with Parallels Desktop, which I used to resolve the Windows breakages via Git for Windows. I'm not sure which MSYS2 environment the CI build uses, but the Git Bash program from Git for Windows seems close enough.

Side quest: Building on Windows 11 ARM64

While I could run test_bzlmod_macros.sh on my Windows ARM64 build, other tests broke.

First, _default_platform() from protoc/private/protoc_toolchains.bzl failed. No protoc/private/protoc_integrity entry contains an exec_compat matching ["@platforms//os:windows", "@platforms//cpu:aarch64"], since no Windows ARM64 protobuf build currently exists. However, Windows ARM can run x86 binaries. So at some point, I may try to commit the following update to _default_platform():

diff --git a/protoc/private/protoc_toolchains.bzl b/protoc/private/protoc_toolchains.bzl
index 389d88c4..efbe8bf6 100644
--- a/protoc/private/protoc_toolchains.bzl
+++ b/protoc/private/protoc_toolchains.bzl
@@ -17,6 +17,11 @@ def _default_platform():
     for platform, info in PROTOC_BUILDS.items():
         if sorted(info["exec_compat"]) == host_platform:
             return platform
+
+    # Temporary measure until native Windows ARM64 builds exist.
+    if host_platform == ["@platforms//cpu:aarch64", "@platforms//os:windows"]:
+        return "win64"
+
     fail(
         "no protoc build found for host platform with constraints: " +
         ", ".join(HOST_CONSTRAINTS),

(Note: The string.join in the last line is a bug fix from minimum-dependency-versions.)

The trickier problem is rules_python:

$ bazel build //src/...

ERROR: C:/users/msb/_bazel_msb/flxik4tq/external/bazel_tools/tools/jdk/BUILD:134:10:
  While resolving toolchains for target @@bazel_tools//tools/jdk:proguard_whitelister (ada0281):
  No matching toolchains found for types:
  @@bazel_tools//tools/python:toolchain_type

Note that @rules_python//python:toolchain_type is an alias to @bazel_tools//tools/python:toolchain_type.

However, Windows ARM64 support may be forthcoming, given recent movement on:

Pending branches

These are branches containing changes I'll submit as pull requests after #1722 lands. All of the following are orthogonal to one another and can land in any order:

  • bzlmod-bumps: Updates to Bazel 7.6.1, rules_python 1.3.0, Guava 33.4.8-jre, Go 1.24.2, etc.

  • test-src: Adds src/... to the bazel build and bazel test commands in test_rules_scala.sh to follow up on Add Java 24 compatibility #1719 and Cleanup WorkerTest after SecurityManager was removed #1721. Joins the contents lines in WorkerTest.testPersistentWorkerArgsfile using the line.separator system property to fix a test failure on Windows.

  • bzlmod-workflows: Uses the [Publish to BCR][] reusable GitHub workflow. Updates .github/workflows/release.yml and adds publish-to-bcr.yml for publishing to the [Bazel Central Registry][].

  • replace-scalafmt-default-repo: Removes the scalafmt_config() macro and replaces it with the new @rules_scala_toolchains//scalafmt:config target. Fixes a bug discovered while writing test_dependency_versions.sh (added in the test-dependency-versions branch described below).

  • minimum-dependency-versions: Separates the latest dependency versions that we test against from the minimum required versions for users. Documents these minimum version requirements in README.md.

  • remove-label-wrappers: Removes Label wrappers around target string literals where they're not strictly necessary. See "More repo name insights, plus Label usage" below.

The following branch depends on #1722, replace-scalafmt-default-repo, and minimum-dependency-versions:

  • test-dependency-versions: Adds test_dependency_versions.sh to validate the minimum Bazel and dependency versions required by rules_scala, with and without the precompiled protocol compiler toolchain. Extracts setup, run, and teardown helpers from test/shell/test_bzlmod_helpers.sh into test_runner.sh for reuse by test_dependency_versions.sh. Adds a mechanism to skip tests by prefixing their name with _ to run_test_local and run_test_ci. Adds the RULES_SCALA_TEST_REGEX environment variable to test_runner.sh. Adds documentation for RULES_SCALA_TEST_{ONLY,REGEX,VERBOSE} to the header comment of test_runner.sh. Adds ./test_dependency_versions jobs to .bazelci/presubmit.yml.

Preview branches

As always, if you want to try the functionality before #1722 lands, please only use either my bzlmod or bzlmod-bazel-8 branches. I'll keep merging all of the Pending branches into them, so they remain stable even when the pending branches change. Both contain all the changes described above.

@mbland
Copy link
Contributor

mbland commented Apr 26, 2025

D'oh! Didn't mean for #1722 to close this yet. I guess my commit/PR message must've triggered that.

@simuons @liucijus Do you want to reopen this until we publish the module, or open a new issue?

mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also fixes a bug in the failure message of `_default_platform()` in
`protoc_toolchains.bzl` by calling `string.join()` on the
`HOST_CONSTRAINTS` list. (Didn't notice this until building on Windows
ARM64, since there's no such binary `protobuf` release yet.)

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also:

- Fixes a bug in the failure message of `_default_platform()` in
  `protoc_toolchains.bzl` by calling `string.join()` on the
  `HOST_CONSTRAINTS` list.

- Downloads the `win64` build for Windows ARM64.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639

I didn't notice the `_default_platform()` error until building on
Windows ARM64, since there's not yet a binary `protobuf` release for
that platform. The `win64` workaround fixes the actual error, since
Windows ARM64 can execute x86 and x64 binaries:

- https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also:

- Fixes a bug in the failure message of `_default_platform()` in
  `protoc_toolchains.bzl` by calling `string.join()` on the
  `HOST_CONSTRAINTS` list.

- Downloads the `win64` build for Windows ARM64.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639

I didn't notice the `_default_platform()` error until building on
Windows ARM64, since there's not yet a binary `protobuf` release for
that platform. The `win64` workaround fixes the actual error, since
Windows ARM64 can execute x86 and x64 binaries:

- https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also:

- Fixes a bug in the failure message of `_default_platform()` in
  `protoc_toolchains.bzl` by calling `string.join()` on the
  `HOST_CONSTRAINTS` list.

- Downloads the `win64` build for Windows ARM64.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639

I didn't notice the `_default_platform()` error until building on
Windows ARM64, since there's not yet a binary `protobuf` release for
that platform. The `win64` workaround fixes the actual error, since
Windows ARM64 can execute x86 and x64 binaries:

- https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also:

- Fixes a bug in the failure message of `_default_platform()` in
  `protoc_toolchains.bzl` by calling `string.join()` on the
  `HOST_CONSTRAINTS` list.

- Downloads the `win64` build for Windows ARM64.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639

I didn't notice the `_default_platform()` error until building on
Windows ARM64, since there's not yet a binary `protobuf` release for
that platform. The `win64` workaround fixes the actual error, since
Windows ARM64 can execute x86 and x64 binaries:

- https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation
mbland added a commit to mbland/rules_scala that referenced this issue Apr 27, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
@simuons simuons reopened this Apr 28, 2025
mbland added a commit to mbland/rules_scala that referenced this issue Apr 28, 2025
Separates the latest dependency versions that we test against from the
minimum required versions and bumps `protobuf` to v30.2. Part of bazelbuild#1482.

Adds `scala/latest_deps.bzl` for `WORKSPACE` and `deps/latest` for
Bzlmod, used by our internal test repos.

Tests used to validate these dependency versions will land in a future
change.

Also:

- Fixes a bug in the failure message of `_default_platform()` in
  `protoc_toolchains.bzl` by calling `string.join()` on the
  `HOST_CONSTRAINTS` list.

- Downloads the `win64` build for Windows ARM64.

---

This avoids forcing users to upgrade to the latest versions that
`rules_scala` tests against.

Inspired by a thread in the #bzlmod channel of the Bazel Slack workspace
on 2025-01-01 indicating that rules should require the minumum versions
possible:

- https://bazelbuild.slack.com/archives/C014RARENH0/p1743597941149639

I didn't notice the `_default_platform()` error until building on
Windows ARM64, since there's not yet a binary `protobuf` release for
that platform. The `win64` workaround fixes the actual error, since
Windows ARM64 can execute x86 and x64 binaries:

- https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation
mbland added a commit to mbland/rules_scala that referenced this issue Apr 28, 2025
Updates `.github/workflows/release.yml` and adds `publish-to-bcr.yml`
for publishing to the Bazel Central Registry. Part of bazelbuild#1482 broken out
from bazelbuild#1722.

`release.yml` now uses the `release_ruleset` workflow from
`bazel-contrib/.github`, which does everything `release.yml` did
previously and adds SLSA provenance attestations. `release.yml` then
invokes the new `publish-to-bcr.yml` workflow after publishing a
successful release to GitHub. Based on aspect-build/rules_lint#498 and
aspect-build/rules_lint#501. See `.bcr/README.md`.

---

Extracting this from bazelbuild#1722 makes that pull request more focused, and
prevents holding it up based on any discussion around these workflow
changes in particular. It's also unclear if the infrastructure will be
in place to support these workflows before we're ready to publish the
first `rules_scala` module. Though these workflows will supersede the
Publish to BCR app, it may take some time to resolve
slsa-framework/slsa-verifier#840.

aspect-build/rules_lint#508, @alexeagle manually triggered a workflow
run based on these workflows, which generated an attestation:

- https://github.com/aspect-build/rules_lint/actions/runs/14095611671
- https://github.com/aspect-build/rules_lint/attestations/5857159

Here are some examples of GitHub's attestation UI in general:

- https://github.com/aspect-build/rules_lint/attestations

And some relevant GitHub docs:

- https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#using-secrets-in-a-workflow
- https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#secrets-context
- https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow
- https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onworkflow_callsecrets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment