Enable additional wasm corefx xunit tests (#16860)
[mono-project.git] / msvc / build-external-btls.bat
blobd4de955a5a0fbf25498df739f7963a4e1bbbfe79
1 :: --------------------------------------------------\r
2 :: Run full BTLS build using msvc toolchain and available cmake generator.\r
3 :: Script needs to be run from within a matching build environment, x86|x64.\r
4 :: When executed from withing Visual Studio build environment current\r
5 :: build environment will be inherited by script.\r
6 ::\r
7 :: %1 Mono BTLS source root directory.\r
8 :: %2 BTLS source root directory.\r
9 :: %3 BTLS build root directory.\r
10 :: %4 Mono distribution root directory.\r
11 :: %5 VS CFLAGS.\r
12 :: %6 VS platform (Win32/x64)\r
13 :: %7 VS configuration (Debug/Release)\r
14 :: %8 VS target\r
15 :: %9 MsBuild bin path, if used.\r
16 :: %10 Force MSBuild (true/false), if used.\r
17 :: --------------------------------------------------\r
19 @echo off\r
20 setlocal\r
22 set TEMP_PATH=%PATH%\r
23 set BUILD_RESULT=1\r
25 set CL_BIN_NAME=cl.exe\r
26 set LINK_BIN_NAME=link.exe\r
27 set GIT_BIN_NAME=git.exe\r
28 set CMAKE_BIN_NAME=cmake.exe\r
29 set NINJA_BIN_NAME=ninja.exe\r
30 set PERL_BIN_NAME=perl.exe\r
31 set YASM_BIN_NAME=yasm.exe\r
33 set MONO_BTLS_DIR=%~1\r
34 shift\r
35 set BTLS_DIR=%~1\r
36 shift\r
37 set BTLS_BUILD_DIR=%~1\r
38 shift\r
39 set MONO_DIST_DIR=%~1\r
40 shift\r
41 set VS_CFLAGS=%~1\r
42 shift\r
43 set VS_PLATFORM=%~1\r
44 shift\r
45 set VS_CONFIGURATION=%~1\r
46 shift\r
47 set VS_TARGET=%~1\r
48 shift\r
49 set MSBUILD_BIN_PATH=%~1\r
50 shift\r
51 set FORCE_MSBUILD=%~1\r
53 :: Setup toolchain.\r
54 :: set GIT=\r
55 :: set CMAKE=\r
56 :: set NINJA=\r
57 set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe\r
59 if "%MONO_BTLS_DIR%" == "" (\r
60     echo Missing mono BTLS source directory argument.\r
61     goto ECHO_USAGE\r
62 )\r
64 if "%BTLS_DIR%" == "" (\r
65     echo Missing BTLS source directory argument.\r
66     goto ECHO_USAGE\r
67 )\r
69 if "%BTLS_BUILD_DIR%" == "" (\r
70     echo Missing BTLS build directory argument.\r
71     goto ECHO_USAGE\r
72 )\r
74 if "%MONO_DIST_DIR%" == "" (\r
75     echo Missing mono install directory argument.\r
76     goto ECHO_USAGE\r
77 )\r
79 if "%VS_CFLAGS%" == "" (\r
80     echo Missing CFLAGS argument.\r
81     goto ECHO_USAGE\r
82 )\r
84 if "%VS_PLATFORM%" == "" (\r
85     set VS_PLATFORM=x64\r
86 )\r
88 if "%VS_CONFIGURATION%" == "" (\r
89     set VS_CONFIGURATION=Release\r
90 )\r
92 if "%VS_TARGET%" == "" (\r
93     set VS_TARGET=Build\r
94 )\r
96 if "%FORCE_MSBUILD%" == "" (\r
97     set FORCE_MSBUILD=false\r
98 )\r
100 if not exist "%MONO_BTLS_DIR%" (\r
101     echo Could not find "%MONO_BTLS_DIR%".\r
102     goto ON_ERROR\r
105 if not exist "%BTLS_DIR%" (\r
106     echo Could not find "%BTLS_DIR%".\r
107     goto ON_ERROR\r
110 set BTLS_CFLAGS=%VS_CFLAGS%\r
111 set BTLS_ARCH=x86_64\r
112 if /i "%VS_PLATFORM%" == "win32" (\r
113     set BTLS_ARCH=i386\r
116 set BTLS_NO_ASM_SUPPORT=1\r
118 :: Check if executed from VS2015/VS2017 build environment.\r
119 if "%VisualStudioVersion%" == "14.0" (\r
120     goto ON_ENV_OK\r
123 if "%VisualStudioVersion%" == "15.0" (\r
124     goto ON_ENV_OK\r
127 :: Executed outside VS2015/VS2017 build environment, try to locate Visual Studio C/C++ compiler and linker.\r
128 call :FIND_PROGRAM "" "%CL_BIN_NAME%" CL_PATH\r
129 if "%CL_PATH%" == "" (\r
130     goto ON_ENV_WARNING\r
133 call :FIND_PROGRAM "" "%LINK_BIN_NAME%" LINK_PATH\r
134 if "%LINK_PATH%" == "" (\r
135     goto ON_ENV_WARNING\r
138 goto ON_ENV_OK\r
140 :ON_ENV_WARNING\r
142 :: VS 2015.\r
143 set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat\r
144 IF EXIST "%VC_VARS_ALL_FILE%" (\r
145     echo For VS2015 builds, make sure to run this from within Visual Studio build or using "VS2015 x86|x64 Native Tools Command Prompt" command prompt.\r
146         echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64".\r
149 :: VS 2017.\r
150 set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe\r
151 if exist "%VSWHERE_TOOLS_BIN%" (\r
152     echo For VS2017 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2017" command prompt.\r
153         for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -latest -property installationPath') do (\r
154                 echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".\r
155         )\r
158 echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected.\r
160 :ON_ENV_OK\r
162 :: Setup all cmake related generator, tools and variables.\r
163 call :SETUP_CMAKE_ENVIRONMENT\r
164 if "%CMAKE%" == "" (\r
165     echo Failed to located working %CMAKE_BIN_NAME%, needs to be accessible in PATH or set using CMAKE environment variable.\r
166     goto ON_ERROR\r
169 if "%CMAKE_GENERATOR%" == "" (\r
170     echo Failed to setup cmake generator.\r
171     goto ON_ERROR\r
174 :: Check target.\r
175 if /i "%VS_TARGET%" == "build" (\r
176     goto ON_BUILD_BTLS\r
179 if /i "%VS_TARGET%" == "install" (\r
180     goto ON_INSTALL_BTLS\r
183 if /i "%VS_TARGET%" == "clean" (\r
184     goto ON_CLEAN_BTLS\r
187 :ON_BUILD_BTLS\r
189 :: If not set by caller, check environment for working git.exe.\r
190 call :FIND_PROGRAM "%GIT%" "%GIT_BIN_NAME%" GIT\r
191 if "%GIT%" == "" (\r
192     echo Failed to located working %GIT_BIN_NAME%, needs to be accessible in PATH or set using GIT environment variable.\r
193     goto ON_ERROR\r
196 :: Make sure boringssl submodule is up to date.\r
197 pushd\r
198 cd "%BTLS_DIR%"\r
199 "%GIT%" submodule update --init\r
200 if not ERRORLEVEL == 0 (\r
201    "%GIT%" submodule init\r
202     "%GIT%" submodule update\r
203     if not ERRORLEVEL == 0 (\r
204         echo Git boringssl submodules failed to updated. You may experience compilation problems if some submodules are out of date.\r
205     )\r
207 popd\r
209 if not exist "%BTLS_BUILD_DIR%" (\r
210     mkdir "%BTLS_BUILD_DIR%"\r
213 cd "%BTLS_BUILD_DIR%"\r
215 :: Make sure cmake pick up msvc toolchain regardless of selected generator (Visual Studio|Ninja)\r
216 set CC=%CL_BIN_NAME%\r
217 set CXX=%CL_BIN_NAME%\r
219 set BTLS_BUILD_TYPE=\r
220 if /i "%CMAKE_GENERATOR%" == "ninja" (\r
221     set BTLS_BUILD_TYPE=-D CMAKE_BUILD_TYPE=%VS_CONFIGURATION%\r
224 :: Run cmake.\r
225 "%CMAKE%" ^\r
226 -D BTLS_ROOT:PATH="%BTLS_DIR%" ^\r
227 -D SRC_DIR:PATH="%MONO_BTLS_DIR%" ^\r
228 -D BTLS_CFLAGS="%BTLS_CFLAGS%" ^\r
229 -D OPENSSL_NO_ASM=%BTLS_NO_ASM_SUPPORT% ^\r
230 -D BTLS_ARCH="%BTLS_ARCH%" ^\r
231 -D BUILD_SHARED_LIBS=1 ^\r
232 %BTLS_BUILD_TYPE% ^\r
233 -G "%CMAKE_GENERATOR%" ^\r
234 "%MONO_BTLS_DIR%"\r
236 if not ERRORLEVEL == 0 (\r
237     goto ON_ERROR\r
240 if /i "%CMAKE_GENERATOR%" == "ninja" (\r
241     :: Build BTLS using ninja build system.\r
242     call "%NINJA%" || (\r
243         goto ON_ERROR\r
244     )\r
245 ) else (\r
246     :: Build BTLS using msbuild build system.\r
247     call "%MSBUILD%" mono-btls.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% /v:m /nologo || (\r
248         goto ON_ERROR\r
249     )\r
252 :ON_INSTALL_BTLS\r
254 if not exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" (\r
255     echo Missing btls build output, "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll"\r
256     goto ON_ERROR\r
259 :: Make sure build output folder exists.\r
260 if not exist "%MONO_DIST_DIR%" (\r
261     echo Could not find "%MONO_DIST_DIR%", creating folder for build output.\r
262     mkdir "%MONO_DIST_DIR%"\r
265 :: Copy files into distribution directory.\r
266 copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" "%MONO_DIST_DIR%" >nul 2>&1\r
268 if exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" (\r
269     copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%" >nul 2>&1\r
272 goto ON_SUCCESS\r
274 :ON_CLEAN_BTLS\r
276 if exist "%BTLS_BUILD_DIR%\build.ninja" (\r
277     pushd\r
278     cd "%BTLS_BUILD_DIR%"\r
279     call "%NINJA%" clean\r
280     popd\r
283 if exist "%BTLS_BUILD_DIR%\mono-btls.sln" (\r
284     "%MSBUILD%" "%BTLS_BUILD_DIR%\mono-btls.sln" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:Clean /v:m /nologo\r
287 goto ON_SUCCESS\r
289 :ON_SUCCESS\r
291 set BUILD_RESULT=0\r
292 goto ON_EXIT\r
294 :ECHO_USAGE:\r
295     ECHO Usage: build-btls.bat [mono_btls_src_dir] [btls_src_dir] [btls_build_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration].\r
297 :ON_ERROR\r
298     echo Failed to build BTLS.\r
299     goto ON_EXIT\r
301 :ON_EXIT\r
302     set PATH=%TEMP_PATH%\r
303     exit /b %BUILD_RESULT%\r
305 :: ##############################################################################################################################\r
306 :: Functions\r
308 :: --------------------------------------------------\r
309 :: Finds a program using environment.\r
310 ::\r
311 :: %1 Existing program to check for.\r
312 :: %2 Name of binary to locate.\r
313 :: %3 Output, variable to set if found requested program.\r
314 :: --------------------------------------------------\r
315 :FIND_PROGRAM\r
317 :: If not set by caller, check environment for program.\r
318 if exist "%~1" (\r
319     goto :EOF\r
322 call where /q "%~2" && (\r
323     for /f "delims=" %%a in ('where "%~2"') do (\r
324         set "%~3=%%a"\r
325     )\r
326 ) || (\r
327     set "%~3="\r
330 goto :EOF\r
332 :: --------------------------------------------------\r
333 :: Setup up cmake build environment, including generator, build tools and variables.\r
334 :: --------------------------------------------------\r
335 :SETUP_CMAKE_ENVIRONMENT\r
337 :: If not set by caller, check environment for working cmake.exe.\r
338 call :FIND_PROGRAM "%CMAKE%" "%CMAKE_BIN_NAME%" CMAKE\r
339 if "%CMAKE%" == "" (\r
340     goto _SETUP_CMAKE_ENVIRONMENT_EXIT\r
343 if /i "%VS_TARGET%" == "build" (\r
344     echo Found CMake: "%CMAKE%"\r
347 if /i "%FORCE_MSBUILD%" == "true" (\r
348     goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR\r
351 :: Check for optional cmake generate and build tools for full BTLS assembler supported build. NOTE, currently BTLS assembler build\r
352 :: can't be done using Visual Studio and must use ninja build generator + yasm and perl.\r
353 call :FIND_PROGRAM "%NINJA%" "%NINJA_BIN_NAME%" NINJA\r
354 call :FIND_PROGRAM "%YASM%" "%YASM_BIN_NAME%" YASM\r
355 call :FIND_PROGRAM "%PERL%" "%PERL_BIN_NAME%" PERL\r
357 if not "%NINJA%" == "" if not "%YASM%" == "" if not "%PERL%" == "" (\r
358     goto _SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR\r
361 :_SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR\r
363 if /i "%VS_TARGET%" == "build" (\r
364     echo Using Visual Studio build generator, disabling full assembler build.\r
367 :: Detect VS version to use right cmake generator.\r
368 set CMAKE_GENERATOR=Visual Studio 14 2015\r
369 if "%VisualStudioVersion%" == "15.0" (\r
370     set CMAKE_GENERATOR=Visual Studio 15 2017\r
373 if /i "%VS_PLATFORM%" == "x64" (\r
374     set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64\r
377 set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\%VS_CONFIGURATION%\r
379 goto _SETUP_CMAKE_ENVIRONMENT_EXIT\r
381 :_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR\r
383 if /i "%VS_TARGET%" == "build" (\r
384     echo Found Ninja: "%NINJA%"\r
385     echo Using Ninja build generator, enabling full assembler build.\r
388 set CMAKE_GENERATOR=Ninja\r
389 set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\r
390 set BTLS_NO_ASM_SUPPORT=0\r
392 :_SETUP_CMAKE_ENVIRONMENT_EXIT\r
394 goto :EOF\r
396 @echo on\r