forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-windows.bat
336 lines (268 loc) · 12.8 KB
/
build-windows.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
:: build-windows.bat
::
:: This source file is part of the Swift.org open source project
::
:: Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
:: Licensed under Apache License v2.0 with Runtime Library Exception
::
:: See https://swift.org/LICENSE.txt for license information
:: See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
:: REQUIRED ENVIRONMENT VARIABLES
:: This script requires to be executed inside one Visual Studio command line,
:: in order for many of the tools and environment variables to be available.
:: Additionally, it needs the following variables:
:: - CMAKE_BUILD_TYPE: Kind of build: Release, RelWithDebInfo, Debug.
:: - PYTHON_HOME: The Python installation directory.
:: REQUIRED PERMISSIONS
:: Practically, it is easier to be in the Adminstrators group to run the
:: script, but it should be possible to execute as a normal user.
:: The user will need permission to write files into the Windows SDK and the
:: VisualC++ folder.
:: @echo off
setlocal enableextensions enabledelayedexpansion
set icu_version_major=64
set icu_version_minor=2
set icu_version=%icu_version_major%_%icu_version_minor%
set icu_version_dashed=%icu_version_major%-%icu_version_minor%
set "exitOnError=|| (exit /b)"
set current_directory=%~dp0
set current_directory=%current_directory:~0,-1%
set source_root=%current_directory%\..\..
:: Resetting source_root with %CD% removes the ..\.. from the paths, and makes
:: the output easier to read.
cd %source_root%
set source_root=%CD%
set full_build_root=%source_root%\build
mkdir %full_build_root%
:: Use the shortest path we can for the build directory, to avoid Windows
:: path problems as much as we can.
subst T: /d
subst T: %full_build_root% %exitOnError%
set build_root=T:
set install_directory=%build_root%\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr
call :clone_repositories %exitOnError%
call :download_icu %exitOnError%
:: TODO: Disabled until we need LLBuild/SwiftPM in this build script.
:: call :download_sqlite3
call :build_llvm %exitOnError%
path %PATH%;%install_directory%\bin
call :build_cmark %exitOnError%
call :prepare_platform_modules %exitOnError%
call :build_swift %exitOnError%
call :build_lldb %exitOnError%
call :build_libdispatch %exitOnError%
path %source_root%\icu-%icu_version%\bin64;%install_directory%\bin;%build_root%\swift\bin;%build_root%\swift\libdispatch-prefix\bin;%PATH%;C:\Program Files\Git\usr\bin
call :test_swift %exitOnError%
call :test_libdispatch %exitOnError%
goto :end
endlocal
:clone_repositories
:: Clones the repositories used by the Windows build.
:: It supposes that the swift repository is already cloned by CI.
:: It supposes the %CD% is the source root.
setlocal enableextensions enabledelayedexpansion
git -C "%source_root%\swift" config --local core.autocrlf input
git -C "%source_root%\swift" config --local core.symlink true
git -C "%source_root%\swift" checkout-index --force --all
git clone --depth 1 --single-branch https://github.com/apple/swift-cmark cmark %exitOnError%
git clone --depth 1 --single-branch --branch swift/master https://github.com/apple/llvm-project llvm-project %exitOnError%
mklink /D "%source_root%\clang" "%source_root%\llvm-project\clang"
mklink /D "%source_root%\llvm" "%source_root%\llvm-project\llvm"
mklink /D "%source_root%\lldb" "%source_root%\llvm-project\lldb"
mklink /D "%source_root%\compiler-rt" "%source_root%\llvm-project\compiler-rt"
mklink /D "%source_root%\libcxx" "%source_root%\llvm-project\libcxx"
mklink /D "%source_root%\clang-tools-extra" "%source_root%\llvm-project\clang-tools-extra"
git clone --depth 1 --single-branch https://github.com/apple/swift-corelibs-libdispatch %exitOnError%
goto :eof
endlocal
:download_icu
:: Downloads ICU, which will be used as a dependency for the Swift Standard
:: Library and Foundation.
setlocal enableextensions enabledelayedexpansion
set file_name=icu4c-%icu_version%-Win64-MSVC2017.zip
curl -L -O "https://github.com/unicode-org/icu/releases/download/release-%icu_version_dashed%/%file_name%" %exitOnError%
:: unzip warns about the paths in the zip using slashes, which raises the
:: errorLevel to 1. We cannot use exitOnError, and have to ignore errors.
"C:\Program Files\Git\usr\bin\unzip.exe" -o %file_name% -d "%source_root%\icu-%icu_version%"
exit /b 0
goto :eof
endlocal
:download_sqlite3
:: Downloads SQLite3, which will be used as a dependency for llbuild and
:: Swift Package Manager.
setlocal enableextensions enabledelayedexpansion
set file_name=sqlite-amalgamation-3270200.zip
curl -L -O "https://www.sqlite.org/2019/%file_name%" %exitOnError%
"C:\Program Files\Git\usr\bin\unzip.exe" -o %file_name% %exitOnError%
goto :eof
endlocal
:prepare_platform_modules
:: Create files into the right places of the Windows SDK to the files in the
:: swift repository, in order to consider the headers of the Windows SDK a
:: module to compile Swift code against them.
setlocal enableextensions enabledelayedexpansion
copy /y "%source_root%\swift\stdlib\public\Platform\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" %exitOnError%
copy /y "%source_root%\swift\stdlib\public\Platform\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" %exitOnError%
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap" %exitOnError%
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes" %exitOnError%
goto :eof
endlocal
:build_llvm
:: Configures, builds, and installs LLVM
setlocal enableextensions enabledelayedexpansion
cmake^
-B "%build_root%\llvm"^
-G Ninja^
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
-DCMAKE_C_COMPILER=cl^
-DCMAKE_CXX_COMPILER=cl^
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
-DLLVM_ENABLE_PDB:BOOL=YES^
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
-DLLVM_ENABLE_PROJECTS:STRING=clang^
-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;X86"^
-DLLVM_INCLUDE_BENCHMARKS:BOOL=NO^
-DLLVM_INCLUDE_DOCS:BOOL=NO^
-DLLVM_INCLUDE_EXAMPLES:BOOL=NO^
-DLLVM_INCLUDE_GO_TESTS:BOOL=NO^
-DLLVM_TOOL_GOLD_BUILD:BOOL=NO^
-DLLVM_ENABLE_OCAMLDOC:BOOL=NO^
-DLLVM_ENABLE_LIBXML2:BOOL=NO^
-DLLVM_ENABLE_ZLIB:BOOL=NO^
-DENABLE_X86_RELAX_RELOCATIONS:BOOL=YES^
-DLLVM_INSTALL_BINUTILS_SYMLINKS:BOOL=YES^
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=YES^
-DLLVM_TOOLCHAIN_TOOLS:STRING="addr2line;ar;c++filt;dsymutil;dwp;llvm-ar;llvm-cov;llvm-cvtres;llvm-cxxfilt;llvm-dlltool;llvm-dwp;llvm-ranlib;llvm-lib;llvm-mt;llvm-nm;llvm-objdump;llvm-pdbutil;llvm-profdata;llvm-rc;llvm-readelf;llvm-readobj;llvm-size;llvm-strip;llvm-symbolizer;llvm-undname;nm;objcopy;objdump;ranlib;readelf;size;strings"^
-DCLANG_TOOLS="clang;clang-format;clang-headers;clang-tidy"^
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-S "%source_root%\llvm" %exitOnError%
cmake --build "%build_root%\llvm" %exitOnError%
cmake --build "%build_root%\llvm" --target install %exitOnError%
goto :eof
endlocal
:build_cmark
:: Configures and builds CMark
setlocal enableextensions enabledelayedexpansion
cmake^
-B "%build_root%\cmark"^
-G Ninja^
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
-DCMAKE_C_COMPILER=cl^
-DCMAKE_CXX_COMPILER=cl^
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-S "%source_root%\cmark" %exitOnError%
cmake --build "%build_root%\cmark" %exitOnError%
goto :eof
endlocal
:build_swift
:: Configures, builds, and installs Swift and the Swift Standard Library
setlocal enableextensions enabledelayedexpansion
:: SWIFT_PARALLEL_LINK_JOBS=8 allows the build machine to use as many CPU as
:: possible, while not exhausting the RAM.
cmake^
-B "%build_root%\swift"^
-G Ninja^
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
-DCMAKE_C_COMPILER=cl^
-DCMAKE_CXX_COMPILER=cl^
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
-DClang_DIR:PATH=%build_root%\llvm\lib\cmake\clang^
-DSWIFT_PATH_TO_CMARK_BUILD:PATH=%build_root%\cmark^
-DSWIFT_PATH_TO_CMARK_SOURCE:PATH=%source_root%\cmark^
-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE:PATH=%source_root%\swift-corelibs-libdispatch^
-DLLVM_DIR:PATH=%build_root%\llvm\lib\cmake\llvm^
-DSWIFT_INCLUDE_DOCS:BOOL=NO^
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE:PATH=%source_root%\icu-%icu_version%\include\unicode^
-DSWIFT_WINDOWS_x86_64_ICU_UC:PATH=%source_root%\icu-%icu_version%\lib64\icuuc.lib^
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE:PATH=%source_root%\icu-%icu_version%\include^
-DSWIFT_WINDOWS_x86_64_ICU_I18N:PATH=%source_root%\icu-%icu_version%\lib64\icuin.lib^
-DSWIFT_BUILD_DYNAMIC_STDLIB:BOOL=YES^
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY:BOOL=YES^
-DSWIFT_BUILD_STATIC_STDLIB:BOOL=NO^
-DSWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL=NO^
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=YES^
-DSWIFT_BUILD_SOURCEKIT:BOOL=YES^
-DSWIFT_ENABLE_SOURCEKIT_TESTS:BOOL=YES^
-DSWIFT_INSTALL_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;editor-integration;tools;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers"^
-DSWIFT_PARALLEL_LINK_JOBS=8^
-DPYTHON_EXECUTABLE:PATH=%PYTHON_HOME%\python.exe^
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-S "%source_root%\swift" %exitOnError%
cmake --build "%build_root%\swift" %exitOnError%
cmake --build "%build_root%\swift" --target install %exitOnError%
goto :eof
endlocal
:test_swift
:: Tests the Swift compiler and the Swift Standard Library
setlocal enableextensions enabledelayedexpansion
cmake --build "%build_root%\swift" --target check-swift %exitOnError%
goto :eof
endlocal
:build_lldb
:: Configures, builds, and installs LLDB
setlocal enableextensions enabledelayedexpansion
cmake^
-B "%build_root%\lldb"^
-G Ninja^
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
-DCMAKE_C_COMPILER=clang-cl^
-DCMAKE_CXX_COMPILER=clang-cl^
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
-DLLVM_DIR:PATH=%build_root%\llvm\lib\cmake\llvm^
-DClang_DIR:PATH=%build_root%\llvm\lib\cmake\clang^
-DSwift_DIR:PATH=%build_root%\swift\lib\cmake\swift^
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
-DLLDB_USE_STATIC_BINDINGS:BOOL=YES^
-DPYTHON_HOME:PATH=%PYTHON_HOME%^
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
-DLLDB_DISABLE_PYTHON=YES^
-DLLDB_INCLUDE_TESTS:BOOL=NO^
-S "%source_root%\lldb" %exitOnError%
cmake --build "%build_root%\lldb" %exitOnError%
cmake --build "%build_root%\lldb" --target install %exitOnError%
goto :eof
endlocal
:build_libdispatch
:: Configures, builds, and installs Dispatch
setlocal enableextensions enabledelayedexpansion
cmake^
-B "%build_root%\swift-corelibs-libdispatch"^
-G Ninja^
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
-DCMAKE_C_COMPILER=clang-cl^
-DCMAKE_CXX_COMPILER=clang-cl^
-DCMAKE_Swift_COMPILER=swiftc^
-DSwift_DIR:PATH=%build_root%\swift\lib\cmake\swift^
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
-DCMAKE_C_COMPILER_TARGET=x86_64-unknown-windows-msvc^
-DCMAKE_CXX_COMPILER_TARGET=x86_64-unknown-windows-msvc^
-DENABLE_SWIFT:BOOL=YES^
-DENABLE_TESTING:BOOL=YES^
-DCMAKE_C_FLAGS:STRING="${CMAKE_C_FLAGS} --target=x86_64-unknown-windows-msvc /GS- /Oy /Gw /Gy"^
-DCMAKE_CXX_FLAGS:STRING="${CMAKE_CXX_FLAGS} --target=x86_64-unknown-windows-msvc /GS- /Oy /Gw /Gy"^
-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
-DCMAKE_SHARED_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
-DCMAKE_Swift_COMPILER_TARGET:STRING=x86_64-unknown-windows-msvc^
-DCMAKE_Swift_FLAGS:STRING="-resource-dir \"%install_directory%\lib\swift\""^
-DCMAKE_Swift_LINK_FLAGS:STRING="-resource-dir \"%install_directory%\lib\swift\""^
-S "%source_root%\swift-corelibs-libdispatch" %exitOnError%
cmake --build "%build_root%\swift-corelibs-libdispatch" %exitOnError%
cmake --build "%build_root%\swift-corelibs-libdispatch" --target install %exitOnError%
goto :eof
endlocal
:test_libdispatch
:: Tests libdispatch C interface
setlocal enableextensions enabledelayedexpansion
cmake --build "%build_root%\swift-corelibs-libdispatch" --target ExperimentalTest %exitOnError%
goto :eof
endlocal
:end