@@ -495,6 +495,80 @@ extension. However, you must register explicitly in your `MODULE.bazel` file any
495495toolchains that you want to take precedence over the toolchains configured by
496496` scala_deps ` .
497497
498+ ### ` @io_bazel_rules_scala_config ` is now ` @rules_scala_config `
499+
500+ Since ` @io_bazel_rules_scala ` is no longer hardcoded in ` rules_scala ` internals,
501+ we've shortened ` @io_bazel_rules_scala_config ` to ` @rules_scala_config ` . This
502+ shouldn't affect most users, but it may break some builds using
503+ ` @io_bazel_rules_scala_config ` to define custom [ cross-compilation targets] (
504+ ./docs/cross-compilation.md).
505+
506+ If you can't fix uses of ` @io_bazel_rules_scala_config ` in your own project
507+ immediately, you can remap ` @rules_scala_config ` via [ ` use_repo() ` ] :
508+
509+ [ `use_repo()` ] : https://bazel.build/rules/lib/globals/module#use_repo
510+
511+ ``` py
512+ scala_config = use_extension(
513+ " @rules_scala//scala/extensions:config.bzl" ,
514+ " scala_config" ,
515+ )
516+
517+ use_repo(scala_config, io_bazel_rules_scala_config = " rules_scala_config" )
518+ ```
519+
520+ If any of your dependencies still require ` @io_bazel_rules_scala_config ` , use
521+ one of the following mechanisms to override it with ` @rules_scala_config ` :
522+
523+ #### Bzlmod
524+
525+ For [ ` bazel_dep() ` ] [ ] dependencies, use [ ` override_repo() ` ] [ ] to
526+ override ` @io_bazel_rules_scala_config ` with ` @rules_scala_config ` :
527+
528+ ``` py
529+ bazel_dep(name = " foo" , version = " 1.0.0" )
530+
531+ foo_ext = use_extension(" @foo//:ext.bzl" , " foo_ext" )
532+ override_repo(foo_ext, io_bazel_rules_scala_config = " rules_scala_config" )
533+ ```
534+
535+ [ `bazel_dep()` ] : https://bazel.build/rules/lib/globals/module#bazel_dep
536+ [ `override_repo()` ] : https://bazel.build/rules/lib/globals/module#override_repo
537+
538+ For [ ` archive_override() ` ] [ ] and [ ` git_override() ` ] [ ] dependencies, use the
539+ ` repo_mapping ` attribute passed through to the underlying [ ` http_archive() ` ] [ ]
540+ and [ ` git_repository() ` ] [ ] rules:
541+
542+ ``` py
543+ archive_override(
544+ ...
545+ repo_mapping = {
546+ " @io_bazel_rules_scala_config" : " @rules_scala_config" ,
547+ }
548+ ...
549+ )
550+ ```
551+
552+ [ `archive_override()` ] : https://bazel.build/rules/lib/globals/module#archive_override
553+ [ `git_override()` ] : https://bazel.build/rules/lib/globals/module#git_override
554+ [ `http_archive()` ] : https://bazel.build/rules/lib/repo/http#http_archive-repo_mapping
555+ [ `git_repository()` ] : https://bazel.build/rules/lib/repo/git#git_repository-repo_mapping
556+
557+ #### ` WORKSPACE `
558+
559+ Use the ` repo_mapping ` attribute of [ ` http_archive() ` ] [ ] or
560+ [ ` git_repository() ` ] [ ] :
561+
562+ ``` py
563+ http_archive(
564+ ...
565+ repo_mapping = {
566+ " @io_bazel_rules_scala_config" : " @rules_scala_config" ,
567+ }
568+ ...
569+ )
570+ ```
571+
498572### Bzlmod configuration (coming soon!)
499573
500574The upcoming Bzlmod implementation will funnel through the ` scala_toolchains() `
@@ -565,7 +639,7 @@ now, as there's not yet a corresponding [`toolchain_type()`](
565639https://bazel.build/versions/6.1.0/reference/be/platform#toolchain_type ) target
566640in ` @rules_java ` .
567641
568- ### Builtin repositories no longer visible without ` use_repo() ` under Bzlmod
642+ ### Builtin repositories no longer visible by default under Bzlmod
569643
570644Under Bzlmod, repos are only visible to the module extension that creates them,
571645unless the ` MODULE.bazel ` file brings them into scope with
@@ -587,9 +661,12 @@ setup_scala_toolchain(
587661)
588662```
589663
590- This worked under ` WORKSPACE ` , but broke under Bzlmod, the error message
591- indicating that the builtin ` @org_scala_sbt_compiler_interface ` toolchain jar
592- isn't visible:
664+ ` setup_scala_toolchains ` is a macro that can take user specified classpath
665+ targets as described in [ docs/scala_toolchain.md] ( ./docs/scala_toolchain.md ) .
666+ Without explicit ` *_classpath ` or ` *_deps ` arguments, ` setup_scala_toolchain() `
667+ defaults to using dependency repositories generated by ` rules_scala ` itself.
668+ This worked under ` WORKSPACE ` , but breaks under Bzlmod, because the builtin
669+ toolchain dependency repos are no longer in the project's scope by default:
593670
594671``` txt
595672ERROR: no such package
@@ -600,20 +677,12 @@ ERROR: no such package
600677 No repository visible as '@org_scala_sbt_compiler_interface_3_3_5'
601678```
602679
603- ` setup_scala_toolchains ` is a macro that can take user specified classpath
604- targets as described in [ docs/scala_toolchain.md] ( ./docs/scala_toolchain.md ) .
605- Otherwise, it _ generates new classpath targets_ using the builtin ` rules_scala `
606- repositories, but these repositories are no longer in the global scope, causing
607- the breakage. (A big part of the Bzlmodification work involved enabling
608- ` rules_scala ` to generate and register toolchains _ without_ forcing users to
609- bring their dependencies into scope.)
610-
611- One way to fix this specific problem is to call ` use_repo ` for every such
612- repository needed by the toolchain. Another fix, in this case, is to [ use
613- ` scala_toolchain ` directly instead] (
614- https://github.com/michalbogacz/scala-bazel-monorepo/blob/2cac860f386dcaa1c3be56cd25a84b247d335743/BUILD.bazel ).
615- Its underlying ` BUILD ` rule uses the builtin toolchain dependencies via existing
616- targets visible within ` rules_scala ` , without forcing users to import them:
680+ In this case, where the toolchain only sets different compiler options, the best
681+ fix is to [ use ` scala_toolchain ` directly instead] [ scala_tc_direct ] . Its
682+ underlying ` BUILD ` rule uses builtin toolchain dependencies via existing targets
683+ visible within ` rules_scala ` , without forcing users to import them:
684+
685+ [ scala_tc_direct ] : https://github.com/michalbogacz/scala-bazel-monorepo/blob/2cac860f386dcaa1c3be56cd25a84b247d335743/BUILD.bazel
617686
618687``` py
619688load(" @rules_scala//scala:scala_toolchain.bzl" , " scala_toolchain" )
@@ -635,6 +704,12 @@ toolchain(
635704)
636705```
637706
707+ A big part of the Bzlmodification work involved enabling ` rules_scala ` to
708+ generate and register toolchains _ without_ forcing users to bring their
709+ dependencies into scope. However, another way to fix this specific problem is to
710+ call ` use_repo ` for every builtin repository needed by the
711+ ` setup_scala_toolchain() ` call.
712+
638713## Breaking changes coming in ` rules_scala ` 8.x
639714
640715__ The main objective of 8.x will be to enable existing users to migrate to Bazel
0 commit comments