Skip to content

Commit

Permalink
Made the default toolchain configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaden Peterson committed Aug 27, 2024
1 parent 23e475e commit d21cc29
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions rules/register_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand All @@ -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 = {
Expand Down
8 changes: 0 additions & 8 deletions rules/scala/BUILD
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
31 changes: 29 additions & 2 deletions rules/scala/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
25 changes: 14 additions & 11 deletions tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ 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",
"@@//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",
"@@//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
Expand Down

0 comments on commit d21cc29

Please sign in to comment.