-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.bat
581 lines (481 loc) · 17.5 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
@echo off
@title mindquantum_build
@rem Copyright 2020 Huawei Technologies Co., Ltd
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem ============================================================================
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
set BASEPATH=%~dp0
set ROOTDIR=%BASEPATH%
set SCRIPTDIR=%BASEPATH%\scripts\build
set PROGRAM=%~nx0
set _IS_MINDSPORE_CI=0
if NOT "%DEVCLOUD_CI%" == "" goto :CI_DEVCLOUD
if NOT "%CI%" == "" goto :CI_JENKINS
goto :CI_FALSE
:CI_DEVCLOUD
if /I "%DEVCLOUD_CI%" == "true" goto :CI_TRUE
if %DEVCLOUD_CI% == 1 goto :CI_TRUE
goto :CI_FALSE
:CI_JENKINS
if /I "%CI%" == "false" goto :CI_FALSE
if %CI% == 0 goto :CI_FALSE
if NOT %JENKINS_URL% == "" (
echo %JENKINS_URL% | findstr /r "^https*://build.mindspore.cn">nul 2>&1
if %errorlevel% == 0 goto :CI_TRUE
)
:CI_FALSE
set _IS_MINDSPORE_CI=0
goto :CI_DONE
:CI_TRUE
echo Detected MindSpore/MindQuantum CI
set _IS_MINDSPORE_CI=1
:CI_DONE
rem ============================================================================
rem Default values for this particular script
set enable_gitee=0
set has_build_dir=0
set delocate_wheel=1
set build_isolation=1
set output_path=%ROOTDIR%\output
set platform_name=
set python_extra_pkgs=wheel-filename>1.2 build
if !_IS_MINDSPORE_CI! == 1 (
set cmake_debug_mode=1
set enable_gitee=1
set enable_gpu=1
set enable_projectq=1
)
call %SCRIPTDIR%\default_values.bat
rem ============================================================================
:initial
set result=false
if "%1" == "" goto :done_parsing
if /I "%1" == "/h" set result=true
if /I "%1" == "/Help" set result=true
if "%result%" == "true" (
call :help_message
goto :END
)
if /I "%1" == "/analyzer" (
set enable_analyzer=1
shift & goto :initial
)
if /I "%1" == "/N" (
set dry_run=1
shift & goto :initial
)
if /I "%1" == "/B" set result=true
if /I "%1" == "/Build" set result=true
if "%result%" == "true" (
set value=%2
if not defined value goto :arg_build
if "!value:~0,1!" == "/" (
:arg_build
echo %PROGRAM%: option requires an argument -- '/B,/Build'
goto :END
)
set has_build_dir=1
set build_dir=!value!
shift & shift & goto :initial
)
if /I "%1" == "/BuildIsolation" (
set build_isolation=1
shift & goto :initial
)
if /I "%1" == "/Clean" (
set do_clean=1
shift & goto :initial
)
if /I "%1" == "/Clean3rdParty" (
set do_clean_3rdparty=1
shift & goto :initial
)
if /I "%1" == "/CleanAll" (
set do_clean_venv=1
set do_clean_build_dir=1
shift & goto :initial
)
if /I "%1" == "/CleanCache" (
set do_clean_cache=1
shift & goto :initial
)
if /I "%1" == "/CleanVenv" (
set do_clean_venv=1
shift & goto :initial
)
if /I "%1" == "/C" set result=true
if /I "%1" == "/Configure" set result=true
if "%result%" == "true" (
set do_configure=1
shift & goto :initial
)
if /I "%1" == "/ConfigureOnly" (
set configure_only=1
shift & goto :initial
)
if /I "%1" == "/CudaArch" (
set value=%2
if not defined value goto :arg_cuda_arch
if "!value:~0,1!" == "/" (
:arg_cuda_arch
echo %PROGRAM%: option requires an argument -- '/CudaArch'
goto :END
)
call :ToCMakeList value
set cuda_arch=!value!
shift & shift & goto :initial
)
if /I "%1" == "/Cxx" (
set enable_cxx=1
shift & goto :initial
)
if /I "%1" == "/Debug" (
set build_type=Debug
shift & goto :initial
)
if /I "%1" == "/DebugCMake" (
set cmake_debug_mode=1
shift & goto :initial
)
if /I "%1" == "/Delocate" (
set delocate_wheel=1
shift & goto :initial
)
if /I "%1" == "/NoDelocate" (
set delocate_wheel=0
shift & goto :initial
)
if /I "%1" == "/NoGitee" (
set enable_gitee=0
shift & goto :initial
)
if /I "%1" == "/NoIsolation" (
set build_isolation=0
shift & goto :initial
)
if /I "%1" == "/Gitee" (
set enable_gitee=1
shift & goto :initial
)
if /I "%1" == "/Gpu" (
set enable_gpu=1
shift & goto :initial
)
if /I "%1" == "/Install" (
set do_install=1
shift & goto :initial
)
if /I "%1" == "/J" set result=true
if /I "%1" == "/Jobs" set result=true
if "%result%" == "true" (
set value=%2
if not defined value goto :arg_build
if "!value:~0,1!" == "/" (
:arg_build
echo %PROGRAM%: option requires an argument -- '/B,/Build'
goto :END
)
set n_jobs=!value!
shift & shift & goto :initial
)
if /I "%1" == "/LocalPkgs" (
set force_local_pkgs=1
shift & goto :initial
)
if /I "%1" == "/Logging" (
set enable_logging=1
shift & goto :initial
)
if /I "%1" == "/LoggingDebug" (
set enable_logging=1
set logging_enable_debug=1
shift & goto :initial
)
if /I "%1" == "/LoggingTrace" (
set enable_logging=1
set logging_enable_trace=1
shift & goto :initial
)
if /I "%1" == "/NoBuildIsolation" (
set build_isolation=0
shift & goto :initial
)
if /I "%1" == "/Ninja" (
set ninja=1
shift & goto :initial
)
if /I "%1" == "/OnlyPytest" (
set install_only_pytest=1
shift & goto :initial
)
if /I "%1" == "/Prefix" (
set value=%2
if not defined value goto :arg_prefix
if "!value:~0,1!" == "/" (
:arg_prefix
echo %PROGRAM%: option requires an argument -- '/Prefix'
goto :END
)
set prefix_dir=!value!
shift & shift & goto :initial
)
if /I "%1" == "/Quiet" (
set cmake_make_silent=1
shift & goto :initial
)
if /I "%1" == "/ShowLibraries" (
call :print_show_libraries
goto :END
)
if /I "%1" == "/Test" (
set enable_tests=1
shift & goto :initial
)
if /I "%1" == "/UpdateVenv" (
set do_update_venv=1
shift & goto :initial
)
if /I "%1" == "/Venv" (
set value=%2
if not defined value goto :arg_venv
if "!value:~0,1!" == "/" (
:arg_venv
echo %PROGRAM%: option requires an argument -- '/Venv'
goto :END
)
set python_venv_path=!value!
shift & shift & goto :initial
)
set value=%1
set with_header=!value:~0,5!
if /I "!with_header!" == "/with" (
set library=!value:~5!
call :LoCase library
if not defined local_pkgs (
set local_pkgs=!library!
) else (
set local_pkgs=!local_pkgs!,!library!
)
shift & goto :initial
)
set unparsed_args=!unparsed_args! %1
shift & goto :initial
:done_parsing
rem ============================================================================
rem Locate python or python3
call %SCRIPTDIR%\locate_python3.bat
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
rem ============================================================================
cd %ROOTDIR%
rem ----------------------------------------------------------------------------
call %SCRIPTDIR%\python_virtualenv_activate.bat
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
rem ------------------------------------------------------------------------------
rem Locate cmake or cmake3
call %SCRIPTDIR%\locate_cmake.bat
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
rem ------------------------------------------------------------------------------
rem Locate ninja if needed
if !ninja! == 1 (
call %SCRIPTDIR%\locate_ninja.bat
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
)
rem ----------------------------------------------------------------------------
call %SCRIPTDIR%\python_virtualenv_update.bat
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
rem ============================================================================
rem Setup arguments for build
set args=-w
if !build_isolation! == 0 set args=!args! --no-isolation
set RETVAL=
call %SCRIPTDIR%\dos\build_cmake_option.bat BUILD_TESTING !enable_tests!
call %SCRIPTDIR%\dos\build_cmake_option.bat CLEAN_3RDPARTY_INSTALL_DIR !do_clean_3rdparty!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_ANALYZER !enable_analyzer!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CMAKE_DEBUG !cmake_debug_mode!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CUDA !enable_gpu!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CXX_EXPERIMENTAL !enable_cxx!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_GITEE !enable_gitee!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_LOGGING !enable_logging!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_LOGGING_DEBUG_LEVEL !logging_enable_debug!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_LOGGING_TRACE_LEVEL !logging_enable_trace!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_PROJECTQ !enable_projectq!
set args=!args! %RETVAL%
if !_IS_MINDSPORE_CI! == 1 (
set args=!args! -C--global-option=--set -C--global-option=MINDSPORE_CI
)
if !cmake_make_silent! == 0 (
set args=!args! -C--global-option=--set -C--global-option=USE_VERBOSE_MAKEFILE
) else (
set args=!args! -C--global-option=--unset -C--global-option=USE_VERBOSE_MAKEFILE
)
if !ninja! == 1 (
set args=!args! -C--global-option=-G"Ninja Multi-Config"
) else (
if !n_jobs! == -1 set n_jobs=!n_jobs_default!
)
if NOT !n_jobs! == -1 (
set args=!args! -C--global-option=--var -C--global-option=JOBS -C--global-option=!n_jobs!
set args=!args! -C--global-option=build_ext -C--global-option=--jobs=!n_jobs!
)
if "!build_type!" == "Debug" set args=!args! -C--global-option=build -C--global-option=--debug
if !force_local_pkgs! == 1 (
set args=!args! -C--global-option=--var -C--global-option=MQ_FORCE_LOCAL_PKGS -C--global-option=all
) else (
if NOT "!local_pkgs!" == "" (
set args=!args! -C--global-option=--var -C--global-option=MQ_FORCE_LOCAL_PKGS -C--global-option=!local_pkgs!
)
)
if !has_build_dir! == 1 set args=!args! -C--global-option=build_ext -C--global-option=--build-dir -C--global-option=!build_dir!
if NOT "!CC!" == "" set args=!args! -C--global-option=--var -C--global-option=CMAKE_C_COMPILER -C--global-option=!CC!
if NOT "!CXX!" == "" set args=!args! -C--global-option=--var -C--global-option=CMAKE_CXX_COMPILER -C--global-option=!CXX!
if NOT "!CUDACXX!" == "" set args=!args! -C--global-option=--var -C--global-option=CMAKE_CUDA_COMPILER -C--global-option=!CUDACXX!
rem ============================================================================
if !enable_gpu! == 1 (
if "!CUDA_PATH" == "" (
if NOT "!CUDA_HOME!" == "" (
rem Older CMake using find_package(CUDA) would rely on CUDA_HOME, but newer CMake only look at CUDACXX and
rem CUDA_PATH
echo CUDA_HOME is defined, but CUDA_PATH is not. Setting CUDA_PATH=CUDA_HOME
set CUDA_PATH=!CUDA_HOME!
)
)
echo CUDA_HOME = !CUDA_HOME!
echo CUDA_PATH = !CUDA_PATH!
)
rem ============================================================================
rem Build the wheels
if !has_build_dir! == 1 (
if !do_clean_build_dir! == 1 (
echo Deleting build folder: !build_dir!
if exist !build_dir! call :call_cmd rd /Q /S !build_dir!
) else (
if !do_clean_cache! == 1 (
echo Removing CMake cache at: !build_dir!\CMakeCache.txt
if exist !build_dir!\CMakeCache.txt call :call_cmd del /Q "!build_dir!\CMakeCache.txt"
echo Removing CMake files at: !build_dir!/CMakeFiles
if exist !build_dir!/CMakeFiles call :call_cmd rd /Q /S "!build_dir!\CMakeFiles"
echo Removing CMake files at: !build_dir!/cmake-ldtest
if exist !build_dir!/CMakeFiles call :call_cmd rd /Q /S "!build_dir!\cmake-ldtest"
)
)
)
if !delocate_wheel! == 1 (
set MQ_DELOCATE_WHEEL=1
set MQ_DELOCATE_WHEEL_PLAT=
if NOT "!platform_name!" == "" set MQ_DELOCATE_WHEEL_PLAT=!platform_name!
if !has_build_dir! == 1 (
set build_dir_for_env=!build_dir!
) else (
if "!fast_build_dir!" == "" (
for /F "delims=" %%i IN ('!PYTHON! -m mindquantum_config --tempdir') DO set build_dir_for_env=%%i
) else (
set build_dir_for_env=!fast_build_dir!
)
)
if !_IS_MINDSPORE_CI! == 1 (
set MQ_LIB_PATHS=!ROOTDIR!\ld_library_paths.txt
) else (
set MQ_LIB_PATHS=!build_dir_for_env!\ld_library_paths.txt
)
set MQ_BUILD_DIR=!build_dir_for_env!
echo MQ_LIB_PATHS = !MQ_LIB_PATHS!
echo MQ_BUILD_DIR = !MQ_BUILD_DIR!
)
call %SCRIPTDIR%\dos\call_cmd.bat !PYTHON! -m build !args! !unparsed_args!
if DEFINED args set args=
if DEFINED unparsed_args set unparsed_args=
if DEFINED MQ_DELOCATE_WHEEL set MQ_DELOCATE_WHEEL=
if DEFINED MQ_DELOCATE_WHEEL_PLAT set MQ_DELOCATE_WHEEL_PLAT=
if DEFINED MQ_LIB_PATHS set MQ_LIB_PATHS=
if DEFINED MQ_BUILD_DIR set MQ_BUILD_DIR=
rem -----------------------------------------------------------------------------
rem Move the wheels to the output directory
IF NOT EXIST "!output_path!" (
md "!output_path!"
)
call %SCRIPTDIR%\dos\call_cmd.bat move /Y %ROOTDIR%\dist\* %output_path%
echo ------Successfully created mindquantum package------
goto :END
rem ============================================================================
:help_message
echo Build binary Python wheel for MindQunantum
echo:
echo This is mainly relevant for developers that want to deploy MindQuantum
echo on machines other than their own.
echo:
echo This script will create a Python virtualenv in the MindQuantum root
echo directory and then build a binary Python wheel of MindQuantum.
echo:
echo Usage:
echo %PROGRAM% [options]
echo:
echo Options:
echo /H,/help Show this help message and exit
echo /N Dry run; only print commands but do not execute them
echo
echo /Analyzer Use the compiler static analysis tool during compilation (GCC & MSVC)
echo /B,/Build [dir] Specify build directory
echo Defaults to: %build_dir%
echo /Clean3rdParty Clean 3rd party installation directory
echo /CleanAll Clean everything before building.
echo Equivalent to /CleanVenv /CleanBuilddir
echo /CleanBuildDir Delete build directory before building
echo /CleanCache Re-run CMake with a clean CMake cache
echo /CleanVenv Delete Python virtualenv before building
echo /Cxx (experimental) Enable MindQuantum C++ support
echo /Debug Build in debug mode
echo /Delocate Delocate the binary wheels after build is finished
echo (enabled by default; pass /NoDelocate to disable)
echo /Gitee Use Gitee (where possible) instead of Github/Gitlab
echo /Gpu Enable GPU support
echo /j,/Jobs [N] Number of parallel jobs for building
echo Defaults to: !n_jobs_default!
echo /LocalPkgs Compile third-party dependencies locally
echo /Logging Enable logging in C++ code
echo /LoggingDebug Enable DEBUG level logging macros (implies /Logging)
echo /LoggingTrace Enable TRACE level logging macros (implies /Logging /LoggingDebug)'
echo /Ninja Use the Ninja CMake generator
echo /NoDelocate Disable delocating the binary wheels after build is finished
echo /NoGitee Do not favor Gitee over Github/Gitlab
echo /NoIsolation Pass --no-isolation to python3 -m build
echo /O, /Output [dir] Output directory for built wheels
echo /PlatName Platform name to use for wheel delocation
echo (only effective if --delocate is used)
echo /Quiet Disable verbose build rules
echo /ShowLibraries Show all known third-party libraries
echo /Venv *path* Path to Python virtual environment
echo Defaults to: %python_venv_path%
echo /With*library* Build the third-party *library* from source (*library* is case-insensitive)
echo (ignored if /LocalPkgs is passed, except for projectq)
rem echo /Without*library* Do not build the third-party library from source (*library* is case-insensitive)
rem echo (ignored if /LocalPkgs is passed, except for projectq)
echo:
echo Test related options:
echo /Test Build C++ tests and install dependencies for Python testing as well
echo /OnlyPytest Only install pytest and its dependencies when creating/building the virtualenv
echo:
echo Python related options:
echo /UpdateVenv Update the python virtual environment
echo:
echo NB: any unknown arguments will be passed on to 'python3 -m build'
echo:
echo Example calls:
echo %PROGRAM%
echo %PROGRAM% /gpu
echo %PROGRAM% /cxx /WithBoost
echo %PROGRAM% "-DCMAKE_CUDA_COMPILER^=/opt/cuda/bin/nvcc"
EXIT /B 0
rem ============================================================================
:END
call %SCRIPTDIR%\unset_values.bat