Skip to content

Commit

Permalink
Revert "Manually register the Twirl compiler toolchain"
Browse files Browse the repository at this point in the history
This reverts commit 1379dc6.
  • Loading branch information
Jaden Peterson committed Dec 6, 2024
1 parent cb4f57c commit 9fcd964
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
2 changes: 0 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ register_toolchains(
"//:repository_default_toolchain_21_definition",
"//scala:zinc_2_13",
"//scala:zinc_3",
"//twirl-toolchain:twirl-2-13",
"//twirl-toolchain:twirl-3",
)

# Please ensure these stay up-to-date with the versions in `versions.bzl`. Unfortunately,
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
workspace(name = "rules_twirl")

# Twirl compiler
load("//twirl-toolchain:register-toolchains.bzl", "twirl_register_toolchains")

twirl_register_toolchains(default_toolchain_name = "twirl-3")
13 changes: 0 additions & 13 deletions twirl-toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_setting")
load(":create-toolchain.bzl", "create_twirl_toolchain")

toolchain_type(name = "toolchain_type")

string_setting(
name = "original-twirl-toolchain",
build_setting_default = "",
visibility = ["//visibility:public"],
)

string_flag(
name = "twirl-toolchain",
build_setting_default = "twirl-3",
visibility = ["//visibility:public"],
)

create_twirl_toolchain(
name = "twirl-3",
twirl_compiler = "//twirl-compiler-cli:twirl-compiler-cli-3",
Expand Down
2 changes: 1 addition & 1 deletion twirl-toolchain/create-toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create_twirl_toolchain(name, twirl_compiler):
native.config_setting(
name = config_setting_name,
flag_values = {
"//twirl-toolchain": name,
"@rules_twirl_toolchain//:twirl-toolchain": name,
},
)

Expand Down
40 changes: 40 additions & 0 deletions twirl-toolchain/register-toolchains.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def _toolchain_configuration_repository_impl(repository_ctx):
repository_ctx.file(
"BUILD.bazel",
"""\
load("@bazel_skylib//rules:common_settings.bzl", "string_setting")
string_setting(
name = "twirl-toolchain",
build_setting_default = "{}",
visibility = ["//visibility:public"],
)
string_setting(
name = "original-twirl-toolchain",
build_setting_default = "",
visibility = ["//visibility:public"],
)
""".format(repository_ctx.attr.default_toolchain_name),
)

_toolchain_configuration_repository = repository_rule(
attrs = {
"default_toolchain_name": attr.string(mandatory = True),
},
doc = "Defines build settings used by the Twirl toolchains to use. This is done in a separate repository so we can provide the default dynamically.",
implementation = _toolchain_configuration_repository_impl,
)

def twirl_register_toolchains(
default_toolchain_name,
toolchains = [
"//twirl-toolchain:twirl-3",
"//twirl-toolchain:twirl-2-13",
]):
_toolchain_configuration_repository(
name = "rules_twirl_toolchain",
default_toolchain_name = default_toolchain_name,
)

native.register_toolchains(*toolchains)
4 changes: 2 additions & 2 deletions twirl-toolchain/transitions.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This approach of incoming transition, store original values, outgoing
# transition, reset to original values is inspired by what the rules_go
# folks are doing.
toolchain_setting_key = "//twirl-toolchain"
original_toolchain_setting_key = "//twirl-toolchain:original-twirl-toolchain"
toolchain_setting_key = "@rules_twirl_toolchain//:twirl-toolchain"
original_toolchain_setting_key = "@rules_twirl_toolchain//:original-twirl-toolchain"

def _twirl_toolchain_transition_impl(settings, attr):
"""Update the rules_twirl toolchain to the overridden value. Store
Expand Down

0 comments on commit 9fcd964

Please sign in to comment.