Skip to content

Commit c648a71

Browse files
authored
Merge pull request swiftlang#24077 from drodriguez/temporary-windows-build-script
[windows] Add build script for Windows.
2 parents 5cb98bf + f23f3fe commit c648a71

File tree

1 file changed

+323
-0
lines changed

1 file changed

+323
-0
lines changed

utils/build-windows.bat

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
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=63_1
29+
30+
set "exitOnError=|| (exit /b)"
31+
set current_directory=%~dp0
32+
set current_directory=%current_directory:~0,-1%
33+
set source_root=%current_directory%\..\..
34+
35+
:: Resetting source_root with %CD% removes the ..\.. from the paths, and makes
36+
:: the output easier to read.
37+
cd %source_root%
38+
set source_root=%CD%
39+
40+
set build_root=%source_root%\build
41+
set install_directory=%build_root%\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr
42+
43+
mkdir %build_root%
44+
45+
call :clone_repositories %exitOnError%
46+
call :download_icu %exitOnError%
47+
:: TODO: Disabled until we need LLBuild/SwiftPM in this build script.
48+
:: call :download_sqlite3
49+
50+
call :build_llvm %exitOnError%
51+
path %PATH%;%install_directory%\bin
52+
53+
call :build_cmark %exitOnError%
54+
55+
call :prepare_platform_modules %exitOnError%
56+
call :build_swift %exitOnError%
57+
58+
call :build_lldb %exitOnError%
59+
60+
path %source_root%\icu-%icu_version%\bin64;%install_directory%\bin;%build_root%\swift\libdispatch-prefix\bin;%PATH%;%ProgramFiles%\Git\usr\bin
61+
call :test_swift %exitOnError%
62+
63+
goto :end
64+
endlocal
65+
66+
:clone_repositories
67+
:: Clones the repositories used by the Windows build.
68+
:: It supposes that the swift repository is already cloned by CI.
69+
:: It supposes the %CD% is the source root.
70+
setlocal enableextensions enabledelayedexpansion
71+
72+
git config --global core.autocrlf false
73+
git clone --depth 1 --single-branch https://github.com/apple/swift-cmark cmark %exitOnError%
74+
git clone --depth 1 --single-branch https://github.com/apple/swift-clang clang %exitOnError%
75+
git clone --depth 1 --single-branch https://github.com/apple/swift-llvm llvm %exitOnError%
76+
git clone --depth 1 --single-branch https://github.com/apple/swift-lldb lldb %exitOnError%
77+
git clone --depth 1 --single-branch https://github.com/apple/swift-compiler-rt compiler-rt %exitOnError%
78+
git clone --depth 1 --single-branch https://github.com/apple/swift-corelibs-libdispatch %exitOnError%
79+
80+
goto :eof
81+
endlocal
82+
83+
84+
:download_icu
85+
:: Downloads ICU, which will be used as a dependency for the Swift Standard
86+
:: Library and Foundation.
87+
setlocal enableextensions enabledelayedexpansion
88+
89+
set file_name=icu4c-%icu_version%-Win64-MSVC2017.zip
90+
curl -L -O -z %file_name% "http://download.icu-project.org/files/icu4c/63.1/%file_name%" %exitOnError%
91+
:: unzip warns about the paths in the zip using slashes, which raises the
92+
:: errorLevel to 1. We cannot use exitOnError, and have to ignore errors.
93+
unzip -o %file_name% -d "%source_root%\icu-%icu_version%"
94+
exit /b 0
95+
96+
goto :eof
97+
endlocal
98+
99+
100+
:download_sqlite3
101+
:: Downloads SQLite3, which will be used as a dependency for llbuild and
102+
:: Swift Package Manager.
103+
setlocal enableextensions enabledelayedexpansion
104+
105+
set file_name=sqlite-amalgamation-3270200.zip
106+
curl -L -O "https://www.sqlite.org/2019/%file_name%" %exitOnError%
107+
unzip -o %file_name% %exitOnError%
108+
109+
goto :eof
110+
endlocal
111+
112+
113+
:prepare_platform_modules
114+
:: Create files into the right places of the Windows SDK to the files in the
115+
:: swift repository, in order to consider the headers of the Windows SDK a
116+
:: module to compile Swift code against them.
117+
setlocal enableextensions enabledelayedexpansion
118+
119+
copy /y "%source_root%\swift\stdlib\public\Platform\ucrt.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap" %exitOnError%
120+
copy /y "%source_root%\swift\stdlib\public\Platform\winsdk.modulemap" "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap" %exitOnError%
121+
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.modulemap" "%VCToolsInstallDir%\include\module.modulemap" %exitOnError%
122+
copy /y "%source_root%\swift\stdlib\public\Platform\visualc.apinotes" "%VCToolsInstallDir%\include\visualc.apinotes" %exitOnError%
123+
124+
goto :eof
125+
endlocal
126+
127+
128+
:build_llvm
129+
:: Configures, builds, and installs LLVM
130+
setlocal enableextensions enabledelayedexpansion
131+
132+
mkdir "%build_root%\llvm" %exitOnError%
133+
pushd "%build_root%\llvm"
134+
135+
cmake "%source_root%\llvm"^
136+
-G Ninja^
137+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
138+
-DCMAKE_C_COMPILER=cl^
139+
-DCMAKE_CXX_COMPILER=cl^
140+
-DCMAKE_INSTALL_PREFIX=%install_directory%^
141+
-DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-windows-msvc^
142+
-DLLVM_ENABLE_PDB:BOOL=YES^
143+
-DLLVM_ENABLE_ASSERTIONS:BOOL=YES^
144+
-DLLVM_ENABLE_PROJECTS:STRING=clang^
145+
-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;X86"^
146+
-DLLVM_INCLUDE_BENCHMARKS:BOOL=NO^
147+
-DLLVM_INCLUDE_DOCS:BOOL=NO^
148+
-DLLVM_INCLUDE_EXAMPLES:BOOL=NO^
149+
-DLLVM_INCLUDE_GO_TESTS:BOOL=NO^
150+
-DLLVM_TOOL_GOLD_BUILD:BOOL=NO^
151+
-DLLVM_ENABLE_OCAMLDOC:BOOL=NO^
152+
-DLLVM_ENABLE_LIBXML2:BOOL=NO^
153+
-DLLVM_ENABLE_ZLIB:BOOL=NO^
154+
-DENABLE_X86_RELAX_RELOCATIONS:BOOL=YES^
155+
-DLLVM_INSTALL_BINUTILS_SYMLINKS:BOOL=YES^
156+
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=YES^
157+
-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"^
158+
-DCLANG_TOOLS="clang;clang-format;clang-headers;clang-tidy"^
159+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
160+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
161+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO %exitOnError%
162+
163+
popd
164+
165+
cmake --build "%build_root%\llvm" %exitOnError%
166+
cmake --build "%build_root%\llvm" --target install %exitOnError%
167+
168+
goto :eof
169+
endlocal
170+
171+
172+
:build_cmark
173+
:: Configures and builds CMark
174+
setlocal enableextensions enabledelayedexpansion
175+
176+
mkdir "%build_root%\cmark" %exitOnError%
177+
pushd "%build_root%\cmark"
178+
179+
cmake "%source_root%\cmark"^
180+
-G Ninja^
181+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
182+
-DCMAKE_C_COMPILER=cl^
183+
-DCMAKE_CXX_COMPILER=cl^
184+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
185+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
186+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO %exitOnError%
187+
188+
popd
189+
190+
cmake --build "%build_root%\cmark" %exitOnError%
191+
192+
goto :eof
193+
endlocal
194+
195+
196+
:build_swift
197+
:: Configures, builds, and installs Swift and the Swift Standard Library
198+
setlocal enableextensions enabledelayedexpansion
199+
200+
mkdir "%build_root%\swift" %exitOnError%
201+
pushd "%build_root%\swift"
202+
203+
:: SWIFT_PARALLEL_LINK_JOBS=8 allows the build machine to use as many CPU as
204+
:: possible, while not exhausting the RAM.
205+
cmake "%source_root%\swift"^
206+
-G Ninja^
207+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
208+
-DCMAKE_C_COMPILER=cl^
209+
-DCMAKE_CXX_COMPILER=cl^
210+
-DCMAKE_INSTALL_PREFIX=%install_directory%^
211+
-DClang_DIR=%build_root%\llvm\lib\cmake\clang^
212+
-DSWIFT_PATH_TO_CMARK_BUILD=%build_root%\cmark^
213+
-DSWIFT_PATH_TO_CMARK_SOURCE=%source_root%\cmark^
214+
-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=%source_root%\swift-corelibs-libdispatch^
215+
-DLLVM_DIR=%build_root%\llvm\lib\cmake\llvm^
216+
-DSWIFT_INCLUDE_DOCS=NO^
217+
-DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE=%source_root%\icu-%icu_version%\include\unicode^
218+
-DSWIFT_WINDOWS_x86_64_ICU_UC=%source_root%\icu-%icu_version%\lib64\icuuc.lib^
219+
-DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE=%source_root%\icu-%icu_version%\include^
220+
-DSWIFT_WINDOWS_x86_64_ICU_I18N=%source_root%\icu-%icu_version%\lib64\icuin.lib^
221+
-DSWIFT_BUILD_DYNAMIC_STDLIB=YES^
222+
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY=YES^
223+
-DSWIFT_BUILD_STATIC_STDLIB=NO^
224+
-DSWIFT_BUILD_STATIC_SDK_OVERLAY=NO^
225+
-DLLVM_INSTALL_TOOLCHAIN_ONLY=YES^
226+
-DSWIFT_BUILD_SOURCEKIT=YES^
227+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=NO^
228+
-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"^
229+
-DSWIFT_PARALLEL_LINK_JOBS=8^
230+
-DPYTHON_EXECUTABLE=%PYTHON_HOME%\python.exe^
231+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
232+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
233+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO %exitOnError%
234+
235+
popd
236+
237+
cmake --build "%build_root%\swift" %exitOnError%
238+
cmake --build "%build_root%\swift" --target install %exitOnError%
239+
240+
goto :eof
241+
endlocal
242+
243+
244+
:test_swift
245+
:: Tests the Swift compiler and the Swift Standard Library
246+
setlocal enableextensions enabledelayedexpansion
247+
248+
cmake --build "%build_root%\swift" --target check-swift %exitOnError%
249+
250+
goto :eof
251+
endlocal
252+
253+
254+
:build_lldb
255+
:: Configures, builds, and installs LLDB
256+
setlocal enableextensions enabledelayedexpansion
257+
258+
mkdir "%build_root%\lldb" %exitOnError%
259+
pushd "%build_root%\lldb"
260+
261+
cmake "%source_root%\lldb"^
262+
-G Ninja^
263+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
264+
-DCMAKE_C_COMPILER=clang-cl^
265+
-DCMAKE_CXX_COMPILER=clang-cl^
266+
-DCMAKE_INSTALL_PREFIX=%install_directory%^
267+
-DLLDB_PATH_TO_CMARK_SOURCE=%source_root%\cmark^
268+
-DLLDB_PATH_TO_CLANG_SOURCE=%source_root%\clang^
269+
-DLLDB_PATH_TO_LLVM_SOURCE=%source_root%\llvm^
270+
-DLLDB_PATH_TO_SWIFT_SOURCE=%source_root%\swift^
271+
-DLLDB_PATH_TO_CMARK_BUILD=%build_root%\cmark^
272+
-DLLDB_PATH_TO_CLANG_BUILD=%build_root%\llvm^
273+
-DLLDB_PATH_TO_LLVM_BUILD=%build_root%\llvm^
274+
-DLLDB_PATH_TO_SWIFT_BUILD=%build_root%\swift^
275+
-DLLVM_ENABLE_ASSERTIONS=YES^
276+
-DLLVM_ALLOW_STATIC_BINDINGS=YES^
277+
-DPYTHON_HOME=%PYTHON_HOME%^
278+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
279+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
280+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO %exitOnError%
281+
282+
popd
283+
284+
cmake --build "%build_root%\lldb" %exitOnError%
285+
cmake --build "%build_root%\lldb" --target install %exitOnError%
286+
287+
goto :eof
288+
endlocal
289+
290+
291+
:build_lldb
292+
:: Configures, builds, and installs Dispatch
293+
setlocal enableextensions enabledelayedexpansion
294+
295+
mkdir "%build_root%\swift-corelibs-libdispatch" %exitOnError%
296+
pushd "%build_root%\swift-corelibs-libdispatch"
297+
298+
cmake "%source_root%\swift-corelibs-libdispatch"^
299+
-G Ninja^
300+
-DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%^
301+
-DCMAKE_C_COMPILER=clang-cl^
302+
-DCMAKE_CXX_COMPILER=clang-cl^
303+
-DCMAKE_SWIFT_COMPILER=%install_directory%\bin\swiftc.exe^
304+
-DSwift_DIR=%build_root%\swift\lib\cmake\swift^
305+
-DCMAKE_INSTALL_PREFIX=%install_directory%^
306+
-DBUILD_SHARED_LIBS=YES^
307+
-DENABLE_TESTING=NO^
308+
-DCMAKE_C_COMPILER_TARGET=x86_64-unknown-windows-msvc^
309+
-DENABLE_SWIFT=YES^
310+
-DCMAKE_CXX_FLAGS:STRING="/GS- /Oy"^
311+
-DCMAKE_EXE_LINKER_FLAGS:STRING=/INCREMENTAL:NO^
312+
-DCMAKE_SHARED_LINKER_FLAGS:STRING=/INCREMENTAL:NO %exitOnError%
313+
314+
popd
315+
316+
cmake --build "%build_root%\swift-corelibs-libdispatch" %exitOnError%
317+
cmake --build "%build_root%\swift-corelibs-libdispatch" --target install %exitOnError%
318+
319+
goto :eof
320+
endlocal
321+
322+
323+
:end

0 commit comments

Comments
 (0)