Sunday 24 January 2016

Minimal Hello World for FASTBuild

FASTBuild is an open source build program with amazing potential. It apparently allows distributed compilation out-of-the-box, which is something Incredibuild charge a lot of money for. But the documentation is minimal so far, and it lacks a functional example. So I put together a "Hello World" for FASTBuild. The HelloWorld.cpp is:

#include <iostream>

int main(int , char * [])
{
 std::cout << "hello world!\n";
 return 0;
}

And the project config file is build.bff:

;-------------------------------------------------------------------------------
; Windows Platform
;-------------------------------------------------------------------------------
.VSBasePath  = 'C:/Program Files (x86)/Microsoft Visual Studio 12.0'
.WindowsSDKBasePath = 'C:/Program Files (x86)/Windows Kits/8.1'
.ClangBasePath  = 'C:/Program Files/LLVM'
.WindowsLibPaths = '$WindowsSDKBasePath$/lib/winv6.3/um'


.BaseIncludePaths  = ' /I"./"'
    + ' /I"$VSBasePath$/VC/include/"'
    + ' /I"$WindowsSDKBasePath$/include/um"'
    + ' /I"$WindowsSDKBasePath$/include/shared"'

Compiler( 'Compiler-x86' )
{
 .Root  = '$VSBasePath$/VC/bin'
 .Executable = '$Root$/cl.exe'
}
; MSVC Toolchain
;---------------
.ToolsBasePath  = '$VSBasePath$/VC/bin'
.Compiler  = 'Compiler-x86'
.Librarian  = '$ToolsBasePath$/lib.exe'
.Linker   = '$ToolsBasePath$/link.exe'
.CompilerOptions = '%1 /Fo%2 /c /Z7'
.CompilerOptions + .BaseIncludePaths
.LibrarianOptions = '/NODEFAULTLIB /OUT:%2 %1'
.LinkerOptions  = ' /OUT:%2 %1 /SUBSYSTEM:CONSOLE'
.LinkerOptions  +  ' /LIBPATH:"$WindowsLibPaths$/x86" /LIBPATH:"$VSBasePath$/VC/lib"'

; Libraries
;----------
Library( 'exelib' )
{
    .CompilerInputPath = '.\\'
    .CompilerOutputPath= 'Out\'
    .LibrarianOutput   = 'Out\exelib.lib'
}
; Executables
;------------
Executable( 'myExe' )
{
 .CompilerInputPath = '.\'
 .CompilerInputPattern    ='*.cpp'
 .CompilerOutputPath= 'Out/'
 .Libraries    = { 'exelib' }
 .LinkerOutput = 'HelloWorld.exe'
 .LinkerOptions + ' /SUBSYSTEM:CONSOLE'
   + ' LIBCMT.LIB'
}

; 'all'
;-------
Alias( 'all' )
{
   .Targets = { 'myExe' }
}


To build it, go to the directory in a command prompt and run FBuild.exe.
This is for Visual Studio 2013 (12.0) - for different versions just change the VSBasePath variable.

One really interesting thing is that you can't seem to compile source files into Executables directly: you have to specify a library (e.g. "exelib" above), and use .CompilerInputPath to specify a directory. It will scan the path for all files of interest (.cpp by default) - you can specify them individually if you want. But the Executable command doesn't compile cpp's and if you don't include a library, it will complain of having no Object files to link.

Update 27/1/2016

FASTBuild author Franta Fulin has posted an official Hello World example: you can find it here.

Tuesday 19 January 2016

$(VCTargetsPath) in MSBuild

MSBuild may fail to build, complaining that
"C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props" was not found
i.e. trying to load the v110 toolset even though you may not have the corresponding Visual Studio version. To fix it, set the environment variable VisualStudioVersion=12.0 for example, or pass it to msbuild on the command line as /p:VisualStudioVersion=12.0.

Friday 8 January 2016

Visual Studio-style mouse controls for Sublime Text

Create C:\Users\(YOURNAME)\AppData\Roaming\Sublime Text 3\Packages\User\Default (Windows).sublime-mousemap, and fill it with:

[
  // Ctrl-click word select
    {
        "button": "button1", "count": 1, "modifiers": ["ctrl"],
        "press_command": "drag_select",
        "press_args": {"by": "words"}
    }
  // Column select
  ,{
        "button": "button1", 
        "count": 1, 
        "modifiers": ["alt"],
        "press_command": "drag_select",
        "press_args": {"by": "columns"}
  }
]

Tuesday 5 January 2016

If your Windows build server is failing to find executables...

... your PATH environment variable is probably too long. Cut it shorter than 2048 characters and things should start working again.