Skip to content

Commit

Permalink
Replace the annex_3 artifact tree with annex
Browse files Browse the repository at this point in the history
annex_3 is unnecessary and using it can cause multiple Scala 2 library
jars to end up on the classpath
  • Loading branch information
James Judd committed Jul 6, 2024
1 parent eb2991a commit 4656049
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 328 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protobuf_deps()
# Specify the scala compiler we wish to use; in this case, we'll use the default one specified in rules_scala_annex
bind(
name = "default_scala",
actual = "@rules_scala_annex//src/main/scala:zinc_2_13_14",
actual = "@rules_scala_annex//src/main/scala:zinc_2_13",
)
```

Expand Down
12 changes: 1 addition & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

# Scala
# Scala 2_13 and 3
load("//rules/scala:workspace.bzl", "scala_register_toolchains", "scala_repositories")

scala_repositories()
Expand All @@ -133,16 +133,6 @@ load("@annex_2_12//:defs.bzl", annex_2_12_pinned_maven_install = "pinned_maven_i

annex_2_12_pinned_maven_install()

# Scala 3

load("//rules/scala:workspace_3.bzl", "scala_3_repositories")

scala_3_repositories()

load("@annex_3//:defs.bzl", annex_3_pinned_maven_install = "pinned_maven_install")

annex_3_pinned_maven_install()

# Scala fmt

load("//rules/scalafmt:workspace.bzl", "scalafmt_default_config", "scalafmt_repositories")
Expand Down
450 changes: 343 additions & 107 deletions annex_install.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions docs/newdocs/scala_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

The scala version used by a buildable target is specified via the `ScalaConfiguration` passed in to the rule's `scala` attribute.

This attribute defaults to using the `default_scala` specified via `bind` in the `WORKSPACE` file of the repo. For example, suppose the `ScalaConfiguration` you wish to default to is defined by `//scala:2_13_14`. In your `WORKSPACE`, you would include:
This attribute defaults to using the `default_scala` specified via `bind` in the `WORKSPACE` file of the repo. For example, suppose the `ScalaConfiguration` you wish to default to is defined by `//scala:2_13`. In your `WORKSPACE`, you would include:

```python
bind(
name = "default_scala",
actual = "//scala:2_13_14",
actual = "//scala:2_13",
)
```

Expand All @@ -16,45 +16,45 @@ We provide two means of creating the `ScalaConfiguration`: `configure_bootstrap_
Example:

```python
compiler_classpath_2_13_14 = [
"@scala_compiler_2_13_14//jar",
"@scala_library_2_13_14//jar",
"@scala_reflect_2_13_14//jar",
compiler_classpath_2_13 = [
"@scala_compiler_2_13//jar",
"@scala_library_2_13//jar",
"@scala_reflect_2_13//jar",
]

runtime_classpath_2_13_14 = [
"@scala_library_2_13_14//jar",
runtime_classpath_2_13 = [
"@scala_library_2_13//jar",
]

# This creates a basic ScalaConfiguration that relies on the scalac compiler
configure_bootstrap_scala(
name = "bootstrap_2_13_14",
compiler_classpath = compiler_classpath_2_13_14,
runtime_classpath = runtime_classpath_2_13_14,
name = "bootstrap_2_13",
compiler_classpath = compiler_classpath_2_13,
runtime_classpath = runtime_classpath_2_13,
version = "2.13.14",
visibility = ["//visibility:public"],
)

# compiler bridge needed to configure zinc compiler
scala_library(
name = "compiler_bridge_2_13_14",
name = "compiler_bridge_2_13",
srcs = [
"@compiler_bridge_2_13//:src",
],
scala = ":bootstrap_2_13_14",
scala = ":bootstrap_2_13",
visibility = ["//visibility:public"],
deps = compiler_classpath_2_13_14 + [
deps = compiler_classpath_2_13 + [
"@scala_annex_org_scala_sbt_compiler_interface//jar",
"@scala_annex_org_scala_sbt_util_interface//jar",
],
)

# This augments the configuration to configure the zinc compiler
configure_zinc_scala(
name = "zinc_2_13_14",
compiler_bridge = ":compiler_bridge_2_13_14",
compiler_classpath = compiler_classpath_2_13_14,
runtime_classpath = runtime_classpath_2_13_14,
name = "zinc_2_13",
compiler_bridge = ":compiler_bridge_2_13",
compiler_classpath = compiler_classpath_2_13,
runtime_classpath = runtime_classpath_2_13,
version = "2.13.14",
visibility = ["//visibility:public"],
)
Expand All @@ -68,13 +68,13 @@ For example:
scala_library(
name = "example_compiled_with_scalac",
srcs = glob(["**/*.scala"])
scala = "<package>:bootstrap_2_13_14
scala = "<package>:bootstrap_2_13
)

scala_library(
name = "example_compiled_with_zinc",
srcs = glob(["**/*.scala"])
scala = "<package>:zinc_2_13_14
scala = "<package>:zinc_2_13
)

# This would use whatever //external:default_scala points to (i.e. what you bind default_scala to in your WORKSPACE)
Expand Down
44 changes: 27 additions & 17 deletions rules/scala/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ filegroup(
visibility = ["//visibility:public"]
)"""

scala_2_13_version = "2.13.14"
scala_3_version = "3.4.2"
zinc_version = "1.10.0"

def scala_artifacts():
return [
"ch.epfl.scala:bloop-frontend_2.12:1.0.0",
Expand All @@ -18,29 +22,36 @@ def scala_artifacts():
"com.thesamet.scalapb:scalapb-runtime_2.13:0.11.17",
"net.sourceforge.argparse4j:argparse4j:0.8.1",
"org.jacoco:org.jacoco.core:0.7.5.201505241946",
"org.scala-lang:scala-compiler:2.13.14",
"org.scala-lang:scala-library:2.13.14",
"org.scala-lang:scala-reflect:2.13.14",
"org.scala-sbt:compiler-interface:1.10.0",
"org.scala-sbt:io_2.13:1.10.0",
"org.scala-sbt:test-interface:1.0",
"org.scala-sbt:util-interface:1.10.0",
"org.scala-sbt:util-logging_2.13:1.10.0",
"org.scala-sbt:zinc_2.13:1.10.0",
"org.scala-sbt:zinc-apiinfo_2.13:1.10.0",
"org.scala-sbt:zinc-classpath_2.13:1.10.0",
"org.scala-sbt:zinc-compile-core_2.13:1.10.0",
"org.scala-sbt:zinc-core_2.13:1.10.0",
"org.scala-sbt:zinc-persist_2.13:1.10.0",
"org.scala-sbt:compiler-interface:{}".format(zinc_version),
"org.scala-sbt:io_2.13:{}".format(zinc_version),
"org.scala-sbt:util-interface:{}".format(zinc_version),
"org.scala-sbt:util-logging_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-apiinfo_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-classpath_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-compile-core_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-core_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-persist_2.13:{}".format(zinc_version),
"org.scala-sbt:compiler-interface:{}".format(zinc_version),
"org.scala-lang:scala-compiler:{}".format(scala_2_13_version),
"org.scala-lang:scala-library:{}".format(scala_2_13_version),
"org.scala-lang:scala-reflect:{}".format(scala_2_13_version),
"org.scala-lang:scala3-compiler_3:{}".format(scala_3_version),
"org.scala-lang:scala3-library_3:{}".format(scala_3_version),
# The compiler bridge has a dependency on compiler-interface, which has a dependency on the Scala 2
# library. We need to set this to neverlink = True to avoid this the Scala 2 library being pulled
# onto the Scala 3, and other Scala versions like 2.12, compiler classpath during runtime.
maven.artifact("org.scala-lang", "scala3-sbt-bridge", scala_3_version, neverlink = True),
# The compiler bridge has a dependency on compiler-interface, which has a dependency on the Scala 2
# library. We need to set this to neverlink = True to avoid this the Scala 2 library being pulled
# onto the Scala 3, and other Scala versions like 2.12, compiler classpath during runtime.
maven.artifact("org.scala-sbt", "compiler-bridge_2.13", "1.10.0", neverlink = True),
maven.artifact("org.scala-sbt", "compiler-bridge_2.13", zinc_version, neverlink = True),
]

def scala_repositories(
java_launcher_version = "5.0.0",
java_launcher_template_sha = "ab1370fd990a8bff61a83c7bd94746a3401a6d5d2299e54b1b6bc02db4f87f68"):
java_launcher_version = "7.2.0",
java_launcher_template_sha = "ee4aa47ae5e639632c67be5cc0ccbc4e941a67a1b884a1ce0c4329357a4b62b2"):
maven_install(
name = "annex",
artifacts = scala_artifacts(),
Expand All @@ -64,7 +75,6 @@ def scala_repositories(
name = "anx_java_stub_template",
sha256 = java_launcher_template_sha,
urls = [
"https://mirror.bazel.build/%s" % java_stub_template_url,
"https://%s" % java_stub_template_url,
],
)
Expand Down
11 changes: 7 additions & 4 deletions rules/scala/workspace_2_12.bzl
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")
load("@rules_scala_annex//rules/scala:workspace.bzl", "zinc_version")

scala_2_12_version = "2.12.19"

def scala_2_12_artifacts():
return [
"org.scala-lang:scala-compiler:2.12.19",
"org.scala-lang:scala-library:2.12.19",
"org.scala-lang:scala-reflect:2.12.19",
"org.scala-lang:scala-compiler:{}".format(scala_2_12_version),
"org.scala-lang:scala-library:{}".format(scala_2_12_version),
"org.scala-lang:scala-reflect:{}".format(scala_2_12_version),
# The compiler bridge has a dependency on compiler-interface, which has a dependency on the Scala 2
# library. We need to set this to neverlink = True to avoid this the Scala 2 library being pulled
# onto the Scala 3, and other Scala versions like 2.12, compiler classpath during runtime.
maven.artifact("org.scala-sbt", "compiler-bridge_2.12", "1.10.0", neverlink = True),
maven.artifact("org.scala-sbt", "compiler-bridge_2.12", zinc_version, neverlink = True),
]

def scala_2_12_repositories():
Expand Down
26 changes: 0 additions & 26 deletions rules/scala/workspace_3.bzl

This file was deleted.

1 change: 0 additions & 1 deletion scripts/gen-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ echo "$(dirname "$0")/.."
echo "generating dependencies for main workspace"
bazel run @unpinned_annex//:pin
bazel run @unpinned_annex_2_12//:pin
bazel run @unpinned_annex_3//:pin
bazel run @unpinned_annex_scalafmt//:pin
bazel run @unpinned_annex_proto//:pin

Expand Down
Loading

0 comments on commit 4656049

Please sign in to comment.