diff --git a/WORKSPACE b/WORKSPACE index 46ee3191..ae4d426e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -119,7 +119,7 @@ load("@annex//:defs.bzl", annex_pinned_maven_install = "pinned_maven_install") annex_pinned_maven_install() -scala_register_toolchains() +scala_register_toolchains(default_scala_toolchain_name = "zinc_2_13") # Scala 2.12 diff --git a/rules/register_toolchain.bzl b/rules/register_toolchain.bzl index 1cf69d91..9f8112dd 100644 --- a/rules/register_toolchain.bzl +++ b/rules/register_toolchain.bzl @@ -188,7 +188,7 @@ def _make_register_toolchain(configuration_rule): native.config_setting( name = "{}-setting".format(name), flag_values = { - "@rules_scala_annex//rules/scala:scala-toolchain": name, + "@rules_scala_annex_scala_toolchain//:scala-toolchain": name, }, ) @@ -210,13 +210,13 @@ def _scala_toolchain_transition_impl(_, attr): return {} return { - "//rules/scala:scala-toolchain": attr.scala_toolchain_name, + "@rules_scala_annex_scala_toolchain//:scala-toolchain": attr.scala_toolchain_name, } scala_toolchain_transition = transition( implementation = _scala_toolchain_transition_impl, inputs = [], - outputs = ["//rules/scala:scala-toolchain"], + outputs = ["@rules_scala_annex_scala_toolchain//:scala-toolchain"], ) scala_toolchain_transition_attributes = { diff --git a/rules/scala/BUILD b/rules/scala/BUILD index b377ccfe..00c38410 100644 --- a/rules/scala/BUILD +++ b/rules/scala/BUILD @@ -1,17 +1,9 @@ -load("@bazel_skylib//rules:common_settings.bzl", "string_setting") - filegroup( name = "bzl", srcs = glob(["**/*.bzl"]), visibility = ["//rules:__pkg__"], ) -string_setting( - name = "scala-toolchain", - build_setting_default = "zinc_3", - visibility = ["//visibility:public"], -) - toolchain_type( name = "toolchain_type", visibility = ["//visibility:public"], diff --git a/rules/scala/workspace.bzl b/rules/scala/workspace.bzl index f7a4ad0e..a9a30550 100644 --- a/rules/scala/workspace.bzl +++ b/rules/scala/workspace.bzl @@ -79,11 +79,38 @@ def scala_repositories( ], ) -def scala_register_toolchains(*args): +def _toolchain_configuration_repository_impl(repository_ctx): + repository_ctx.file( + "BUILD", + """\ +load("@bazel_skylib//rules:common_settings.bzl", "string_setting") + +string_setting( + name = "scala-toolchain", + build_setting_default = "{}", + visibility = ["//visibility:public"], +) +""".format(repository_ctx.attr.default_scala_toolchain_name), + ) + +_toolchain_configuration_repository = repository_rule( + attrs = { + "default_scala_toolchain_name": attr.string(mandatory = True), + }, + doc = "Defines a setting for the Scala toolchain to use. This is done in a separate repository so we can provide the default dynamically.", + implementation = _toolchain_configuration_repository_impl, +) + +def scala_register_toolchains(default_scala_toolchain_name, toolchains = []): + _toolchain_configuration_repository( + name = "rules_scala_annex_scala_toolchain", + default_scala_toolchain_name = default_scala_toolchain_name, + ) + native.register_toolchains( "//src/main/scala:bootstrap_2_13", "//src/main/scala:bootstrap_3", "//src/main/scala:zinc_2_13", "//src/main/scala:zinc_3", - *args, + *toolchains ) diff --git a/tests/WORKSPACE b/tests/WORKSPACE index 6c327f45..851ccdfb 100644 --- a/tests/WORKSPACE +++ b/tests/WORKSPACE @@ -94,19 +94,22 @@ load("@annex//:defs.bzl", annex_pinned_maven_install = "pinned_maven_install") annex_pinned_maven_install() scala_register_toolchains( - "@@//dependencies/indirect:test_zinc_2_13_direct_deps_off", - "@@//dependencies/indirect:test_zinc_2_13_used_deps_off", - "@@//plugins/kind-projector:test_zinc_2_13_with_kind_projector", - "@@//plugins/semanticdb:scala_2_13_with_semanticdb", - "@@//plugins/semanticdb:scala_3_with_semanticdb", - "@@//scala:test_bootstrap_2_12", - "@@//scala:test_bootstrap_2_13", - "@@//scala:test_bootstrap_3", - "@@//scala:test_zinc_2_12", - "@@//scala:test_zinc_2_13", - "@@//scala:test_zinc_3", - "@@//scala:test_zinc_2_13_fatal_deprecation_opt", - "@@//scala:test_zinc_2_13_log_level_debug", + default_scala_toolchain_name = "test_zinc_2_13", + toolchains = [ + "@@//dependencies/indirect:test_zinc_2_13_direct_deps_off", + "@@//dependencies/indirect:test_zinc_2_13_used_deps_off", + "@@//plugins/kind-projector:test_zinc_2_13_with_kind_projector", + "@@//plugins/semanticdb:scala_2_13_with_semanticdb", + "@@//plugins/semanticdb:scala_3_with_semanticdb", + "@@//scala:test_bootstrap_2_12", + "@@//scala:test_bootstrap_2_13", + "@@//scala:test_bootstrap_3", + "@@//scala:test_zinc_2_12", + "@@//scala:test_zinc_2_13", + "@@//scala:test_zinc_3", + "@@//scala:test_zinc_2_13_fatal_deprecation_opt", + "@@//scala:test_zinc_2_13_log_level_debug", + ], ) # Scala 2.12