Skip to content

Commit

Permalink
Allow configuring multiple Scala versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aszady committed May 15, 2024
1 parent 268203e commit d508c19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cross-compilation-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`).

Expand All @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion scala_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
),
Expand All @@ -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,
)

0 comments on commit d508c19

Please sign in to comment.