-
Notifications
You must be signed in to change notification settings - Fork 556
/
build.bat
376 lines (323 loc) · 10.3 KB
/
build.bat
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
@echo off
setlocal
if not exist env.bat copy env.bat.template env.bat
if exist env.bat call env.bat
if not defined WEASEL_ROOT set WEASEL_ROOT=%CD%
if not defined VERSION_MAJOR set VERSION_MAJOR=0
if not defined VERSION_MINOR set VERSION_MINOR=16
if not defined VERSION_PATCH set VERSION_PATCH=3
if not defined WEASEL_VERSION set WEASEL_VERSION=%VERSION_MAJOR%.%VERSION_MINOR%.%VERSION_PATCH%
if not defined WEASEL_BUILD set WEASEL_BUILD=0
rem use numeric build version for release build
set PRODUCT_VERSION=%WEASEL_VERSION%.%WEASEL_BUILD%
rem for non-release build, try to use git commit hash as product build version
if not defined RELEASE_BUILD (
rem check if git is installed and available, then get the short commit id of head
git --version >nul 2>&1
if not errorlevel 1 (
for /f "delims=" %%i in ('git tag --sort=-creatordate ^| findstr /r "%WEASEL_VERSION%"') do (
set LAST_TAG=%%i
goto found_tag
)
:found_tag
for /f "delims=" %%i in ('git rev-list %LAST_TAG%..HEAD --count') do (
set WEASEL_BUILD=%%i
)
rem get short commmit id of head
for /F %%i in ('git rev-parse --short HEAD') do (set PRODUCT_VERSION=%WEASEL_VERSION%.%WEASEL_BUILD%.%%i)
)
)
rem FILE_VERSION is always 4 numbers; same as PRODUCT_VERSION in release build
if not defined FILE_VERSION set FILE_VERSION=%WEASEL_VERSION%.%WEASEL_BUILD%
echo PRODUCT_VERSION=%PRODUCT_VERSION%
echo WEASEL_VERSION=%WEASEL_VERSION%
echo WEASEL_BUILD=%WEASEL_BUILD%
echo WEASEL_ROOT=%WEASEL_ROOT%
echo WEASEL_BUNDLED_RECIPES=%WEASEL_BUNDLED_RECIPES%
echo.
if defined GITHUB_ENV (
setlocal enabledelayedexpansion
echo git_ref_name=%PRODUCT_VERSION%>>!GITHUB_ENV!
)
if defined BOOST_ROOT (
if exist "%BOOST_ROOT%\boost" goto boost_found
)
echo Error: Boost not found! Please set BOOST_ROOT in env.bat.
exit /b 1
:boost_found
echo BOOST_ROOT=%BOOST_ROOT%
echo.
if not defined BJAM_TOOLSET (
rem the number actually means platform toolset, not %VisualStudioVersion%
set BJAM_TOOLSET=msvc-14.2
)
if not defined PLATFORM_TOOLSET (
set PLATFORM_TOOLSET=v142
)
if defined DEVTOOLS_PATH set PATH=%DEVTOOLS_PATH%%PATH%
set build_config=Release
set build_option=/t:Build
set build_boost=0
set boost_build_variant=release
set build_data=0
set build_opencc=0
set build_rime=0
set rime_build_variant=release
set build_weasel=0
set build_installer=0
set build_arm64=0
rem parse the command line options
:parse_cmdline_options
if "%1" == "" goto end_parsing_cmdline_options
if "%1" == "debug" (
set build_config=Debug
set boost_build_variant=debug
set rime_build_variant=debug
)
if "%1" == "release" (
set build_config=Release
set boost_build_variant=release
set rime_build_variant=release
)
if "%1" == "rebuild" set build_option=/t:Rebuild
if "%1" == "boost" set build_boost=1
if "%1" == "data" set build_data=1
if "%1" == "opencc" set build_opencc=1
if "%1" == "rime" set build_rime=1
if "%1" == "librime" set build_rime=1
if "%1" == "weasel" set build_weasel=1
if "%1" == "installer" set build_installer=1
if "%1" == "arm64" set build_arm64=1
if "%1" == "all" (
set build_boost=1
set build_data=1
set build_opencc=1
set build_rime=1
set build_weasel=1
set build_installer=1
set build_arm64=1
)
shift
goto parse_cmdline_options
:end_parsing_cmdline_options
if %build_weasel% == 0 (
if %build_boost% == 0 (
if %build_data% == 0 (
if %build_opencc% == 0 (
if %build_rime% == 0 (
set build_weasel=1
)))))
rem quit WeaselServer.exe before building
cd /d %WEASEL_ROOT%
if exist output\weaselserver.exe (
output\weaselserver.exe /q
)
rem build booost
if %build_boost% == 1 (
call :build_boost
if errorlevel 1 exit /b 1
cd /d %WEASEL_ROOT%
)
rem -------------------------------------------------------------------------
rem build librime x64 and Win32
if %build_rime% == 1 (
if not exist librime\build.bat (
git submodule update --init --recursive
)
cd %WEASEL_ROOT%\librime
rem clean cache before building
for %%a in ( build dist lib ^
deps\glog\build ^
deps\googletest\build ^
deps\leveldb\build ^
deps\marisa-trie\build ^
deps\opencc\build ^
deps\yaml-cpp\build ) do (
if exist %%a rd /s /q %%a
)
rem build x64 librime
set ARCH=x64
call :build_librime_platform x64 %WEASEL_ROOT%\lib64 %WEASEL_ROOT%\output
rem build Win32 librime
set ARCH=Win32
call :build_librime_platform Win32 %WEASEL_ROOT%\lib %WEASEL_ROOT%\output\Win32
rem clean the modified file
rem git checkout .
rem git submodule foreach git checkout .
)
rem -------------------------------------------------------------------------
if %build_weasel% == 1 (
if not exist output\data\essay.txt (
set build_data=1
)
if not exist output\data\opencc\TSCharacters.ocd* (
set build_opencc=1
)
)
if %build_data% == 1 call :build_data
if %build_opencc% == 1 call :build_opencc_data
if %build_weasel% == 0 goto end
cd /d %WEASEL_ROOT%
set WEASEL_PROJECT_PROPERTIES=BOOST_ROOT^
PLATFORM_TOOLSET^
VERSION_MAJOR^
VERSION_MINOR^
VERSION_PATCH^
PRODUCT_VERSION^
FILE_VERSION
cscript.exe render.js weasel.props %WEASEL_PROJECT_PROPERTIES%
del msbuild*.log
if %build_arm64% == 1 (
msbuild.exe weasel.sln %build_option% /p:Configuration=%build_config% /p:Platform="ARM" /fl6
if errorlevel 1 goto error
msbuild.exe weasel.sln %build_option% /p:Configuration=%build_config% /p:Platform="ARM64" /fl5
if errorlevel 1 goto error
)
msbuild.exe weasel.sln %build_option% /p:Configuration=%build_config% /p:Platform="x64" /fl2
if errorlevel 1 goto error
msbuild.exe weasel.sln %build_option% /p:Configuration=%build_config% /p:Platform="Win32" /fl1
if errorlevel 1 goto error
if %build_arm64% == 1 (
pushd arm64x_wrapper
call build.bat
if errorlevel 1 goto error
popd
copy arm64x_wrapper\weaselARM64X.dll output
if errorlevel 1 goto error
copy arm64x_wrapper\weaselARM64X.ime output
if errorlevel 1 goto error
)
if %build_installer% == 1 (
"%ProgramFiles(x86)%"\NSIS\Bin\makensis.exe ^
/DWEASEL_VERSION=%WEASEL_VERSION% ^
/DWEASEL_BUILD=%WEASEL_BUILD% ^
/DPRODUCT_VERSION=%PRODUCT_VERSION% ^
output\install.nsi
if errorlevel 1 goto error
)
goto end
rem -------------------------------------------------------------------------
rem build boost
:build_boost
set BJAM_OPTIONS_COMMON=-j%NUMBER_OF_PROCESSORS%^
--with-filesystem^
--with-json^
--with-locale^
--with-regex^
--with-serialization^
--with-system^
--with-thread^
define=BOOST_USE_WINAPI_VERSION=0x0603^
toolset=%BJAM_TOOLSET%^
link=static^
runtime-link=static^
--build-type=complete
set BJAM_OPTIONS_X86=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=32
set BJAM_OPTIONS_X64=%BJAM_OPTIONS_COMMON%^
architecture=x86^
address-model=64
set BJAM_OPTIONS_ARM32=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=32
set BJAM_OPTIONS_ARM64=%BJAM_OPTIONS_COMMON%^
define=BOOST_USE_WINAPI_VERSION=0x0A00^
architecture=arm^
address-model=64
cd /d %BOOST_ROOT%
if not exist b2.exe call bootstrap.bat
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_X86% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_X64% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
if %build_arm64% == 1 (
b2 %BJAM_OPTIONS_ARM32% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
b2 %BJAM_OPTIONS_ARM64% stage %BOOST_COMPILED_LIBS%
if errorlevel 1 goto error
)
exit /b
rem ---------------------------------------------------------------------------
:build_data
copy %WEASEL_ROOT%\LICENSE.txt output\
copy %WEASEL_ROOT%\README.md output\README.txt
copy %WEASEL_ROOT%\plum\rime-install.bat output\
set plum_dir=plum
set rime_dir=output/data
set WSLENV=plum_dir:rime_dir
bash plum/rime-install %WEASEL_BUNDLED_RECIPES%
if errorlevel 1 goto error
exit /b
rem ---------------------------------------------------------------------------
:build_opencc_data
if not exist %WEASEL_ROOT%\librime\share\opencc\TSCharacters.ocd2 (
cd %WEASEL_ROOT%\librime
call build.bat deps %rime_build_variant%
if errorlevel 1 goto error
)
cd %WEASEL_ROOT%
if not exist output\data\opencc mkdir output\data\opencc
copy %WEASEL_ROOT%\librime\share\opencc\*.* output\data\opencc\
if errorlevel 1 goto error
exit /b
rem ---------------------------------------------------------------------------
rem %1 : ARCH
rem %2 : push | pop , push to backup when pop to restore
:stash_build
pushd %WEASEL_ROOT%\librime
for %%a in ( build dist lib ^
deps\glog\build ^
deps\googletest\build ^
deps\leveldb\build ^
deps\marisa-trie\build ^
deps\opencc\build ^
deps\yaml-cpp\build ) do (
if "%2"=="push" (
if exist %%a move %%a %%a_%1
)
if "%2"=="pop" (
if exist %%a_%1 move %%a_%1 %%a
)
)
popd
exit /b
rem ---------------------------------------------------------------------------
rem %1 : ARCH
rem %2 : target_path of rime.lib, base %WEASEL_ROOT% or abs path
rem %3 : target_path of rime.dll, base %WEASEL_ROOT% or abs path
:build_librime_platform
rem restore backuped %1 build
call :stash_build %1 pop
cd %WEASEL_ROOT%\librime
if not exist env.bat (
copy %WEASEL_ROOT%\env.bat env.bat
)
if not exist lib\opencc.lib (
call build.bat deps %rime_build_variant%
if errorlevel 1 (
call :stash_build %1 push
goto error
)
)
call build.bat %rime_build_variant%
if errorlevel 1 (
call :stash_build %1 push
goto error
)
cd %WEASEL_ROOT%\librime
call :stash_build %1 push
copy /Y %WEASEL_ROOT%\librime\dist_%1\include\rime_*.h %WEASEL_ROOT%\include\
if errorlevel 1 goto error
copy /Y %WEASEL_ROOT%\librime\dist_%1\lib\rime.lib %2\
if errorlevel 1 goto error
copy /Y %WEASEL_ROOT%\librime\dist_%1\lib\rime.dll %3\
if errorlevel 1 goto error
exit /b
rem ---------------------------------------------------------------------------
:error
echo error building weasel...
:end
cd %WEASEL_ROOT%