-4

https://docs.scala-lang.org/overviews/compiler-options/index.html says

Scala compiler scalac offers various compiler options, also referred to as compiler flags, to change how to compile your program.

Nowadays, most people are not running scalac from the command line. Instead, they use sbt, an IDE, and other tools as their interface to the compiler. Therefore they may not even have scalac installed, and won’t think to do man scalac.

Does "the compiler" refer to scalac?

If yes, is "they use sbt, an IDE, and other tools as their interface to the compiler" contrary to "therefore they may not even have scalac installed"?

Does sbt rely on scalac?

Thanks.

Community
  • 1
  • 1
Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

2

Scala compiler can be accessed programmatically via an API packaged by scala-compiler.jar dependency, hence tools such as IDEs and SBT can implement their own client frontends over this API to drive compiler functionality. scalac is just a bash script that executes scala.tools.nsc.MainClass class from scala-compiler.jar.


Does sbt rely on scalac?

No, sbt uses compiler API directly. One of the key concepts to understand regarding sbt is that the build definition is itself Scala code, either vanilla or DSL, but Scala nevertheless. The version of Scala used to compile the build definition is separate from the version of Scala used to compile project proper. The build definition source code in build.sbt and project/*.scala will be compiled using Scala version specified indirectly via sbt.version=1.2.8 setting in project/build.properties, whilst project source code proper in src/main/scala/* will be compiled using Scala version specified directly via scalaVersion := "2.13.1" setting in build.sbt. Note how they can indeed differ. Think of the build definition as simply another Scala app which uses sbt API for its implementation.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • Thanks. What compiler does sbt rely on? – Tim Mar 15 '20 at 13:04
  • Do you mean sbt (and IDE such as IntelliJ) doesn't use `scalac`? – Tim Mar 15 '20 at 14:16
  • 2
    Why would a tool written in Scala or Java use the wrapper script around the compiler API when they can use the compiler API? – Jörg W Mittag Mar 15 '20 at 14:24
  • @JörgWMittag Thanks. In case of Java, do Java IDEs and build tools also work in similar way as Scala's? Do they rely on `javac` and `java` commands? – Tim Mar 15 '20 at 18:07
  • @JörgWMittag https://stackoverflow.com/questions/60697141/do-java-ides-and-build-tools-rely-on-javac-and-java-commands – Tim Mar 15 '20 at 20:07