diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2020-01-09 20:06:53 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2020-01-09 20:06:53 +0300 |
commit | c9dc20f59ebe7fbed2a439d69c2d03a2d4500577 (patch) | |
tree | 9982042e01e7cca13ec592a5b1f8f8b3e9e8307c /msvc | |
parent | 46f834fda73a7d6d95f3577aeaf667c5cf705644 (diff) |
Fix line endings in .bat files
They need to be CRLF otherwise we'll get conflicts when moving into dotnet/runtime which has a .gitattributes setting forcing .bat to CRLF.
Diffstat (limited to 'msvc')
-rwxr-xr-x | msvc/build-external-btls.bat | 972 | ||||
-rwxr-xr-x | msvc/build-external-llvm.bat | 998 | ||||
-rwxr-xr-x | msvc/install-llvm-mono-build.bat | 154 | ||||
-rwxr-xr-x | msvc/jaystuff.bat | 36 | ||||
-rwxr-xr-x | msvc/mono-sgen-msvc.bat | 192 | ||||
-rwxr-xr-x | msvc/run-msbuild.bat | 168 | ||||
-rwxr-xr-x | msvc/setup-solution.bat | 38 | ||||
-rwxr-xr-x | msvc/setup-vs-msbuild-env.bat | 286 | ||||
-rwxr-xr-x | msvc/setup-vs-msvcbuild-env.bat | 418 | ||||
-rwxr-xr-x | msvc/setup-windows-env.bat | 126 |
10 files changed, 1694 insertions, 1694 deletions
diff --git a/msvc/build-external-btls.bat b/msvc/build-external-btls.bat index 216134cd3b5..a8fb4e3d0b5 100755 --- a/msvc/build-external-btls.bat +++ b/msvc/build-external-btls.bat @@ -1,487 +1,487 @@ -:: --------------------------------------------------
-:: 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 BTLS source root directory.
-:: %2 BTLS source root directory.
-:: %3 BTLS build root directory.
-:: %4 Mono distribution root directory.
-:: %5 VS CFLAGS.
-:: %6 VS platform (Win32/x64)
-:: %7 VS configuration (Debug/Release)
-:: %8 VS target
-:: %9 VS PlatformToolSet, if used.
-:: %10 Win SDK, if used.
-:: %11 MsBuild bin path, if used.
-:: %12 Force MSBuild (true/false), if used.
-:: --------------------------------------------------
-
-@echo off
-setlocal
-
-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_BTLS_DIR=%~1
-shift
-set BTLS_DIR=%~1
-shift
-set BTLS_BUILD_DIR=%~1
-shift
-set MONO_DIST_DIR=%~1
-shift
-set VS_CFLAGS=%~1
-shift
-set VS_PLATFORM=%~1
-shift
-set VS_CONFIGURATION=%~1
-shift
-set VS_TARGET=%~1
-shift
-set VS_PLATFORM_TOOL_SET=%~1
-shift
-set VS_WIN_SDK_VERSION=%~1
-shift
-set MSBUILD_BIN_PATH=%~1
-shift
-set FORCE_MSBUILD=%~1
-
-:: Setup toolchain.
-:: set GIT=
-:: set CMAKE=
-:: set NINJA=
-set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe
-
-if "%MONO_BTLS_DIR%" == "" (
- echo Missing mono BTLS source directory argument.
- goto ECHO_USAGE
-)
-
-if "%BTLS_DIR%" == "" (
- echo Missing BTLS source directory argument.
- goto ECHO_USAGE
-)
-
-if "%BTLS_BUILD_DIR%" == "" (
- echo Missing BTLS build directory argument.
- goto ECHO_USAGE
-)
-
-if "%MONO_DIST_DIR%" == "" (
- echo Missing mono install directory argument.
- goto ECHO_USAGE
-)
-
-if "%VS_CFLAGS%" == "" (
- echo Missing CFLAGS argument.
- goto ECHO_USAGE
-)
-
-if "%VS_PLATFORM%" == "" (
- set VS_PLATFORM=x64
-)
-
-if "%VS_CONFIGURATION%" == "" (
- set VS_CONFIGURATION=Release
-)
-
-if "%VS_TARGET%" == "" (
- set VS_TARGET=Build
-)
-
-if "%VS_PLATFORM_TOOL_SET%" == "" (
- set VS_PLATFORM_TOOL_SET=v142
-)
-
-if "%VS_WIN_SDK_VERSION%" == "" (
- set VS_WIN_SDK_VERSION=10.0
-)
-
-if "%FORCE_MSBUILD%" == "" (
- set FORCE_MSBUILD=false
-)
-
-set BTLS_CFLAGS=%VS_CFLAGS%
-set BTLS_ARCH=x86_64
-if /i "%VS_PLATFORM%" == "win32" (
- set BTLS_ARCH=i386
-)
-
-set BTLS_NO_ASM_SUPPORT=1
-
-:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation.
-set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
-set VS_COMMON_EXTENSION_TOOLS_PATHS=
-
-:: Check if executed from VS2015/VS2017/VS2019 build environment.
-if "%VisualStudioVersion%" == "14.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v140" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-if "%VisualStudioVersion%" == "15.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v141" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-if "%VisualStudioVersion%" == "16.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v142" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-:: Executed outside VS2015/VS2017/VS2019 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
-)
-
-goto ON_ENV_OK
-
-:ON_ENV_WARNING
-
-:: VS 2019.
-if exist "%VSWHERE_TOOLS_BIN%" (
- echo For VS2019 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2019" command prompt.
- for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- echo Setup a "x86|x64 Native Tools Command Prompt for VS2019" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".
- goto ON_ENV_WARNING_DONE
- )
-)
-
-:: VS 2017.
-if exist "%VSWHERE_TOOLS_BIN%" (
- 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.
- for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do (
- echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".
- goto ON_ENV_WARNING_DONE
- )
-)
-
-:: VS 2015.
-set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
-IF EXIST "%VC_VARS_ALL_FILE%" (
- 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.
- echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64".
- goto ON_ENV_WARNING_DONE
-)
-
-:ON_ENV_WARNING_DONE
-
-echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected.
-
-:ON_ENV_OK
-
-:: Append paths to VS installed common extension tools at end of PATH (Vs2017/VS2019).
-call :FIND_VS_COMMON_EXTENSION_TOOLS_PATHS VS_COMMON_EXTENSION_TOOLS_PATHS
-if not "%VS_COMMON_EXTENSION_TOOLS_PATHS%" == "" (
- set "PATH=%PATH%;%VS_COMMON_EXTENSION_TOOLS_PATHS%"
-)
-
-:: 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
-)
-
-if /i "%VS_TARGET%" == "install" (
- goto ON_INSTALL_BTLS
-)
-
-if /i "%VS_TARGET%" == "clean" (
- goto ON_CLEAN_BTLS
-)
-
-:ON_BUILD_BTLS
-
-:: If not set by caller, check environment for working git.exe.
-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.
+:: -------------------------------------------------- +:: 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 BTLS source root directory. +:: %2 BTLS source root directory. +:: %3 BTLS build root directory. +:: %4 Mono distribution root directory. +:: %5 VS CFLAGS. +:: %6 VS platform (Win32/x64) +:: %7 VS configuration (Debug/Release) +:: %8 VS target +:: %9 VS PlatformToolSet, if used. +:: %10 Win SDK, if used. +:: %11 MsBuild bin path, if used. +:: %12 Force MSBuild (true/false), if used. +:: -------------------------------------------------- + +@echo off +setlocal + +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_BTLS_DIR=%~1 +shift +set BTLS_DIR=%~1 +shift +set BTLS_BUILD_DIR=%~1 +shift +set MONO_DIST_DIR=%~1 +shift +set VS_CFLAGS=%~1 +shift +set VS_PLATFORM=%~1 +shift +set VS_CONFIGURATION=%~1 +shift +set VS_TARGET=%~1 +shift +set VS_PLATFORM_TOOL_SET=%~1 +shift +set VS_WIN_SDK_VERSION=%~1 +shift +set MSBUILD_BIN_PATH=%~1 +shift +set FORCE_MSBUILD=%~1 + +:: Setup toolchain. +:: set GIT= +:: set CMAKE= +:: set NINJA= +set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe + +if "%MONO_BTLS_DIR%" == "" ( + echo Missing mono BTLS source directory argument. + goto ECHO_USAGE +) + +if "%BTLS_DIR%" == "" ( + echo Missing BTLS source directory argument. + goto ECHO_USAGE +) + +if "%BTLS_BUILD_DIR%" == "" ( + echo Missing BTLS build directory argument. + goto ECHO_USAGE +) + +if "%MONO_DIST_DIR%" == "" ( + echo Missing mono install directory argument. + goto ECHO_USAGE +) + +if "%VS_CFLAGS%" == "" ( + echo Missing CFLAGS argument. + goto ECHO_USAGE +) + +if "%VS_PLATFORM%" == "" ( + set VS_PLATFORM=x64 +) + +if "%VS_CONFIGURATION%" == "" ( + set VS_CONFIGURATION=Release +) + +if "%VS_TARGET%" == "" ( + set VS_TARGET=Build +) + +if "%VS_PLATFORM_TOOL_SET%" == "" ( + set VS_PLATFORM_TOOL_SET=v142 +) + +if "%VS_WIN_SDK_VERSION%" == "" ( + set VS_WIN_SDK_VERSION=10.0 +) + +if "%FORCE_MSBUILD%" == "" ( + set FORCE_MSBUILD=false +) + +set BTLS_CFLAGS=%VS_CFLAGS% +set BTLS_ARCH=x86_64 +if /i "%VS_PLATFORM%" == "win32" ( + set BTLS_ARCH=i386 +) + +set BTLS_NO_ASM_SUPPORT=1 + +:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation. +set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe +set VS_COMMON_EXTENSION_TOOLS_PATHS= + +:: Check if executed from VS2015/VS2017/VS2019 build environment. +if "%VisualStudioVersion%" == "14.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v140" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +if "%VisualStudioVersion%" == "15.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v141" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +if "%VisualStudioVersion%" == "16.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v142" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +:: Executed outside VS2015/VS2017/VS2019 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 +) + +goto ON_ENV_OK + +:ON_ENV_WARNING + +:: VS 2019. +if exist "%VSWHERE_TOOLS_BIN%" ( + echo For VS2019 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2019" command prompt. + for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + echo Setup a "x86|x64 Native Tools Command Prompt for VS2019" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat". + goto ON_ENV_WARNING_DONE + ) +) + +:: VS 2017. +if exist "%VSWHERE_TOOLS_BIN%" ( + 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. + for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do ( + echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat". + goto ON_ENV_WARNING_DONE + ) +) + +:: VS 2015. +set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat +IF EXIST "%VC_VARS_ALL_FILE%" ( + 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. + echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64". + goto ON_ENV_WARNING_DONE +) + +:ON_ENV_WARNING_DONE + +echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected. + +:ON_ENV_OK + +:: Append paths to VS installed common extension tools at end of PATH (Vs2017/VS2019). +call :FIND_VS_COMMON_EXTENSION_TOOLS_PATHS VS_COMMON_EXTENSION_TOOLS_PATHS +if not "%VS_COMMON_EXTENSION_TOOLS_PATHS%" == "" ( + set "PATH=%PATH%;%VS_COMMON_EXTENSION_TOOLS_PATHS%" +) + +:: 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 +) + +if /i "%VS_TARGET%" == "install" ( + goto ON_INSTALL_BTLS +) + +if /i "%VS_TARGET%" == "clean" ( + goto ON_CLEAN_BTLS +) + +:ON_BUILD_BTLS + +:: If not set by caller, check environment for working git.exe. +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. echo Updating submodule "%BTLS_DIR%" -"%GIT%" submodule update --init -- "%BTLS_DIR%"
-if not ERRORLEVEL == 0 (
- "%GIT%" submodule init -- "%BTLS_DIR%"
- "%GIT%" submodule update -- "%BTLS_DIR%"
- if not ERRORLEVEL == 0 (
- echo Git boringssl submodules failed to updated. You may experience compilation problems if some submodules are out of date.
- )
-)
-
-if not exist "%BTLS_DIR%" (
- echo Could not find "%BTLS_DIR%".
- goto ON_ERROR
-)
-
-if not exist "%BTLS_BUILD_DIR%" (
- mkdir "%BTLS_BUILD_DIR%"
-)
-
-cd "%BTLS_BUILD_DIR%"
-
-:: 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=
-set CMAKE_GENERATOR_TOOLSET=
-if /i "%CMAKE_GENERATOR%" == "ninja" (
- set BTLS_BUILD_TYPE=-D CMAKE_BUILD_TYPE=%VS_CONFIGURATION%
-) else (
- set CMAKE_GENERATOR_TOOLSET=%VS_PLATFORM_TOOL_SET%
-)
-
-if not "%CMAKE_GENERATOR_ARCH%" == "" (
- set CMAKE_GENERATOR_ARCH=-A %CMAKE_GENERATOR_ARCH%
-)
-
-:: Run cmake.
-"%CMAKE%" ^
--D BTLS_ROOT:PATH="%BTLS_DIR%" ^
--D SRC_DIR:PATH="%MONO_BTLS_DIR%" ^
--D BTLS_CFLAGS="%BTLS_CFLAGS%" ^
--D OPENSSL_NO_ASM=%BTLS_NO_ASM_SUPPORT% ^
--D BTLS_ARCH="%BTLS_ARCH%" ^
--D BUILD_SHARED_LIBS=1 ^
--D CMAKE_SYSTEM_VERSION=%VS_WIN_SDK_VERSION% ^
-%CMAKE_GENERATOR_TOOLSET% ^
-%BTLS_BUILD_TYPE% ^
--G "%CMAKE_GENERATOR%" ^
-%CMAKE_GENERATOR_ARCH% ^
-"%MONO_BTLS_DIR%"
-
-if not ERRORLEVEL == 0 (
- goto ON_ERROR
-)
-
-if /i "%CMAKE_GENERATOR%" == "ninja" (
- :: Build BTLS using ninja build system.
- call "%NINJA%" -j4 || (
- 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% /v:m /nologo /m || (
- goto ON_ERROR
- )
-)
-
-:ON_INSTALL_BTLS
-
-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.
-if not exist "%MONO_DIST_DIR%" (
- echo Could not find "%MONO_DIST_DIR%", creating folder for build output.
- mkdir "%MONO_DIST_DIR%"
-)
-
-:: Copy files into distribution directory.
-copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" "%MONO_DIST_DIR%" >nul 2>&1
-
-if exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" (
- copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%" >nul 2>&1
-)
-
-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 /v:m /nologo
-)
-
-goto ON_SUCCESS
-
-:ON_SUCCESS
-
-set BUILD_RESULT=0
-goto ON_EXIT
-
-:ECHO_USAGE:
- ECHO Usage: build-btls.bat [mono_btls_src_dir] [btls_src_dir] [btls_build_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration].
-
-:ON_ERROR
- echo Failed to build BTLS.
- goto ON_EXIT
-
-:ON_EXIT
- exit /b %BUILD_RESULT%
-
-:: ##############################################################################################################################
-:: Functions
-
-:: --------------------------------------------------
-:: Locates PATHS to installed common extension tools.
-:: %1 Output, variable including paths.
-:: --------------------------------------------------
-:FIND_VS_COMMON_EXTENSION_TOOLS_PATHS
-
-set VS_COMMON_EXTENSION_PATH=
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- set VS_COMMON_EXTENSION_PATH=%%a\Common7\IDE\CommonExtensions\Microsoft
- )
-)
-
-if exist "%VS_COMMON_EXTENSION_PATH%" (
- set "%~1=%VS_COMMON_EXTENSION_PATH%\TeamFoundation\Team Explorer\Git\cmd;%VS_COMMON_EXTENSION_PATH%\CMake\CMake\bin;%VS_COMMON_EXTENSION_PATH%\CMake\Ninja"
-)
-
-goto :EOF
-
-:: --------------------------------------------------
-:: 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
-)
-
-if /i "%VS_TARGET%" == "build" (
- echo Found CMake: "%CMAKE%"
-)
-
-if /i "%FORCE_MSBUILD%" == "true" (
- goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
-)
-
-:: 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
-
-if /i "%VS_TARGET%" == "build" (
- echo Using Visual Studio build generator, disabling full assembler build.
-)
-
-set CMAKE_GENERATOR_ARCH=
-
-:: Detect VS platform tool set to use matching cmake generator.
-if /i "%VS_PLATFORM_TOOL_SET%" == "v140" (
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
- ) else (
- set CMAKE_GENERATOR=Visual Studio 14 2015
- )
-)
-
-if /i "%VS_PLATFORM_TOOL_SET%" == "v141" (
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
- ) else (
- set CMAKE_GENERATOR=Visual Studio 15 2017
- )
-)
-
-if /i "%VS_PLATFORM_TOOL_SET%" == "v142" (
- set CMAKE_GENERATOR=Visual Studio 16 2019
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR_ARCH=x64
- ) else (
- set CMAKE_GENERATOR_ARCH=Win32
- )
-)
-
-set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\%VS_CONFIGURATION%
-
-goto _SETUP_CMAKE_ENVIRONMENT_EXIT
-
-:_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
-
-if /i "%VS_TARGET%" == "build" (
- echo Found Ninja: "%NINJA%"
- echo Using Ninja build generator, enabling full assembler build.
-)
-
-set CMAKE_GENERATOR_ARCH=
-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
+"%GIT%" submodule update --init -- "%BTLS_DIR%" +if not ERRORLEVEL == 0 ( + "%GIT%" submodule init -- "%BTLS_DIR%" + "%GIT%" submodule update -- "%BTLS_DIR%" + if not ERRORLEVEL == 0 ( + echo Git boringssl submodules failed to updated. You may experience compilation problems if some submodules are out of date. + ) +) + +if not exist "%BTLS_DIR%" ( + echo Could not find "%BTLS_DIR%". + goto ON_ERROR +) + +if not exist "%BTLS_BUILD_DIR%" ( + mkdir "%BTLS_BUILD_DIR%" +) + +cd "%BTLS_BUILD_DIR%" + +:: 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= +set CMAKE_GENERATOR_TOOLSET= +if /i "%CMAKE_GENERATOR%" == "ninja" ( + set BTLS_BUILD_TYPE=-D CMAKE_BUILD_TYPE=%VS_CONFIGURATION% +) else ( + set CMAKE_GENERATOR_TOOLSET=%VS_PLATFORM_TOOL_SET% +) + +if not "%CMAKE_GENERATOR_ARCH%" == "" ( + set CMAKE_GENERATOR_ARCH=-A %CMAKE_GENERATOR_ARCH% +) + +:: Run cmake. +"%CMAKE%" ^ +-D BTLS_ROOT:PATH="%BTLS_DIR%" ^ +-D SRC_DIR:PATH="%MONO_BTLS_DIR%" ^ +-D BTLS_CFLAGS="%BTLS_CFLAGS%" ^ +-D OPENSSL_NO_ASM=%BTLS_NO_ASM_SUPPORT% ^ +-D BTLS_ARCH="%BTLS_ARCH%" ^ +-D BUILD_SHARED_LIBS=1 ^ +-D CMAKE_SYSTEM_VERSION=%VS_WIN_SDK_VERSION% ^ +%CMAKE_GENERATOR_TOOLSET% ^ +%BTLS_BUILD_TYPE% ^ +-G "%CMAKE_GENERATOR%" ^ +%CMAKE_GENERATOR_ARCH% ^ +"%MONO_BTLS_DIR%" + +if not ERRORLEVEL == 0 ( + goto ON_ERROR +) + +if /i "%CMAKE_GENERATOR%" == "ninja" ( + :: Build BTLS using ninja build system. + call "%NINJA%" -j4 || ( + 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% /v:m /nologo /m || ( + goto ON_ERROR + ) +) + +:ON_INSTALL_BTLS + +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. +if not exist "%MONO_DIST_DIR%" ( + echo Could not find "%MONO_DIST_DIR%", creating folder for build output. + mkdir "%MONO_DIST_DIR%" +) + +:: Copy files into distribution directory. +copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" "%MONO_DIST_DIR%" >nul 2>&1 + +if exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" ( + copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%" >nul 2>&1 +) + +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 /v:m /nologo +) + +goto ON_SUCCESS + +:ON_SUCCESS + +set BUILD_RESULT=0 +goto ON_EXIT + +:ECHO_USAGE: + ECHO Usage: build-btls.bat [mono_btls_src_dir] [btls_src_dir] [btls_build_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration]. + +:ON_ERROR + echo Failed to build BTLS. + goto ON_EXIT + +:ON_EXIT + exit /b %BUILD_RESULT% + +:: ############################################################################################################################## +:: Functions + +:: -------------------------------------------------- +:: Locates PATHS to installed common extension tools. +:: %1 Output, variable including paths. +:: -------------------------------------------------- +:FIND_VS_COMMON_EXTENSION_TOOLS_PATHS + +set VS_COMMON_EXTENSION_PATH= +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + set VS_COMMON_EXTENSION_PATH=%%a\Common7\IDE\CommonExtensions\Microsoft + ) +) + +if exist "%VS_COMMON_EXTENSION_PATH%" ( + set "%~1=%VS_COMMON_EXTENSION_PATH%\TeamFoundation\Team Explorer\Git\cmd;%VS_COMMON_EXTENSION_PATH%\CMake\CMake\bin;%VS_COMMON_EXTENSION_PATH%\CMake\Ninja" +) + +goto :EOF + +:: -------------------------------------------------- +:: 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 +) + +if /i "%VS_TARGET%" == "build" ( + echo Found CMake: "%CMAKE%" +) + +if /i "%FORCE_MSBUILD%" == "true" ( + goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR +) + +:: 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 + +if /i "%VS_TARGET%" == "build" ( + echo Using Visual Studio build generator, disabling full assembler build. +) + +set CMAKE_GENERATOR_ARCH= + +:: Detect VS platform tool set to use matching cmake generator. +if /i "%VS_PLATFORM_TOOL_SET%" == "v140" ( + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR=Visual Studio 14 2015 Win64 + ) else ( + set CMAKE_GENERATOR=Visual Studio 14 2015 + ) +) + +if /i "%VS_PLATFORM_TOOL_SET%" == "v141" ( + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 + ) else ( + set CMAKE_GENERATOR=Visual Studio 15 2017 + ) +) + +if /i "%VS_PLATFORM_TOOL_SET%" == "v142" ( + set CMAKE_GENERATOR=Visual Studio 16 2019 + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR_ARCH=x64 + ) else ( + set CMAKE_GENERATOR_ARCH=Win32 + ) +) + +set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\%VS_CONFIGURATION% + +goto _SETUP_CMAKE_ENVIRONMENT_EXIT + +:_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR + +if /i "%VS_TARGET%" == "build" ( + echo Found Ninja: "%NINJA%" + echo Using Ninja build generator, enabling full assembler build. +) + +set CMAKE_GENERATOR_ARCH= +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 diff --git a/msvc/build-external-llvm.bat b/msvc/build-external-llvm.bat index 697681879fd..95b0fb6dcf3 100755 --- a/msvc/build-external-llvm.bat +++ b/msvc/build-external-llvm.bat @@ -1,282 +1,282 @@ -:: --------------------------------------------------
-:: Run full LLVM 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 LLVM source root directory.
-:: %2 LLVM build root directory.
-:: %3 LLVM install root directory.
-:: %4 Mono distribution root directory.
-:: %5 VS CFLAGS.
-:: %6 Additional CMake arguments.
-:: %7 VS platform (Win32/x64).
-:: %8 VS configuration (Debug/Release).
-:: %9 VS target.
-:: %9 VS PlatformToolSet, if used.
-:: %10 Win SDK, if used.
-:: %11 MsBuild bin path, if used.
-:: %12 Force MSBuild (true/false), if used.
-:: --------------------------------------------------
-
-@echo off
-setlocal
-
-set BUILD_RESULT=1
-
-set BUILD_EXTERNAL_LLVM_SCRIPT_PATH=%~dp0
-
-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 PYTHON_BIN_NAME=python.exe
-
-set LLVM_DIR=%~1
-shift
-set LLVM_BUILD_DIR=%~1
-shift
-set LLVM_INSTALL_DIR=%~1
-shift
-set MONO_DIST_DIR=%~1
-shift
-set VS_CFLAGS=%~1
-shift
-set LLVM_ADDITIONAL_CMAKE_ARGS=%~1
-shift
-set VS_PLATFORM=%~1
-shift
-set VS_CONFIGURATION=%~1
-shift
-set VS_TARGET=%~1
-shift
-set VS_PLATFORM_TOOL_SET=%~1
-shift
-set VS_WIN_SDK_VERSION=%~1
-shift
-set MSBUILD_BIN_PATH=%~1
-shift
-set FORCE_MSBUILD=%~1
-
-:: Setup toolchain.
-:: set GIT=
-:: set CMAKE=
-:: set NINJA=
-set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe
-
-if "%LLVM_DIR%" == "" (
- echo Missing LLVM source directory argument.
- goto ECHO_USAGE
-)
-
-if "%LLVM_BUILD_DIR%" == "" (
- echo Missing LLVM build directory argument.
- goto ECHO_USAGE
-)
-
-if "%LLVM_INSTALL_DIR%" == "" (
- echo Missing LLVM install directory argument.
- goto ECHO_USAGE
-)
-
-if "%MONO_DIST_DIR%" == "" (
- echo Missing Mono dist directory argument.
- goto ECHO_USAGE
-)
-
-if "%VS_CFLAGS%" == "" (
- echo Missing CFLAGS argument.
- goto ECHO_USAGE
-)
-
-if "%VS_PLATFORM%" == "" (
- set VS_PLATFORM=x64
-)
-
-if "%VS_CONFIGURATION%" == "" (
- set VS_CONFIGURATION=Release
-)
-
-if "%VS_TARGET%" == "" (
- set VS_TARGET=Build
-)
-
-if "%VS_PLATFORM_TOOL_SET%" == "" (
- set VS_PLATFORM_TOOL_SET=v142
-)
-
-if "%VS_WIN_SDK_VERSION%" == "" (
- set VS_WIN_SDK_VERSION=10.0
-)
-
-if "%FORCE_MSBUILD%" == "" (
- set FORCE_MSBUILD=false
-)
-
-set LLVM_CFLAGS=%VS_CFLAGS%
-set LLVM_ARCH=x86_64
-if /i "%VS_PLATFORM%" == "win32" (
- set LLVM_ARCH=i386
-)
-
-:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation.
-set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
-set VS_COMMON_EXTENSION_TOOLS_PATHS=
-
-:: Check if executed from VS2015/VS2017/2019 build environment.
-if "%VisualStudioVersion%" == "14.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v140" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-if "%VisualStudioVersion%" == "15.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v141" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-if "%VisualStudioVersion%" == "16.0" (
- if /i not "%VS_PLATFORM_TOOL_SET%" == "v142" (
- echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild.
- set FORCE_MSBUILD=true
- )
- goto ON_ENV_OK
-)
-
-:: Executed outside VS2015/VS2017/VS2019 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
-)
-
-goto ON_ENV_OK
-
-:ON_ENV_WARNING
-
-set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
-
-:: VS 2019.
-if exist "%VSWHERE_TOOLS_BIN%" (
- echo For VS2019 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2019" command prompt.
- for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- echo Setup a "x86|x64 Native Tools Command Prompt for VS2019" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".
- goto ON_ENV_WARNING_DONE
- )
-)
-
-:: VS 2017.
-if exist "%VSWHERE_TOOLS_BIN%" (
- 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.
- for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do (
- echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".
- goto ON_ENV_WARNING_DONE
- )
-)
-
-:: VS 2015.
-set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
-IF EXIST "%VC_VARS_ALL_FILE%" (
- 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.
- echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64".
- goto ON_ENV_WARNING_DONE
-)
-
-:ON_ENV_WARNING_DONE
-
-echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected.
-
-:ON_ENV_OK
-
-:: Append paths to VS installed common extension tools at end of PATH (Vs2017/VS2019).
-call :FIND_VS_COMMON_EXTENSION_TOOLS_PATHS VS_COMMON_EXTENSION_TOOLS_PATHS
-if not "%VS_COMMON_EXTENSION_TOOLS_PATHS%" == "" (
- set "PATH=%PATH%;%VS_COMMON_EXTENSION_TOOLS_PATHS%"
-)
-
-:: 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_LLVM
-)
-
-if /i "%VS_TARGET%" == "install" (
- goto ON_INSTALL_LLVM
-)
-
-if /i "%VS_TARGET%" == "clean" (
- goto ON_CLEAN_LLVM
-)
-
-:ON_BUILD_LLVM
-
-:: If not set by caller, check environment for working git.exe.
-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 llvm submodule is up to date.
+:: -------------------------------------------------- +:: Run full LLVM 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 LLVM source root directory. +:: %2 LLVM build root directory. +:: %3 LLVM install root directory. +:: %4 Mono distribution root directory. +:: %5 VS CFLAGS. +:: %6 Additional CMake arguments. +:: %7 VS platform (Win32/x64). +:: %8 VS configuration (Debug/Release). +:: %9 VS target. +:: %9 VS PlatformToolSet, if used. +:: %10 Win SDK, if used. +:: %11 MsBuild bin path, if used. +:: %12 Force MSBuild (true/false), if used. +:: -------------------------------------------------- + +@echo off +setlocal + +set BUILD_RESULT=1 + +set BUILD_EXTERNAL_LLVM_SCRIPT_PATH=%~dp0 + +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 PYTHON_BIN_NAME=python.exe + +set LLVM_DIR=%~1 +shift +set LLVM_BUILD_DIR=%~1 +shift +set LLVM_INSTALL_DIR=%~1 +shift +set MONO_DIST_DIR=%~1 +shift +set VS_CFLAGS=%~1 +shift +set LLVM_ADDITIONAL_CMAKE_ARGS=%~1 +shift +set VS_PLATFORM=%~1 +shift +set VS_CONFIGURATION=%~1 +shift +set VS_TARGET=%~1 +shift +set VS_PLATFORM_TOOL_SET=%~1 +shift +set VS_WIN_SDK_VERSION=%~1 +shift +set MSBUILD_BIN_PATH=%~1 +shift +set FORCE_MSBUILD=%~1 + +:: Setup toolchain. +:: set GIT= +:: set CMAKE= +:: set NINJA= +set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe + +if "%LLVM_DIR%" == "" ( + echo Missing LLVM source directory argument. + goto ECHO_USAGE +) + +if "%LLVM_BUILD_DIR%" == "" ( + echo Missing LLVM build directory argument. + goto ECHO_USAGE +) + +if "%LLVM_INSTALL_DIR%" == "" ( + echo Missing LLVM install directory argument. + goto ECHO_USAGE +) + +if "%MONO_DIST_DIR%" == "" ( + echo Missing Mono dist directory argument. + goto ECHO_USAGE +) + +if "%VS_CFLAGS%" == "" ( + echo Missing CFLAGS argument. + goto ECHO_USAGE +) + +if "%VS_PLATFORM%" == "" ( + set VS_PLATFORM=x64 +) + +if "%VS_CONFIGURATION%" == "" ( + set VS_CONFIGURATION=Release +) + +if "%VS_TARGET%" == "" ( + set VS_TARGET=Build +) + +if "%VS_PLATFORM_TOOL_SET%" == "" ( + set VS_PLATFORM_TOOL_SET=v142 +) + +if "%VS_WIN_SDK_VERSION%" == "" ( + set VS_WIN_SDK_VERSION=10.0 +) + +if "%FORCE_MSBUILD%" == "" ( + set FORCE_MSBUILD=false +) + +set LLVM_CFLAGS=%VS_CFLAGS% +set LLVM_ARCH=x86_64 +if /i "%VS_PLATFORM%" == "win32" ( + set LLVM_ARCH=i386 +) + +:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation. +set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe +set VS_COMMON_EXTENSION_TOOLS_PATHS= + +:: Check if executed from VS2015/VS2017/2019 build environment. +if "%VisualStudioVersion%" == "14.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v140" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +if "%VisualStudioVersion%" == "15.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v141" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +if "%VisualStudioVersion%" == "16.0" ( + if /i not "%VS_PLATFORM_TOOL_SET%" == "v142" ( + echo VisualStudioVersion/PlatformToolchain missmatch, forcing msbuild. + set FORCE_MSBUILD=true + ) + goto ON_ENV_OK +) + +:: Executed outside VS2015/VS2017/VS2019 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 +) + +goto ON_ENV_OK + +:ON_ENV_WARNING + +set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe + +:: VS 2019. +if exist "%VSWHERE_TOOLS_BIN%" ( + echo For VS2019 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2019" command prompt. + for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + echo Setup a "x86|x64 Native Tools Command Prompt for VS2019" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat". + goto ON_ENV_WARNING_DONE + ) +) + +:: VS 2017. +if exist "%VSWHERE_TOOLS_BIN%" ( + 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. + for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do ( + echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat". + goto ON_ENV_WARNING_DONE + ) +) + +:: VS 2015. +set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat +IF EXIST "%VC_VARS_ALL_FILE%" ( + 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. + echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64". + goto ON_ENV_WARNING_DONE +) + +:ON_ENV_WARNING_DONE + +echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected. + +:ON_ENV_OK + +:: Append paths to VS installed common extension tools at end of PATH (Vs2017/VS2019). +call :FIND_VS_COMMON_EXTENSION_TOOLS_PATHS VS_COMMON_EXTENSION_TOOLS_PATHS +if not "%VS_COMMON_EXTENSION_TOOLS_PATHS%" == "" ( + set "PATH=%PATH%;%VS_COMMON_EXTENSION_TOOLS_PATHS%" +) + +:: 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_LLVM +) + +if /i "%VS_TARGET%" == "install" ( + goto ON_INSTALL_LLVM +) + +if /i "%VS_TARGET%" == "clean" ( + goto ON_CLEAN_LLVM +) + +:ON_BUILD_LLVM + +:: If not set by caller, check environment for working git.exe. +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 llvm submodule is up to date. echo Updating submodule "%LLVM_DIR%" -"%GIT%" submodule update --init -- "%LLVM_DIR%"
-if not ERRORLEVEL == 0 (
- "%GIT%" submodule init -- "%LLVM_DIR%"
- "%GIT%" submodule update -- "%LLVM_DIR%"
- if not ERRORLEVEL == 0 (
- echo Git llvm submodules failed to updated. You may experience compilation problems if some submodules are out of date.
- )
-)
-
-if not exist "%LLVM_DIR%" (
- echo Could not find "%LLVM_DIR%".
- goto ON_ERROR
-)
-
-if not exist "%LLVM_BUILD_DIR%" (
- mkdir "%LLVM_BUILD_DIR%"
-)
-
-cd "%LLVM_BUILD_DIR%"
-
-:: 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 CMAKE_GENERATOR_ARGS=
-set CMAKE_GENERATOR_TOOLSET=
-if /i "%CMAKE_GENERATOR%" == "ninja" (
- set CMAKE_GENERATOR_ARGS=-DCMAKE_BUILD_TYPE=%VS_CONFIGURATION%
-) else (
- set CMAKE_GENERATOR_ARGS=-Thost=x64
- set CMAKE_GENERATOR_TOOLSET=%VS_PLATFORM_TOOL_SET%
-)
-
-if not "%CMAKE_GENERATOR_ARCH%" == "" (
- set CMAKE_GENERATOR_ARCH=-A %CMAKE_GENERATOR_ARCH%
-)
-
+"%GIT%" submodule update --init -- "%LLVM_DIR%" +if not ERRORLEVEL == 0 ( + "%GIT%" submodule init -- "%LLVM_DIR%" + "%GIT%" submodule update -- "%LLVM_DIR%" + if not ERRORLEVEL == 0 ( + echo Git llvm submodules failed to updated. You may experience compilation problems if some submodules are out of date. + ) +) + +if not exist "%LLVM_DIR%" ( + echo Could not find "%LLVM_DIR%". + goto ON_ERROR +) + +if not exist "%LLVM_BUILD_DIR%" ( + mkdir "%LLVM_BUILD_DIR%" +) + +cd "%LLVM_BUILD_DIR%" + +:: 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 CMAKE_GENERATOR_ARGS= +set CMAKE_GENERATOR_TOOLSET= +if /i "%CMAKE_GENERATOR%" == "ninja" ( + set CMAKE_GENERATOR_ARGS=-DCMAKE_BUILD_TYPE=%VS_CONFIGURATION% +) else ( + set CMAKE_GENERATOR_ARGS=-Thost=x64 + set CMAKE_GENERATOR_TOOLSET=%VS_PLATFORM_TOOL_SET% +) + +if not "%CMAKE_GENERATOR_ARCH%" == "" ( + set CMAKE_GENERATOR_ARCH=-A %CMAKE_GENERATOR_ARCH% +) + :: Check if LLVM_DIR is just repro root or if we should build :: a llvm subfolder within that repository. set "LLVM_SOURCE_DIR=%LLVM_DIR%" @@ -284,225 +284,225 @@ if exist "%LLVM_SOURCE_DIR%\llvm\CMakeLists.txt" ( set "LLVM_SOURCE_DIR=%LLVM_DIR%\llvm" ) -:: Run cmake.
-"%CMAKE%" ^
--DCMAKE_INSTALL_PREFIX="%LLVM_INSTALL_DIR%" ^
--DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" ^
--DLLVM_BUILD_TESTS=Off ^
--DLLVM_INCLUDE_TESTS=Off ^
--DLLVM_BUILD_EXAMPLES=Off ^
--DLLVM_INCLUDE_EXAMPLES=Off ^
--DLLVM_TOOLS_TO_BUILD="opt;llc;llvm-config;llvm-dis;llvm-mc;llvm-as" ^
--DLLVM_ENABLE_LIBXML2=Off ^
--DCMAKE_SYSTEM_PROCESSOR="%LLVM_ARCH%" ^
--D CMAKE_SYSTEM_VERSION=%VS_WIN_SDK_VERSION% ^
-%CMAKE_GENERATOR_TOOLSET% ^
-%LLVM_ADDITIONAL_CMAKE_ARGS% ^
-%CMAKE_GENERATOR_ARGS% ^
--G "%CMAKE_GENERATOR%" ^
-%CMAKE_GENERATOR_ARCH% ^
+:: Run cmake. +"%CMAKE%" ^ +-DCMAKE_INSTALL_PREFIX="%LLVM_INSTALL_DIR%" ^ +-DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64" ^ +-DLLVM_BUILD_TESTS=Off ^ +-DLLVM_INCLUDE_TESTS=Off ^ +-DLLVM_BUILD_EXAMPLES=Off ^ +-DLLVM_INCLUDE_EXAMPLES=Off ^ +-DLLVM_TOOLS_TO_BUILD="opt;llc;llvm-config;llvm-dis;llvm-mc;llvm-as" ^ +-DLLVM_ENABLE_LIBXML2=Off ^ +-DCMAKE_SYSTEM_PROCESSOR="%LLVM_ARCH%" ^ +-D CMAKE_SYSTEM_VERSION=%VS_WIN_SDK_VERSION% ^ +%CMAKE_GENERATOR_TOOLSET% ^ +%LLVM_ADDITIONAL_CMAKE_ARGS% ^ +%CMAKE_GENERATOR_ARGS% ^ +-G "%CMAKE_GENERATOR%" ^ +%CMAKE_GENERATOR_ARCH% ^ "%LLVM_SOURCE_DIR%" -
-if not ERRORLEVEL == 0 (
- goto ON_ERROR
-)
-
-if /i "%CMAKE_GENERATOR%" == "ninja" (
- :: Build LLVM using ninja build system.
- call "%NINJA%" -j4 || (
- goto ON_ERROR
- )
-) else (
- :: Build LLVM using msbuild build system.
- call "%MSBUILD%" llvm.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% /v:m /nologo /m || (
- goto ON_ERROR
- )
-)
-
-:ON_INSTALL_LLVM
-
-:: Make sure build install folder exists.
-if not exist "%LLVM_INSTALL_DIR%" (
- echo Could not find "%LLVM_INSTALL_DIR%", creating folder for build output.
- mkdir "%LLVM_INSTALL_DIR%"
-)
-
-:: Make sure Mono dist folder exists.
-if not exist "%MONO_DIST_DIR%" (
- echo Could not find "%MONO_DIST_DIR%", creating folder for build output.
- mkdir "%MONO_DIST_DIR%"
-)
-
-if exist "%LLVM_BUILD_DIR%\build.ninja" (
- pushd
- cd "%LLVM_BUILD_DIR%"
- call "%NINJA%" install
- popd
-)
-
-if exist "%LLVM_BUILD_DIR%\install.vcxproj" (
- "%MSBUILD%" "%LLVM_BUILD_DIR%\install.vcxproj" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /v:m /nologo
-)
-
-call "%BUILD_EXTERNAL_LLVM_SCRIPT_PATH%\install-llvm-mono-build.bat" "%LLVM_INSTALL_DIR%" "%MONO_DIST_DIR%" || (
- goto ON_ERROR
-)
-
-goto ON_SUCCESS
-
-:ON_CLEAN_LLVM
-
-if exist "%LLVM_BUILD_DIR%\build.ninja" (
- pushd
- cd "%LLVM_BUILD_DIR%"
- call "%NINJA%" clean
- popd
-)
-
-if exist "%LLVM_BUILD_DIR%\llvm.sln" (
- "%MSBUILD%" "%LLVM_BUILD_DIR%\llvm.sln" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:Clean /v:m /nologo
-)
-
-goto ON_SUCCESS
-
-:ON_SUCCESS
-
-set BUILD_RESULT=0
-goto ON_EXIT
-
-:ECHO_USAGE:
- ECHO Usage: build-external-llvm.bat [llvm_src_dir] [llvm_build_dir] [llvm_install_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration].
-
-:ON_ERROR
- echo Failed to build LLVM.
- goto ON_EXIT
-
-:ON_EXIT
- exit /b %BUILD_RESULT%
-
-:: ##############################################################################################################################
-:: Functions
-
-:: --------------------------------------------------
-:: Locates PATHS to installed common extension tools.
-:: %1 Output, variable including paths.
-:: --------------------------------------------------
-:FIND_VS_COMMON_EXTENSION_TOOLS_PATHS
-
-set VS_COMMON_EXTENSION_PATH=
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- set VS_COMMON_EXTENSION_PATH=%%a\Common7\IDE\CommonExtensions\Microsoft
- )
-)
-
-if exist "%VS_COMMON_EXTENSION_PATH%" (
- set "%~1=%VS_COMMON_EXTENSION_PATH%\TeamFoundation\Team Explorer\Git\cmd;%VS_COMMON_EXTENSION_PATH%\CMake\CMake\bin;%VS_COMMON_EXTENSION_PATH%\CMake\Ninja"
-)
-
-goto :EOF
-
-:: --------------------------------------------------
-:: 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
-)
-
-if /i "%VS_TARGET%" == "build" (
- echo Found CMake: "%CMAKE%"
-)
-
-if /i "%FORCE_MSBUILD%" == "true" (
- goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
-)
-
-:: Check for optional cmake generate and build tools.
-call :FIND_PROGRAM "%NINJA%" "%NINJA_BIN_NAME%" NINJA
-
-if not "%NINJA%" == "" (
- goto _SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
-)
-
-:_SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
-
-if /i "%VS_TARGET%" == "build" (
- echo Using Visual Studio build generator.
-)
-
-set CMAKE_GENERATOR_ARCH=
-
-:: Detect VS platform tool set to use matching cmake generator.
-if /i "%VS_PLATFORM_TOOL_SET%" == "v140" (
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
- ) else (
- set CMAKE_GENERATOR=Visual Studio 14 2015
- )
-)
-
-if /i "%VS_PLATFORM_TOOL_SET%" == "v141" (
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
- ) else (
- set CMAKE_GENERATOR=Visual Studio 15 2017
- )
-)
-
-if /i "%VS_PLATFORM_TOOL_SET%" == "v142" (
- set CMAKE_GENERATOR=Visual Studio 16 2019
- if /i "%VS_PLATFORM%" == "x64" (
- set CMAKE_GENERATOR_ARCH=x64
- ) else (
- set CMAKE_GENERATOR_ARCH=Win32
- )
-)
-
-set LLVM_BUILD_OUTPUT_DIR=%LLVM_BUILD_DIR%\%VS_CONFIGURATION%
-
-goto _SETUP_CMAKE_ENVIRONMENT_EXIT
-
-:_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
-
-if /i "%VS_TARGET%" == "build" (
- echo Found Ninja: "%NINJA%"
- echo Using Ninja build generator.
-)
-
-set CMAKE_GENERATOR_ARCH=
-set CMAKE_GENERATOR=Ninja
-set LLVM_BUILD_OUTPUT_DIR=%LLVM_BUILD_DIR%
-
-:_SETUP_CMAKE_ENVIRONMENT_EXIT
-
-goto :EOF
-
-@echo on
+ +if not ERRORLEVEL == 0 ( + goto ON_ERROR +) + +if /i "%CMAKE_GENERATOR%" == "ninja" ( + :: Build LLVM using ninja build system. + call "%NINJA%" -j4 || ( + goto ON_ERROR + ) +) else ( + :: Build LLVM using msbuild build system. + call "%MSBUILD%" llvm.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% /v:m /nologo /m || ( + goto ON_ERROR + ) +) + +:ON_INSTALL_LLVM + +:: Make sure build install folder exists. +if not exist "%LLVM_INSTALL_DIR%" ( + echo Could not find "%LLVM_INSTALL_DIR%", creating folder for build output. + mkdir "%LLVM_INSTALL_DIR%" +) + +:: Make sure Mono dist folder exists. +if not exist "%MONO_DIST_DIR%" ( + echo Could not find "%MONO_DIST_DIR%", creating folder for build output. + mkdir "%MONO_DIST_DIR%" +) + +if exist "%LLVM_BUILD_DIR%\build.ninja" ( + pushd + cd "%LLVM_BUILD_DIR%" + call "%NINJA%" install + popd +) + +if exist "%LLVM_BUILD_DIR%\install.vcxproj" ( + "%MSBUILD%" "%LLVM_BUILD_DIR%\install.vcxproj" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /v:m /nologo +) + +call "%BUILD_EXTERNAL_LLVM_SCRIPT_PATH%\install-llvm-mono-build.bat" "%LLVM_INSTALL_DIR%" "%MONO_DIST_DIR%" || ( + goto ON_ERROR +) + +goto ON_SUCCESS + +:ON_CLEAN_LLVM + +if exist "%LLVM_BUILD_DIR%\build.ninja" ( + pushd + cd "%LLVM_BUILD_DIR%" + call "%NINJA%" clean + popd +) + +if exist "%LLVM_BUILD_DIR%\llvm.sln" ( + "%MSBUILD%" "%LLVM_BUILD_DIR%\llvm.sln" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:Clean /v:m /nologo +) + +goto ON_SUCCESS + +:ON_SUCCESS + +set BUILD_RESULT=0 +goto ON_EXIT + +:ECHO_USAGE: + ECHO Usage: build-external-llvm.bat [llvm_src_dir] [llvm_build_dir] [llvm_install_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration]. + +:ON_ERROR + echo Failed to build LLVM. + goto ON_EXIT + +:ON_EXIT + exit /b %BUILD_RESULT% + +:: ############################################################################################################################## +:: Functions + +:: -------------------------------------------------- +:: Locates PATHS to installed common extension tools. +:: %1 Output, variable including paths. +:: -------------------------------------------------- +:FIND_VS_COMMON_EXTENSION_TOOLS_PATHS + +set VS_COMMON_EXTENSION_PATH= +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + set VS_COMMON_EXTENSION_PATH=%%a\Common7\IDE\CommonExtensions\Microsoft + ) +) + +if exist "%VS_COMMON_EXTENSION_PATH%" ( + set "%~1=%VS_COMMON_EXTENSION_PATH%\TeamFoundation\Team Explorer\Git\cmd;%VS_COMMON_EXTENSION_PATH%\CMake\CMake\bin;%VS_COMMON_EXTENSION_PATH%\CMake\Ninja" +) + +goto :EOF + +:: -------------------------------------------------- +:: 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 +) + +if /i "%VS_TARGET%" == "build" ( + echo Found CMake: "%CMAKE%" +) + +if /i "%FORCE_MSBUILD%" == "true" ( + goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR +) + +:: Check for optional cmake generate and build tools. +call :FIND_PROGRAM "%NINJA%" "%NINJA_BIN_NAME%" NINJA + +if not "%NINJA%" == "" ( + goto _SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR +) + +:_SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR + +if /i "%VS_TARGET%" == "build" ( + echo Using Visual Studio build generator. +) + +set CMAKE_GENERATOR_ARCH= + +:: Detect VS platform tool set to use matching cmake generator. +if /i "%VS_PLATFORM_TOOL_SET%" == "v140" ( + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR=Visual Studio 14 2015 Win64 + ) else ( + set CMAKE_GENERATOR=Visual Studio 14 2015 + ) +) + +if /i "%VS_PLATFORM_TOOL_SET%" == "v141" ( + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 + ) else ( + set CMAKE_GENERATOR=Visual Studio 15 2017 + ) +) + +if /i "%VS_PLATFORM_TOOL_SET%" == "v142" ( + set CMAKE_GENERATOR=Visual Studio 16 2019 + if /i "%VS_PLATFORM%" == "x64" ( + set CMAKE_GENERATOR_ARCH=x64 + ) else ( + set CMAKE_GENERATOR_ARCH=Win32 + ) +) + +set LLVM_BUILD_OUTPUT_DIR=%LLVM_BUILD_DIR%\%VS_CONFIGURATION% + +goto _SETUP_CMAKE_ENVIRONMENT_EXIT + +:_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR + +if /i "%VS_TARGET%" == "build" ( + echo Found Ninja: "%NINJA%" + echo Using Ninja build generator. +) + +set CMAKE_GENERATOR_ARCH= +set CMAKE_GENERATOR=Ninja +set LLVM_BUILD_OUTPUT_DIR=%LLVM_BUILD_DIR% + +:_SETUP_CMAKE_ENVIRONMENT_EXIT + +goto :EOF + +@echo on diff --git a/msvc/install-llvm-mono-build.bat b/msvc/install-llvm-mono-build.bat index ebb1a86780c..55b443a768f 100755 --- a/msvc/install-llvm-mono-build.bat +++ b/msvc/install-llvm-mono-build.bat @@ -1,77 +1,77 @@ -:: --------------------------------------------------
-:: Install needed LLVM binaries from LLVM install directory
-:: into Mono build output directory.
-::
-:: %1 LLVM install root directory (internal or external LLVM build).
-:: %2 Mono distribution root directory.
-:: --------------------------------------------------
-
-@echo off
-setlocal
-
-set BUILD_RESULT=1
-
-set LLVM_INSTALL_DIR=%~1
-shift
-set MONO_DIST_DIR=%~1
-shift
-
-if "%LLVM_INSTALL_DIR%" == "" (
- echo Missing LLVM install directory argument.
- goto ECHO_USAGE
-)
-
-if "%MONO_DIST_DIR%" == "" (
- echo Missing Mono dist directory argument.
- goto ECHO_USAGE
-)
-
-if not exist "%LLVM_INSTALL_DIR%\bin\opt.exe" (
- echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\opt.exe"
- goto ON_ERROR
-)
-
-if not exist "%LLVM_INSTALL_DIR%\bin\llc.exe" (
- echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llc.exe"
- goto ON_ERROR
-)
-
-if not exist "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe" (
- echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe"
- goto ON_ERROR
-)
-
-if not exist "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe" (
- echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe"
- goto ON_ERROR
-)
-
-if not exist "%LLVM_INSTALL_DIR%\bin\llvm-as.exe" (
- echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-as.exe"
- goto ON_ERROR
-)
-
-copy /Y "%LLVM_INSTALL_DIR%\bin\opt.exe" "%MONO_DIST_DIR%" >nul 2>&1
-copy /Y "%LLVM_INSTALL_DIR%\bin\llc.exe" "%MONO_DIST_DIR%" >nul 2>&1
-copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe" "%MONO_DIST_DIR%" >nul 2>&1
-copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe" "%MONO_DIST_DIR%" >nul 2>&1
-copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-as.exe" "%MONO_DIST_DIR%" >nul 2>&1
-
-goto ON_SUCCESS
-
-:ON_SUCCESS
-
-set BUILD_RESULT=0
-goto ON_EXIT
-
-:ECHO_USAGE:
- ECHO Usage: install-llvm-mono-build.bat [llvm_install_dir] [mono_dist_dir].
-
-:ON_ERROR
- echo Failed to install LLVM binaries into Mono build output directory.
- goto ON_EXIT
-
-:ON_EXIT
- exit /b %BUILD_RESULT%
-
-@echo on
+:: -------------------------------------------------- +:: Install needed LLVM binaries from LLVM install directory +:: into Mono build output directory. +:: +:: %1 LLVM install root directory (internal or external LLVM build). +:: %2 Mono distribution root directory. +:: -------------------------------------------------- + +@echo off +setlocal + +set BUILD_RESULT=1 + +set LLVM_INSTALL_DIR=%~1 +shift +set MONO_DIST_DIR=%~1 +shift + +if "%LLVM_INSTALL_DIR%" == "" ( + echo Missing LLVM install directory argument. + goto ECHO_USAGE +) + +if "%MONO_DIST_DIR%" == "" ( + echo Missing Mono dist directory argument. + goto ECHO_USAGE +) + +if not exist "%LLVM_INSTALL_DIR%\bin\opt.exe" ( + echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\opt.exe" + goto ON_ERROR +) + +if not exist "%LLVM_INSTALL_DIR%\bin\llc.exe" ( + echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llc.exe" + goto ON_ERROR +) + +if not exist "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe" ( + echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe" + goto ON_ERROR +) + +if not exist "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe" ( + echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe" + goto ON_ERROR +) + +if not exist "%LLVM_INSTALL_DIR%\bin\llvm-as.exe" ( + echo Missing LLVM build output, "%LLVM_INSTALL_DIR%\bin\llvm-as.exe" + goto ON_ERROR +) + +copy /Y "%LLVM_INSTALL_DIR%\bin\opt.exe" "%MONO_DIST_DIR%" >nul 2>&1 +copy /Y "%LLVM_INSTALL_DIR%\bin\llc.exe" "%MONO_DIST_DIR%" >nul 2>&1 +copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-dis.exe" "%MONO_DIST_DIR%" >nul 2>&1 +copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-mc.exe" "%MONO_DIST_DIR%" >nul 2>&1 +copy /Y "%LLVM_INSTALL_DIR%\bin\llvm-as.exe" "%MONO_DIST_DIR%" >nul 2>&1 + +goto ON_SUCCESS + +:ON_SUCCESS + +set BUILD_RESULT=0 +goto ON_EXIT + +:ECHO_USAGE: + ECHO Usage: install-llvm-mono-build.bat [llvm_install_dir] [mono_dist_dir]. + +:ON_ERROR + echo Failed to install LLVM binaries into Mono build output directory. + goto ON_EXIT + +:ON_EXIT + exit /b %BUILD_RESULT% + +@echo on diff --git a/msvc/jaystuff.bat b/msvc/jaystuff.bat index a8736d85b08..0c4b2ec7b09 100755 --- a/msvc/jaystuff.bat +++ b/msvc/jaystuff.bat @@ -1,18 +1,18 @@ -.\mono\mcs\jay\jay.exe -cv < .\mono\mcs\jay\skeleton.cs .\mono\mcs\mcs\cs-parser.jay > .\mono\mcs\mcs\cs-parser.cs
-
-.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.XML\System.Xml.XPath\Parser.jay > .\mono\mcs\class\System.XML\System.Xml.XPath\Parser.cs
-
-.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternParser.jay > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.cs
-
-echo #define XSLT_PATTERN > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt
-
-type .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.cs > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternParser.cs
-
-type .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt .\mono\mcs\class\System.XML\System.Xml.XPath\Tokenizer.cs > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternTokenizer.cs
-
-.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.Data\Mono.Data.SqlExpressions\Parser.jay > .\mono\mcs\class\System.Data\Mono.Data.SqlExpressions\Parser.cs
-
-.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\Commons.Xml.Relaxng\Commons.Xml.Relaxng.Rnc\RncParser.jay > .\mono\mcs\class\Commons.Xml.Relaxng\Commons.Xml.Relaxng.Rnc\RncParser.cs
-
-.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\ilasm\parser\ILParser.jay > .\mono\mcs\ilasm\ILParser.cs
-
+.\mono\mcs\jay\jay.exe -cv < .\mono\mcs\jay\skeleton.cs .\mono\mcs\mcs\cs-parser.jay > .\mono\mcs\mcs\cs-parser.cs + +.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.XML\System.Xml.XPath\Parser.jay > .\mono\mcs\class\System.XML\System.Xml.XPath\Parser.cs + +.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternParser.jay > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.cs + +echo #define XSLT_PATTERN > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt + +type .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.cs > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternParser.cs + +type .\mono\mcs\class\System.XML\Mono.Xml.Xsl\Pattern.txt .\mono\mcs\class\System.XML\System.Xml.XPath\Tokenizer.cs > .\mono\mcs\class\System.XML\Mono.Xml.Xsl\PatternTokenizer.cs + +.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\System.Data\Mono.Data.SqlExpressions\Parser.jay > .\mono\mcs\class\System.Data\Mono.Data.SqlExpressions\Parser.cs + +.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\class\Commons.Xml.Relaxng\Commons.Xml.Relaxng.Rnc\RncParser.jay > .\mono\mcs\class\Commons.Xml.Relaxng\Commons.Xml.Relaxng.Rnc\RncParser.cs + +.\mono\mcs\jay\jay.exe -ct < .\mono\mcs\jay\skeleton.cs .\mono\mcs\ilasm\parser\ILParser.jay > .\mono\mcs\ilasm\ILParser.cs + diff --git a/msvc/mono-sgen-msvc.bat b/msvc/mono-sgen-msvc.bat index 5458a8fe7a1..62693322c76 100755 --- a/msvc/mono-sgen-msvc.bat +++ b/msvc/mono-sgen-msvc.bat @@ -1,97 +1,97 @@ -:: Set up VS MSVC environment when running MSVC build mono-sgen.exe with all supplied arguments.
-:: Simplify the setup of VS and MSVC toolchain, when running Mono AOT compiler
-:: since it need to locate correct compiler and OS libraries as well as clang.exe and link.exe
-:: from VS setup for the corresponding architecture.
-
-@echo off
-setlocal
-
-set EXECUTE_RESULT=1
-
-:: Get path for current running script.
-set RUN_MONO_SGEN_MSVC_SCRIPT_PATH=%~dp0
-
-:: Optimization, check if we need to setup full build environment, only needed when running mono-sgen.exe as AOT compiler.
-if "%MONO_AS_AOT_COMPILER%" == "1" (
- goto SETUP_VS_ENV
-)
-
-set MONO_AS_AOT_COMPILER=0
-:: Look for --aot or --aot=, --aot-path alone should not trigger setup of VS env.
-echo.%* | findstr /r /c:".*--aot[^-a-zA-Z0-9].*" > nul && (
- set MONO_AS_AOT_COMPILER=1
-)
-
-if %MONO_AS_AOT_COMPILER% == 1 (
- goto SETUP_VS_ENV
-)
-
-:: mono-sgen.exe not invoked as a AOT compiler, no need to setup full build environment.
-goto ON_EXECUTE
-
-:: Try setting up VS MSVC build environment.
-:SETUP_VS_ENV
-
-:: Optimization, check if we have something that looks like a VS MSVC build environment
-:: already available.
-if /i not "%VCINSTALLDIR%" == "" (
- if /i not "%INCLUDE%" == "" (
- if /i not "%LIB%" == "" (
- goto ON_EXECUTE
- )
- )
-)
-
-:: Setup Windows environment.
-call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-windows-env.bat
-
-if "%MONO_VS_MSVCBUILD_ENV_FILE%" == "" (
- set MONO_VS_MSVCBUILD_ENV_FILE=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe.env
-)
-
-:: Check import of VS MSVC build environment using a file instead of running all commands.
-:: NOTE, this is an optimization since setting up a development command
-:: prompt could take some time.
-if /i "%MONO_IMPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (
- if exist "%MONO_VS_MSVCBUILD_ENV_FILE%" (
- for /f "delims=" %%a in (%MONO_VS_MSVCBUILD_ENV_FILE%) do SET %%a
- )
-)
-
-if not "%MONO_MSVC_PATH%" == "" (
- set "PATH=%MONO_MSVC_PATH%;%PATH%"
- goto ON_EXECUTE
-)
-
-:: Setup VS MSVC build environment.
-set TEMP_PATH=%PATH%
-call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-vs-msvcbuild-env.bat
-call set MONO_MSVC_PATH=%%PATH:%TEMP_PATH%=%%
-
-:: Check if msvc env should be exported into file for later import.
-for /f %%a in ('uuidgen.exe') do set NEW_UUID=%%a
-if /i "%MONO_EXPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (
- SET VCINSTALLDIR >> "%TEMP%\%NEW_UUID%.env"
- SET INCLUDE >> "%TEMP%\%NEW_UUID%.env"
- SET LIB >> "%TEMP%\%NEW_UUID%.env"
- SET MONO_MSVC_PATH >> "%TEMP%\%NEW_UUID%.env"
- move /Y "%TEMP%\%NEW_UUID%.env" "%MONO_VS_MSVCBUILD_ENV_FILE%" >nul 2>&1
-)
-
-:ON_EXECUTE
-
-:: Add mono.sgen.exe (needed for optional LLVM tooling) to PATH
-set "PATH=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%;%PATH%"
-
-call "%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe" %* && (
- set EXECUTE_RESULT=0
-) || (
- set EXECUTE_RESULT=1
- if not %ERRORLEVEL% == 0 (
- set EXECUTE_RESULT=%ERRORLEVEL%
- )
-)
-
-exit /b %EXECUTE_RESULT%
-
+:: Set up VS MSVC environment when running MSVC build mono-sgen.exe with all supplied arguments. +:: Simplify the setup of VS and MSVC toolchain, when running Mono AOT compiler +:: since it need to locate correct compiler and OS libraries as well as clang.exe and link.exe +:: from VS setup for the corresponding architecture. + +@echo off +setlocal + +set EXECUTE_RESULT=1 + +:: Get path for current running script. +set RUN_MONO_SGEN_MSVC_SCRIPT_PATH=%~dp0 + +:: Optimization, check if we need to setup full build environment, only needed when running mono-sgen.exe as AOT compiler. +if "%MONO_AS_AOT_COMPILER%" == "1" ( + goto SETUP_VS_ENV +) + +set MONO_AS_AOT_COMPILER=0 +:: Look for --aot or --aot=, --aot-path alone should not trigger setup of VS env. +echo.%* | findstr /r /c:".*--aot[^-a-zA-Z0-9].*" > nul && ( + set MONO_AS_AOT_COMPILER=1 +) + +if %MONO_AS_AOT_COMPILER% == 1 ( + goto SETUP_VS_ENV +) + +:: mono-sgen.exe not invoked as a AOT compiler, no need to setup full build environment. +goto ON_EXECUTE + +:: Try setting up VS MSVC build environment. +:SETUP_VS_ENV + +:: Optimization, check if we have something that looks like a VS MSVC build environment +:: already available. +if /i not "%VCINSTALLDIR%" == "" ( + if /i not "%INCLUDE%" == "" ( + if /i not "%LIB%" == "" ( + goto ON_EXECUTE + ) + ) +) + +:: Setup Windows environment. +call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-windows-env.bat + +if "%MONO_VS_MSVCBUILD_ENV_FILE%" == "" ( + set MONO_VS_MSVCBUILD_ENV_FILE=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe.env +) + +:: Check import of VS MSVC build environment using a file instead of running all commands. +:: NOTE, this is an optimization since setting up a development command +:: prompt could take some time. +if /i "%MONO_IMPORT_VS_MSVCBUILD_ENV_FILE%" == "true" ( + if exist "%MONO_VS_MSVCBUILD_ENV_FILE%" ( + for /f "delims=" %%a in (%MONO_VS_MSVCBUILD_ENV_FILE%) do SET %%a + ) +) + +if not "%MONO_MSVC_PATH%" == "" ( + set "PATH=%MONO_MSVC_PATH%;%PATH%" + goto ON_EXECUTE +) + +:: Setup VS MSVC build environment. +set TEMP_PATH=%PATH% +call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-vs-msvcbuild-env.bat +call set MONO_MSVC_PATH=%%PATH:%TEMP_PATH%=%% + +:: Check if msvc env should be exported into file for later import. +for /f %%a in ('uuidgen.exe') do set NEW_UUID=%%a +if /i "%MONO_EXPORT_VS_MSVCBUILD_ENV_FILE%" == "true" ( + SET VCINSTALLDIR >> "%TEMP%\%NEW_UUID%.env" + SET INCLUDE >> "%TEMP%\%NEW_UUID%.env" + SET LIB >> "%TEMP%\%NEW_UUID%.env" + SET MONO_MSVC_PATH >> "%TEMP%\%NEW_UUID%.env" + move /Y "%TEMP%\%NEW_UUID%.env" "%MONO_VS_MSVCBUILD_ENV_FILE%" >nul 2>&1 +) + +:ON_EXECUTE + +:: Add mono.sgen.exe (needed for optional LLVM tooling) to PATH +set "PATH=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%;%PATH%" + +call "%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe" %* && ( + set EXECUTE_RESULT=0 +) || ( + set EXECUTE_RESULT=1 + if not %ERRORLEVEL% == 0 ( + set EXECUTE_RESULT=%ERRORLEVEL% + ) +) + +exit /b %EXECUTE_RESULT% + @echo on
\ No newline at end of file diff --git a/msvc/run-msbuild.bat b/msvc/run-msbuild.bat index ceb8c0662c9..aae07978a31 100755 --- a/msvc/run-msbuild.bat +++ b/msvc/run-msbuild.bat @@ -1,85 +1,85 @@ -:: Set up build environment and run execute msbuild with all supplied arguments.
-
-:: Arguments:
-:: -------------------------------------------------------
-:: %1 Visual Studio target, build|clean, default build
-:: %2 Host CPU architecture, x86_64|i686, default x86_64
-:: %3 Visual Studio configuration, debug|release, default release
-:: %4 Additional arguments passed to msbuild, needs to be quoted if multiple.
-:: %5 Project to build.
-:: -------------------------------------------------------
-
-@echo off
-setlocal
-
-set BUILD_RESULT=1
-
-:: Get path for current running script.
-set RUN_MSBUILD_SCRIPT_PATH=%~dp0
-
-:: Configure all known build arguments.
-set VS_TARGET=build
-if /i "%~1" == "clean" (
- set VS_TARGET="clean"
-)
-shift
-
-set VS_PLATFORM=x64
-if /i "%~1" == "i686" (
- set VS_PLATFORM="Win32"
-)
-if /i "%~1" == "win32" (
- set VS_PLATFORM="Win32"
-)
-shift
-
-set VS_CONFIGURATION=Release
-if /i "%~1" == "debug" (
- set VS_CONFIGURATION="Debug"
-)
-shift
-
-set VS_TARGET_GC=sgen
-if /i "%~1" == "boehm" (
- set VS_TARGET_GC="boehm"
-)
-shift
-
-set VS_ADDITIONAL_ARGUMENTS=
-if not "%~1" == "" (
- set VS_ADDITIONAL_ARGUMENTS=%~1
-)
-shift
-
-set VS_BUILD_PROJ=mono.sln
-if /i not "%~1" == "" (
- set VS_BUILD_PROJ=%~1
-)
-
-if not exist %VS_BUILD_PROJ% (
- set VS_BUILD_PROJ=%RUN_MSBUILD_SCRIPT_PATH%%VS_BUILD_PROJ%
-)
-
-:: Setup Windows environment.
-call %RUN_MSBUILD_SCRIPT_PATH%setup-windows-env.bat
-
-:: Setup VS msbuild environment.
-call %RUN_MSBUILD_SCRIPT_PATH%setup-vs-msbuild-env.bat
-
-if "%VS_ADDITIONAL_ARGUMENTS%" == "" (
- set "VS_ADDITIONAL_ARGUMENTS=/p:PlatformToolset=%VS_DEFAULT_PLATFORM_TOOL_SET%"
-)
-
-set VS_BUILD_ARGS=/p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /p:MONO_TARGET_GC=%VS_TARGET_GC% %VS_ADDITIONAL_ARGUMENTS% /t:%VS_TARGET% /m
-call msbuild.exe %VS_BUILD_ARGS% "%VS_BUILD_PROJ%" && (
- set BUILD_RESULT=0
-) || (
- set BUILD_RESULT=1
- if not %ERRORLEVEL% == 0 (
- set BUILD_RESULT=%ERRORLEVEL%
- )
-)
-
-exit /b %BUILD_RESULT%
-
+:: Set up build environment and run execute msbuild with all supplied arguments. + +:: Arguments: +:: ------------------------------------------------------- +:: %1 Visual Studio target, build|clean, default build +:: %2 Host CPU architecture, x86_64|i686, default x86_64 +:: %3 Visual Studio configuration, debug|release, default release +:: %4 Additional arguments passed to msbuild, needs to be quoted if multiple. +:: %5 Project to build. +:: ------------------------------------------------------- + +@echo off +setlocal + +set BUILD_RESULT=1 + +:: Get path for current running script. +set RUN_MSBUILD_SCRIPT_PATH=%~dp0 + +:: Configure all known build arguments. +set VS_TARGET=build +if /i "%~1" == "clean" ( + set VS_TARGET="clean" +) +shift + +set VS_PLATFORM=x64 +if /i "%~1" == "i686" ( + set VS_PLATFORM="Win32" +) +if /i "%~1" == "win32" ( + set VS_PLATFORM="Win32" +) +shift + +set VS_CONFIGURATION=Release +if /i "%~1" == "debug" ( + set VS_CONFIGURATION="Debug" +) +shift + +set VS_TARGET_GC=sgen +if /i "%~1" == "boehm" ( + set VS_TARGET_GC="boehm" +) +shift + +set VS_ADDITIONAL_ARGUMENTS= +if not "%~1" == "" ( + set VS_ADDITIONAL_ARGUMENTS=%~1 +) +shift + +set VS_BUILD_PROJ=mono.sln +if /i not "%~1" == "" ( + set VS_BUILD_PROJ=%~1 +) + +if not exist %VS_BUILD_PROJ% ( + set VS_BUILD_PROJ=%RUN_MSBUILD_SCRIPT_PATH%%VS_BUILD_PROJ% +) + +:: Setup Windows environment. +call %RUN_MSBUILD_SCRIPT_PATH%setup-windows-env.bat + +:: Setup VS msbuild environment. +call %RUN_MSBUILD_SCRIPT_PATH%setup-vs-msbuild-env.bat + +if "%VS_ADDITIONAL_ARGUMENTS%" == "" ( + set "VS_ADDITIONAL_ARGUMENTS=/p:PlatformToolset=%VS_DEFAULT_PLATFORM_TOOL_SET%" +) + +set VS_BUILD_ARGS=/p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /p:MONO_TARGET_GC=%VS_TARGET_GC% %VS_ADDITIONAL_ARGUMENTS% /t:%VS_TARGET% /m +call msbuild.exe %VS_BUILD_ARGS% "%VS_BUILD_PROJ%" && ( + set BUILD_RESULT=0 +) || ( + set BUILD_RESULT=1 + if not %ERRORLEVEL% == 0 ( + set BUILD_RESULT=%ERRORLEVEL% + ) +) + +exit /b %BUILD_RESULT% + @echo on
\ No newline at end of file diff --git a/msvc/setup-solution.bat b/msvc/setup-solution.bat index 0674972d9ab..3d43d4492c1 100755 --- a/msvc/setup-solution.bat +++ b/msvc/setup-solution.bat @@ -1,20 +1,20 @@ -@echo off
-csc -debug -out:scripts\monowrap.exe scripts\monowrap.cs
-if errorlevel 1 goto error
-csc -nowarn:414 -debug -out:scripts\genproj.exe scripts\genproj.cs
-if errorlevel 1 goto error
-csc -debug -out:scripts\prepare.exe scripts\prepare.cs
-if errorlevel 1 goto error
-cd scripts
-prepare.exe ..\\..\\..\\mcs core
-if errorlevel 1 goto error
-genproj.exe
-if errorlevel 1 goto error
-cd ..
-echo Setup complete, you need at least a mcs\class\lib\basic directory with
-echo mcs.exe mscorlib.dll System.dll System.Xml.dll
-echo to bootstrap
-goto end
-: error
-echo Error: solution is not configured.
+@echo off +csc -debug -out:scripts\monowrap.exe scripts\monowrap.cs +if errorlevel 1 goto error +csc -nowarn:414 -debug -out:scripts\genproj.exe scripts\genproj.cs +if errorlevel 1 goto error +csc -debug -out:scripts\prepare.exe scripts\prepare.cs +if errorlevel 1 goto error +cd scripts +prepare.exe ..\\..\\..\\mcs core +if errorlevel 1 goto error +genproj.exe +if errorlevel 1 goto error +cd .. +echo Setup complete, you need at least a mcs\class\lib\basic directory with +echo mcs.exe mscorlib.dll System.dll System.Xml.dll +echo to bootstrap +goto end +: error +echo Error: solution is not configured. :end
\ No newline at end of file diff --git a/msvc/setup-vs-msbuild-env.bat b/msvc/setup-vs-msbuild-env.bat index e705a2fc50c..ef9ce9c977b 100755 --- a/msvc/setup-vs-msbuild-env.bat +++ b/msvc/setup-vs-msbuild-env.bat @@ -1,144 +1,144 @@ -:: Set up VS msbuild environment depending on installed VS versions.
-:: Script will setup environment variables directly in callers environment.
-
-:: Make sure we can restore current working directory after setting up environment.
-:: Some of the VS scripts can change the current working directory.
-set CALLER_WD=%CD%
-
-:: Get path for current running script.
-set RUN_SETUP_VS_MSBUILD_ENV_SCRIPT_PATH=%~dp0
-
-:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation.
-set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
-
-:: Visual Studio 2015 == 14.0
-if "%VisualStudioVersion%" == "14.0" (
- goto SETUP_VS_2015
-)
-
-:: Visual Studio 2017 == 15.0
-if "%VisualStudioVersion%" == "15.0" (
- goto SETUP_VS_2017
-)
-
-:: Visual Studio 2019 == 16.0
-if "%VisualStudioVersion%" == "16.0" (
- goto SETUP_VS_2019
-)
-
-:SETUP_VS_2019
-
-:SETUP_VS_2019_BUILD_TOOLS
-
-:: Try to locate VS2019 build tools installation.
-set VS_2019_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsMSBuildCmd.bat
-
-:: Setup VS2019 VC development environment using build tools installation.
-call :setup_build_env "%VS_2019_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v142
- goto ON_EXIT
-)
-
-:SETUP_VS_2019_VC
-
-set VS_2019_DEV_CMD=
-
-:: Try to locate installed VS2019 VC environment.
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- set VS_2019_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat
- )
-)
-
-:: Setup VS2019 VC development environment using VS installation.
-call :setup_build_env "%VS_2019_DEV_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v142
- goto ON_EXIT
-)
-
-:SETUP_VS_2017
-
-:SETUP_VS_2017_BUILD_TOOLS
-
-:: Try to locate VS2017 build tools installation.
-set VS_2017_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat
-
-:: Setup VS2017 VC development environment using build tools installation.
-call :setup_build_env "%VS_2017_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v141
- goto ON_EXIT
-)
-
-:SETUP_VS_2017_VC
-
-set VS_2017_DEV_CMD=
-
-:: Try to locate installed VS2017 VC environment.
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do (
- set VS_2017_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat
- )
-)
-
-:: Setup VS2017 VC development environment using VS installation.
-call :setup_build_env "%VS_2017_DEV_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v141
- goto ON_EXIT
-)
-
-:SETUP_VS_2015
-
-:SETUP_VS_2015_BUILD_TOOLS
-
-:: Try to locate VS2015 build tools installation.
-set VS_2015_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual C++ Build Tools\vcbuildtools_msbuild.bat
-
-:: Setup VS2015 VC development environment using build tools installation.
-call :setup_build_env "%VS_2015_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v140
- goto ON_EXIT
-)
-
-:SETUP_VS_2015_VC
-
-:: Try to locate installed VS2015 VC environment.
-set VS_2015_DEV_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat
-
-:: Setup VS2015 VC development environment using VS installation.
-call :setup_build_env "%VS_2015_DEV_CMD%" "%CALLER_WD%" && (
- set VS_DEFAULT_PLATFORM_TOOL_SET=v140
- goto ON_EXIT
-)
-
-:ON_ENV_ERROR
-
-echo Warning, failed to setup VS build environment needed by VS tooling.
-echo Incomplete build environment can cause build error's due to missing compiler,
-echo linker and platform libraries.
-
-exit /b 1
-
-:ON_EXIT
-
-exit /b 0
-
-:setup_build_env
-
-:: Check if VS build environment script exists.
-if not exist "%~1" (
- goto setup_build_env_error
-)
-
-:: Run VS build environment script.
-call "%~1" > NUL
-
-:: Restore callers working directory in case it has been changed by VS scripts.
-cd /d "%~2"
-
-goto setup_build_env_exit
-
-:setup_build_env_error
-exit /b 1
-
-:setup_build_env_exit
+:: Set up VS msbuild environment depending on installed VS versions. +:: Script will setup environment variables directly in callers environment. + +:: Make sure we can restore current working directory after setting up environment. +:: Some of the VS scripts can change the current working directory. +set CALLER_WD=%CD% + +:: Get path for current running script. +set RUN_SETUP_VS_MSBUILD_ENV_SCRIPT_PATH=%~dp0 + +:: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation. +set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe + +:: Visual Studio 2015 == 14.0 +if "%VisualStudioVersion%" == "14.0" ( + goto SETUP_VS_2015 +) + +:: Visual Studio 2017 == 15.0 +if "%VisualStudioVersion%" == "15.0" ( + goto SETUP_VS_2017 +) + +:: Visual Studio 2019 == 16.0 +if "%VisualStudioVersion%" == "16.0" ( + goto SETUP_VS_2019 +) + +:SETUP_VS_2019 + +:SETUP_VS_2019_BUILD_TOOLS + +:: Try to locate VS2019 build tools installation. +set VS_2019_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsMSBuildCmd.bat + +:: Setup VS2019 VC development environment using build tools installation. +call :setup_build_env "%VS_2019_BUILD_TOOLS_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v142 + goto ON_EXIT +) + +:SETUP_VS_2019_VC + +set VS_2019_DEV_CMD= + +:: Try to locate installed VS2019 VC environment. +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + set VS_2019_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat + ) +) + +:: Setup VS2019 VC development environment using VS installation. +call :setup_build_env "%VS_2019_DEV_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v142 + goto ON_EXIT +) + +:SETUP_VS_2017 + +:SETUP_VS_2017_BUILD_TOOLS + +:: Try to locate VS2017 build tools installation. +set VS_2017_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat + +:: Setup VS2017 VC development environment using build tools installation. +call :setup_build_env "%VS_2017_BUILD_TOOLS_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v141 + goto ON_EXIT +) + +:SETUP_VS_2017_VC + +set VS_2017_DEV_CMD= + +:: Try to locate installed VS2017 VC environment. +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do ( + set VS_2017_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat + ) +) + +:: Setup VS2017 VC development environment using VS installation. +call :setup_build_env "%VS_2017_DEV_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v141 + goto ON_EXIT +) + +:SETUP_VS_2015 + +:SETUP_VS_2015_BUILD_TOOLS + +:: Try to locate VS2015 build tools installation. +set VS_2015_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual C++ Build Tools\vcbuildtools_msbuild.bat + +:: Setup VS2015 VC development environment using build tools installation. +call :setup_build_env "%VS_2015_BUILD_TOOLS_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v140 + goto ON_EXIT +) + +:SETUP_VS_2015_VC + +:: Try to locate installed VS2015 VC environment. +set VS_2015_DEV_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat + +:: Setup VS2015 VC development environment using VS installation. +call :setup_build_env "%VS_2015_DEV_CMD%" "%CALLER_WD%" && ( + set VS_DEFAULT_PLATFORM_TOOL_SET=v140 + goto ON_EXIT +) + +:ON_ENV_ERROR + +echo Warning, failed to setup VS build environment needed by VS tooling. +echo Incomplete build environment can cause build error's due to missing compiler, +echo linker and platform libraries. + +exit /b 1 + +:ON_EXIT + +exit /b 0 + +:setup_build_env + +:: Check if VS build environment script exists. +if not exist "%~1" ( + goto setup_build_env_error +) + +:: Run VS build environment script. +call "%~1" > NUL + +:: Restore callers working directory in case it has been changed by VS scripts. +cd /d "%~2" + +goto setup_build_env_exit + +:setup_build_env_error +exit /b 1 + +:setup_build_env_exit goto :EOF
\ No newline at end of file diff --git a/msvc/setup-vs-msvcbuild-env.bat b/msvc/setup-vs-msvcbuild-env.bat index 64383200efc..5371fb02682 100755 --- a/msvc/setup-vs-msvcbuild-env.bat +++ b/msvc/setup-vs-msvcbuild-env.bat @@ -1,210 +1,210 @@ -:: Set up VS MSVC environment depending on installed VS versions.
-:: Script will setup environment variables directly in callers environment.
-
-:: Make sure we can restore current working directory after setting up environment.
-:: Some of the VS scripts can change the current working directory.
-set CALLER_WD=%CD%
-
-:: Get path for current running script.
-set RUN_SETUP_VS_MSVCBUILD_ENV_SCRIPT_PATH=%~dp0
-
-:: NOTE, MSVC build Mono full AOT tooling currently support 64-bit AMD codegen. Below will only setup
-:: amd64 versions of VS MSVC build environment and corresponding Clang compiler.
-set VS_2015_TOOLCHAIN_ARCH=amd64
-set VS_2015_VCVARS_ARCH=%VS_2015_TOOLCHAIN_ARCH%\vcvars64.bat
-set VS_2015_CLANG_ARCH=%VS_2015_TOOLCHAIN_ARCH%
-set VS_2017_VCVARS_ARCH=vcvars64.bat
-set VS_2017_CLANG_ARCH=HostX64
-set VS_2019_VCVARS_ARCH=%VS_2017_VCVARS_ARCH%
-
-:: 32-bit AOT toolchains for MSVC build mono-sgen.exe is currently not supported.
-:: set VS_2015_TOOLCHAIN_ARCH=x86
-:: set VS_2015_VCVARS_ARCH=vcvars32.bat
-:: set VS_2015_CLANG_ARCH=%VS_2015_TOOLCHAIN_ARCH%
-:: set VS_2017_VCVARS_ARCH=vcvars32.bat
-:: set VS_2017_CLANG_ARCH=HostX86
-:: set VS_2019_VCVARS_ARCH=%VS_2017_VCVARS_ARCH%
-
-set VS_CLANG_TOOLS_BIN_PATH=
-
-:: VS2019/VS2017 includes vswhere.exe that can be used to locate current VS installation.
-set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
-
-:: Visual Studio 2015 == 14.0
-if "%VisualStudioVersion%" == "14.0" (
- goto SETUP_VS_2015
-)
-
-:: Visual Studio 2017 == 15.0
-if "%VisualStudioVersion%" == "15.0" (
- goto SETUP_VS_2017
-)
-
-:: Visual Studio 2019 == 16.0
-if "%VisualStudioVersion%" == "16.0" (
- goto SETUP_VS_2019
-)
-
-:SETUP_VS_2019
-
-set VS_2019_VCINSTALL_DIR=
-
-:: Try to locate installed VS2019 VC environment.
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do (
- set VS_2019_VCINSTALL_DIR=%%a\VC\
- )
-)
-
-:: Try to locate installed VS2019 Clang.
-set VS_2019_CLANG_TOOLS_BIN_PATH=%VS_2019_VCINSTALL_DIR%Tools\llvm\bin\
-set VS_2019_CLANG_TOOLS_BIN=%VS_2019_CLANG_TOOLS_BIN_PATH%clang.exe
-if not exist "%VS_2019_CLANG_TOOLS_BIN%" (
- goto SETUP_VS_2017
-)
-
-:SETUP_VS_2019_BUILD_TOOLS
-
-:: Try to locate VS2019 build tools installation.
-set VS_2019_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\
-set VS_2019_BUILD_TOOLS_CMD=%VS_2019_BUILD_TOOLS_INSTALL_DIR%VC\Auxiliary\Build\%VS_2019_VCVARS_ARCH%
-
-:: Setup VS2019 VC development environment using build tools installation.
-call :setup_build_env "%VS_2019_BUILD_TOOLS_CMD%" "" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2019_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v142
- goto ON_EXIT
-)
-
-:SETUP_VS_2019_VC
-
-:: Try to locate installed VS2019 VC environment.
-set VS_2019_DEV_CMD=%VS_2019_VCINSTALL_DIR%Auxiliary\Build\%VS_2019_VCVARS_ARCH%
-
-:: Setup VS2019 VC development environment using VS installation.
-call :setup_build_env "%VS_2019_DEV_CMD%" "" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v142
- goto ON_EXIT
-)
-
-:SETUP_VS_2017
-
-set VS_2017_VCINSTALL_DIR=
-
-:: Try to locate installed VS2017 VC environment.
-if exist "%VSWHERE_TOOLS_BIN%" (
- for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do (
- set VS_2017_VCINSTALL_DIR=%%a\VC\
- )
-)
-
-:: Try to locate installed VS2017 Clang.
-SET VS_2017_CLANG_VERSION_FILE=%VS_2017_VCINSTALL_DIR%Auxiliary/Build/Microsoft.ClangC2Version.default.txt
-if not exist "%VS_2017_CLANG_VERSION_FILE%" (
- goto SETUP_VS_2015
-)
-
-set /p VS_2017_CLANG_VERSION=<"%VS_2017_CLANG_VERSION_FILE%"
-set VS_2017_CLANG_TOOLS_BIN_PATH=%VS_2017_VCINSTALL_DIR%Tools\ClangC2\%VS_2017_CLANG_VERSION%\bin\%VS_2017_CLANG_ARCH%\
-set VS_2017_CLANG_TOOLS_BIN=%VS_2017_CLANG_TOOLS_BIN_PATH%clang.exe
-if not exist "%VS_2017_CLANG_TOOLS_BIN%" (
- goto SETUP_VS_2015
-)
-
-:SETUP_VS_2017_BUILD_TOOLS
-
-:: Try to locate VS2017 build tools installation.
-set VS_2017_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\
-set VS_2017_BUILD_TOOLS_CMD=%VS_2017_BUILD_TOOLS_INSTALL_DIR%VC\Auxiliary\Build\%VS_2017_VCVARS_ARCH%
-
-:: Setup VS2017 VC development environment using build tools installation.
-call :setup_build_env "%VS_2017_BUILD_TOOLS_CMD%" "" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v141
- goto ON_EXIT
-)
-
-:SETUP_VS_2017_VC
-
-:: Try to locate installed VS2017 VC environment.
-set VS_2017_DEV_CMD=%VS_2017_VCINSTALL_DIR%Auxiliary\Build\%VS_2017_VCVARS_ARCH%
-
-:: Setup VS2017 VC development environment using VS installation.
-call :setup_build_env "%VS_2017_DEV_CMD%" "" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v141
- goto ON_EXIT
-)
-
-:SETUP_VS_2015
-
-set VS_2015_VCINSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\
-
-:: Try to locate installed VS2015 Clang.
-SET VS_2015_CLANG_TOOLS_BIN_PATH=%VS_2015_VCINSTALL_DIR%ClangC2\bin\%VS_2015_CLANG_ARCH%\
-SET VS_2015_CLANG_TOOLS_BIN=%VS_2015_CLANG_TOOLS_BIN_PATH%clang.exe
-
-if not exist "%VS_2015_CLANG_TOOLS_BIN%" (
- goto ON_ENV_ERROR
-)
-
-:SETUP_VS_2015_BUILD_TOOLS
-
-:: Try to locate VS2015 build tools installation.
-set VS_2015_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual C++ Build Tools\
-set VS_2015_BUILD_TOOLS_CMD=%VS_2015_BUILD_TOOLS_INSTALL_DIR%vcbuildtools.bat
-
-:: Setup VS2015 VC development environment using build tools installation.
-call :setup_build_env "%VS_2015_BUILD_TOOLS_CMD%" "%VS_2015_TOOLCHAIN_ARCH%" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2015_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v140
- goto ON_EXIT
-)
-
-:SETUP_VS_2015_VC
-
-:: Try to locate installed VS2015 VC environment.
-set VS_2015_DEV_CMD=%VS_2015_VCINSTALL_DIR%bin\%VS_2015_VCVARS_ARCH%
-
-call :setup_build_env "%VS_2015_DEV_CMD%" "" "%CALLER_WD%" && (
- set "VS_CLANG_TOOLS_BIN_PATH=%VS_2015_CLANG_TOOLS_BIN_PATH%"
- set VS_DEFAULT_PLATFORM_TOOL_SET=v140
- goto ON_EXIT
-)
-
-:ON_ENV_ERROR
-
-echo Warning, failed to setup VS build environment needed by VS tooling.
-echo Incomplete build environment can cause build error's due to missing compiler,
-echo linker and platform libraries.
-
-exit /b 1
-
-:ON_EXIT
-
-:: Add Clang folders to PATH
-set "PATH=%VS_CLANG_TOOLS_BIN_PATH%;%PATH%"
-
-exit /b 0
-
-:setup_build_env
-
-:: Check if VS build environment script exists.
-if not exist "%~1" (
- goto setup_build_env_error
-)
-
-:: Run VS build environment script.
-call "%~1" %~2 > NUL
-
-:: Restore callers working directory in case it has been changed by VS scripts.
-cd /d "%~3"
-
-goto setup_build_env_exit
-
-:setup_build_env_error
-exit /b 1
-
-:setup_build_env_exit
+:: Set up VS MSVC environment depending on installed VS versions. +:: Script will setup environment variables directly in callers environment. + +:: Make sure we can restore current working directory after setting up environment. +:: Some of the VS scripts can change the current working directory. +set CALLER_WD=%CD% + +:: Get path for current running script. +set RUN_SETUP_VS_MSVCBUILD_ENV_SCRIPT_PATH=%~dp0 + +:: NOTE, MSVC build Mono full AOT tooling currently support 64-bit AMD codegen. Below will only setup +:: amd64 versions of VS MSVC build environment and corresponding Clang compiler. +set VS_2015_TOOLCHAIN_ARCH=amd64 +set VS_2015_VCVARS_ARCH=%VS_2015_TOOLCHAIN_ARCH%\vcvars64.bat +set VS_2015_CLANG_ARCH=%VS_2015_TOOLCHAIN_ARCH% +set VS_2017_VCVARS_ARCH=vcvars64.bat +set VS_2017_CLANG_ARCH=HostX64 +set VS_2019_VCVARS_ARCH=%VS_2017_VCVARS_ARCH% + +:: 32-bit AOT toolchains for MSVC build mono-sgen.exe is currently not supported. +:: set VS_2015_TOOLCHAIN_ARCH=x86 +:: set VS_2015_VCVARS_ARCH=vcvars32.bat +:: set VS_2015_CLANG_ARCH=%VS_2015_TOOLCHAIN_ARCH% +:: set VS_2017_VCVARS_ARCH=vcvars32.bat +:: set VS_2017_CLANG_ARCH=HostX86 +:: set VS_2019_VCVARS_ARCH=%VS_2017_VCVARS_ARCH% + +set VS_CLANG_TOOLS_BIN_PATH= + +:: VS2019/VS2017 includes vswhere.exe that can be used to locate current VS installation. +set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe + +:: Visual Studio 2015 == 14.0 +if "%VisualStudioVersion%" == "14.0" ( + goto SETUP_VS_2015 +) + +:: Visual Studio 2017 == 15.0 +if "%VisualStudioVersion%" == "15.0" ( + goto SETUP_VS_2017 +) + +:: Visual Studio 2019 == 16.0 +if "%VisualStudioVersion%" == "16.0" ( + goto SETUP_VS_2019 +) + +:SETUP_VS_2019 + +set VS_2019_VCINSTALL_DIR= + +:: Try to locate installed VS2019 VC environment. +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -property installationPath') do ( + set VS_2019_VCINSTALL_DIR=%%a\VC\ + ) +) + +:: Try to locate installed VS2019 Clang. +set VS_2019_CLANG_TOOLS_BIN_PATH=%VS_2019_VCINSTALL_DIR%Tools\llvm\bin\ +set VS_2019_CLANG_TOOLS_BIN=%VS_2019_CLANG_TOOLS_BIN_PATH%clang.exe +if not exist "%VS_2019_CLANG_TOOLS_BIN%" ( + goto SETUP_VS_2017 +) + +:SETUP_VS_2019_BUILD_TOOLS + +:: Try to locate VS2019 build tools installation. +set VS_2019_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\ +set VS_2019_BUILD_TOOLS_CMD=%VS_2019_BUILD_TOOLS_INSTALL_DIR%VC\Auxiliary\Build\%VS_2019_VCVARS_ARCH% + +:: Setup VS2019 VC development environment using build tools installation. +call :setup_build_env "%VS_2019_BUILD_TOOLS_CMD%" "" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2019_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v142 + goto ON_EXIT +) + +:SETUP_VS_2019_VC + +:: Try to locate installed VS2019 VC environment. +set VS_2019_DEV_CMD=%VS_2019_VCINSTALL_DIR%Auxiliary\Build\%VS_2019_VCVARS_ARCH% + +:: Setup VS2019 VC development environment using VS installation. +call :setup_build_env "%VS_2019_DEV_CMD%" "" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v142 + goto ON_EXIT +) + +:SETUP_VS_2017 + +set VS_2017_VCINSTALL_DIR= + +:: Try to locate installed VS2017 VC environment. +if exist "%VSWHERE_TOOLS_BIN%" ( + for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do ( + set VS_2017_VCINSTALL_DIR=%%a\VC\ + ) +) + +:: Try to locate installed VS2017 Clang. +SET VS_2017_CLANG_VERSION_FILE=%VS_2017_VCINSTALL_DIR%Auxiliary/Build/Microsoft.ClangC2Version.default.txt +if not exist "%VS_2017_CLANG_VERSION_FILE%" ( + goto SETUP_VS_2015 +) + +set /p VS_2017_CLANG_VERSION=<"%VS_2017_CLANG_VERSION_FILE%" +set VS_2017_CLANG_TOOLS_BIN_PATH=%VS_2017_VCINSTALL_DIR%Tools\ClangC2\%VS_2017_CLANG_VERSION%\bin\%VS_2017_CLANG_ARCH%\ +set VS_2017_CLANG_TOOLS_BIN=%VS_2017_CLANG_TOOLS_BIN_PATH%clang.exe +if not exist "%VS_2017_CLANG_TOOLS_BIN%" ( + goto SETUP_VS_2015 +) + +:SETUP_VS_2017_BUILD_TOOLS + +:: Try to locate VS2017 build tools installation. +set VS_2017_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\ +set VS_2017_BUILD_TOOLS_CMD=%VS_2017_BUILD_TOOLS_INSTALL_DIR%VC\Auxiliary\Build\%VS_2017_VCVARS_ARCH% + +:: Setup VS2017 VC development environment using build tools installation. +call :setup_build_env "%VS_2017_BUILD_TOOLS_CMD%" "" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v141 + goto ON_EXIT +) + +:SETUP_VS_2017_VC + +:: Try to locate installed VS2017 VC environment. +set VS_2017_DEV_CMD=%VS_2017_VCINSTALL_DIR%Auxiliary\Build\%VS_2017_VCVARS_ARCH% + +:: Setup VS2017 VC development environment using VS installation. +call :setup_build_env "%VS_2017_DEV_CMD%" "" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2017_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v141 + goto ON_EXIT +) + +:SETUP_VS_2015 + +set VS_2015_VCINSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\ + +:: Try to locate installed VS2015 Clang. +SET VS_2015_CLANG_TOOLS_BIN_PATH=%VS_2015_VCINSTALL_DIR%ClangC2\bin\%VS_2015_CLANG_ARCH%\ +SET VS_2015_CLANG_TOOLS_BIN=%VS_2015_CLANG_TOOLS_BIN_PATH%clang.exe + +if not exist "%VS_2015_CLANG_TOOLS_BIN%" ( + goto ON_ENV_ERROR +) + +:SETUP_VS_2015_BUILD_TOOLS + +:: Try to locate VS2015 build tools installation. +set VS_2015_BUILD_TOOLS_INSTALL_DIR=%ProgramFiles(x86)%\Microsoft Visual C++ Build Tools\ +set VS_2015_BUILD_TOOLS_CMD=%VS_2015_BUILD_TOOLS_INSTALL_DIR%vcbuildtools.bat + +:: Setup VS2015 VC development environment using build tools installation. +call :setup_build_env "%VS_2015_BUILD_TOOLS_CMD%" "%VS_2015_TOOLCHAIN_ARCH%" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2015_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v140 + goto ON_EXIT +) + +:SETUP_VS_2015_VC + +:: Try to locate installed VS2015 VC environment. +set VS_2015_DEV_CMD=%VS_2015_VCINSTALL_DIR%bin\%VS_2015_VCVARS_ARCH% + +call :setup_build_env "%VS_2015_DEV_CMD%" "" "%CALLER_WD%" && ( + set "VS_CLANG_TOOLS_BIN_PATH=%VS_2015_CLANG_TOOLS_BIN_PATH%" + set VS_DEFAULT_PLATFORM_TOOL_SET=v140 + goto ON_EXIT +) + +:ON_ENV_ERROR + +echo Warning, failed to setup VS build environment needed by VS tooling. +echo Incomplete build environment can cause build error's due to missing compiler, +echo linker and platform libraries. + +exit /b 1 + +:ON_EXIT + +:: Add Clang folders to PATH +set "PATH=%VS_CLANG_TOOLS_BIN_PATH%;%PATH%" + +exit /b 0 + +:setup_build_env + +:: Check if VS build environment script exists. +if not exist "%~1" ( + goto setup_build_env_error +) + +:: Run VS build environment script. +call "%~1" %~2 > NUL + +:: Restore callers working directory in case it has been changed by VS scripts. +cd /d "%~3" + +goto setup_build_env_exit + +:setup_build_env_error +exit /b 1 + +:setup_build_env_exit goto :EOF
\ No newline at end of file diff --git a/msvc/setup-windows-env.bat b/msvc/setup-windows-env.bat index 7b47754e0b1..80b5b7d8dba 100755 --- a/msvc/setup-windows-env.bat +++ b/msvc/setup-windows-env.bat @@ -1,64 +1,64 @@ -:: Script will setup environment variables directly in callers environment.
-
-:: If we are running from none Windows shell we will need to restore a clean PATH
-:: before setting up VS MSVC build environment. If not there is a risk we will pick up
-:: for example cygwin binaries when running toolchain commands not explicitly setup by
-:: VS MSVC build environment.
-set HKCU_ENV_PATH=
-set HKLM_ENV_PATH=
-if "%SHELL%" == "/bin/bash" (
- for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKCU\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (
- SET HKCU_ENV_PATH=%%b
- )
- for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (
- SET HKLM_ENV_PATH=%%b
- )
-)
-
-:: Restore default path, if we are running from none Windows shell.
-if "%SHELL%" == "/bin/bash" (
- call :restore_default_path "%HKCU_ENV_PATH%" "%HKLM_ENV_PATH%"
-)
-
-:: There is still a scenario where the default path can include cygwin\bin folder. If that's the case
-:: there is still a big risk that build tools will be incorrectly resolved towards cygwin bin folder.
-:: Make sure to adjust path and drop all cygwin paths.
-set NEW_PATH=
-call where /Q "cygpath.exe" && (
- echo Warning, PATH includes cygwin bin folders. This can cause build errors due to incorrectly
- echo located build tools. Build script will drop all cygwin folders from used PATH.
- for %%a in ("%PATH:;=";"%") do (
- if not exist "%%~a\cygpath.exe" (
- call :add_to_new_path "%%~a"
- )
- )
-)
-
-if not "%NEW_PATH%" == "" (
- set "PATH=%NEW_PATH%"
-)
-
-exit /b 0
-
-:restore_default_path
-
-:: Restore default PATH.
-if not "%~2" == "" (
- if not "%~1" == "" (
- set "PATH=%~2;%~1"
- ) else (
- set "PATH=%~2"
- )
-)
-
-goto :EOF
-
-:add_to_new_path
-
-if "%NEW_PATH%" == "" (
- set "NEW_PATH=%~1"
-) else (
- SET "NEW_PATH=%NEW_PATH%;%~1"
-)
-
+:: Script will setup environment variables directly in callers environment. + +:: If we are running from none Windows shell we will need to restore a clean PATH +:: before setting up VS MSVC build environment. If not there is a risk we will pick up +:: for example cygwin binaries when running toolchain commands not explicitly setup by +:: VS MSVC build environment. +set HKCU_ENV_PATH= +set HKLM_ENV_PATH= +if "%SHELL%" == "/bin/bash" ( + for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKCU\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do ( + SET HKCU_ENV_PATH=%%b + ) + for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do ( + SET HKLM_ENV_PATH=%%b + ) +) + +:: Restore default path, if we are running from none Windows shell. +if "%SHELL%" == "/bin/bash" ( + call :restore_default_path "%HKCU_ENV_PATH%" "%HKLM_ENV_PATH%" +) + +:: There is still a scenario where the default path can include cygwin\bin folder. If that's the case +:: there is still a big risk that build tools will be incorrectly resolved towards cygwin bin folder. +:: Make sure to adjust path and drop all cygwin paths. +set NEW_PATH= +call where /Q "cygpath.exe" && ( + echo Warning, PATH includes cygwin bin folders. This can cause build errors due to incorrectly + echo located build tools. Build script will drop all cygwin folders from used PATH. + for %%a in ("%PATH:;=";"%") do ( + if not exist "%%~a\cygpath.exe" ( + call :add_to_new_path "%%~a" + ) + ) +) + +if not "%NEW_PATH%" == "" ( + set "PATH=%NEW_PATH%" +) + +exit /b 0 + +:restore_default_path + +:: Restore default PATH. +if not "%~2" == "" ( + if not "%~1" == "" ( + set "PATH=%~2;%~1" + ) else ( + set "PATH=%~2" + ) +) + +goto :EOF + +:add_to_new_path + +if "%NEW_PATH%" == "" ( + set "NEW_PATH=%~1" +) else ( + SET "NEW_PATH=%NEW_PATH%;%~1" +) + goto :EOF
\ No newline at end of file |