How to call / call fsc, F # compiler, from FAKE?

How to tell FAKE to compile a file .fswith fsc?

Bonus points for explaining how to pass arguments like -aand -target:dll.

EDIT: I have to clarify that I'm trying to do this without the MSBuild / xbuild / file .sln. In other words, I want FAKE to completely replace MSBuild / xbuild.

+4
source share
3 answers

FAKE has tasks for calling the F # compiler directly. You can usually use a task Fsc. If you want the target to compile the F # source file MyFile.fsin MyFile.exe, you can do:

Target "MyFile.exe" (fun _ ->
  ["MyFile.fs"]
  |> Fsc (fun ps -> ps))

Fsc F #. , . , .

+3

Ian Battersby FAKE

:

:

#!/bin/bash
TARGET=$1
BUILDTARGETS=$2

if [ -z "$BUILDTARGETS" ]
    then
                BUILDTARGETS="/Library/Frameworks/Mono.framework/Libraries/mono/xbuild/Microsoft/VisualStudio/v9.0"
fi

if [ -z "$TARGET" ]
    then
    CTARGET="Default"
else
    CTARGET=`echo ${TARGET:0:1} | tr "[:lower:]" "[:upper:]"``echo ${TARGET:1} | tr "[:upper:]" "[:lower:]"`
fi

if [ ! -d "$BUILDTARGETS" ]
    then
    echo "BuildTargets directory '${BUILDTARGETS}' does not exist."
    exit $?
else
    export BUILDTARGETS="$BUILDTARGETS"
fi

echo "Executing command: $CTARGET"

mono packages/FAKE.1.64.6/tools/Fake.exe build.fsx target=$CTARGET

#I @"packages/FAKE.1.64.6/tools"
#r "FakeLib.dll"
open Fake

let buildDir = @"./build/"
let testDir = @"./test"

let fxReferences = !! @"*/*.csproj"
let testReferences = !! @"Tests/**/*.csproj"
let buildTargets = environVarOrDefault "BUILDTARGETS" ""

Target "Clean" (fun _ ->
    CleanDirs [buildDir; testDir]
)

Target "Build" (fun _ ->
    MSBuild buildDir "Build" ["Configuration","Debug"; "VSToolsPath",buildTargets] fxReferences
        |> Log "Build-Output: "
)

Target "BuildTest" (fun _ ->
    MSBuildRelease testDir "Build" testReferences
        |> Log "Test-Output: "
)

Target "Test" (fun _ ->
    !! (testDir  + @"/*.Tests.dll")
        |> xUnit (fun p ->
            { p with
                ShadowCopy = true;
                HtmlOutput = true;
                XmlOutput = true;
                OutputDir = testDir })
)

"Clean"
  ==> "Build"

"Build"
  ==> "BuildTest"

Target "Default" DoNothing

RunParameterTargetOrDefault "target" "Default"
+1

, , Yawar, , FAKE, , , .

Fsc , , . !! , FileIncludes, . FileIncludes , Fsc Seq.toList.

To be solid, I also convert things into relative paths (perhaps only a personal quirk).

So, here is an example of finding all *.fsfiles and compiling them with some compiler options:

Target "BuildApp" (fun _ ->                            // Compile application source code
  !! (srcApp @@ @"**/*.fs")                            // Look for F# source files
    |> Seq.map toRelativePath                          // Pathnames relative to current directory
    |> Seq.toList                                      // Convert FileIncludes to string list
    |> Fsc (fun p ->                                   //  which is what the Fsc task wants
      {p with                                          // Fsc parameters: making an executable, 
         FscTarget   = Exe                             //  for any CPU, directing output to build 
         Platform    = AnyCpu                          //  area (both assembly & XML doc).
         Output      = ...exe file...                  // Executable generated
         OtherParams = ["--doc:" + ...xmldoc file...) ]})
)                                                      // 

As Jawar noted, there is a boat of other compiler options described in the tutorial .

+1
source

Source: https://habr.com/ru/post/1545373/


All Articles