1
1
# scala_toolchain
2
2
3
- ` scala_toolchain ` allows you to define global configuration to all Scala targets.
3
+ ` scala_toolchain ` allows you to define the global configuration for all Scala
4
+ targets.
4
5
5
- ** Some scala_toolchain must be registered!**
6
+ ** Some ` scala_toolchain ` must be registered!**
6
7
7
- ## Several options to configure ` scala_toolchain `
8
+ ## Options to configure ` scala_toolchain `
8
9
9
10
### A) Use the builtin Scala toolchain via ` scala_toolchains `
10
11
11
- In your workspace file add the following lines:
12
+ Add the following lines to ` WORKSPACE ` :
12
13
13
14
``` py
14
15
# WORKSPACE
@@ -26,48 +27,84 @@ scala_register_toolchains()
26
27
27
28
### B) Defining your own ` scala_toolchain ` requires 2 steps
28
29
29
- 1 . Add your own definition of ` scala_toolchain ` to a ` BUILD ` file:
30
- Example assumes external libraries are resolved with [ rules_jvm_external] ( https://github.com/bazelbuild/rules_jvm_external )
31
-
32
- ``` py
33
- # //toolchains/BUILD
34
- load(" @rules_scala//scala:scala.bzl" , " setup_scala_toolchain" )
35
-
36
- setup_scala_toolchain(
37
- name = " my_toolchain" ,
38
- # configure toolchain dependecies
39
- parser_combinators_deps = [
40
- " @maven//:org_scala_lang_modules_scala_parser_combinators_2_12" ,
41
- ],
42
- scala_compile_classpath = [
43
- " @maven//:org_scala_lang_scala_compiler" ,
44
- " @maven//:org_scala_lang_scala_library" ,
45
- " @maven//:org_scala_lang_scala_reflect" ,
46
- ],
47
- scala_library_classpath = [
48
- " @maven//:org_scala_lang_scala_library" ,
49
- " @maven//:org_scala_lang_scala_reflect" ,
50
- ],
51
- scala_macro_classpath = [
52
- " @maven//:org_scala_lang_scala_library" ,
53
- " @maven//:org_scala_lang_scala_reflect" ,
54
- ],
55
- scala_xml_deps = [
56
- " @maven//:org_scala_lang_modules_scala_xml_2_12" ,
57
- ],
58
- # example of setting attribute values
59
- scalacopts = [" -Ywarn-unused" ],
60
- unused_dependency_checker_mode = " off" ,
61
- visibility = [" //visibility:public" ]
62
- )
63
- ```
64
-
65
- 2 . Register your custom toolchain from `WORKSPACE ` :
66
-
67
- ```py
68
- # WORKSPACE
69
- register_toolchains(" //toolchains:my_scala_toolchain" )
70
- ```
30
+ #### Step 1
31
+
32
+ You can add your own ` scala_toolchain ` definition to a ` BUILD ` file in one of
33
+ two ways. If you only want to set different [ configuration
34
+ options] ( #configuration-options ) , but rely on the builtin toolchain JARs, use
35
+ ` scala_toolchain ` directly. This example is inspired by [ ` BUILD.bazel ` from michalbogacz/scala-bazel-monorepo/] (
36
+ https://github.com/michalbogacz/scala-bazel-monorepo/blob/2cac860f386dcaa1c3be56cd25a84b247d335743/BUILD.bazel )):
37
+
38
+ ``` py
39
+ load(" @rules_scala//scala:scala_toolchain.bzl" , " scala_toolchain" )
40
+
41
+ scala_toolchain(
42
+ name = " my_toolchain_impl" ,
43
+ scalacopts = [
44
+ " -Wunused:all" ,
45
+ ],
46
+ strict_deps_mode = " error" ,
47
+ unused_dependency_checker_mode = " warn" ,
48
+ )
49
+
50
+ toolchain(
51
+ name = " my_toolchain" ,
52
+ toolchain = " :my_toolchain_impl" ,
53
+ toolchain_type = " @rules_scala//scala:toolchain_type" ,
54
+ visibility = [" //visibility:public" ],
55
+ )
56
+ ```
57
+
58
+ If you want to use your own compiler JARs, use ` setup_scala_toolchain() `
59
+ instead. This example assumes the external libraries are resolved with
60
+ [ rules_jvm_external] ( https://github.com/bazelbuild/rules_jvm_external )
61
+
62
+ ``` py
63
+ # //toolchains/BUILD
64
+ load(" @rules_scala//scala:scala.bzl" , " setup_scala_toolchain" )
65
+
66
+ setup_scala_toolchain(
67
+ name = " my_toolchain" ,
68
+ # configure toolchain dependecies
69
+ parser_combinators_deps = [
70
+ " @maven//:org_scala_lang_modules_scala_parser_combinators_2_12" ,
71
+ ],
72
+ scala_compile_classpath = [
73
+ " @maven//:org_scala_lang_scala_compiler" ,
74
+ " @maven//:org_scala_lang_scala_library" ,
75
+ " @maven//:org_scala_lang_scala_reflect" ,
76
+ ],
77
+ scala_library_classpath = [
78
+ " @maven//:org_scala_lang_scala_library" ,
79
+ " @maven//:org_scala_lang_scala_reflect" ,
80
+ ],
81
+ scala_macro_classpath = [
82
+ " @maven//:org_scala_lang_scala_library" ,
83
+ " @maven//:org_scala_lang_scala_reflect" ,
84
+ ],
85
+ scala_xml_deps = [
86
+ " @maven//:org_scala_lang_modules_scala_xml_2_12" ,
87
+ ],
88
+ # example of setting attribute values
89
+ scalacopts = [" -Ywarn-unused" ],
90
+ unused_dependency_checker_mode = " off" ,
91
+ visibility = [" //visibility:public" ]
92
+ )
93
+ ```
94
+
95
+ #### Step 2
96
+
97
+ Register your custom toolchain:
98
+
99
+ ``` py
100
+ # MODULE.bazel or WORKSPACE
101
+ register_toolchains(" //toolchains:my_scala_toolchain" )
102
+ ```
103
+
104
+ ## Configuration options
105
+
106
+ The following attributes apply to both ` scala_toolchain ` and
107
+ ` setup_scala_toolchain ` .
71
108
72
109
<table class =" table table-condensed table-bordered table-params " >
73
110
<colgroup >
0 commit comments