Open andyscott opened 4 years ago
Sounds good. You're doing it so that you can utilize metals and vscode?
Also if this is about metals then does this relate / duplicate #915 ?
It's related in the sense that bloop uses SemanticDB, but this serves a different purpose: prebuilding SemanticDB files for large repos in the CI build.
For what purpose? Asking out of curiosity of course as I’m not that familiar with SemanticDB itself.
There's probably lots of possibilities from a tooling perspective, but one concrete thing I can think of is enabling us to apply tools like Scalafix.
How I solved this (without direct rules_scala support):
semanticdb = "@maven//:org_scalameta_semanticdb_scalac_%s" % scala_version_suffix
semanticdb_scalaopts = [ "-Xplugin:$(location %s)" % semanticdb, "-Yrangepos", ]
semanticdb_deps = [ semanticdb, ]
compiler_deps = semanticdb_deps
declare_deps_provider( name = "my_scala_compile_classpath_provider", deps_id = "scala_compile_classpath", visibility = ["//visibility:public"], deps = [ "@maven//:org_scala_lang_scala_compiler", "@maven//:org_scala_lang_scala_library", "@maven//:org_scala_lang_scala_reflect", ] + compiler_deps, )
scala_library(
scalacopts = semanticdb_scalaopts, deps = semanticdb_deps, )
As an extra detail, how I managed to use Scalafix after the above was applied:
```shell
# Install coursier (`cs`) with whatever method.
# Install scalafix:
cs install scalafix
scalafix --version
# I wanted to use ZIO scalafix rules, so download and build ZIO scalafix rules:
git clone https://github.com/zio/zio/
cd zio
sbt scalafixRules/publishLocal
# In your repo:
# Build a deploy jar:
bazel build //some/custom/path:library_deploy.jar
# Run scalafix:
scalafix --tool-classpath $HOME/.ivy2/local/dev.zio/scalafixrules_2.13/2.0.5+38-7efadb73-SNAPSHOT/jars/scalafixrules_2.13.jar --rules Zio2Upgrade --files some/custom/path/src/main/scala/ --classpath bazel-bin/some/custom/path/library_deploy.jar
This issue can probably be closed now. SemanticDB support was added in #1508
Stripe's Scala team has an intern, and this quarter we're planning work that requires SemanticDB outputs!
I believe SemanticDB support can be easily encapsulated in a new optional phase that:
This pattern was already prototyped in higherkindness/rules_scala, so I'm confident that it will work here too.
We'll circle back soon with an update once we can commit to this work.