1 :: Set up VS MSVC environment when running MSVC build mono-sgen.exe with all supplied arguments.
2 :: Simplify the setup of VS and MSVC toolchain, when running Mono AOT compiler
3 :: since it need to locate correct compiler and OS libraries as well as clang.exe and link.exe
4 :: from VS setup for the corresponding architecture.
11 :: Get path for current running script.
12 set RUN_MONO_SGEN_MSVC_SCRIPT_PATH=%~dp0
14 :: Optimization, check if we need to setup full build environment, only needed when running mono-sgen.exe as AOT compiler.
15 if "%MONO_AS_AOT_COMPILER%" == "1" (
19 set MONO_AS_AOT_COMPILER=0
20 :: Look for --aot or --aot=, --aot-path alone should not trigger setup of VS env.
21 echo.%* | findstr /r /c:".*--aot[^-a-zA-Z0-9].*" > nul && (
22 set MONO_AS_AOT_COMPILER=1
25 if %MONO_AS_AOT_COMPILER% == 1 (
29 :: mono-sgen.exe not invoked as a AOT compiler, no need to setup full build environment.
32 :: Try setting up VS MSVC build environment.
35 :: Optimization, check if we have something that looks like a VS MSVC build environment
37 if /i not "%VCINSTALLDIR%" == "" (
38 if /i not "%INCLUDE%" == "" (
39 if /i not "%LIB%" == "" (
45 :: Setup Windows environment.
46 call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-windows-env.bat
48 if "%MONO_VS_MSVCBUILD_ENV_FILE%" == "" (
49 set MONO_VS_MSVCBUILD_ENV_FILE=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe.env
52 :: Check import of VS MSVC build environment using a file instead of running all commands.
53 :: NOTE, this is an optimization since setting up a development command
54 :: prompt could take some time.
55 if /i "%MONO_IMPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (
56 if exist "%MONO_VS_MSVCBUILD_ENV_FILE%" (
57 for /f "delims=" %%a in (%MONO_VS_MSVCBUILD_ENV_FILE%) do SET %%a
61 if not "%MONO_MSVC_PATH%" == "" (
62 set "PATH=%MONO_MSVC_PATH%;%PATH%"
66 :: Setup VS MSVC build environment.
68 call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-vs-msvcbuild-env.bat
69 call set MONO_MSVC_PATH=%%PATH:%TEMP_PATH%=%%
71 :: Check if msvc env should be exported into file for later import.
72 for /f %%a in ('uuidgen.exe') do set NEW_UUID=%%a
73 if /i "%MONO_EXPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (
74 SET VCINSTALLDIR >> "%TEMP%\%NEW_UUID%.env"
75 SET INCLUDE >> "%TEMP%\%NEW_UUID%.env"
76 SET LIB >> "%TEMP%\%NEW_UUID%.env"
77 SET MONO_MSVC_PATH >> "%TEMP%\%NEW_UUID%.env"
78 move /Y "%TEMP%\%NEW_UUID%.env" "%MONO_VS_MSVCBUILD_ENV_FILE%" >nul 2>&1
83 :: Add mono.sgen.exe (needed for optional LLVM tooling) to PATH
84 set "PATH=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%;%PATH%"
86 call "%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe" %* && (
90 if not %ERRORLEVEL% == 0 (
91 set EXECUTE_RESULT=%ERRORLEVEL%
95 exit /b %EXECUTE_RESULT%