Cross-Compiling Scala for .NET
Scala, a popular language for the Java platform, is making inroads to .NET thanks to a project run by École Polytechnique Fédérale de Lausanne and funded by Microsoft. The project heavily relies on Jeroen Frijters’ IKVM, which is a Java Virtual Machine that runs on the CLR (.NET and Mono).
InfoQ has been reporting on Scala since we were founded in 2006 when the language was seeing only about 1,000 downloads a month. Since then it has taken Java world by storm with notable sites such as Twitter using it for their back-end software. Even the European Research Council has granted funding to the ten year old language.
Scala originally did have support for the .NET platform, but that has not been maintained and the last public reference to it mentions Scala version 1.4, which is no longer available. Miguel Garcia of EPFL writes,
The cross-compiler was an excellent piece of work but ran on JDK only. Its sources had a lot of dependencies on JDK APIs. This is pretty typical of any Scala applications. Scala programmers still rely on features provided by the JDK, although many times the equivalent can be found in the Scala SDK. We had the cross-compiler but missed a way to automatically replace the JDK dependencies with calls to libraries in the .Net environment.
What Scala needed is a way to replace those JDK dependencies with the equivalents from the IKVM library in an automated fashion. He continues,
The first step was to create an initial set of transforms that would be needed at the source level. The next stage was to extend the Scala compiler to apply the transforms. Not all compilers are flexible enough or provide these types of services, however. The Scala compiler is very modular and supports plug-ins so it was a lot easier to adapt. A new Scala plugin JDK2IKVM was created that applies the source transform in a batch mode. The resulting source code then passes through the rest of the standard compiler phases producing MSIL byte-code with IKVM library references. Voila, we have Scala.Net, a Scala compiler and it can compile itself. Bootstrapping achieved.
The Scala group at EPFL plans on also offering a Visual Studio plugin for Scala.
You can develop Scala programs directly in MS Visual Studio. In the fall the Visual Studio plug-in for Scala will support the basic functionality expected of the IDE namely, code completion, code browsing, line breaks, expression breaks and exception reporting and so on. However, in the short term the current plug-in does not yet support code completion or code browsing. For that reason some developers may prefer to write code on the JVM using Eclipse or Intellij and then do final debugging under Visual Studio. You can find a "how to use" guide here and a slide presentation overview of Scala.Net project here.
Sarah Howe Jul 06, 2015