diff --git a/MODULE.bazel b/MODULE.bazel index c71fe6a..d020a44 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -22,6 +22,8 @@ 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, diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index bc40ea6..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,6 +0,0 @@ -workspace(name = "rules_twirl") - -# Twirl compiler -load("//twirl-toolchain:register-toolchains.bzl", "twirl_register_toolchains") - -twirl_register_toolchains(default_toolchain_name = "twirl-3") diff --git a/twirl-toolchain/BUILD.bazel b/twirl-toolchain/BUILD.bazel index 9c394e0..8079558 100644 --- a/twirl-toolchain/BUILD.bazel +++ b/twirl-toolchain/BUILD.bazel @@ -1,8 +1,21 @@ 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", diff --git a/twirl-toolchain/create-toolchain.bzl b/twirl-toolchain/create-toolchain.bzl index ecc7a68..5a61198 100644 --- a/twirl-toolchain/create-toolchain.bzl +++ b/twirl-toolchain/create-toolchain.bzl @@ -12,7 +12,7 @@ def create_twirl_toolchain(name, twirl_compiler): native.config_setting( name = config_setting_name, flag_values = { - "@rules_twirl_toolchain//:twirl-toolchain": name, + "//twirl-toolchain": name, }, ) diff --git a/twirl-toolchain/register-toolchains.bzl b/twirl-toolchain/register-toolchains.bzl deleted file mode 100644 index 8cb1eb8..0000000 --- a/twirl-toolchain/register-toolchains.bzl +++ /dev/null @@ -1,40 +0,0 @@ -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) diff --git a/twirl-toolchain/transitions.bzl b/twirl-toolchain/transitions.bzl index 23e9e79..99dbdc4 100644 --- a/twirl-toolchain/transitions.bzl +++ b/twirl-toolchain/transitions.bzl @@ -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 = "@rules_twirl_toolchain//:twirl-toolchain" -original_toolchain_setting_key = "@rules_twirl_toolchain//:original-twirl-toolchain" +toolchain_setting_key = "//twirl-toolchain" +original_toolchain_setting_key = "//twirl-toolchain:original-twirl-toolchain" def _twirl_toolchain_transition_impl(settings, attr): """Update the rules_twirl toolchain to the overridden value. Store