Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SemanticDB phases #952

Open
andyscott opened this issue Jan 23, 2020 · 7 comments
Open

SemanticDB phases #952

andyscott opened this issue Jan 23, 2020 · 7 comments

Comments

@andyscott
Copy link
Contributor

andyscott commented Jan 23, 2020

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:

  1. adds the scalac plugin
  2. declares the new SemanticDB output files

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.

@ittaiz
Copy link
Member

ittaiz commented Jan 23, 2020

Sounds good.
You're doing it so that you can utilize metals and vscode?

@ittaiz
Copy link
Member

ittaiz commented Jan 24, 2020

Also if this is about metals then does this relate / duplicate #915 ?

@andyscott
Copy link
Contributor Author

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.

@ittaiz
Copy link
Member

ittaiz commented Jan 24, 2020

For what purpose? Asking out of curiosity of course as I’m not that familiar with SemanticDB itself.

@long-stripe
Copy link
Contributor

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.

https://scalameta.org/docs/semanticdb/guide.html#scalafix

@gergelyfabian
Copy link
Contributor

gergelyfabian commented Jan 5, 2023

How I solved this (without direct rules_scala support):

  1. Added semanticdb as a dependency with rules_jvm_external: "org.scalameta:semanticdb-scalac_%s:4.7.1" % scala_version
  2. Set up your scalacopts and compiler plugins accordingly:
semanticdb = "@maven//:org_scalameta_semanticdb_scalac_%s" % scala_version_suffix

semanticdb_scalaopts = [
    "-Xplugin:$(location %s)" % semanticdb,
    "-Yrangepos",
]

semanticdb_deps = [
    semanticdb,
]

compiler_deps = semanticdb_deps

# Ensure your deps provider for the scala compiler includes the compiler 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,
)

# In your targets ensure to provide scalaopts and deps:
scala_library(
  # ...
  scalacopts = semanticdb_scalaopts,
  deps = semanticdb_deps,
)

As an extra detail, how I managed to use Scalafix after the above was applied:

# 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

@crt-31
Copy link
Contributor

crt-31 commented Nov 30, 2023

This issue can probably be closed now. SemanticDB support was added in #1508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants