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

Scala compilation with sbt/zinc #2158

Open
dforsl opened this Issue May 26, 2017 · 9 comments

Comments

Projects
None yet
8 participants
@dforsl
Copy link

dforsl commented May 26, 2017

Gradle currently supports Scala compilation with the typesafe/zinc-compiler, which is in maintenance mode.

However, new development is now ongoing under sbt/zinc. It would be great if the scala-plugin could support this new initiative that is actively further developing Scala compilation.

@ijuma

This comment has been minimized.

Copy link
Contributor

ijuma commented Aug 11, 2017

sbt/zinc includes much improved incremental compilation:

This depends on some factors such as how your classes are organized, but you can see 3x ~ 40x improvements. The reason for the speedup is because it compiles fewer source files than before by untangling the classes from source files. In the example adding a method to scala/scala’s Platform class, sbt 0.13’s name hashing used to compile 72 sources, but the new Zinc compiles 6 sources.

https://developer.lightbend.com/blog/2017-04-18-sbt-1-0-roadmap-and-beta1/#zinc-1-class-based-name-hashing

Also, my understanding is that there is/will be a supported Java API.

@dforsl

This comment has been minimized.

Copy link

dforsl commented Aug 20, 2017

Maybe this should be put in it's own ticket, and probably thought of already, but I just wanted to say that it would be absolutely brilliant if this also utilised the new worker api for parallelism within the same project!

@jjohannes

This comment has been minimized.

Copy link
Member

jjohannes commented Aug 23, 2017

I checked if I could do a quick update to sbt/zinc and run it through our test pipeline. Unfortunately the API seems to be quite different compared to typesafe/zinc. So it is not only a matter of changing the namespace.

If anyone here is more familiar with sbt/zinc and would be willing to provide a PR, I will happily review and merge it.

The integration is encapsulated in ZincScalaCompiler.java and ZincScalaCompilerFactory.java. Ideally we would only need to adjust these two classes.

@dforsl

This comment has been minimized.

Copy link

dforsl commented Aug 24, 2017

As @ijuma hinted, there appears to be a task to provide a proper Java API through sbt/zinc#300. The ticket also points Pants' implementation for Scala compilation with zinc, which could perhaps be of help.

@jjohannes jjohannes removed their assignment Aug 28, 2017

@ijuma

This comment has been minimized.

Copy link
Contributor

ijuma commented Nov 3, 2017

A blog discussing the impressive performance improvement in the new release: http://scala-lang.org/blog/2017/11/03/zinc-blog-1.0.html

@yawaramin

This comment has been minimized.

Copy link

yawaramin commented Dec 16, 2018

Hi, I'm taking a look at this issue. The new zinc API is basically an interface with a bunch of static methods: https://github.com/sbt/zinc/blob/9bef954753a1ae033722d5bc9e89b945a9f2da3e/zinc/src/main/java/xsbti/compile/ZincCompilerUtil.java

However, when I try to use one of these methods, e.g. IncrementalCompiler compiler = ZincCompilerUtil.defaultIncrementalCompiler();

I get the following error:

gradle/subprojects/language-scala/src/main/java/org/gradle/api/internal/tasks/scala/ZincScalaCompiler.java:65: error: static interface method invocations are not supported in -source 1.6
            IncrementalCompiler compiler = ZincCompilerUtil.defaultIncrementalCompiler();
                                                           ^
  (use -source 8 or higher to enable static interface method invocations)

The error does not go away even when I try to force Java 8 source in the language-scala.gradle.kts build file:

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
}

I'm probably doing something wrong w.r.t. setting the source version, would appreciate any help.

@wolfs

This comment has been minimized.

Copy link
Member

wolfs commented Dec 20, 2018

@yawaramin Can you try setting moduleType = ModuleType.REQUIRES_JAVA_8 in

gradlebuildJava {
// Needs to run in the compiler daemon
moduleType = ModuleType.WORKER
}

That should do the trick.

@yawaramin

This comment has been minimized.

Copy link

yawaramin commented Dec 21, 2018

@wolfs thank you, that worked! Now on to the next error :-)

@lunaticare

This comment has been minimized.

Copy link

lunaticare commented Jan 12, 2019

@yawaramin found code for migration to new Zinc API by @samskivert scaled/scala-compiler@c62a27f
Commit message explains a lot 😄
Also pantsbuild/pants#4728
Hope it helps!

@big-guy big-guy added this to the 5.3 RC1 milestone Jan 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment