Skip to content

Latest commit

 

History

History
216 lines (193 loc) · 6.31 KB

scala_toolchain.md

File metadata and controls

216 lines (193 loc) · 6.31 KB

scala_toolchain

scala_toolchain allows you to define the global configuration for all Scala targets.

Some scala_toolchain must be registered!

Options to configure scala_toolchain

A) Use the builtin Scala toolchain via scala_toolchains

Add the following lines to WORKSPACE:

# WORKSPACE
# register default scala toolchain
load(
    "@rules_scala//scala:toolchains.bzl",
    "scala_register_toolchains",
    "scala_toolchains",
)

scala_toolchains()

scala_register_toolchains()

B) Defining your own scala_toolchain requires 2 steps

Step 1

You can add your own scala_toolchain definition to a BUILD file in one of two ways. If you only want to set different configuration options, but rely on the builtin toolchain JARs, use scala_toolchain directly. This example is inspired by BUILD.bazel from michalbogacz/scala-bazel-monorepo/):

load("@rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")

scala_toolchain(
    name = "my_toolchain_impl",
    scalacopts = [
        "-Wunused:all",
    ],
    strict_deps_mode = "error",
    unused_dependency_checker_mode = "warn",
)

toolchain(
    name = "my_toolchain",
    toolchain = ":my_toolchain_impl",
    toolchain_type = "@rules_scala//scala:toolchain_type",
    visibility = ["//visibility:public"],
)

If you want to use your own compiler JARs, use setup_scala_toolchain() instead. This example assumes the external libraries are resolved with rules_jvm_external

# //toolchains/BUILD
load("@rules_scala//scala:scala.bzl", "setup_scala_toolchain")

setup_scala_toolchain(
    name = "my_toolchain",
    # configure toolchain dependecies
    parser_combinators_deps = [
        "@maven//:org_scala_lang_modules_scala_parser_combinators_2_12",
    ],
    scala_compile_classpath = [
        "@maven//:org_scala_lang_scala_compiler",
        "@maven//:org_scala_lang_scala_library",
        "@maven//:org_scala_lang_scala_reflect",
    ],
    scala_library_classpath = [
        "@maven//:org_scala_lang_scala_library",
        "@maven//:org_scala_lang_scala_reflect",
    ],
    scala_macro_classpath = [
        "@maven//:org_scala_lang_scala_library",
        "@maven//:org_scala_lang_scala_reflect",
    ],
    scala_xml_deps = [
        "@maven//:org_scala_lang_modules_scala_xml_2_12",
    ],
    # example of setting attribute values
    scalacopts = ["-Ywarn-unused"],
    unused_dependency_checker_mode = "off",
    visibility = ["//visibility:public"]
)

Step 2

Register your custom toolchain:

# MODULE.bazel or WORKSPACE
register_toolchains("//toolchains:my_scala_toolchain")

Configuration options

The following attributes apply to both scala_toolchain and setup_scala_toolchain.

Attributes
dep_providers

List of labels; optional

Allows to configure dependencies lists by configuring DepInfo provider targets. Currently supported dep ids: scala_compile_classpath, scala_library_classpath, scala_macro_classpath, scala_xml, parser_combinators, semanticdb

scalacopts

List of strings; optional

Extra compiler options for this binary to be passed to scalac.

scalac_jvm_flags

List of strings; optional

List of JVM flags to be passed to scalac. For example ["-Xmx5G"] could be passed to control memory usage of Scalac.

This is overridden by the scalac_jvm_flags attribute on individual targets.

scala_test_jvm_flags

List of strings; optional

List of JVM flags to be passed to the ScalaTest runner. For example ["-Xmx5G"] could be passed to control memory usage of the ScalaTest runner.

This is overridden by the jvm_flags attribute on individual targets.

unused_dependency_checker_mode

String; optional

Enable unused dependency checking (see Unused dependency checking). Possible values are: off, warn and error.

dependency_tracking_strict_deps_patterns

List of Strings; optional

List of target prefixes included for strict deps analysis. Exclude patetrns with '-'

dependency_tracking_unused_deps_patterns

List of Strings; optional

List of target prefixes included for unused deps analysis. Exclude patetrns with '-'

enable_semanticdb

Boolean; optional (default False)

Enables semanticdb output.

semanticdb_bundle_in_jar

Boolean; optional (default False)

When False, *.semanticdb files are added to the filesystem in a directory.

When True, *.semanticdb files will be bundled inside the jar file.