F# Compiler Source Drop, April 2010

F# 2.0 Compiler + Library Source Code Drop, matching Visual Studio 2010 (R) SP1 binary release

This directory contains a drop of the source code for an F# 2.0 compiler and core library. The code has been cleaned up "a little" to try to help ensure better stability as more development is done on the codebase.

Before we start, are sure you're in the right place?

To emphasize, this distribution should not be seen as a way to "get" an F# compiler for immediate use. For that you're better going to fsharp.net or tryfsharp.org  

Copyright: Copyright 2002-2010 (c) Microsoft Corporation.

License: subject to terms and conditions of the Apache License, Version 2.0. A copy of the license can be found in the License.html file at the root of this distribution. By using this source code in any fashion, you are agreeing to be bound by the terms of the Apache License, Version 2.0.

You must not remove this notice, or any other, from this software.

Questions? If you have questions about the source code, please ask on a forum, or start a forum for community discussions, or post to the forum on fsharppowerpack.codeplex.com. Please do not ask the F# team at Microsoft for help with this source code: they like to be friendly, but they are very busy working on improving F# and need to focus on that.

Updates? The F# team do not do active development in this repository, though some changes such as cleanup or additional tools may be submitted. They aspire to update the tree as and when future versions of F# compilers are released from Microsoft.

What do I get when I compile?

When you compile, you get fsc.exe, fsi.exe, FSharp.Core.dll and some related DLLs.

How do I compile?

The prerequisites and build command line for compiling the source (on Windows) are shown later in this README. Here's the logic of the build:

Some additional tools are required to build the compiler, notably fslex.exe, fsyacc.exe, FSharp.PowerPack.Build.Tasks.dll, FsSrGen.exe, FSharp.SRGen.Build.Tasks.dll and the other tools found in the lkg directory. These are "Last Known Good" binaries created from a version of the F# Power Pack on CodePlex. If you like you can throw away these binaries and use your own compiled versions of these. tools.

Strong names and versions

When you build the compiler using the instructions below, the compiler and library binaries produced are not strong-named or signed, and use CLI assembly version nunmber 1.9.9.999. Without a strong-name you will not be able to add FSharp.Core.dll to the GAC, though that is not always a problem since the FSharp.Core.dll you compile can be copied as part of your application.

To enable strong names, you should place a copy of mono.snk in the 'src' directory. Fetch it from http://github.com/fsharp/fsharp/raw/master/mono.snk. You will need to enable strong names if you want to run any automated tests under src\tests.

Once you have an F# compiler, you will normally be able to reference another or an existing FSharp.Core.dll and matching mscorlib.dll explicitly to target that profile.

Our recommendation is not to use the version number 2.0 on your binaries, since that can get confusing if you already have an installation of an F# 2.0 compiler, unless you are deliberately building a public release of F#, e.g. as part of a release of Mono.

Steps - Cleaning (if needed)

cd src 
rmdir /s /q ..\Proto
rmdir /s /q ..\Debug
rmdir /s /q ..\Release

Steps - Building a Proto Compiler for Mono or .NET 4.0 using .NET 4.0 tools

  cd src 
  msbuild fsharp-proto-build.proj /p:TargetFramework=cli\4.0

Note: Make sure you run the .NET 4.0 msbuild.exe, e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.

Steps - NGEN the Proto Compiler for faster future startup (optional)

ngen install ..\Proto\cli\4.0\bin\fsc.exe

Steps - Building the F# core library and unittests for running on Mono or .NET 4.0, using the Proto compiler

msbuild fsharp-library-build.proj /p:TargetFramework=cli\4.0

Note: Make sure you run the .NET 4.0 msbuild.exe, e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.

Steps - Building a bootstrapped F# Compiler for running on Mono or .NET 4.0, using the Proto Compiler

msbuild fsharp-compiler-build.proj /p:TargetFramework=cli\4.0

Note: Make sure you run the .NET 4.0 msbuild.exe, e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe.

Steps - Building a F# Compiler unit tests for NUnit for running on Mono or .NET 4.0, using the Proto Compiler

msbuild fsharp-library-unittests-build.proj /p:TargetFramework=cli\4.0
msbuild fsharp-compiler-unittests-build.proj /p:TargetFramework=cli\4.0

Note: You must have NUnit installed.

Validation and Use

ngen install ..\Debug\cli\4.0\bin\fsi.exe
..\Debug\cli\4.0\bin\fsi.exe
1 + 1;;
#q;;
..\Debug\cli\4.0\bin\fsi.exe /help
..\Debug\cli\4.0\bin\fsc.exe /help
echo printfn "hello world" > hello.fs
..\Debug\cli\4.0\bin\fsc.exe hello.fs
copy ..\Debug\cli\4.0\bin\FSharp.Core.dll .
hello.exe
del /q FSharp.Core.dll 

Some alternative Steps - Building the F# core library and unittests for alternative CLI/.NET/CIL implementations, using the Proto compiler

msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\3.0
msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0
msbuild fsharp-library-build.proj /p:TargetFramework=WindowsPhone7\Silverlight\4.0
msbuild fsharp-library-build.proj /p:TargetFramework=CompactFramework\2.0
msbuild fsharp-library-build.proj /p:TargetFramework=CompactFramework\3.5

Some alternative Steps - Building for .NET 2.0 profile

cd src 
msbuild fsharp-proto-build.proj /p:TargetFramework=cli\2.0
msbuild fsharp-library-build.proj /p:TargetFramework=cli\2.0
msbuild fsharp-compiler-build.proj /p:TargetFramework=cli\2.0
msbuild fsharp-library-unittests-build.proj /p:TargetFramework=cli\2.0
msbuild fsharp-compiler-unittests-build.proj /p:TargetFramework=cli\2.0

ngen install ..\Debug\cli\2.0\bin\fsi.exe
..\Debug\cli\2.0\bin\fsi.exe
1 + 1;;
#q;;
..\Debug\cli\2.0\bin\fsi.exe /help
..\Debug\cli\2.0\bin\fsc.exe /help
echo printfn "hello world" > hello.fs
..\Debug\cli\2.0\bin\fsc.exe hello.fs
copy ..\Debug\cli\2.0\bin\FSharp.Core.dll .
hello.exe
del /q FSharp.Core.dll 

Some alternative Steps - Building an optimized (Release) compiler for .NET 4.0 profile

msbuild fsharp-compiler-build.proj /p:TargetFramework=cli\4.0 /p:Configuration=Release

ngen install ..\Release\cli\4.0\bin\fsi.exe
..\Release\cli\4.0\bin\fsi.exe
1 + 1;;
#q;;
..\Release\cli\4.0\bin\fsi.exe /help
..\Release\cli\4.0\bin\fsc.exe /help
echo printfn "hello world" > hello.fs
..\Release\cli\4.0\bin\fsc.exe hello.fs
copy ..\Release\cli\4.0\bin\FSharp.Core.dll .
hello.exe
del /q FSharp.Core.dll 

Some alternative Steps - Other examples of building for Release mode (choose some of these as you need)


msbuild fsharp-library-build.proj /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=cli\2.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=cli\4.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\3.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=WindowsPhone7\Silverlight\4.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=CompactFramework\2.0 /p:Configuration=Release
msbuild fsharp-library-build.proj /p:TargetFramework=CompactFramework\3.5 /p:Configuration=Release

msbuild fsharp-compiler-build.proj /p:TargetFramework=cli\2.0 /p:Configuration=Release

Editing and Building on Windows using Visual Studio 2010

Prerequisites

Editing and Building

Open all-vs2010.sln, and edit in modes Debug or Release. The compiler takes a long time to compile and that can be a bit invasive to the work flow, so it's normally better to do the actual compilation from the command line, see above.

Building where a Proto compiler is run on Mono 2.8, Windows

This can be useful if you want to prove to yourself that it's possible to build without running the base compiler using .NET CLR. At the moment however the steps below still use MSBuild and compile against the .NET 2.0 reference assemblies. It would need more work to get the build going against the Mono libraries.

Prerequisites

Building

See below for some of the sample steps. On Windows it is best to use fsc-mono.bat files to act as a "compiler that just happens to run using Mono".

Steps - Building a Proto Compiler for Mono or .NET 2.0 (either one)

cd src 
REM Prepare driver batch files that run the corresponding exe using Mono
copy /y setups\run-as-mono.bat ..\lkg\bin\fsc-mono.bat
copy /y setups\run-as-mono.bat  ..\lkg\FSharp-2.0.50726.900\bin\fslex-mono.bat
copy /y setups\run-as-mono.bat  ..\lkg\FSharp-2.0.50726.900\bin\fsyacc-mono.bat
msbuild fsharp-proto-build.proj /p:TargetFramework=mono\2.0

Steps - Prepare proto compiler for execution on Mono by registering FSharp.Core.dll for the base compiler


copy /y "C:\Program Files\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0\FSharp.Core.dll" setups\FSharp.Core.dll
"C:\Program Files\Mono-2.8\bin\sn" -R setups\FSharp.Core.dll setups\mono.snk  
"C:\Program Files\Mono-2.8\bin\gacutil" /i setups\FSharp.Core.dll 
del setups\FSharp.Core.dll

Steps - Prepare driver batch files that run the corresponding exe with mono


copy /y setups\run-as-mono.bat ..\Proto\cli\2.0\bin\fsc-proto-mono.bat
copy /y setups\run-as-mono.bat  ..\lkg\FSharp-2.0.50726.900\bin\fslex-mono.bat
copy /y setups\run-as-mono.bat  ..\lkg\FSharp-2.0.50726.900\bin\fsyacc-mono.bat

Steps - Build the core library using the proto compiler, running the proto with Mono on Windows



msbuild fsharp-library-build.proj /p:TargetFramework=mono\2.0

Steps - Bootstrap the compiler using the proto compiler, running the proto with Mono on Windows


msbuild fsharp-compiler-build.proj /p:TargetFramework=mono\2.0

Validation and Use

"c:\Program Files\Mono-2.8\bin\mono.exe" ..\Debug\mono\2.0\bin\fsi.exe
1 + 1;;
#q;;
"c:\Program Files\Mono-2.8\bin\mono.exe" ..\Debug\mono\2.0\bin\fsi.exe /help
"c:\Program Files\Mono-2.8\bin\mono.exe" ..\Debug\mono\2.0\bin\fsc.exe /help
echo printfn "hello world" > hello.fs
"c:\Program Files\Mono-2.8\bin\mono.exe" ..\Debug\mono\2.0\bin\fsc.exe hello.fs
copy ..\Debug\mono\2.0\bin\FSharp.Core.dll .
"c:\Program Files\Mono-2.8\bin\mono.exe" hello.exe
del /q FSharp.Core.dll 


Building on Unix with Mono

Because of some issues with xbuild, some shell scripts are provided to build the compiler on Unix. You may need to adapt the paths in config.sh first.

./make_proto.sh
./make_library.sh
./make_compiler.sh

Running Tests

Some NUnit unit tests are included if you build fsharp-library-unittests-build.proj. These can be built for a variety of CLI frameworks. Use NUnit to run the tests in the compiled DLL.

Some tests are included under src\tests\fsharp. These are a drop of a (somewhat adhoc) subset of tests used by the F# team. You run them by going to a directory and running build.bat and run.bat. These require that you strong-name sign FSharp.Core.dll and add it to the GAC, and that fsc.exe and fsi.exe are on the path. The tests currently only run on Windows, using the Microsoft .NET CLR. Considerable work would be required to make these tests run on Mono, or on Linux/Mac, because of the use of batch files, though individual tests may normally be compiled and run manually using the command-line compiler.

To run tests:

  cd src\tests\fsharp
  ..\build-and-run-all-installed-ilx-configs.bat results.log

You can inspect the output in results.log as the tests proceed. Ensure you have NGEN'd the F# compiler fsc.exe before running the tests or they will take a very long time.