Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Lorensson <lateralusx.github@gmail.com>2018-10-22 22:58:52 +0300
committerMartin Baulig <mabaul@microsoft.com>2018-10-22 22:58:52 +0300
commitf2d67cd299e7730819f6838b77de8a061621cce1 (patch)
treea54a1d0f6509f346b55e9fe9fda82bcbc206988d /msvc/build-external-btls.bat
parentab17f4555d080bb07e668ad6ab00368cfbb91000 (diff)
Windows BTLS assembler build support (cygwin/msvc). (#11234)
* Add support for BTLS assembler build on Windows (cygwin/msvc). Building BTLS with assembler support on Windows requires several additional build tools (except cmake) for both cygwin/msvc builds. On cygwin, perl and yasm will be needed and on msvc, ninja, perl and yasm. On msvc builds BTLS doesn’t support Visual Studio generator when building with assembler support, so this commit adds support for ninja build system covering that scenario. This commit adds support for auto detection of needed build tools and enable assembler builds if all needed tools have been identified as available. Commit also fixes the execution of msbuild on CI to just use the original PATH variable instead of the cygwin PATH to make sure correct version of identified build tools gets used (Windows version of git, ninja, perl and yasm). Both cygwin and msvc build will use nasm compiler (through use of yasm) since generated assembler won’t compile with mingw’s gcc version. * Bump BTLS commit. * Fix a couple of warnings on BTLS build. * Fix failing certificate import test using BTLS on Windows. Mono BTLS library assumes all passwords are ANSI encoded strings since SafePasswordHandle gets passed directly through pinvokes. This is only true for SafePasswordHandle implemented on Unix:es. On Windows, SafePasswordHandle stores passwords as Unicode, most likely due to Windows Crypto API accepting Unicode passwords. When using BTLS on Windows this difference submerged since passwords passed to BTLS will be Unicode encoded failing the decryption of PCKS12 structure. Keeping the pattern already in place, passing SafePasswordHandler all the way through pinvokes, the needed conversion will be done just before calling into OpenSSL library as part of mono's BTLS library adapter.
Diffstat (limited to 'msvc/build-external-btls.bat')
-rw-r--r--msvc/build-external-btls.bat247
1 files changed, 179 insertions, 68 deletions
diff --git a/msvc/build-external-btls.bat b/msvc/build-external-btls.bat
index bd684667a56..d107104d3f3 100644
--- a/msvc/build-external-btls.bat
+++ b/msvc/build-external-btls.bat
@@ -1,14 +1,9 @@
-@echo off
-setlocal
-
-set TEMP_PATH=%PATH%
-set BUILD_RESULT=1
-
-set CMAKE_BIN_NAME=cmake.exe
-set GIT_BIN_NAME=git.exe
-
-:: Arguments
-:: --------------------------------------------
+:: --------------------------------------------------
+:: Run full BTLS build using msvc toolchain and available cmake generator.
+:: Script needs to be run from within a matching build environment, x86|x64.
+:: When executed from withing Visual Studio build environment current
+:: build environment will be inherited by script.
+::
:: %1 Mono source root directory.
:: %2 Mono build root directory.
:: %3 Mono distribution root directory.
@@ -17,6 +12,21 @@ set GIT_BIN_NAME=git.exe
:: %6 VS configuration (Debug/Release)
:: %7 VS target
:: %8 MsBuild bin path, if used.
+:: --------------------------------------------------
+
+@echo off
+setlocal
+
+set TEMP_PATH=%PATH%
+set BUILD_RESULT=1
+
+set CL_BIN_NAME=cl.exe
+set LINK_BIN_NAME=link.exe
+set GIT_BIN_NAME=git.exe
+set CMAKE_BIN_NAME=cmake.exe
+set NINJA_BIN_NAME=ninja.exe
+set PERL_BIN_NAME=perl.exe
+set YASM_BIN_NAME=yasm.exe
set MONO_DIR=%~1
set MONO_BUILD_DIR=%~2
@@ -28,8 +38,9 @@ set VS_TARGET=%~7
set MSBUILD_BIN_PATH=%~8
:: Setup toolchain.
-:: set CMAKE=
:: set GIT=
+:: set CMAKE=
+:: set NINJA=
set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe
if "%MONO_DIR%" == "" (
@@ -87,11 +98,26 @@ if /i "%VS_PLATFORM%" == "win32" (
set BTLS_ARCH=i386
)
+set BTLS_NO_ASM_SUPPORT=1
set BTLS_BUILD_DIR=%MONO_BUILD_DIR%
-:: Check build environment.
-if "%VisualStudioVersion%" == "" (
- echo VisualStudioVersion environment variable not set.
+:: Check if executed from VS2015/VS2017 build environment.
+if "%VisualStudioVersion%" == "14.0" (
+ goto ON_ENV_OK
+)
+
+if "%VisualStudioVersion%" == "15.0" (
+ goto ON_ENV_OK
+)
+
+:: Executed outside VS2015/VS2017 build environment, try to locate Visual Studio C/C++ compiler and linker.
+call :FIND_PROGRAM "" "%CL_BIN_NAME%" CL_PATH
+if "%CL_PATH%" == "" (
+ goto ON_ENV_WARNING
+)
+
+call :FIND_PROGRAM "" "%LINK_BIN_NAME%" LINK_PATH
+if "%LINK_PATH%" == "" (
goto ON_ENV_WARNING
)
@@ -119,6 +145,18 @@ echo Could not detect Visual Studio build environment. You may experience build
:ON_ENV_OK
+:: Setup all cmake related generator, tools and variables.
+call :SETUP_CMAKE_ENVIRONMENT
+if "%CMAKE%" == "" (
+ echo Failed to located working %CMAKE_BIN_NAME%, needs to be accessible in PATH or set using CMAKE environment variable.
+ goto ON_ERROR
+)
+
+if "%CMAKE_GENERATOR%" == "" (
+ echo Failed to setup cmake generator.
+ goto ON_ERROR
+)
+
:: Check target.
if /i "%VS_TARGET%" == "build" (
goto ON_BUILD_BTLS
@@ -135,15 +173,10 @@ if /i "%VS_TARGET%" == "clean" (
:ON_BUILD_BTLS
:: If not set by caller, check environment for working git.exe.
-if not exist "%GIT%" (
- call where /q %GIT_BIN_NAME% && (
- echo Using %GIT_BIN_NAME% available in PATH:
- where %GIT_BIN_NAME%
- set GIT=%GIT_BIN_NAME%
- ) || (
- echo Failed to located working %GIT_BIN_NAME%, needs to be accessible in PATH or set using GIT environment variable.
- goto ON_ERROR
- )
+call :FIND_PROGRAM "%GIT%" "%GIT_BIN_NAME%" GIT
+if "%GIT%" == "" (
+ echo Failed to located working %GIT_BIN_NAME%, needs to be accessible in PATH or set using GIT environment variable.
+ goto ON_ERROR
)
:: Make sure boringssl submodule is up to date.
@@ -160,47 +193,30 @@ if not ERRORLEVEL == 0 (
)
popd
-:: If not set by caller, check environment for working cmake.exe.
-if not exist "%CMAKE%" (
- call where /q %CMAKE_BIN_NAME% && (
- echo Using %CMAKE_BIN_NAME% available in PATH:
- where %CMAKE_BIN_NAME%
- set CMAKE=%CMAKE_BIN_NAME%
- ) || (
- echo Failed to located working %CMAKE_BIN_NAME%, needs to be accessible in PATH or set using CMAKE environment variable.
- goto ON_ERROR
- )
-)
-
-
-:: TODO, check installed yasm, needed to do btls build with assembler support.
-:: TODO, check installed ninja, needed to do btls build with assembler support.
-
-:: Detect VS version to use right cmake generator.
-set CMAKE_GENERATOR=Visual Studio 14 2015
-if "%VisualStudioVersion%" == "15.0" (
- set CMAKE_GENERATOR=Visual Studio 15 2017
-)
-
-if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64
-)
-
if not exist "%BTLS_BUILD_DIR%" (
mkdir "%BTLS_BUILD_DIR%"
)
cd "%BTLS_BUILD_DIR%"
-: Run cmake.
+:: Make sure cmake pick up msvc toolchain regardless of selected generator (Visual Studio|Ninja)
+set CC=%CL_BIN_NAME%
+set CXX=%CL_BIN_NAME%
+
+set BTLS_BUILD_TYPE=
+if /i "%CMAKE_GENERATOR%" == "ninja" (
+ set BTLS_BUILD_TYPE=-D CMAKE_BUILD_TYPE=%VS_CONFIGURATION%
+)
+
+:: Run cmake.
"%CMAKE%" ^
-D BTLS_ROOT:PATH="%BTLS_ROOT_PATH%" ^
-D SRC_DIR:PATH="%MONO_BTLS_ROOT_PATH%" ^
-D BTLS_CFLAGS="%BTLS_CFLAGS%" ^
--D OPENSSL_NO_ASM=1 ^
+-D OPENSSL_NO_ASM=%BTLS_NO_ASM_SUPPORT% ^
-D BTLS_ARCH="%BTLS_ARCH%" ^
-D BUILD_SHARED_LIBS=1 ^
--D CMAKE_BUILD_TYPE=%VS_CONFIGURATION% ^
+%BTLS_BUILD_TYPE% ^
-G "%CMAKE_GENERATOR%" ^
"%MONO_BTLS_ROOT_PATH%"
@@ -208,35 +224,49 @@ if not ERRORLEVEL == 0 (
goto ON_ERROR
)
-: Build BTLS.
-call "%MSBUILD%" mono-btls.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% || (
- goto ON_ERROR
+if /i "%CMAKE_GENERATOR%" == "ninja" (
+ :: Build BTLS using ninja build system.
+ call "%NINJA%" || (
+ goto ON_ERROR
+ )
+) else (
+ :: Build BTLS using msbuild build system.
+ call "%MSBUILD%" mono-btls.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% || (
+ goto ON_ERROR
+ )
)
:ON_INSTALL_BTLS
-if not exist "%VS_CONFIGURATION%\libmono-btls-shared.dll" (
- echo Missing btls build output, "%VS_CONFIGURATION%\libmono-btls-shared.dll"
+if not exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" (
+ echo Missing btls build output, "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll"
goto ON_ERROR
)
-: Make sure build output folder exists.
+:: Make sure build output folder exists.
if not exist %MONO_DIST_DIR% (
echo Could not find "%MONO_DIST_DIR%", creating folder for build output.
- mkdir "%MONO_DIST_DIR%""
+ mkdir "%MONO_DIST_DIR%"
)
-: Copy files into distribution directory.
-copy "%VS_CONFIGURATION%\libmono-btls-shared.dll" "%MONO_DIST_DIR%"
+:: Copy files into distribution directory.
+copy "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" "%MONO_DIST_DIR%"
-if exist "%VS_CONFIGURATION%\libmono-btls-shared.pdb" (
- copy "%VS_CONFIGURATION%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%"
+if exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" (
+ copy "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%"
)
goto ON_SUCCESS
:ON_CLEAN_BTLS
+if exist "%BTLS_BUILD_DIR%\build.ninja" (
+ pushd
+ cd "%BTLS_BUILD_DIR%"
+ call "%NINJA%" clean
+ popd
+)
+
if exist "%BTLS_BUILD_DIR%\mono-btls.sln" (
"%MSBUILD%" "%BTLS_BUILD_DIR%\mono-btls.sln" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:Clean
)
@@ -252,11 +282,92 @@ goto ON_EXIT
ECHO Usage: build-btls.bat [mono_src_dir] [mono_build_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration].
:ON_ERROR
- echo Failed to build BTLS.
- goto ON_EXIT
+ echo Failed to build BTLS.
+ goto ON_EXIT
:ON_EXIT
- set PATH=%TEMP_PATH%
- exit /b %BUILD_RESULT%
+ set PATH=%TEMP_PATH%
+ exit /b %BUILD_RESULT%
+
+:: ##############################################################################################################################
+:: Functions
+
+:: --------------------------------------------------
+:: Finds a program using environment.
+::
+:: %1 Existing program to check for.
+:: %2 Name of binary to locate.
+:: %3 Output, variable to set if found requested program.
+:: --------------------------------------------------
+:FIND_PROGRAM
+
+:: If not set by caller, check environment for program.
+if exist "%~1" (
+ goto :EOF
+)
+
+call where /q "%~2" && (
+ for /f "delims=" %%a in ('where "%~2"') do (
+ set "%~3=%%a"
+ )
+) || (
+ set "%~3="
+)
+
+goto :EOF
+
+:: --------------------------------------------------
+:: Setup up cmake build environment, including generator, build tools and variables.
+:: --------------------------------------------------
+:SETUP_CMAKE_ENVIRONMENT
+
+:: If not set by caller, check environment for working cmake.exe.
+call :FIND_PROGRAM "%CMAKE%" "%CMAKE_BIN_NAME%" CMAKE
+if "%CMAKE%" == "" (
+ goto _SETUP_CMAKE_ENVIRONMENT_EXIT
+)
+
+echo Found CMake: %CMAKE%
+
+:: Check for optional cmake generate and build tools for full BTLS assembler supported build. NOTE, currently BTLS assembler build
+:: can't be done using Visual Studio and must use ninja build generator + yasm and perl.
+call :FIND_PROGRAM "%NINJA%" "%NINJA_BIN_NAME%" NINJA
+call :FIND_PROGRAM "%YASM%" "%YASM_BIN_NAME%" YASM
+call :FIND_PROGRAM "%PERL%" "%PERL_BIN_NAME%" PERL
+
+if not "%NINJA%" == "" if not "%YASM%" == "" if not "%PERL%" == "" (
+ goto _SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
+)
+
+:_SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
+
+echo Using Visual Studio build generator, disabling full assembler build.
+
+:: Detect VS version to use right cmake generator.
+set CMAKE_GENERATOR=Visual Studio 14 2015
+if "%VisualStudioVersion%" == "15.0" (
+ set CMAKE_GENERATOR=Visual Studio 15 2017
+)
+
+if /i "%VS_PLATFORM%" == "x64" (
+ set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64
+)
+
+set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\%VS_CONFIGURATION%
+
+goto _SETUP_CMAKE_ENVIRONMENT_EXIT
+
+:_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
+
+echo Found Ninja: %NINJA%
+echo Using Ninja build generator, enabling full assembler build.
+
+set CMAKE_GENERATOR=Ninja
+set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%
+set BTLS_NO_ASM_SUPPORT=0
+
+:_SETUP_CMAKE_ENVIRONMENT_EXIT
+
+goto :EOF
@echo on \ No newline at end of file