Wednesday, June 3, 2009

Compiling Remotely

As you may know, the fsc compiler, the recommended way to compile Scala, and used by the Scala interpreter by default, detaches a daemon service the first time it is run. After that, fsc will always call the daemon service to compile for it, to save time.

It does this through TCP, which begs the question... can I compile remotely? The answer is Yes! It's not documented, and it is a bit awkward, but...

First, you get fsc running on the server by running fsc -verbose, like this:

$fsc -verbose
[Server arguments: -d C:\Users\Daniel\Documents\Programas\. -verbose]
[VM arguments: ]
[Temp directory: C:\PROGRA~1\Scala\bin\..\var\scala-devel]
[Executed command: C:\PROGRA~1\Scala\bin\..\bin\scala.bat]
[Port number: 1385]
[Connected to compilation daemon at port 1385]
Usage: fsc
where possible standard options include:
-g: Specify level of generated debugging info (none,source,line,vars,notailcalls)
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-unchecked Enable detailed unchecked warnings
-classpath Specify where to find user class files
-sourcepath Specify where to find input source files
-bootclasspath Override location of bootstrap class files
-extdirs Override location of installed extensions
-d Specify where to place generated class files
-encoding Specify character encoding used by source files
-target: Specify for which target object files should be built (jvm-1.5,jvm-1.4,msil)
-print Print program with all Scala-specific features removed
-optimise Generates faster bytecode by applying optimisations to the program
-explaintypes Explain type errors in more detail
-uniqid Print identifiers with unique names for debugging
-version Print product version and exit
-help Print a synopsis of standard options
-X Print a synopsis of advanced options
@<file> A text file containing compiler arguments (options and source files)

This will get you the port number. Next, you can compile whatever you like from a remote client like this:

$fsc -server strategy.scala

That's it. Cool, eh?

No comments:

Post a Comment