Skip to content

Commit adda5b7

Browse files
authored
Merge pull request swiftlang#33506 from compnerd/rebranch
build: add a builder script for the rebranch
2 parents 7b1a43b + 14ad9cc commit adda5b7

File tree

1 file changed

+346
-0
lines changed

1 file changed

+346
-0
lines changed

utils/build-windows-rebranch.bat

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
:: build-windows.bat
2+
::
3+
:: This source file is part of the Swift.org open source project
4+
::
5+
:: Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
:: Licensed under Apache License v2.0 with Runtime Library Exception
7+
::
8+
:: See https://swift.org/LICENSE.txt for license information
9+
:: See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
11+
:: REQUIRED ENVIRONMENT VARIABLES
12+
:: This script requires to be executed inside one Visual Studio command line,
13+
:: in order for many of the tools and environment variables to be available.
14+
:: Additionally, it needs the following variables:
15+
:: - CMAKE_BUILD_TYPE: Kind of build: Release, RelWithDebInfo, Debug.
16+
:: - PYTHON_HOME: The Python installation directory.
17+
18+
:: REQUIRED PERMISSIONS
19+
:: Practically, it is easier to be in the Adminstrators group to run the
20+
:: script, but it should be possible to execute as a normal user.
21+
:: The user will need permission to write files into the Windows SDK and the
22+
:: VisualC++ folder.
23+
24+
:: @echo off
25+
26+
setlocal enableextensions enabledelayedexpansion
27+
28+
set icu_version_major=64
29+
set icu_version_minor=2
30+
set icu_version=%icu_version_major%_%icu_version_minor%
31+
set icu_version_dashed=%icu_version_major%-%icu_version_minor%
32+
33+
set "exitOnError=|| (exit /b)"
34+
set current_directory=%~dp0
35+
set current_directory=%current_directory:~0,-1%
36+
set source_root=%current_directory%\..\..
37+
38+
:: Resetting source_root with %CD% removes the ..\.. from the paths, and makes
39+
:: the output easier to read.
40+
cd %source_root%
41+
set source_root=%CD%
42+
43+
set full_build_root=%source_root%\build
44+
mkdir %full_build_root%
45+
46+
:: Use the shortest path we can for the build directory, to avoid Windows
47+
:: path problems as much as we can.
48+
subst T: /d
49+
subst T: %full_build_root% %exitOnError%
50+
set build_root=T:
51+
set install_directory=%build_root%\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr
52+
53+
md %build_root%\tmp
54+
set TMPDIR=%build_root%\tmp
55+
56+
md %build_root%\tmp\org.llvm.clang
57+
set CUSTOM_CLANG_MODULE_CACHE=%build_root%\tmp\org.llvm.clang.9999
58+
59+
md %build_root%\tmp\org.swift.package-manager
60+
set SWIFTPM_MODULECACHE_OVERRIDE=%build_root%\tmp\org.swift.package-manager
61+
62+
call :clone_repositories %exitOnError%
63+
call :download_icu %exitOnError%
64+
:: TODO: Disabled until we need LLBuild/SwiftPM in this build script.
65+
:: call :download_sqlite3
66+
67+
call :build_llvm %exitOnError%
68+
path %PATH%;%install_directory%\bin
69+
70+
call :build_cmark %exitOnError%
71+
72+
call :prepare_platform_modules %exitOnError%
73+
call :build_swift %exitOnError%
74+
75+
call :build_lldb %exitOnError%
76+
77+
call :build_libdispatch %exitOnError%
78+
79+
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
80+
call :test_swift %exitOnError%
81+
call :test_libdispatch %exitOnError%
82+
83+
goto :end
84+
endlocal
85+
86+
:clone_repositories
87+
:: Clones the repositories used by the Windows build.
88+
:: It supposes that the swift repository is already cloned by CI.
89+
:: It supposes the %CD% is the source root.
90+
setlocal enableextensions enabledelayedexpansion
91+
92+
git -C "%source_root%\swift" config --local core.autocrlf input
93+
git -C "%source_root%\swift" config --local core.symlink true
94+
git -C "%source_root%\swift" checkout-index --force --all
95+
96+
git clone --depth 1 --single-branch https://github.com/apple/swift-cmark cmark %exitOnError%
97+
git clone --depth 1 --single-branch --branch swift/master-rebranch https://github.com/apple/llvm-project llvm-project %exitOnError%
98+
mklink /D "%source_root%\clang" "%source_root%\llvm-project\clang"
99+
mklink /D "%source_root%\llvm" "%source_root%\llvm-project\llvm"
100+
mklink /D "%source_root%\lld" "%source_root%\llvm-project\lld"
101+
mklink /D "%source_root%\lldb" "%source_root%\llvm-project\lldb"
102+
mklink /D "%source_root%\compiler-rt" "%source_root%\llvm-project\compiler-rt"
103+
mklink /D "%source_root%\libcxx" "%source_root%\llvm-project\libcxx"
104+
mklink /D "%source_root%\clang-tools-extra" "%source_root%\llvm-project\clang-tools-extra"
105+
git clone --depth 1 --single-branch https://github.com/apple/swift-corelibs-libdispatch %exitOnError%
106+
107+
goto :eof
108+
endlocal
109+
110+
111+
:download_icu
112+
:: Downloads ICU, which will be used as a dependency for the Swift Standard
113+
:: Library and Foundation.
114+
setlocal enableextensions enabledelayedexpansion
115+
116+
set file_name=icu4c-%icu_version%-Win64-MSVC2017.zip
117+
curl -L -O "https://github.com/unicode-org/icu/releases/download/release-%icu_version_dashed%/%file_name%" %exitOnError%
118+
:: unzip warns about the paths in the zip using slashes, which raises the
119+
:: errorLevel to 1. We cannot use exitOnError, and have to ignore errors.
120+
"C:\Program Files\Git\usr\bin\unzip.exe" -o %file_name% -d "%source_root%\icu-%icu_version%"
121+
exit /b 0
122+
123+
goto :eof
124+
endlocal
125+
126+
127+
:download_sqlite3
128+
:: Downloads SQLite3, which will be used as a dependency for llbuild and
129+
:: Swift Package Manager.
130+
setlocal enableextensions enabledelayedexpansion
131+
132+
set file_name=sqlite-amalgamation-3270200.zip
133+
curl -L -O "https://www.sqlite.org/2019/%file_name%" %exitOnError%
134+
"C:\Program Files\Git\usr\bin\unzip.exe" -o %file_name% %exitOnError%
135+
136+
goto :eof
137+
endlocal
138+
139+
140+
:prepare_platform_modules
141+
:: Create files into the right places of the Windows SDK to the files in the
142+
:: swift repository, in order to consider the headers of the Windows SDK a
143+
:: module to compile Swift code against them.
144+
setlocal enableextensions enabledelayedexpansion
145+
146+
copy /y "%source_root%\swift\stdlib\public\Platform\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" %exitOnError%
147+
copy /y "%source_root%\swift\stdlib\public\Platform\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" %exitOnError%
148+
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap" %exitOnError%
149+
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes" %exitOnError%
150+
151+
goto :eof
152+
endlocal
153+
154+
155+
:build_llvm
156+
:: Configures, builds, and installs LLVM
157+
setlocal enableextensions enabledelayedexpansion
158+
159+
cmake^
160+
-B "%build_root%\llvm"^
161+
-G Ninja^
162+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
163+
-DCMAKE_C_COMPILER=cl^
164+
-DCMAKE_CXX_COMPILER=cl^
165+
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
166+
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
167+
-DLLVM_ENABLE_PDB:BOOL=YES^
168+
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
169+
-DLLVM_ENABLE_PROJECTS:STRING=lld;clang^
170+
-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;X86"^
171+
-DLLVM_INCLUDE_BENCHMARKS:BOOL=NO^
172+
-DLLVM_INCLUDE_DOCS:BOOL=NO^
173+
-DLLVM_INCLUDE_EXAMPLES:BOOL=NO^
174+
-DLLVM_INCLUDE_GO_TESTS:BOOL=NO^
175+
-DLLVM_TOOL_GOLD_BUILD:BOOL=NO^
176+
-DLLVM_ENABLE_OCAMLDOC:BOOL=NO^
177+
-DLLVM_ENABLE_LIBXML2:BOOL=NO^
178+
-DLLVM_ENABLE_ZLIB:BOOL=NO^
179+
-DENABLE_X86_RELAX_RELOCATIONS:BOOL=YES^
180+
-DLLVM_INSTALL_BINUTILS_SYMLINKS:BOOL=YES^
181+
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=YES^
182+
-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"^
183+
-DCLANG_TOOLS="clang;clang-format;clang-headers;clang-tidy"^
184+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
185+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
186+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
187+
-S "%source_root%\llvm" %exitOnError%
188+
189+
cmake --build "%build_root%\llvm" %exitOnError%
190+
cmake --build "%build_root%\llvm" --target install %exitOnError%
191+
192+
goto :eof
193+
endlocal
194+
195+
196+
:build_cmark
197+
:: Configures and builds CMark
198+
setlocal enableextensions enabledelayedexpansion
199+
200+
cmake^
201+
-B "%build_root%\cmark"^
202+
-G Ninja^
203+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
204+
-DCMAKE_C_COMPILER=cl^
205+
-DCMAKE_CXX_COMPILER=cl^
206+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
207+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
208+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
209+
-S "%source_root%\cmark" %exitOnError%
210+
211+
cmake --build "%build_root%\cmark" %exitOnError%
212+
213+
goto :eof
214+
endlocal
215+
216+
217+
:build_swift
218+
:: Configures, builds, and installs Swift and the Swift Standard Library
219+
setlocal enableextensions enabledelayedexpansion
220+
221+
:: SWIFT_PARALLEL_LINK_JOBS=8 allows the build machine to use as many CPU as
222+
:: possible, while not exhausting the RAM.
223+
cmake^
224+
-B "%build_root%\swift"^
225+
-G Ninja^
226+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
227+
-DCMAKE_C_COMPILER=cl^
228+
-DCMAKE_CXX_COMPILER=cl^
229+
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
230+
-DClang_DIR:PATH=%build_root%\llvm\lib\cmake\clang^
231+
-DSWIFT_PATH_TO_CMARK_BUILD:PATH=%build_root%\cmark^
232+
-DSWIFT_PATH_TO_CMARK_SOURCE:PATH=%source_root%\cmark^
233+
-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE:PATH=%source_root%\swift-corelibs-libdispatch^
234+
-DLLVM_DIR:PATH=%build_root%\llvm\lib\cmake\llvm^
235+
-DSWIFT_INCLUDE_DOCS:BOOL=NO^
236+
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE:PATH=%source_root%\icu-%icu_version%\include\unicode^
237+
-DSWIFT_WINDOWS_x86_64_ICU_UC:PATH=%source_root%\icu-%icu_version%\lib64\icuuc.lib^
238+
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE:PATH=%source_root%\icu-%icu_version%\include^
239+
-DSWIFT_WINDOWS_x86_64_ICU_I18N:PATH=%source_root%\icu-%icu_version%\lib64\icuin.lib^
240+
-DSWIFT_BUILD_DYNAMIC_STDLIB:BOOL=YES^
241+
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY:BOOL=YES^
242+
-DSWIFT_BUILD_STATIC_STDLIB:BOOL=NO^
243+
-DSWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL=NO^
244+
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=YES^
245+
-DSWIFT_BUILD_SOURCEKIT:BOOL=YES^
246+
-DSWIFT_ENABLE_SOURCEKIT_TESTS:BOOL=YES^
247+
-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"^
248+
-DSWIFT_PARALLEL_LINK_JOBS=8^
249+
-DPYTHON_EXECUTABLE:PATH=%PYTHON_HOME%\python.exe^
250+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
251+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
252+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
253+
-S "%source_root%\swift" %exitOnError%
254+
255+
cmake --build "%build_root%\swift" %exitOnError%
256+
cmake --build "%build_root%\swift" --target install %exitOnError%
257+
258+
goto :eof
259+
endlocal
260+
261+
262+
:test_swift
263+
:: Tests the Swift compiler and the Swift Standard Library
264+
setlocal enableextensions enabledelayedexpansion
265+
266+
cmake --build "%build_root%\swift" --target check-swift %exitOnError%
267+
268+
goto :eof
269+
endlocal
270+
271+
272+
:build_lldb
273+
:: Configures, builds, and installs LLDB
274+
setlocal enableextensions enabledelayedexpansion
275+
276+
cmake^
277+
-B "%build_root%\lldb"^
278+
-G Ninja^
279+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
280+
-DCMAKE_C_COMPILER=clang-cl^
281+
-DCMAKE_CXX_COMPILER=clang-cl^
282+
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
283+
-DLLVM_DIR:PATH=%build_root%\llvm\lib\cmake\llvm^
284+
-DClang_DIR:PATH=%build_root%\llvm\lib\cmake\clang^
285+
-DSwift_DIR:PATH=%build_root%\swift\lib\cmake\swift^
286+
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
287+
-DLLDB_USE_STATIC_BINDINGS:BOOL=YES^
288+
-DPYTHON_HOME:PATH=%PYTHON_HOME%^
289+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
290+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
291+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
292+
-DLLDB_DISABLE_PYTHON=YES^
293+
-DLLDB_INCLUDE_TESTS:BOOL=NO^
294+
-S "%source_root%\lldb" %exitOnError%
295+
296+
cmake --build "%build_root%\lldb" %exitOnError%
297+
cmake --build "%build_root%\lldb" --target install %exitOnError%
298+
299+
goto :eof
300+
endlocal
301+
302+
303+
:build_libdispatch
304+
:: Configures, builds, and installs Dispatch
305+
setlocal enableextensions enabledelayedexpansion
306+
307+
cmake^
308+
-B "%build_root%\swift-corelibs-libdispatch"^
309+
-G Ninja^
310+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
311+
-DCMAKE_C_COMPILER=clang-cl^
312+
-DCMAKE_CXX_COMPILER=clang-cl^
313+
-DCMAKE_Swift_COMPILER=swiftc^
314+
-DSwift_DIR:PATH=%build_root%\swift\lib\cmake\swift^
315+
-DCMAKE_INSTALL_PREFIX:PATH=%install_directory%^
316+
-DCMAKE_C_COMPILER_TARGET=x86_64-unknown-windows-msvc^
317+
-DCMAKE_CXX_COMPILER_TARGET=x86_64-unknown-windows-msvc^
318+
-DENABLE_SWIFT:BOOL=YES^
319+
-DENABLE_TESTING:BOOL=YES^
320+
-DCMAKE_C_FLAGS:STRING="${CMAKE_C_FLAGS} --target=x86_64-unknown-windows-msvc /GS- /Oy /Gw /Gy"^
321+
-DCMAKE_CXX_FLAGS:STRING="${CMAKE_CXX_FLAGS} --target=x86_64-unknown-windows-msvc /GS- /Oy /Gw /Gy"^
322+
-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
323+
-DCMAKE_SHARED_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
324+
-DCMAKE_Swift_COMPILER_TARGET:STRING=x86_64-unknown-windows-msvc^
325+
-DCMAKE_Swift_FLAGS:STRING="-resource-dir \"%install_directory%\lib\swift\""^
326+
-DCMAKE_Swift_LINK_FLAGS:STRING="-resource-dir \"%install_directory%\lib\swift\""^
327+
-S "%source_root%\swift-corelibs-libdispatch" %exitOnError%
328+
329+
cmake --build "%build_root%\swift-corelibs-libdispatch" %exitOnError%
330+
cmake --build "%build_root%\swift-corelibs-libdispatch" --target install %exitOnError%
331+
332+
goto :eof
333+
endlocal
334+
335+
336+
:test_libdispatch
337+
:: Tests libdispatch C interface
338+
setlocal enableextensions enabledelayedexpansion
339+
340+
cmake --build "%build_root%\swift-corelibs-libdispatch" --target ExperimentalTest %exitOnError%
341+
342+
goto :eof
343+
endlocal
344+
345+
346+
:end

0 commit comments

Comments
 (0)