From d508c196da292c5d369bf8c36fdf0c4d8493f0bd Mon Sep 17 00:00:00 2001 From: Adam Szady Date: Fri, 22 Mar 2024 11:50:15 +0100 Subject: [PATCH] Allow configuring multiple Scala versions --- cross-compilation-doc.md | 4 +++- scala_config.bzl | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cross-compilation-doc.md b/cross-compilation-doc.md index b3c142b25..57b420e43 100644 --- a/cross-compilation-doc.md +++ b/cross-compilation-doc.md @@ -7,7 +7,7 @@ The support for cross-compilation is currently under development. `scala_config` creates the repository `@io_bazel_rules_scala_config`. File created there, `config.bzl`, consists of many variables. In particular: * `SCALA_VERSION` – representing the default Scala version, e.g. `"3.3.1"`; -* `SCALA_VERSIONS` – representing all configured Scala versions (currently one), e.g. `["3.3.1"]`. +* `SCALA_VERSIONS` – representing all configured Scala versions, e.g. `["2.12.18", "3.3.1"]`. ## Build settings @@ -22,6 +22,7 @@ string_setting( values = ["3.3.1"], visibility = ["//visibility:public"], ) +... ``` This build setting can be subject of change by [transitions](https://bazel.build/extending/config#user-defined-transitions) (within allowed `values`). @@ -32,6 +33,7 @@ config_setting( name = "scala_version_3_3_1", flag_values = {":scala_version": "3.3.1"}, ) +... ``` The `name` of `config_setting` corresponds to `"scala_version" + version_suffix(scala_version)`. One may use this config setting in `select()` e.g. to provide dependencies relevant to a currently used Scala version. diff --git a/scala_config.bzl b/scala_config.bzl index b0d7b288f..af74464f7 100644 --- a/scala_config.bzl +++ b/scala_config.bzl @@ -28,7 +28,7 @@ def _store_config(repository_ctx): ) # All versions supported - scala_versions = [scala_version] + scala_versions = [scala_version] + [v for v in repository_ctx.attr.scala_versions if v != scala_version] enable_compiler_dependency_tracking = repository_ctx.os.environ.get( "ENABLE_COMPILER_DEPENDENCY_TRACKING", @@ -68,6 +68,9 @@ _config_repository = repository_rule( "scala_version": attr.string( mandatory = True, ), + "scala_versions": attr.string_list( + mandatory = True, + ), "enable_compiler_dependency_tracking": attr.bool( mandatory = True, ), @@ -77,9 +80,11 @@ _config_repository = repository_rule( def scala_config( scala_version = _default_scala_version(), + scala_versions = [], enable_compiler_dependency_tracking = False): _config_repository( name = "io_bazel_rules_scala_config", scala_version = scala_version, + scala_versions = scala_versions, enable_compiler_dependency_tracking = enable_compiler_dependency_tracking, )