diff --git a/BUILD b/BUILD index 66193e3bd..e69de29bb 100644 --- a/BUILD +++ b/BUILD @@ -1 +0,0 @@ -exports_files([".scalafmt.conf"]) diff --git a/MODULE.bazel b/MODULE.bazel index 5c38e8f90..babdd531b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -95,7 +95,6 @@ use_repo( "rules_scala_toolchains", "scala_compiler_sources", ) -scala_deps.scala() # Register some of our testing toolchains first when building our repo. register_toolchains( @@ -119,6 +118,7 @@ dev_deps = use_extension( "scala_deps", dev_dependency = True, ) +dev_deps.scala() dev_deps.jmh() dev_deps.junit() dev_deps.scala_proto() diff --git a/README.md b/README.md index 8526c1d43..fb2c8303d 100644 --- a/README.md +++ b/README.md @@ -930,19 +930,36 @@ parameter list, which is almost in complete correspondence with parameters from the previous macros. The `WORKSPACE` files in this repository also provide many examples. -### Replacing toolchain registration macros in `WORKSPACE` +### Replacing toolchain registration macros Almost all `rules_scala` toolchains configured using `scala_toolchains()` are -automatically registered by `scala_register_toolchains()`. There are two -toolchain macro replacements that require special handling. +automatically registered by `scala_register_toolchains()`. The same is true for +toolchains configured using the `scala_deps` module extension under Bzlmod. +There are two toolchain macro replacements that require special handling. The first is replacing `scala_proto_register_enable_all_options_toolchain()` -with the following `scala_toolchains()` parameters: +with the following: ```py +# MODULE.bazel + +scala_deps.scala_proto( + "default_gen_opts" = [ + "flat_package", + "grpc", + "single_line_to_proto_string", + ], +) + +# WORKSPACE scala_toolchains( - scala_proto = True, - scala_proto_options = [], + scala_proto = { + "default_gen_opts": [ + "flat_package", + "grpc", + "single_line_to_proto_string", + ], + }, ) ``` diff --git a/docs/phase_scalafmt.md b/docs/phase_scalafmt.md index 37e606b84..2bc56b164 100644 --- a/docs/phase_scalafmt.md +++ b/docs/phase_scalafmt.md @@ -71,25 +71,21 @@ bazel run .format-test to check the format (without modifying source code). -The extension provides a default configuration, but there are 2 ways to use -a custom configuration: - -- Put `.scalafmt.conf` at the root of your workspace -- Pass `.scalafmt.conf` in via `scala_toolchains`: - - ```py - # MODULE.bazel - scala_deps.scalafmt( - default_config = "//path/to/my/custom:scalafmt.conf", - ) - - # WORKSPACE - scala_toolchains( - # Other toolchains settings... - scalafmt = True, - scalafmt_default_config = "//path/to/my/custom:scalafmt.conf", - ) - ``` +The extension provides a default configuration. To use a custom configuration, +pass its path or target Label to the toolchain configuration: + +```py +# MODULE.bazel +scala_deps.scalafmt( + default_config = "path/to/my/custom/scalafmt.conf", +) + +# WORKSPACE +scala_toolchains( + # Other toolchains settings... + scalafmt = {"default_config": "path/to/my/custom/scalafmt.conf"}, +) +``` When using Scala 3, you must append `runner.dialect = scala3` to `.scalafmt.conf`. diff --git a/docs/scala_proto_library.md b/docs/scala_proto_library.md index ab77b6077..07122a07e 100644 --- a/docs/scala_proto_library.md +++ b/docs/scala_proto_library.md @@ -1,22 +1,40 @@ # scala_proto_library -To use this rule, you'll first need to add the following to your `WORKSPACE` file, -which adds a few dependencies needed for ScalaPB: +To use this rule, add the following configuration, which adds the dependencies +needed for ScalaPB: ```py -scala_toolchains( - # Other toolchains settings... - scala_proto = True, - scala_proto_options = [ +# MODULE.bazel +scala_deps.scala_proto( + "default_gen_opts" = [ "grpc", "flat_package", "scala3_sources", ], ) +``` + +```py +# WORKSPACE +scala_toolchains( + # Other toolchains settings... + scala_proto = { + "default_gen_opts": [ + "grpc", + "flat_package", + "scala3_sources", + ], + }, +) scala_register_toolchains() ``` +See the __scalapbc__ column of the [__ScalaPB: SBT Settings > Additional options +to the generator__]( +https://scalapb.github.io/docs/sbt-settings#additional-options-to-the-generator +) table for `default_gen_opts` values. + Then you can import `scala_proto_library` in any `BUILD` file like this: ```py diff --git a/scala/extensions/deps.bzl b/scala/extensions/deps.bzl index 433252f4e..5ee96a6e7 100644 --- a/scala/extensions/deps.bzl +++ b/scala/extensions/deps.bzl @@ -14,8 +14,8 @@ Provides the `scala_deps` module extension with the following tag classes: - `twitter_scrooge` - `jmh` -For documentation, see the `_tag_classes` dict, and the `__attrs` dict -corresponding to each `` listed above. +For documentation, see the `_{general,toolchain}_tag_classes` dicts and the +`__attrs` dict corresponding to each `` listed above. See the `scala/private/macros/bzlmod.bzl` docstring for a description of the defaults, attrs, and tag class dictionaries pattern employed here. @@ -27,6 +27,7 @@ load( "root_module_tags", "single_tag_values", ) +load("//scala/private:toolchain_defaults.bzl", "TOOLCHAIN_DEFAULTS") load("//scala:scala_cross_version.bzl", "default_maven_server_urls") load("//scala:toolchains.bzl", "scala_toolchains") @@ -89,35 +90,26 @@ _compiler_srcjar_attrs = { "integrity": attr.string(), } -_scalafmt_defaults = { - "default_config": "//:.scalafmt.conf", -} +_scalafmt_defaults = TOOLCHAIN_DEFAULTS["scalafmt"] _scalafmt_attrs = { "default_config": attr.label( default = _scalafmt_defaults["default_config"], doc = "The default config file for Scalafmt targets", + allow_single_file = True, ), } -_scala_proto_defaults = { - "options": [], -} +_scala_proto_defaults = TOOLCHAIN_DEFAULTS["scala_proto"] _scala_proto_attrs = { - "options": attr.string_list( - default = _scala_proto_defaults["options"], + "default_gen_opts": attr.string_list( + default = _scala_proto_defaults["default_gen_opts"], doc = "Protobuf options, like 'scala3_sources' or 'grpc'", ), } -_twitter_scrooge_defaults = { - "libthrift": None, - "scrooge_core": None, - "scrooge_generator": None, - "util_core": None, - "util_logging": None, -} +_twitter_scrooge_defaults = TOOLCHAIN_DEFAULTS["twitter_scrooge"] _twitter_scrooge_attrs = { k: attr.label(default = v) @@ -186,39 +178,51 @@ _toolchain_tag_classes = { ), } -_tag_classes = _general_tag_classes | _toolchain_tag_classes +def _toolchain_settings(module_ctx, tags, tc_names, toolchain_defaults): + """Configures all builtin toolchains enabled throughout the module graph. + + Configures toolchain options for enabled toolchains that support them based + on the root module's settings for each toolchain. In other words, it uses: -def _toolchains(mctx): - result = {k: False for k in _toolchain_tag_classes} + - the root module's tag class settings, if present; and + - the default tag class settings otherwise. - for mod in mctx.modules: - values = {tc: len(getattr(mod.tags, tc)) != 0 for tc in result} + This avoids trying to reconcile different toolchain settings across the + module graph. Non root modules that require specific settings should either: - if mod.is_root: - return values + - publish their required toolchain settings, or + - define and register a custom toolchain instead. - # Don't overwrite `True` values with `False` from another tag. - result.update({k: v for k, v in values.items() if v}) + Args: + module_ctx: the module context object + tags: a tags object, presumably the result of `root_module_tags()` + tc_names: names of all supported toolchains + toolchain_defaults: a dict of `{toolchain_name: default options dict}` - return result + Returns: + a dict of `{toolchain_name: bool or options dict}` to pass as keyword + arguments to `scala_toolchains()` + """ + toolchains = {k: False for k in tc_names} -def _scala_proto_options(mctx): - result = {} + for mod in module_ctx.modules: + values = {tc: len(getattr(mod.tags, tc)) != 0 for tc in toolchains} - for mod in mctx.modules: - for tag in mod.tags.scala_proto: - result.update({opt: True for opt in tag.options}) + # Don't overwrite True values with False from another tag. + toolchains.update({k: v for k, v in values.items() if v}) - return sorted(result.keys()) + for tc, defaults in toolchain_defaults.items(): + if toolchains[tc]: + values = single_tag_values(module_ctx, getattr(tags, tc), defaults) + toolchains[tc] = {k: v for k, v in values.items() if v != None} + + return toolchains + +_tag_classes = _general_tag_classes | _toolchain_tag_classes def _scala_deps_impl(module_ctx): tags = root_module_tags(module_ctx, _tag_classes.keys()) - scalafmt = single_tag_values(module_ctx, tags.scalafmt, _scalafmt_defaults) - scrooge_deps = single_tag_values( - module_ctx, - tags.twitter_scrooge, - _twitter_scrooge_defaults, - ) + tc_names = [tc for tc in _toolchain_tag_classes] scala_toolchains( overridden_artifacts = repeated_tag_values( @@ -229,13 +233,9 @@ def _scala_deps_impl(module_ctx): tags.compiler_srcjar, _compiler_srcjar_attrs, ), - scala_proto_options = _scala_proto_options(module_ctx), - # `None` breaks the `attr.string_dict` in `scala_toolchains_repo`. - twitter_scrooge_deps = {k: v for k, v in scrooge_deps.items() if v}, **( single_tag_values(module_ctx, tags.settings, _settings_defaults) | - {"scalafmt_%s" % k: v for k, v in scalafmt.items()} | - _toolchains(module_ctx) + _toolchain_settings(module_ctx, tags, tc_names, TOOLCHAIN_DEFAULTS) ) ) @@ -244,8 +244,11 @@ scala_deps = module_extension( tag_classes = _tag_classes, doc = """Selects and configures builtin toolchains. -If the root module explicitly uses the extension, it assumes responsibility for -selecting all required toolchains by insantiating the corresponding tag classes: +Modules throughout the dependency graph can enable a builtin toolchain by +instantiating its corresponding tag class. The root module controls the +configuration of all toolchains it directly enables. Any other builtin +toolchain required by other modules will use that toolchain's default +configuration values. ```py scala_deps = use_extension( @@ -253,14 +256,14 @@ scala_deps = use_extension( "scala_deps", ) scala_deps.scala() -scala_deps.scala_proto() +scala_deps.scala_proto(default_gen_opts = ["grpc", "scala3_sources"]) dev_deps = use_extension( "@rules_scala//scala/extensions:deps.bzl", "scala_deps", dev_dependency = True, ) -dev_deps.scalafmt() +dev_deps.scalafmt(default_config = "path/to/scalafmt.conf") dev_deps.scalatest() # And so on... diff --git a/scala/private/toolchain_defaults.bzl b/scala/private/toolchain_defaults.bzl new file mode 100644 index 000000000..06904f6f7 --- /dev/null +++ b/scala/private/toolchain_defaults.bzl @@ -0,0 +1,20 @@ +"""Gathers defaults for toolchain macros in one place. + +Used by both //scala:toolchains.bzl and //scala/extensions:deps.bzl. +""" + +load( + "//scala/scalafmt/toolchain:setup_scalafmt_toolchain.bzl", + _scalafmt = "TOOLCHAIN_DEFAULTS", +) +load("//scala_proto:toolchains.bzl", _scala_proto = "TOOLCHAIN_DEFAULTS") +load( + "//twitter_scrooge/toolchain:toolchain.bzl", + _twitter_scrooge = "TOOLCHAIN_DEFAULTS", +) + +TOOLCHAIN_DEFAULTS = { + "scalafmt": _scalafmt, + "scala_proto": _scala_proto, + "twitter_scrooge": _twitter_scrooge, +} diff --git a/scala/scalafmt/toolchain/setup_scalafmt_toolchain.bzl b/scala/scalafmt/toolchain/setup_scalafmt_toolchain.bzl index e1e576a23..aa511e78b 100644 --- a/scala/scalafmt/toolchain/setup_scalafmt_toolchain.bzl +++ b/scala/scalafmt/toolchain/setup_scalafmt_toolchain.bzl @@ -8,6 +8,13 @@ load("//scala:providers.bzl", "declare_deps_provider") load("//scala:scala_cross_version.bzl", "version_suffix") load("@rules_scala_config//:config.bzl", "SCALA_VERSIONS") +TOOLCHAIN_DEFAULTS = { + # Used by `scala_toolchains{,_repo}` to generate + # `@rules_scala_toolchains//scalafmt:config`, the default config for + # `ext_scalafmt` from `phase_scalafmt_ext.bzl`. + "default_config": Label("//:.scalafmt.conf"), +} + def setup_scalafmt_toolchain( name, scalafmt_classpath, diff --git a/scala/toolchains.bzl b/scala/toolchains.bzl index 82779fb7b..c652e3854 100644 --- a/scala/toolchains.bzl +++ b/scala/toolchains.bzl @@ -7,6 +7,7 @@ load( "scala_version_artifact_ids", "setup_scala_compiler_sources", ) +load("//scala/private:toolchain_defaults.bzl", "TOOLCHAIN_DEFAULTS") load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_artifact_ids") load("//scala:scala_cross_version.bzl", "default_maven_server_urls") load("//scala:toolchains_repo.bzl", "scala_toolchains_repo") @@ -18,14 +19,69 @@ load("//third_party/repositories:repositories.bzl", "repositories") load( "//twitter_scrooge/toolchain:toolchain.bzl", "twitter_scrooge_artifact_ids", - _TWITTER_SCROOGE_DEPS = "TOOLCHAIN_DEPS", ) load("@rules_scala_config//:config.bzl", "SCALA_VERSIONS") -def _get_unknown_entries(entries, allowed_entries): - return [e for e in entries if e not in allowed_entries] +_DEFAULT_TOOLCHAINS_REPO_NAME = "rules_scala_toolchains" + +def _toolchain_opts(tc_arg): + """Converts a toolchain parameter to a (bool, dict of options). + + Used by `scala_toolchains` to parse toolchain arguments as True, False, + None, or a dict of options. + + Args: + tc_arg: a bool, dict, or None + + Returns: + a bool indicating whether the toolchain is enabled, and a dict + containing any provided toolchain options + """ + if tc_arg == False or tc_arg == None: + return False, {} + return True, ({} if tc_arg == True else tc_arg) + +def _process_toolchain_options(toolchain_defaults, **kwargs): + """Checks the validity of toolchain options and provides defaults. + + Updates each toolchain option dictionary with defaults for every missing + entry. + + Args: + toolchain_defaults: a dict of `{toolchain_name: default options dict}` + **kwargs: keyword arguments of the form `toolchain_name = options_dict` + + Returns: + a list of error messages for invalid toolchains or options + """ + errors = [] + + for tc, options in kwargs.items(): + defaults = toolchain_defaults.get(tc, None) + + if defaults == None: + errors.append("unknown toolchain or doesn't have defaults: " + tc) + continue + + unexpected = [a for a in options if a not in defaults] + + if unexpected: + plural = "s" if len(unexpected) != 1 else "" + errors.append( + "unexpected %s toolchain attribute%s: " % (tc, plural) + + ", ".join(unexpected), + ) + + options.update({ + k: v + for k, v in defaults.items() + if k not in options and v != None + }) + + return errors def scala_toolchains( + name = _DEFAULT_TOOLCHAINS_REPO_NAME, maven_servers = default_maven_server_urls(), overridden_artifacts = {}, fetch_sources = False, @@ -36,12 +92,9 @@ def scala_toolchains( junit = False, specs2 = False, scalafmt = False, - scalafmt_default_config = Label("//:.scalafmt.conf"), scala_proto = False, - scala_proto_options = [], jmh = False, - twitter_scrooge = False, - twitter_scrooge_deps = {}): + twitter_scrooge = False): """Instantiates rules_scala toolchains and all their dependencies. Provides a unified interface to configuring `rules_scala` both directly in a @@ -54,6 +107,7 @@ def scala_toolchains( All arguments are optional. Args: + name: Name of the generated toolchains repository maven_servers: Maven servers used to fetch dependency jar files overridden_artifacts: artifacts overriding the defaults for the configured Scala version, in the format: @@ -82,28 +136,26 @@ def scala_toolchains( scalatest: whether to instantiate the ScalaTest toolchain junit: whether to instantiate the JUnit toolchain specs2: whether to instantiate the Specs2 JUnit toolchain - scalafmt: whether to instantiate the Scalafmt toolchain - scalafmt_default_config: the default config file for Scalafmt targets - scala_proto: whether to instantiate the scala_proto toolchain - scala_proto_options: protobuf options, like 'scala3_sources' or 'grpc'; - `scala_proto` must also be `True` for this to take effect + scalafmt: boolean or dictionary of Scalafmt options: + - default_config: default Scalafmt config file target + scala_proto: boolean or dictionary of `setup_scala_proto_toolchain()` + options jmh: whether to instantiate the Java Microbenchmarks Harness toolchain - twitter_scrooge: whether to instantiate the twitter_scrooge toolchain - twitter_scrooge_deps: dictionary of string to Label containing overrides - for twitter_scrooge toolchain dependency providers with keys: - libthrift - scrooge_core - scrooge_generator - util_core - util_logging + twitter_scrooge: bool or dictionary of `setup_scrooge_toolchain()` + options """ - unknown_ts_deps = _get_unknown_entries( - twitter_scrooge_deps, - _TWITTER_SCROOGE_DEPS, + scalafmt, scalafmt_options = _toolchain_opts(scalafmt) + scala_proto, scala_proto_options = _toolchain_opts(scala_proto) + twitter_scrooge, twitter_scrooge_options = _toolchain_opts(twitter_scrooge) + + errors = _process_toolchain_options( + TOOLCHAIN_DEFAULTS, + scalafmt = scalafmt_options, + scala_proto = scala_proto_options, + twitter_scrooge = twitter_scrooge_options, ) - - if unknown_ts_deps: - fail("unknown twitter_scrooge_deps:", ", ".join(unknown_ts_deps)) + if errors: + fail("\n".join(errors)) setup_scala_compiler_sources(scala_compiler_srcjars) @@ -135,7 +187,7 @@ def scala_toolchains( if twitter_scrooge: artifact_ids_to_fetch_sources.update({ id: False - for id in twitter_scrooge_artifact_ids(**twitter_scrooge_deps) + for id in twitter_scrooge_artifact_ids(**twitter_scrooge_options) }) for scala_version in SCALA_VERSIONS: @@ -174,20 +226,21 @@ def scala_toolchains( ) scala_toolchains_repo( + name = name, scalatest = scalatest, junit = junit, specs2 = specs2, scalafmt = scalafmt, - scalafmt_default_config = scalafmt_default_config, + scalafmt_default_config = scalafmt_options["default_config"], scala_proto = scala_proto, - scala_proto_options = scala_proto_options, + scala_proto_options = scala_proto_options["default_gen_opts"], jmh = jmh, twitter_scrooge = twitter_scrooge, - twitter_scrooge_deps = twitter_scrooge_deps, + twitter_scrooge_deps = twitter_scrooge_options, ) -def scala_register_toolchains(): - native.register_toolchains("@rules_scala_toolchains//...:all") +def scala_register_toolchains(name = _DEFAULT_TOOLCHAINS_REPO_NAME): + native.register_toolchains("@%s//...:all" % name) def scala_register_unused_deps_toolchains(): native.register_toolchains( diff --git a/scala/toolchains_repo.bzl b/scala/toolchains_repo.bzl index 2c854d7f5..1f58adfe3 100644 --- a/scala/toolchains_repo.bzl +++ b/scala/toolchains_repo.bzl @@ -28,26 +28,21 @@ def _generate_testing_toolchain_build_file_args(repo_attr): "specs2_junit": framework_deps.get("specs2_junit"), } -_TWITTER_SCROOGE_ARGS = [ - "libthrift", - "scrooge_core", - "scrooge_generator", - "util_core", - "util_logging", -] +def _stringify(value): + """Wraps string values in double quotes for use in `BUILD` files.""" + return "\"%s\"" % value if type(value) == "string" else value -def _stringify_template_args(args, arg_names): - return { - arg: ("\"%s\"" % value if type(value) == "string" else value) - for arg, value in {name: args.get(name) for name in arg_names}.items() - } +def _stringify_args(args, indent = " " * 4): + """Formats a dict as `BUILD` rule or macro arguments.""" + return "".join([ + "%s%s = %s,\n" % (indent, k, _stringify(v)) + for k, v in args.items() + ]) def _scala_toolchains_repo_impl(repository_ctx): repo_attr = repository_ctx.attr format_args = { "rules_scala_repo": Label("//:all").repo_name, - "proto_options": repo_attr.scala_proto_options, - "scalafmt_default_config": repo_attr.scalafmt_default_config, } toolchains = {} @@ -55,14 +50,16 @@ def _scala_toolchains_repo_impl(repository_ctx): toolchains["scala"] = _SCALA_TOOLCHAIN_BUILD if repo_attr.scala_proto: toolchains["scala_proto"] = _SCALA_PROTO_TOOLCHAIN_BUILD + format_args["scala_proto_opts"] = _stringify_args({ + "default_gen_opts": repo_attr.scala_proto_options, + }) if repo_attr.jmh: toolchains["jmh"] = _JMH_TOOLCHAIN_BUILD if repo_attr.twitter_scrooge: toolchains["twitter_scrooge"] = _TWITTER_SCROOGE_TOOLCHAIN_BUILD - format_args.update(_stringify_template_args( + format_args["twitter_scrooge_opts"] = _stringify_args( repo_attr.twitter_scrooge_deps, - _TWITTER_SCROOGE_ARGS, - )) + ) testing_build_args = _generate_testing_toolchain_build_file_args(repo_attr) if testing_build_args != None: @@ -71,6 +68,11 @@ def _scala_toolchains_repo_impl(repository_ctx): if repo_attr.scalafmt: toolchains["scalafmt"] = _SCALAFMT_TOOLCHAIN_BUILD + config_path = repository_ctx.path(repo_attr.scalafmt_default_config) + + if not config_path.exists: + fail("Scalafmt default config file doesn't exist:", config_path) + repository_ctx.symlink(config_path, "scalafmt/scalafmt.conf") # Generate a root package so that the `register_toolchains` call in # `MODULE.bazel` always succeeds. @@ -83,7 +85,7 @@ def _scala_toolchains_repo_impl(repository_ctx): executable = False, ) -_scala_toolchains_repo = repository_rule( +scala_toolchains_repo = repository_rule( implementation = _scala_toolchains_repo_impl, doc = "Creates a repo containing Scala toolchain packages", attrs = { @@ -103,10 +105,7 @@ _scala_toolchains_repo = repository_rule( doc = "Instantiate the scala_proto toolchain", ), "scala_proto_options": attr.string_list( - doc = ( - "Protobuf generator options; " + - "`scala_proto` must also be `True` for this to take effect" - ), + doc = "Protobuf generator options", ), "jmh": attr.bool( doc = "Instantiate the Java Microbenchmarks Harness toolchain", @@ -116,25 +115,11 @@ _scala_toolchains_repo = repository_rule( ), # attr.string_keyed_label_dict isn't available in Bazel 6 "twitter_scrooge_deps": attr.string_dict( - doc = ( - "overrides for twitter_scrooge toolchain dependency " + - "providers with keys:\n" + - " libthrift\n" + - " scrooge_core\n" + - " scrooge_generator\n" + - " util_core\n" + - " util_logging" - ), + doc = "twitter_scrooge toolchain dependency provider overrides", ), }, ) -def scala_toolchains_repo(name = "rules_scala_toolchains", **kwargs): - _scala_toolchains_repo( - name = name, - **kwargs - ) - _SCALA_TOOLCHAIN_BUILD = """ load( "@@{rules_scala_repo}//scala/private:macros/setup_scala_toolchain.bzl", @@ -204,9 +189,9 @@ load( "setup_scalafmt_toolchains", ) -alias( +filegroup( name = "config", - actual = "{scalafmt_default_config}", + srcs = [":scalafmt.conf"], visibility = ["//visibility:public"], ) @@ -228,8 +213,7 @@ load( setup_scala_proto_toolchains( name = "scala_proto", - default_gen_opts = {proto_options}, -) +{scala_proto_opts}) declare_deps_provider( name = "scalapb_compile_deps_provider", @@ -260,10 +244,5 @@ load( setup_scrooge_toolchain( name = "scrooge_toolchain", - libthrift = {libthrift}, - scrooge_core = {scrooge_core}, - scrooge_generator = {scrooge_generator}, - util_core = {util_core}, - util_logging = {util_logging}, -) +{twitter_scrooge_opts}) """ diff --git a/scala_proto/toolchains.bzl b/scala_proto/toolchains.bzl index a315732a4..05ef99c98 100644 --- a/scala_proto/toolchains.bzl +++ b/scala_proto/toolchains.bzl @@ -4,16 +4,22 @@ load( "scalapb_toolchain", ) -_default_gen_opts = [ - "grpc", -] +TOOLCHAIN_DEFAULTS = { + "default_gen_opts": ["grpc"], +} -def setup_scala_proto_toolchains(name, default_gen_opts = _default_gen_opts): +def setup_scala_proto_toolchains( + name, + default_gen_opts = ["grpc"]): """Used by @rules_scala_toolchains//scala_proto/BUILD. See //scala/private:macros/toolchains_repo.bzl for details, especially the _SCALA_PROTO_TOOLCHAIN_BUILD string template. + See the `scalapbc` column of the "ScalaPB: SBT Settings > Additional options + to the generator" table below for `default_gen_opts` values: + - https://scalapb.github.io/docs/sbt-settings#additional-options-to-the-generator + Args: name: prefix for all generate toolchains default_gen_opts: parameters passed to the default generator diff --git a/test_version/MODULE.bazel.template b/test_version/MODULE.bazel.template index 1c30aeb30..5673d470d 100644 --- a/test_version/MODULE.bazel.template +++ b/test_version/MODULE.bazel.template @@ -49,9 +49,7 @@ scala_deps.settings( fetch_sources = True, ) scala_deps.scala() -scala_deps.scala_proto( - options = ["grpc"], -) +scala_deps.scala_proto() scala_deps.scalatest() scala_deps.specs2() diff --git a/test_version/scrooge_repositories.bzl b/test_version/scrooge_repositories.bzl index 9f7ba5440..2c977e8b2 100644 --- a/test_version/scrooge_repositories.bzl +++ b/test_version/scrooge_repositories.bzl @@ -109,6 +109,7 @@ def scrooge_repositories(version = None): scala_toolchains_repo( name = "twitter_scrooge_test_toolchain", + scala = False, twitter_scrooge = True, twitter_scrooge_deps = toolchain_deps, ) diff --git a/twitter_scrooge/toolchain/toolchain.bzl b/twitter_scrooge/toolchain/toolchain.bzl index bb95c197a..908a0bea9 100644 --- a/twitter_scrooge/toolchain/toolchain.bzl +++ b/twitter_scrooge/toolchain/toolchain.bzl @@ -14,14 +14,6 @@ DEP_PROVIDERS = [ "compiler_classpath", ] -TOOLCHAIN_DEPS = [ - "libthrift", - "scrooge_core", - "scrooge_generator", - "util_core", - "util_logging", -] - def twitter_scrooge_artifact_ids( libthrift = None, scrooge_core = None, @@ -78,6 +70,14 @@ export_scrooge_deps = rule( toolchains = [_toolchain_type], ) +TOOLCHAIN_DEFAULTS = { + "libthrift": None, + "scrooge_core": None, + "scrooge_generator": None, + "util_core": None, + "util_logging": None, +} + def setup_scrooge_toolchain( name, libthrift = None,