diff --git a/docs/stardoc/rules_scala.md b/docs/stardoc/rules_scala.md index 71942597..258c3778 100644 --- a/docs/stardoc/rules_scala.md +++ b/docs/stardoc/rules_scala.md @@ -9,7 +9,7 @@
 load("@//rules:rules_scala.bzl", "emulate_rules_scala")
 
-emulate_rules_scala(scala, scalatest, extra_deps)
+emulate_rules_scala(scalatest, extra_deps)
 
@@ -19,7 +19,6 @@ emulate_rules_scala(scala, scala |

-

| none | | scalatest |

-

| none | | extra_deps |

-

| `[]` | diff --git a/docs/stardoc/scala.md b/docs/stardoc/scala.md index 47a10b09..8882a5aa 100644 --- a/docs/stardoc/scala.md +++ b/docs/stardoc/scala.md @@ -2,34 +2,6 @@ - - -## configure_bootstrap_scala - -
-load("@//rules:scala.bzl", "configure_bootstrap_scala")
-
-configure_bootstrap_scala(name, compiler_classpath, global_plugins, global_scalacopts,
-                          runtime_classpath, semanticdb_bundle, use_ijar, version)
-
- -Configures a Scala compiler that's used for compiling the Scala targets used by `configure_zinc_scala`. You probably want `configure_zinc_scala` instead (even if you're not using incremental compilation), as this rule doesn't support features like dependency checking and compilation workers. - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| compiler_classpath | JVM targets that will always be on the compiler classpath. Usually, this is the compiler itself and the standard library. | List of labels | required | | -| global_plugins | scalac plugins that will always be enabled. | List of labels | optional | `[]` | -| global_scalacopts | scalac options that will always be enabled. | List of strings | optional | `[]` | -| runtime_classpath | JVM targets that will always be on the runtime classpath. Usually, this is the standard library. | List of labels | required | | -| semanticdb_bundle | Whether to bundle SemanticDB files in the resulting JAR. Note that in Scala 2, this requires the SemanticDB compiler plugin. | Boolean | optional | `True` | -| use_ijar | Whether to use ijar for this compiler. See https://github.com/bazelbuild/bazel/blob/master/third_party/ijar/README.txt for more information. | Boolean | optional | `True` | -| version | The Scala version this compiler corresponds to. | String | required | | - - ## scala_binary @@ -39,7 +11,7 @@ load("@//rules:scala.bzl", "scala_binary") scala_binary(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist, javacopts, jvm_flags, main_class, plugins, resource_jars, resource_strip_prefix, - runtime_deps, scala, scalacopts) + runtime_deps, scala_toolchain_name, scalacopts) Compiles and links a Scala JVM executable. @@ -71,7 +43,7 @@ To run the program: `bazel run ` | resource_jars | The JARs to merge into the output JAR. | List of labels | optional | `[]` | | resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | The Scalac options. | List of strings | optional | `[]` | @@ -112,7 +84,7 @@ load("@//rules:scala.bzl", "scala_library") scala_library(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist, exports, javacopts, macro, neverlink, plugins, resource_jars, resource_strip_prefix, - runtime_deps, scala, scalacopts) + runtime_deps, scala_toolchain_name, scalacopts) Compiles a Scala JVM library. @@ -137,7 +109,7 @@ Compiles a Scala JVM library. | resource_jars | The JARs to merge into the output JAR. | List of labels | optional | `[]` | | resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | The Scalac options. | List of strings | optional | `[]` | @@ -148,7 +120,7 @@ Compiles a Scala JVM library.
 load("@//rules:scala.bzl", "scala_repl")
 
-scala_repl(name, deps, data, jvm_flags, scala, scalacopts)
+scala_repl(name, deps, data, jvm_flags, scala_toolchain_name, scalacopts)
 
Launches a REPL with all given dependencies available. @@ -164,7 +136,7 @@ To run: `bazel run ` | deps | Dependencies that should be made available to the REPL. | List of labels | optional | `[]` | | data | The additional runtime files needed by this REPL. | List of labels | optional | `[]` | | jvm_flags | The JVM runtime flags. | List of strings | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | Options to pass to scalac. | List of strings | optional | `[]` | @@ -177,7 +149,7 @@ load("@//rules:scala.bzl", "scala_test") scala_test(name, deps, srcs, data, resources, deps_unused_whitelist, deps_used_whitelist, frameworks, isolation, javacopts, jvm_flags, plugins, resource_jars, resource_strip_prefix, - runner, runtime_deps, scala, scalacopts, shared_deps, subprocess_runner) + runner, runtime_deps, scala_toolchain_name, scalacopts, shared_deps, subprocess_runner) Compiles and links a collection of Scala tests. @@ -210,7 +182,7 @@ To build and run a specific test: `bazel test --test_filter=resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runner | - | Label | optional | `"@//src/main/scala/higherkindness/rules_scala/workers/zinc/test"` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | Options to pass to scalac. | List of strings | optional | `[]` | | shared_deps | If isolation is "classloader", the list of deps to keep loaded between tests | List of labels | optional | `[]` | | subprocess_runner | - | Label | optional | `"@//src/main/scala/higherkindness/rules_scala/common/sbt-testing:subprocess"` | @@ -223,7 +195,7 @@ To build and run a specific test: `bazel test --test_filter= load("@//rules:scala.bzl", "scaladoc") -scaladoc(name, deps, srcs, compiler_deps, scala, scalacopts, title) +scaladoc(name, deps, srcs, compiler_deps, scala_toolchain_name, scalacopts, title) Generates Scaladoc. @@ -237,46 +209,11 @@ Generates Scaladoc. | deps | Dependencies that should be made available to the Scaladoc tool. These may include libraries referenced in Scaladoc or public signatures. | List of labels | optional | `[]` | | srcs | Sources from which to generate Scaladoc. These may include `*.java` files, `*.scala` files, and source JARs. | List of labels | optional | `[]` | | compiler_deps | JVM targets that should be included on the compile classpath. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | Options to pass to scalac. | List of strings | optional | `[]` | | title | The name of the project. If none is provided, the target label will be used. | String | optional | `""` | - - -## configure_zinc_scala - -
-load("@//rules:scala.bzl", "configure_zinc_scala")
-
-configure_zinc_scala(compiler_bridge, compiler_classpath, version, global_plugins,
-                     global_scalacopts, incremental, log_level, runtime_classpath, semanticdb_bundle,
-                     use_ijar, kwargs)
-
- -Configures a Scala compiler. - -You can use this for a Scala target by setting the `scala` attribute to your `configure_zinc_scala` target. - - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| compiler_bridge | The compiler bridge (org.scala-sbt.compiler-bridge). | none | -| compiler_classpath | JVM targets that will always be on the compiler classpath. Usually, this is the compiler itself and the standard library. | none | -| version | The Scala version this compiler corresponds to. | none | -| global_plugins | scalac plugins that will always be enabled. | `[]` | -| global_scalacopts | scalac options that will always be enabled. | `[]` | -| incremental | Whether Zinc's incremental compilation will be available for this Zinc compiler. If True, this requires additional configuration to use incremental compilation. | `False` | -| log_level | The compiler log level. One of "error", "warn", "info", "debug", or "none". | `"warn"` | -| runtime_classpath | JVM targets that will always be on the runtime classpath. Usually, this is the standard library. | `[]` | -| semanticdb_bundle | Whether to bundle SemanticDB files in the resulting JAR. Note that in Scala 2, this requires the SemanticDB compiler plugin. | `True` | -| use_ijar | Whether to use ijar for this compiler. See https://github.com/bazelbuild/bazel/blob/master/third_party/ijar/README.txt for more information. | `True` | -| kwargs |

-

| none | - - ## make_scala_binary diff --git a/docs/stardoc/scala_with_scalafmt.md b/docs/stardoc/scala_with_scalafmt.md index 73cd6de5..36c1e6dd 100644 --- a/docs/stardoc/scala_with_scalafmt.md +++ b/docs/stardoc/scala_with_scalafmt.md @@ -23,7 +23,7 @@ load("@//rules:scala_with_scalafmt.bzl", "scala_binary") scala_binary(name, deps, srcs, data, resources, config, deps_unused_whitelist, deps_used_whitelist, format, javacopts, jvm_flags, main_class, plugins, resource_jars, resource_strip_prefix, - runtime_deps, scala, scalacopts) + runtime_deps, scala_toolchain_name, scalacopts) Compiles and links a Scala JVM executable. @@ -57,7 +57,7 @@ To run the program: `bazel run ` | resource_jars | The JARs to merge into the output JAR. | List of labels | optional | `[]` | | resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | The Scalac options. | List of strings | optional | `[]` | @@ -70,7 +70,7 @@ load("@//rules:scala_with_scalafmt.bzl", "scala_library") scala_library(name, deps, srcs, data, resources, config, deps_unused_whitelist, deps_used_whitelist, exports, format, javacopts, macro, neverlink, plugins, resource_jars, - resource_strip_prefix, runtime_deps, scala, scalacopts) + resource_strip_prefix, runtime_deps, scala_toolchain_name, scalacopts) Compiles a Scala JVM library. @@ -97,7 +97,7 @@ Compiles a Scala JVM library. | resource_jars | The JARs to merge into the output JAR. | List of labels | optional | `[]` | | resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | The Scalac options. | List of strings | optional | `[]` | @@ -110,7 +110,7 @@ load("@//rules:scala_with_scalafmt.bzl", "scala_test") scala_test(name, deps, srcs, data, resources, config, deps_unused_whitelist, deps_used_whitelist, format, frameworks, isolation, javacopts, jvm_flags, plugins, resource_jars, - resource_strip_prefix, runner, runtime_deps, scala, scalacopts, shared_deps, + resource_strip_prefix, runner, runtime_deps, scala_toolchain_name, scalacopts, shared_deps, subprocess_runner) @@ -146,7 +146,7 @@ To build and run a specific test: `bazel test --test_filter=resource_strip_prefix | The path prefix to strip from classpath resources. | String | optional | `""` | | runner | - | Label | optional | `"@//src/main/scala/higherkindness/rules_scala/workers/zinc/test"` | | runtime_deps | The JVM runtime-only library dependencies. | List of labels | optional | `[]` | -| scala | The Scala compiler to use (a `configure_bootstrap_scala` or `configure_zinc_scala` target). Defaults to the `default_scala` target specified in the WORKSPACE file. | Label | optional | `"@//external:default_scala"` | +| scala_toolchain_name | The name of the Scala toolchain to use for this target (as provided to `register_*_toolchain`) | String | optional | `""` | | scalacopts | Options to pass to scalac. | List of strings | optional | `[]` | | shared_deps | If isolation is "classloader", the list of deps to keep loaded between tests | List of labels | optional | `[]` | | subprocess_runner | - | Label | optional | `"@//src/main/scala/higherkindness/rules_scala/common/sbt-testing:subprocess"` | diff --git a/docs/stardoc/scala_workspace.md b/docs/stardoc/scala_workspace.md index 826e075f..2c76b6dc 100644 --- a/docs/stardoc/scala_workspace.md +++ b/docs/stardoc/scala_workspace.md @@ -23,11 +23,18 @@ scala_artifacts()
 load("@//rules/scala:workspace.bzl", "scala_register_toolchains")
 
-scala_register_toolchains()
+scala_register_toolchains(default_scala_toolchain_name, toolchains)
 
+Registers the provided Scala toolchains with Bazel and sets a default one to use. + +**PARAMETERS** +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| default_scala_toolchain_name | The name of the default Scala toolchain to use. | none | +| toolchains | The toolchains to register. | `[]` | @@ -47,7 +54,7 @@ scala_repositories(java_laun | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| java_launcher_version |

-

| `"7.2.0"` | +| java_launcher_version |

-

| `"7.4.0"` | | java_launcher_template_sha |

-

| `"ee4aa47ae5e639632c67be5cc0ccbc4e941a67a1b884a1ce0c4329357a4b62b2"` | diff --git a/rules/BUILD b/rules/BUILD index 7e3250fb..bab5e0eb 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -49,5 +49,6 @@ bzl_library( "@bazel_skylib//lib:shell", "@rules_java//toolchains:toolchain_utils", "@rules_jvm_external//:implementation", + "@rules_scala_annex_scala_toolchain//:default", ], ) diff --git a/rules/scala/workspace.bzl b/rules/scala/workspace.bzl index 7d72a07f..3a944241 100644 --- a/rules/scala/workspace.bzl +++ b/rules/scala/workspace.bzl @@ -83,6 +83,7 @@ def _toolchain_configuration_repository_impl(repository_ctx): "BUILD", """\ load(":default.bzl", "default_scala_toolchain_name") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "string_setting") string_setting( @@ -96,6 +97,12 @@ string_setting( build_setting_default = default_scala_toolchain_name, visibility = ["//visibility:public"], ) + +bzl_library( + name = "default", + srcs = ["default.bzl"], + visibility = ["//visibility:public"], +) """, ) @@ -115,6 +122,13 @@ _toolchain_configuration_repository = repository_rule( ) def scala_register_toolchains(default_scala_toolchain_name, toolchains = []): + """Registers the provided Scala toolchains with Bazel and sets a default one to use. + + Args: + default_scala_toolchain_name: The name of the default Scala toolchain to use. + toolchains: The toolchains to register. + """ + _toolchain_configuration_repository( name = "rules_scala_annex_scala_toolchain", default_scala_toolchain_name = default_scala_toolchain_name,