2 setlocal EnableDelayedExpansion
4 :: Set the default arguments for build
7 set __BuildOS=Windows_NT
10 set __VSVersion=VS2013
11 set __VSProductVersion=120
13 :: Set the various build properties here so that CMake and MSBuild can pick them up
14 set "__ProjectDir=%~dp0"
15 :: remove trailing slash
16 if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%"
17 set "__ProjectFilesDir=%__ProjectDir%"
18 set "__SourceDir=%__ProjectDir%\src"
19 set "__PackagesDir=%__ProjectDir%\packages"
20 set "__RootBinDir=%__ProjectDir%\bin"
21 set "__LogsDir=%__RootBinDir%\Logs"
22 set __MSBCleanBuildArgs=
25 if "%1" == "" goto ArgsDone
26 if /i "%1" == "/?" goto Usage
27 if /i "%1" == "x64" (set __BuildArch=x64&&shift&goto Arg_Loop)
29 if /i "%1" == "debug" (set __BuildType=Debug&shift&goto Arg_Loop)
30 if /i "%1" == "release" (set __BuildType=Release&shift&goto Arg_Loop)
32 if /i "%1" == "clean" (set __CleanBuild=1&shift&goto Arg_Loop)
34 if /i "%1" == "freebsdmscorlib" (set __MscorlibOnly=1&set __BuildOS=FreeBSD&shift&goto Arg_Loop)
35 if /i "%1" == "linuxmscorlib" (set __MscorlibOnly=1&set __BuildOS=Linux&shift&goto Arg_Loop)
36 if /i "%1" == "osxmscorlib" (set __MscorlibOnly=1&set __BuildOS=OSX&shift&goto Arg_Loop)
37 if /i "%1" == "windowsmscorlib" (set __MscorlibOnly=1&set __BuildOS=Windows_NT&shift&goto Arg_Loop)
39 if /i "%1" == "vs2013" (set __VSVersion=%1&set __VSProductVersion=120&shift&goto Arg_Loop)
40 if /i "%1" == "vs2015" (set __VSVersion=%1&set __VSProductVersion=140&shift&goto Arg_Loop)
42 echo Invalid commandline argument: %1
47 echo Commencing CoreCLR Repo build
50 :: Set the remaining variables based upon the determined build configuration
51 set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%"
52 set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
53 set "__PackagesBinDir=%__BinDir%\.nuget"
54 set "__TestBinDir=%__RootBinDir%\tests\%__BuildOS%.%__BuildArch%.%__BuildType%"
55 set "__TestIntermediatesDir=%__RootBinDir%\tests\obj\%__BuildOS%.%__BuildArch%.%__BuildType%"
57 :: Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash
58 set "__CMakeBinDir=%__BinDir%"
59 set "__CMakeBinDir=%__CMakeBinDir:\=/%"
61 :: Configure environment if we are doing a clean build.
62 if not defined __CleanBuild goto MakeDirs
63 echo Doing a clean build
66 :: MSBuild projects would need a rebuild
67 set __MSBCleanBuildArgs=/t:rebuild
69 :: Cleanup the previous output for the selected configuration
70 if exist "%__BinDir%" rd /s /q "%__BinDir%"
71 if exist "%__IntermediatesDir%" rd /s /q "%__IntermediatesDir%"
73 if exist "%__TestBinDir%" rd /s /q "%__TestBinDir%"
74 if exist "%__TestIntermediatesDir%" rd /s /q "%__TestIntermediatesDir%"
76 if exist "%__LogsDir%" del /f /q "%__LogsDir%\*_%__BuildOS%__%__BuildArch%__%__BuildType%.*"
79 if not exist "%__BinDir%" md "%__BinDir%"
80 if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%"
81 if not exist "%__LogsDir%" md "%__LogsDir%"
83 :: CMake isn't a requirement when building mscorlib only
84 if defined __MscorlibOnly goto CheckVS
87 :: Check prerequisites
88 echo Checking pre-requisites...
90 :: Eval the output from probe-win1.ps1
91 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a
96 :: Check presence of VS
97 if defined VS%__VSProductVersion%COMNTOOLS goto CheckVSExistence
98 echo Visual Studio 2013+ (Community is free) is a pre-requisite to build this repository.
99 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
103 :: Does VS 2013 or VS 2015 really exist?
104 if exist "!VS%__VSProductVersion%COMNTOOLS!\..\IDE\devenv.exe" goto CheckMSBuild
105 echo Visual Studio 2013+ (Community is free) is a pre-requisite to build this repository.
106 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
110 :: Note: We've disabled node reuse because it causes file locking issues.
111 :: The issue is that we extend the build with our own targets which
112 :: means that that rebuilding cannot successfully delete the task
114 if /i "%__VSVersion%" =="vs2015" goto MSBuild14
115 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe"
116 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\12.0\Bin\MSBuild.exe"
117 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
120 set _msbuildexe="%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
121 set UseRoslynCompiler=true
123 if not exist %_msbuildexe% set _msbuildexe="%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe"
124 if not exist %_msbuildexe% echo Error: Could not find MSBuild.exe. Please see https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md for build instructions. && exit /b 1
126 :: All set to commence the build
129 if defined __MscorlibOnly goto PerformMScorlibBuild
131 echo Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType%
134 :: Set the environment for the native build
135 call "!VS%__VSProductVersion%COMNTOOLS!\..\..\VC\vcvarsall.bat" x86_amd64
137 if exist "%VSINSTALLDIR%DIA SDK" goto GenVSSolution
138 echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
139 This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^
140 at VS install location of previous version. Workaround is to copy DIA SDK folder from VS install location ^
141 of previous version to "%VSINSTALLDIR%" and then resume build.
142 :: DIA SDK not included in Express editions
143 echo Visual Studio 2013 Express does not include the DIA SDK. ^
144 You need Visual Studio 2013+ (Community is free).
145 echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites
149 :: Regenerate the VS solution
150 pushd "%__IntermediatesDir%"
151 call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion%
155 if exist "%__IntermediatesDir%\install.vcxproj" goto BuildCoreCLR
156 echo Failed to generate native component build project!
161 set "__CoreCLRBuildLog=%__LogsDir%\CoreCLR_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
162 %_msbuildexe% "%__IntermediatesDir%\install.vcxproj" %__MSBCleanBuildArgs% /nologo /maxcpucount /nodeReuse:false /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% /fileloggerparameters:Verbosity=normal;LogFile="%__CoreCLRBuildLog%"
163 IF NOT ERRORLEVEL 1 goto PerformMScorlibBuild
164 echo Native component build failed. Refer !__CoreCLRBuildLog! for details.
167 :PerformMScorlibBuild
168 REM endlocal to rid us of environment changes from vcvarsall.bat
171 REM setlocal to prepare for vsdevcmd.bat
173 set __AdditionalMSBuildArgs=
175 rem Explicitly set Platform causes conflicts in mscorlib project files. Clear it to allow building from VS x64 Native Tools Command Prompt
178 if defined __MscorlibOnly set __AdditionalMSBuildArgs=/p:BuildNugetPackage=false
180 :: Set the environment for the managed build
181 call "!VS%__VSProductVersion%COMNTOOLS!\VsDevCmd.bat"
182 echo Commencing build of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
184 set "__MScorlibBuildLog=%__LogsDir%\MScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
185 %_msbuildexe% "%__ProjectFilesDir%\build.proj" %__MSBCleanBuildArgs% /nologo /maxcpucount /verbosity:minimal /nodeReuse:false /fileloggerparameters:Verbosity=normal;LogFile="%__MScorlibBuildLog%" /p:OSGroup=%__BuildOS% %__AdditionalMSBuildArgs%
186 IF NOT ERRORLEVEL 1 (
187 if defined __MscorlibOnly exit /b 0
188 goto CrossGenMscorlib
191 echo MScorlib build failed. Refer !__MScorlibBuildLog! for details.
195 echo Generating native image of mscorlib for %__BuildOS%.%__BuildArch%.%__BuildType%
197 set "__CrossGenMScorlibLog=%__LogsDir%\CrossgenMScorlib_%__BuildOS%__%__BuildArch%__%__BuildType%.log"
198 %__BinDir%\crossgen.exe %__BinDir%\mscorlib.dll > "%__CrossGenMScorlibLog%" 2>&1
199 IF NOT ERRORLEVEL 1 (
200 goto PerformTestBuild
203 echo CrossGen mscorlib failed. Refer !__CrossGenMScorlibLog! for details.
208 echo Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType%
210 call %__ProjectDir%\tests\buildtest.cmd
211 IF NOT ERRORLEVEL 1 goto SuccessfulBuild
212 echo Test binaries build failed. Refer !__MScorlibBuildLog! for details.
217 echo Repo successfully built.
219 echo Product binaries are available at !__BinDir!
220 echo Test binaries are available at !__TestBinDir!
226 echo %0 BuildArch BuildType [clean] [vsversion] where:
228 echo BuildArch can be: x64
229 echo BuildType can be: Debug, Release
230 echo Clean - optional argument to force a clean build.
231 echo VSVersion - optional argument to use VS2013 or VS2015 (default VS2013)
232 echo windowsmscorlib - Build mscorlib for Windows
233 echo linuxmscorlib - Build mscorlib for Linux
234 echo osxmscorlib - Build mscorlib for OS X