Skip to content

Commit d4d8316

Browse files
authored
Allow configuring multiple Scala versions (#1579)
1 parent e69da66 commit d4d8316

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

cross-compilation-doc.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The support for cross-compilation is currently under development.
77
`scala_config` creates the repository `@io_bazel_rules_scala_config`.
88
File created there, `config.bzl`, consists of many variables. In particular:
99
* `SCALA_VERSION` – representing the default Scala version, e.g. `"3.3.1"`;
10-
* `SCALA_VERSIONS` – representing all configured Scala versions (currently one), e.g. `["3.3.1"]`.
10+
* `SCALA_VERSIONS` – representing all configured Scala versions, e.g. `["2.12.18", "3.3.1"]`.
1111

1212

1313
## Build settings
@@ -22,6 +22,7 @@ string_setting(
2222
values = ["3.3.1"],
2323
visibility = ["//visibility:public"],
2424
)
25+
...
2526
```
2627
This build setting can be subject of change by [transitions](https://bazel.build/extending/config#user-defined-transitions) (within allowed `values`).
2728

@@ -32,6 +33,7 @@ config_setting(
3233
name = "scala_version_3_3_1",
3334
flag_values = {":scala_version": "3.3.1"},
3435
)
36+
...
3537
```
3638
The `name` of `config_setting` corresponds to `"scala_version" + version_suffix(scala_version)`.
3739
One may use this config setting in `select()` e.g. to provide dependencies relevant to a currently used Scala version.

scala_config.bzl

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def _store_config(repository_ctx):
2828
)
2929

3030
# All versions supported
31-
scala_versions = [scala_version]
31+
scala_versions = repository_ctx.attr.scala_versions
32+
if not scala_versions:
33+
scala_versions = [scala_version]
34+
elif scala_version not in scala_versions:
35+
fail("You have to include the default Scala version (%s) in the `scala_versions` list." % scala_version)
3236

3337
enable_compiler_dependency_tracking = repository_ctx.os.environ.get(
3438
"ENABLE_COMPILER_DEPENDENCY_TRACKING",
@@ -67,6 +71,11 @@ _config_repository = repository_rule(
6771
attrs = {
6872
"scala_version": attr.string(
6973
mandatory = True,
74+
doc = "Default Scala version",
75+
),
76+
"scala_versions": attr.string_list(
77+
mandatory = True,
78+
doc = "List of all Scala versions to configure. Must include the default one.",
7079
),
7180
"enable_compiler_dependency_tracking": attr.bool(
7281
mandatory = True,
@@ -77,9 +86,11 @@ _config_repository = repository_rule(
7786

7887
def scala_config(
7988
scala_version = _default_scala_version(),
89+
scala_versions = [],
8090
enable_compiler_dependency_tracking = False):
8191
_config_repository(
8292
name = "io_bazel_rules_scala_config",
8393
scala_version = scala_version,
94+
scala_versions = scala_versions,
8495
enable_compiler_dependency_tracking = enable_compiler_dependency_tracking,
8596
)

0 commit comments

Comments
 (0)