-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves the `toolchain` targets for `//scala:toolchain_type` to a new `@io_bazel_rules_scala_toolchains` repository as a step towards Bzlmodification. Part of #1482. Instantiating toolchains in their own repository enables module extensions to define the the repositories required by those toolchains within the extension's own namespace. Bzlmod users can then register the toolchains from this repository without having to import all the toolchains' dependencies into their own namespace via `use_repo()`. --- The `scala_toolchains_repo()` macro wraps the underlying repository rule and assigns it the standard name `io_bazel_rules_scala_toolchains`. Right now it's only instantiating the main Scala toolchain via the default `scala = True` parameter. Future changes will expand this macro and repository rule with more boolean parameters to instantiate other toolchains, specifically: - `scalatest` - `junit` - `specs2` - `twitter_scrooge` - `jmh` - `scala_proto` and `scala_proto_enable_all_options` - `testing` (includes all of `scalatest`, `junit`, and `specs2`) - `scalafmt` --- `WORKSPACE` users will now have to import and call the `scala_toolchains_repo()` macro to instantiate `@io_bazel_rules_scala_toolchains`. ```py load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config") scala_config() load( "//scala:scala.bzl", "rules_scala_setup", "rules_scala_toolchain_deps_repositories", "scala_toolchains_repo", ) rules_scala_setup() rules_scala_toolchain_deps_repositories() scala_toolchains_repo() register_toolchains("@io_bazel_rules_scala_toolchains//...:all") ``` This is what the corresponding `MODULE.bazel` setup would look like: ```py module(name = "rules_scala", version = "7.0.0") scala_config = use_extension( "//scala/extensions:config.bzl", "scala_config" ) scala_config.settings(scala_version = "2.13.14") scala_deps = use_extension("//scala/extensions:deps.bzl", "scala_deps") scala_deps.toolchains() ``` The `register_toolchains()` call in `WORKSPACE` isn't strictly required at this point, but is recommended. However, all the `WORKSPACE` files in this repo already register their required toolchains using existing macros, which have been updated in this change. In fact, calling `register_toolchains()` right after `scala_toolchains_repo()` as shown above breaks two tests that depend on the existing `WORKSPACE` toolchain registration: - `test_compilation_fails_with_plus_one_deps_undefined` from `test/shell/test_compilation.sh` depends on `scala_register_unused_deps_toolchains()` setting up its toolchain to resolve first. `//scala:unused_dependency_checker_error_toolchain` sets the `scala_toolchain()` parameters `dependency_tracking_method = "ast-plus"` and `unused_dependency_checker_mode = "error"`, and the `@io_bazel_rules_scala_toolchains//scala` toolchains don't. - `test_scala_binary_allows_opt_in_to_use_of_argument_file_in_runner_for_improved_performance` from `test/shell/test_scala_binary.sh` depends on the `use_argument_file_in_runner` parameter of `scala_toolchain` being `False`. This is the default, but the `@io_bazel_rules_scala_toolchains//scala` toolchains explicitly set this to `True` instead. In the Bzlmod case, the `register_toolchains()` call isn't necessary at all. This is because `@io_bazel_rules_scala_toolchains` includes one package per set of toolchains, and the rules_scala `MODULE.bazel` calls `register_toolchains("@io_bazel_rules_scala_toolchains//...:all")`. This will automatically register all configured rules_scala toolchains, while allowing users to override any of them using `register_toolchains()` in their own `MODULE.bazel` files. Technically, the `scala_deps.toolchains()` call isn't required when only using the default `scala = True` parameter; the rules_scala `MODULE.bazel` will instantiate this automatically, too.
- Loading branch information
Showing
24 changed files
with
202 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""Creates a repo containing Scala toolchain packages""" | ||
|
||
def _scala_toolchains_repo_impl(repository_ctx): | ||
repo_attr = repository_ctx.attr | ||
format_args = { | ||
"rules_scala_repo": Label("//:all").repo_name, | ||
} | ||
toolchains = {} | ||
|
||
if repo_attr.scala: | ||
toolchains["scala"] = _SCALA_TOOLCHAIN_BUILD | ||
|
||
if len(toolchains) == 0: | ||
fail("no toolchains specified") | ||
|
||
for pkg, build in toolchains.items(): | ||
repository_ctx.file( | ||
pkg + "/BUILD", | ||
content = build.format(**format_args), | ||
executable = False, | ||
) | ||
|
||
_scala_toolchains_repo = repository_rule( | ||
implementation = _scala_toolchains_repo_impl, | ||
attrs = { | ||
"scala": attr.bool(default = True), | ||
}, | ||
) | ||
|
||
def scala_toolchains_repo(**kwargs): | ||
_scala_toolchains_repo( | ||
name = "io_bazel_rules_scala_toolchains", | ||
**kwargs | ||
) | ||
|
||
_SCALA_TOOLCHAIN_BUILD = """ | ||
load( | ||
"@@{rules_scala_repo}//scala/private:macros/setup_scala_toolchain.bzl", | ||
"default_deps", | ||
"setup_scala_toolchain", | ||
) | ||
load("@@{rules_scala_repo}//scala:providers.bzl", "declare_deps_provider") | ||
load("@@{rules_scala_repo}//scala:scala_cross_version.bzl", "version_suffix") | ||
load( | ||
"@io_bazel_rules_scala_config//:config.bzl", | ||
"SCALA_VERSION", | ||
"SCALA_VERSIONS", | ||
) | ||
[ | ||
setup_scala_toolchain( | ||
name = "toolchain" + version_suffix(scala_version), | ||
scala_version = scala_version, | ||
use_argument_file_in_runner = True, | ||
) | ||
for scala_version in SCALA_VERSIONS | ||
] | ||
[ | ||
declare_deps_provider( | ||
name = deps_id + "_provider", | ||
deps_id = deps_id, | ||
visibility = ["//visibility:public"], | ||
deps = default_deps(deps_id, SCALA_VERSION), | ||
) | ||
for deps_id in [ | ||
"scala_xml", | ||
"parser_combinators", | ||
"scala_compile_classpath", | ||
"scala_library_classpath", | ||
"scala_macro_classpath", | ||
"semanticdb", | ||
] | ||
] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.