Skip to content

Commit a9daa00

Browse files
authored
Merge pull request #26298 from compnerd/android-sdk-cross-compilation
docs: add initial documentation for android SDK
2 parents 1ef9dff + 0f25b88 commit a9daa00

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

docs/AndroidBuild.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Building Swift SDK for Android on Windows
2+
3+
Visual Studio 2019 or newer is needed to build the Swift SDK for Android on
4+
Windows.
5+
6+
## 1. Install Dependencies
7+
- Install the latest version of [Visual Studio](https://www.visualstudio.com/downloads/)
8+
- Make sure to include the android NDK in your installation.
9+
10+
## 1. Clone the repositories
11+
1. Configure git to work with Unix file endings
12+
1. Clone `apple/swift-llvm` into a directory named `llvm`
13+
1. Clone `apple/swift-corelibs-libdispatch` into a directory named `swift-corelibs-libdispatch`
14+
1. Clone `apple/swift-corelibs-foundation` into a directory named `swift-corelibs-foundation`G
15+
1. Clone `apple/swift-corelibs-xctest` into a directory named `swift-corelibs-xctest`
16+
1. Clone `compnerd/swift-windows` into a directory named `swift-windows`
17+
18+
- Currently, other repositories in the Swift project have not been tested and
19+
may not be supported.
20+
21+
This guide assumes that your sources live at the root of `S:`. If your sources
22+
live elsewhere, you can create a subsitution for this:
23+
24+
```cmd
25+
subst S: <path to sources>
26+
```
27+
28+
```cmd
29+
S:
30+
git clone https://github.com/apple/swift-llvm llvm
31+
git clone https://github.com/apple/swift-corelibs-libdispatch swift-corelibs-libdispatch
32+
git clone https://github.com/apple/swift-corelibs-foundation swift-corelibs-foundation
33+
git clone https://github.com/apple/swift-corelibs-xctest swift-corelibs-xctest
34+
git clone https://github.com/compnerd/swift-windows swift-windows
35+
```
36+
37+
## 1. Acquire the lastest toolchain and dependencies
38+
39+
1. Download the toolchain, ICU, libxml2, and curl for android from
40+
[Azure](https://dev.azure.com/compnerd/windows-swift) into `S:\b\a\Library`.
41+
42+
- You can alternatively use `Download-AndroidArtifacts.ps1` from
43+
[compnerd/windows-swift](https://www.github.com/compnerd/windows-swift) under
44+
the utilities directory. This will implicitly setup the requisite directory
45+
structure.
46+
47+
## 1. Configure LLVM
48+
49+
```cmd
50+
md S:\b\a\llvm
51+
cd S:\b\a\llvm
52+
cmake -C S:\swift-windows\cmake\caches\android-armv7.cmake ^
53+
-G Ninja ^
54+
-DCMAKE_BUILD_TYPE=Release ^
55+
-DCMAKE_TOOLCHAIN_FILE=S:\swift-windows\cmake\toolchains\android.toolchain.cmake ^
56+
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
57+
-DLLVM_HOST_TRIPLE=armv7-unknown-linux-androideabi ^
58+
S:/llvm
59+
```
60+
61+
## 1. Build and install the standard library
62+
63+
- We must build and install the standard library to build the remainder of the
64+
SDK
65+
66+
```cmd
67+
md S:\b\a\stdlib
68+
cd S:\b\a\stdlib
69+
cmake -C S:\windows-swift\cmake\caches\android-armv7.cmake ^
70+
-C S:\windows-swift\cmake\caches\swift-stdlib-android-armv7.cmake ^
71+
-G Ninja ^
72+
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
73+
-DCMAKE_INSTALL_PREFIX=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk/usr ^
74+
-DCMAKE_TOOLCHAIN_FILE=S:\windows-swift\cmake\toolchains\android.toolchain.cmake ^
75+
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
76+
-DLLVM_DIR=S:/b/a/llvm/lib/cmake/llvm ^
77+
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin ^
78+
-DSWIFT_ANDROID_armv7_ICU_UC_INCLUDE=S:/b/a/Library/icu-64/usr/include/unicode ^
79+
-DSWIFT_ANDROID_armv7_ICU_UC=S:/b/a/Library/icu-64/usr/lib/libicuuc64.so ^
80+
-DSWIFT_ANDROID_armv7_ICU_I18N_INCLUDE=S:/b/a/Library/icu-64/usr/include ^
81+
-DSWIFT_ANDROID_armv7_ICU_I18N=S:/b/a/Library/icu-64/usr/lib/libicuin64.so ^
82+
S:/swift
83+
ninja
84+
ninja install
85+
```
86+
87+
## 1. Build libdispatch
88+
89+
- We *cannot* install libdispatch until after all builds are complete as that
90+
will cause the Dispatch module to be imported twice and fail to build.
91+
92+
```cmd
93+
md S:\b\a\libdispatch
94+
cd S:\b\a\libdispatch
95+
cmake -C S:\windows-swift\cmake\caches\android-armv7.cmake ^
96+
-DSWIFT_ANDROID_SDK=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk ^
97+
-C S:\windows-swift\cmake\caches\android-armv7-swift-flags.cmake ^
98+
-G Ninja ^
99+
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
100+
-DCMAKE_INSTALL_PREFIX=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk/usr ^
101+
-DCMAKE_SWIFT_COMPILER=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe ^
102+
-DCMAKE_TOOLCHAIN_FILE=S:\windows-swift\cmake\toolchains\android.toolchain.cmake ^
103+
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
104+
-DENABLE_SWIFT=YES ^
105+
-DENABLE_TESTING=NO ^
106+
S:/swift-corelibs-libdispatch
107+
ninja
108+
```
109+
110+
## 1. Build foundation
111+
112+
```cmd
113+
md S:\b\a\foundation
114+
cd S:\b\a\foundation
115+
cmake -C S:\windows-swift\cmake\caches\android-armv7.cmake ^
116+
-DSWIFT_ANDROID_SDK=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk ^
117+
-C S:\windows-swift\cmake\caches\android-armv7-swift-flags.cmake ^
118+
-G Ninja ^
119+
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
120+
-DCMAKE_INSTALL_PREFIX=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk/usr ^
121+
-DCMAKE_SWIFT_COMPILER=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe ^
122+
-DCMAKE_TOOLCHAIN_FILE=S:\windows-swift\cmake\toolchains\android.toolchain.cmake ^
123+
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
124+
-DCURL_LIBRARY=S:/b/a/Library/libcurl-development/usr/lib/libcurl.a ^
125+
-DCURL_INCLUDE_DIR=S:/b/a/Library/libcurl-development/usr/include ^
126+
-DICU_INCLUDE_DIR=S:/b/a/Library/icu-64/usr/include ^
127+
-DICU_UC_LIBRARY=S:/b/a/Library/icu-64/usr/lib/libicuuc64.so ^
128+
-DICU_UC_LIBRARY_RELEASE=S:/b/a/Library/icu-64/usr/lib/libicuuc64.so ^
129+
-DICU_I18N_LIBRARY=S:/b/a/Library/icu-64/usr/lib/libiucin64.so ^
130+
-DICU_I18N_LIBRARY_RELEASE=S:/b/a/Library/icu-64/usr/lib/libicuin64.so ^
131+
-DLIBXML2_LIBRARY=S:/b/a/Library/libxml2-development/usr/lib/libxml2.a ^
132+
-DLIBXML2_INCLUDE_DIR=S:/b/a/Library/libxml2-development/usr/include/libxml2 ^
133+
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=S:/swift-corelibs-libdispatch ^
134+
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=S:/b/a/libdispatch ^
135+
S:/swift-corelibs-foundation
136+
ninja
137+
```
138+
139+
## 1. Build XCTest
140+
141+
```cmd
142+
md S:\b\a\xctest
143+
cd S:\b\a\xctest
144+
cmake -C S:\swift-windows\cmake\caches\android-armv7.cmake ^
145+
-C S:\swift-windows\cmake\caches\android-armv7-swift-flags.cmake ^
146+
-G Ninja ^
147+
-DCMAKE_BUILD_TYPE=RelWithDebInfo ^
148+
-DCMAKE_INSTALL_PREFIX=S:/b/a/Library/Developer/Platforms/android.platform/Developer/SDKs/android.sdk/usr ^
149+
-DCMAKE_SWIFT_COMPILER=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe ^
150+
-DCMAKE_TOOLCHAIN_FILE=S:\swift-windows\cmake\toolchains\android.toolchain.cmake ^
151+
-DANDROID_ALTERNATE_TOOLCHAIN=S:/b/a/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ^
152+
-DSWIFT_ANDROID_SDK=S:/b/a/Library/Developer/Platforms/andrfoid.platform/Developer/SDKs/android.sdk ^
153+
-DXCTEST_PATH_TO_FOUNDATION_BUILD=S:/b/a/foundation ^
154+
-DXCTEST_PATH_TO_LIBDISPATCH_SOURCE=S:/swift-corelibs-libdispatch ^
155+
-DXCTEST_PATH_TO_LIBDISPATCH_BUILD=S:/b/a/libdispatch ^
156+
-DENABLE_TESTING=NO ^
157+
S:/swift-corelibs-foundation
158+
ninja
159+
```
160+
161+
## 1. Install libdispatch
162+
163+
```cmd
164+
cd S:\b\a\libdispatch
165+
ninja install
166+
```
167+
168+
## 1. Install Foundation
169+
170+
```cmd
171+
cd S:\b\a\foundation
172+
ninja install
173+
```
174+
175+
## 1. Install XCTest
176+
177+
```cmd
178+
cd S:\b\a\xctest
179+
ninja install
180+
```
181+

0 commit comments

Comments
 (0)