Open meisam opened 2 years ago
I investigated this issue a bit and I have a hunch why it might be happening. It looks like ScalaWorker3.java
, which is the class that packs the arguments for the Scala3 compiler and calls the compiler, is called with Scala2 libraries.
To be more specific, if I patch ScalaWorker3.java
and print the ScalaVersion during the build, i get scala version: 2.13.5
.
diff --git a/src/java/io/bazel/rulesscala/scalac/ScalacWorker3.java b/src/java/io/bazel/rulesscala/scalac/ScalacWorker3.java
index 370be29..ef136ee 100644
--- a/src/java/io/bazel/rulesscala/scalac/ScalacWorker3.java
+++ b/src/java/io/bazel/rulesscala/scalac/ScalacWorker3.java
@@ -4,0 +5 @@ import scala.Tuple2;
+import scala.util.Properties;
@@ -75,0 +79 @@ class ScalacWorker3 implements Worker.Interface {
+ System.out.println("scala version: " + Properties.versionNumberString());
The compiler runs in the same process as ScalaWorker3.java
, it is just a call to the doCompile
method:
Compiler compiler = driver.newCompiler(r._2);
Reporter reporter = driver.doCompile(compiler, r._1, r._2);
It makes sense that a new process is not spawn for each new compile task, so pay the startup and warmup cost of the scala compiler once, but it sounds like the reported scala version at runtime should match the expected scala3 version.
Cats-effect is an involved library and exercises advanced features in the scala compiler. I thinks that's why this crash does not happen with all the libraries.
I'll do more tests and report the findings.
Got a reproducible nix + bazel build
https://github.com/LibreCybernetics/Monorepo/tree/ref-bazelbuild-scala-3-typelevel-issue
nix develop --ignore-environment
bazel build //code/lib/toml/core:toml-core
vs sbt
cd code/
sbt "toml-coreJVM/compile"
Relating to the comment on https://github.com/bazelbuild/rules_scala/pull/1465#issuecomment-1406636236
The reproducer seems to be failing due to missing dependency on cats-kernel
.
https://github.com/LibreCybernetics/Monorepo/blob/11a67bd75485439f256070be0337d8a77447e7b3/code/lib/toml/core/BUILD#L7
I'm new to Bazel, but as I understand this example for maven_install the project can add a top-level artifact to install the dependency, but each of transitive dependencies needs to be listed in the deps
for given target.
I tested it locally using release 6.6.0 and main with Scala 3.2.1/3.3.1 and 3.3.3 respectively and was able to reproduce the compiler crash. Adding the missing transitive dependency fixed the problem.
I'll try to create a self-contained reproducer for the missing transitive dependency and we'll check if we can make the Scala compiler create a meaningful error instead of crashing the build.
I believe It allows to close this and the linked issues.
Steps to reproduce the crash:
The Scala3 compiler, dotty, crashes with: