-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cmd
More file actions
213 lines (173 loc) · 6.22 KB
/
build.cmd
File metadata and controls
213 lines (173 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
@echo off
setlocal enabledelayedexpansion
set root_dir=%~dp0
set tools_dir=%~dp0.cache\tools\
set cppfront=%tools_dir%\cppfront.exe
set cppfront_include_dir=%~dp0.cache\repos\cppfront\include
set cpp2b_dist=%~dp0dist\debug\cpp2b
set modules_dir=%~dp0.cache\modules
if not exist .cache\cpp2 ( mkdir .cache\cpp2 )
if not exist .cache\cpp2\source ( mkdir .cache\cpp2\source )
if not exist .cache\repos ( mkdir .cache\repos )
if not exist %modules_dir% ( mkdir %modules_dir% )
if not exist .cache\tools ( mkdir .cache\tools )
if not exist dist ( mkdir dist )
if not exist dist\debug ( mkdir dist\debug )
set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
for /f "usebackq tokens=*" %%i in (`%vswhere% -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set vs_install_dir=%%i
)
if exist "%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" (
set /p Version=<"%vs_install_dir%\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
set LatestVCToolsVersion=!Version: =!
)
set "msvc_root=%vs_install_dir%\VC\Tools\MSVC"
set "chosen_minor=0"
set "chosen_patch=0"
:: Iterate over all MSVC versions installed
for /f "delims=" %%v in ('dir /b /ad "%msvc_root%"') do (
call :check_version "%%v"
)
if not defined chosen_version (
echo ERROR: MSVC version less than or equal to 14.43 not found
exit 1
)
echo INFO: using chosen version !chosen_version!
call "%vs_install_dir%\Common7\Tools\vsdevcmd.bat" -arch=x64 -host_arch=x64 -no_logo -vcvars_ver=!chosen_version!
if "%VCToolsInstallDir%"=="" (
echo ERROR: missing VCToolsInstallDir after running vsdevcmd.bat
exit 1
)
echo INFO: using vs tools %VCToolsVersion%
set vs_tools_dir=%VCToolsInstallDir%
if exist .cache\repos\cppfront\ (
@rem TODO - report which cppfront version is being used
) else (
git clone --quiet --branch=v0.8.1 --depth=1 https://github.com/hsutter/cppfront.git .cache/repos/cppfront
)
if not exist "%modules_dir%\std.ifc" (
echo Compiling std module...
pushd %modules_dir%
cl /D"_CRT_SECURE_NO_WARNINGS=1" /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.ixx"
popd
)
if not exist "%modules_dir%\std.compat.ifc" (
echo Compiling std.compat module...
pushd %modules_dir%
cl /std:c++latest /EHsc /nologo /W4 /MDd /c "%vs_tools_dir%\modules\std.compat.ixx"
popd
)
if not exist "%root_dir%.cache\cpp2\source\_build" ( mkdir "%root_dir%.cache\cpp2\source\_build" )
echo INFO: compiling cpp2b module...
if exist "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" (
del "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx" /F
)
setlocal enableextensions disabledelayedexpansion
set "search=@CPP2B_PROJECT_ROOT@"
set "replace=%root_dir%"
set "inputFile=%root_dir%share\cpp2b\cpp2b.cppm.tpl"
set "outputFile=%root_dir%.cache\cpp2\source\_build\cpp2b.ixx"
for /f "delims=" %%i in ('type "%inputFile%"') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%outputFile%" echo(!line:%search%=%replace%!
endlocal
)
endlocal
@REM attrib +r "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx"
pushd %modules_dir%
cl /nologo ^
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c "%root_dir%.cache\cpp2\source\_build\cpp2b.ixx"
popd
if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile cpp2b module
exit %ERRORLEVEL%
)
echo INFO: compiling dylib module...
pushd %modules_dir%
cl /nologo ^
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c /interface /TP "%root_dir%src\dylib.cppm" > NUL
popd
if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile dylib module
exit %ERRORLEVEL%
)
echo INFO: compiling nlohmann.json module...
pushd %modules_dir%
cl /nologo ^
/std:c++latest /W4 /MDd /EHsc ^
/reference "%modules_dir%\std.ifc" ^
/reference "%modules_dir%\std.compat.ifc" ^
/c /interface /TP "%root_dir%src\nlohmann.json.cppm" > NUL
popd
if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile nlohmann.json module
exit %ERRORLEVEL%
)
if not exist %cppfront% (
pushd .cache\repos\cppfront\source
echo INFO: compiling cppfront...
cl /nologo /std:c++latest /EHsc cppfront.cpp
xcopy cppfront.exe %tools_dir% /Y /Q
popd
)
if %ERRORLEVEL% neq 0 (
echo ERROR: failed to compile cppfront
exit %ERRORLEVEL%
)
if not exist "%root_dir%.cache/cpp2/source/src" ( mkdir "%root_dir%.cache/cpp2/source/src" )
%cppfront% src/main.cpp2 -pure -import-std -l -format-colon-errors -o "%root_dir%.cache/cpp2/source/src/main.cpp"
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
cl /nologo "%root_dir%.cache/cpp2/source/src/main.cpp" ^
/diagnostics:column /permissive- ^
/reference "%modules_dir%\std.ifc" "%modules_dir%\std.obj" ^
/reference "%modules_dir%\std.compat.ifc" "%modules_dir%\std.compat.obj" ^
/reference "%modules_dir%\dylib.ifc" "%modules_dir%\dylib.obj" ^
/reference "%modules_dir%\nlohmann.json.ifc" "%modules_dir%\nlohmann.json.obj" ^
/reference "%modules_dir%\cpp2b.ifc" "%modules_dir%\cpp2b.obj" ^
/std:c++latest /W4 /MDd /EHsc ^
/DEBUG:FULL /Zi /FC ^
-I"%cppfront_include_dir%" ^
/Fe"%cpp2b_dist%" ^
/Fd"%cpp2b_dist%.pdb"
if %ERRORLEVEL% neq 0 exit %ERRORLEVEL%
echo %cpp2b_dist%.exe
:: -------------------------------
:: Subroutine: check_version
:: %1 = version string like 14.43.32706
:: -------------------------------
:check_version
set "ver=%~1"
for /f "tokens=1-3 delims=." %%a in ("!ver!") do (
set "major=%%a"
set "minor=%%b"
set "patch=%%c"
)
if "%major%"=="14" (
set /a m=!minor!
set /a p=!patch!
if !m! LEQ 43 (
if not defined chosen_version (
set "chosen_version=!ver!"
set "chosen_minor=!m!"
set "chosen_patch=!p!"
) else (
if !m! GTR !chosen_minor! (
set "chosen_version=!ver!"
set "chosen_minor=!m!"
set "chosen_patch=!p!"
) else if !m! EQU !chosen_minor! if !p! GTR !chosen_patch! (
set "chosen_version=!ver!"
set "chosen_minor=!m!"
set "chosen_patch=!p!"
)
)
)
)
goto :eof