A few months ago, I was playing around with seeing how I could adapt an existing Java code base so that I could finish doing the work in better languages -- and have the code work on both the JVM and the CLR.
It seems that frustration will inevitably follow any attempt to incorporate any J# into the .Net versions of the stack (both IKVM and the Scala-net compilers bork when they see another Java in the stack) -- even though you can call Jython into Scala into Java on the JVM, this Tower of Babel cannot stand on the CLR with the J# runtime in the picture -- Java e.g. a Swing-based GUI using the J# extensions, has to stand off to one side.
That said, the Scala on .Net "hello world" with Scala 2.7.1 is comparatively painless.
- Install the scala-msil package (
sbaz install scala-msil
) - Create file
Hello.scala
as
import System.Console object test extends Application { Console.WriteLine("Hello world!") }
- In a Visual Studio command prompt, issue
%SCALA_HOME%\bin\scalac-net.bat hello.scala
- Copy
%SCALA_HOME%\lib\*.dll
to the current directory - Run the resulting
test.exe
This uses the 1.0 version of mscorlib.dll
; as a post-processing step you may wish to re-base against the .Net 2.0 version -- for this, you need to rebuild predef.dll
and scalaruntime.dll
using the same technique as needed to strong-name them after the fact; only this time you want to reset the mscorlib
reference from
.assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 1:0:5000:0 }
.assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 2:0:0:0 }
as well as doing any strong-naming you may desire.
To set the assembly name, add -Xassem [assembly name]
to the compile command, to generate hello.exe
.
To control the type of the generated assembly (.dll
rather than .exe
), I've not found a way other than taking the generated [assembly name].msil
and ilasm
ing it manually. In particular trying to skip generating the unwanted .exe
will mean figuring why using scalac.bat -target:msil
always gives
error: fatal error: class scala.runtime.BoxedBooleanArray not found.
whatever I do with -Xassem-path
or tweaking environment variables.
No comments:
Post a Comment