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.
The compiler is normally compiled as a set of .NET 4.0 components. The compiler can also be compiled as a Silverlight 4.0 component, which allows it to be hosted in a browser, e.g. to implement websites like Try F# as well as browser-hosted code-editing and type-checking for F# code.
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.
When you compile, you get fsc.exe, fsi.exe, FSharp.Core.dll and some related DLLs.
The compiler can be compiled to a Silverlight 4.0 component FSharp.Compiler.Silverlight.dll, which can be incorporated into a browser-hosted Silverlight application to implement websites like Try F#. A sample application is included in samples\SilverlightHostedCompilerServices showing how to use the different compiler services.
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.
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.
cd src rmdir /s /q ..\Proto rmdir /s /q ..\Debug rmdir /s /q ..\Release
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.
Optiona: NGEN the Proto Compiler for faster future startup (optional)
ngen install ..\Proto\cli\4.0\bin\fsc-proto.exe
This uses the proto compiler to build the FSharp.Core library and unit tests, for Mono/.NET 4.0.
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.
This uses the proto compiler to build the FSharp.Compiler.dll and fsc.exe to run on for Mono/.NET 4.0.
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.
This uses the proto compiler to build the unit tests that check some parts of FSharp.Core.dll and FSharp.Compiler.dll. There is also another set of tests under src\tests\fsharp.
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.
This builds FSharp.Compiler.Silverlight.dll which is a Silverlight 4.0 or 5.0 component for hosting in the browser.
-- Debug configuration for browser-hosted compiler for Silverlight 4.0: msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0\Compiler msbuild fsharp-compiler-build.proj /p:TargetFramework=Silverlight\4.0\Compiler -- Release configuration for browser-hosted compiler for Silverlight 4.0: msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0\Compiler /p:Configuration=Release msbuild fsharp-compiler-build.proj /p:TargetFramework=Silverlight\4.0\Compiler /p:Configuration=Release -- Debug configuration for browser-hosted compiler for Silverlight 5.0: msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\5.0\Compiler msbuild fsharp-compiler-build.proj /p:TargetFramework=Silverlight\5.0\Compiler -- Release configuration for browser-hosted compiler for Silverlight 5.0: msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\5.0\Compiler /p:Configuration=Release msbuild fsharp-compiler-build.proj /p:TargetFramework=Silverlight\5.0\Compiler /p:Configuration=Release
The binaries are placed in Debug\Silverlight\4.0\Compiler, Release\Silverlight\4.0\Compiler, Debug\Silverlight\5.0\Compiler and/or Release\Silverlight\5.0\Compiler. A custom FSharp.Core.dll is used for this configuration, be sure to reference it rather than any other FSharp.Core.dll for Silverlight. You may have to edit your project file by hand to ensure you get exactly the right reference to FSharp.Core.dll.
msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0 msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\5.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 msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\4.0 /p:Configuration=Release msbuild fsharp-library-build.proj /p:TargetFramework=Silverlight\5.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
Here are some simple tests to validate what you have built by checking fsi.exe (F# Interactive) starts up:
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
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
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
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
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.
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.
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".
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
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
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
msbuild fsharp-library-build.proj /p:TargetFramework=mono\2.0
msbuild fsharp-compiler-build.proj /p:TargetFramework=mono\2.0
"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
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
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.