Skip to content

Commit a28c1c1

Browse files
committed
Android SDK build
1 parent 530626e commit a28c1c1

File tree

2 files changed

+29
-54
lines changed

2 files changed

+29
-54
lines changed

swift-ci/sdks/android/build

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ $HOST_TOOLCHAIN/bin/swift --version
3636
# ensure the correct Swift is first in the PATH
3737
export PATH=$HOST_TOOLCHAIN/bin:$PATH
3838

39-
# fetch the patches
40-
PATCHDIR=${SDKROOT}/patches
41-
if [[ ! -d ${PATCHDIR} ]]; then
42-
git clone https://github.com/finagolfin/swift-android-sdk.git ${PATCHDIR}
43-
fi
44-
4539
export ANDROID_NDK_HOME=${SDKROOT}/ndk/${NDK}
4640
export ANDROID_NDK=${ANDROID_NDK_HOME}
4741

@@ -61,5 +55,28 @@ if [[ ! -d ${SDKROOT}/src ]]; then
6155
scripts/fetch-source.sh --source-dir ${SDKROOT}/src
6256
fi
6357

64-
./scripts/build.sh --patch-dir ${PATCHDIR} --products-dir ${SDKROOT}/products --source-dir ${SDKROOT}/src --build-dir ${SDKROOT}/build --ndk-home ${ANDROID_NDK_HOME} --android-api ${API} --host-toolchain ${HOST_TOOLCHAIN} --archs $ARCH
58+
# fetch and apply the patches
59+
PATCHDIR=${SDKROOT}/patches
60+
if [[ ! -d ${PATCHDIR} ]]; then
61+
git clone https://github.com/finagolfin/swift-android-sdk.git ${PATCHDIR}
62+
fi
63+
64+
pushd ${SDKROOT}/src/swift-project
65+
# TODO: need to selectively apply patches based on release or not release
66+
git apply $PATCHDIR/swift-android.patch || true
67+
git apply -C1 $PATCHDIR/swift-android-ci.patch || true
68+
69+
# need to un-apply libandroid-spawn since we don't need it for API ???+
70+
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
71+
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
72+
# fix for Process.swift:953:57: error: value of optional type 'posix_spawnattr_t?' (aka 'Optional<OpaquePointer>') must be unwrapped to a value of type 'posix_spawnattr_t' (aka 'OpaquePointer')
73+
perl -pi -e 's%canImport\(Darwin\) \|\| os\(Android\) \|\| os\(OpenBSD\)%canImport\(Darwin\) || os\(AndroidXXX\) || os\(OpenBSD\)%g' swift-corelibs-foundation/Sources/Foundation/Process.swift
74+
75+
git apply $PATCHDIR/swift-android-ci-release.patch || true
76+
git apply $PATCHDIR/swift-android-testing-release.patch || true
77+
78+
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
79+
popd
80+
81+
./scripts/build.sh --products-dir ${SDKROOT}/products --source-dir ${SDKROOT}/src --build-dir ${SDKROOT}/build --ndk-home ${ANDROID_NDK_HOME} --android-api ${API} --host-toolchain ${HOST_TOOLCHAIN} --archs $ARCH
6582

swift-ci/sdks/android/scripts/build.sh

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,11 @@ source_dir=
108108
ndk_home=${ANDROID_NDK}
109109
build_dir=$(pwd)/build
110110
products_dir=
111-
patch_dir=
112111

113112
while [ "$#" -gt 0 ]; do
114113
case "$1" in
115114
--source-dir)
116115
source_dir="$2"; shift ;;
117-
--patch-dir)
118-
patch_dir="$2"; shift ;;
119116
--ndk-home)
120117
ndk_home="$2"; shift ;;
121118
--host-toolchain)
@@ -143,7 +140,7 @@ done
143140
# Change the commas for spaces
144141
archs="${archs//,/ }"
145142

146-
if [[ -z "$source_dir" || -z "$products_dir" || -z "$patch_dir" || -z "$ndk_home" || -z "$host_toolchain" ]]; then
143+
if [[ -z "$source_dir" || -z "$products_dir" || -z "$ndk_home" || -z "$host_toolchain" ]]; then
147144
usage
148145
exit 1
149146
fi
@@ -222,30 +219,10 @@ function run() {
222219
"$@"
223220
}
224221

225-
HOST=linux-x86_64
226-
ndktoolchain=$ndk_home/toolchains/llvm/prebuilt/$HOST
227-
228-
function export_toolchain_vars {
229-
# needed for libxml, but breaks Swift build-script,
230-
# so need to call unexport_toolchain_vars aferwards
231-
export AR=$ndktoolchain/bin/llvm-ar
232-
export AS=$ndktoolchain/bin/llvm-as
233-
export CC=$ndktoolchain/bin/$compiler_target_host-clang
234-
export CXX=$ndktoolchain/bin/$compiler_target_host-clang++
235-
export LD=$ndktoolchain/bin/ld
236-
export RANLIB=$ndktoolchain/bin/llvm-ranlib
237-
export STRIP=$ndktoolchain/bin/llvm-strip
238-
}
222+
#HOST=linux-x86_64
223+
HOST=$(uname -s -m | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
239224

240-
function unexport_toolchain_vars {
241-
export AR=
242-
export AS=
243-
export CC=
244-
export CXX=
245-
export LD=
246-
export RANLIB=
247-
export STRIP=
248-
}
225+
ndktoolchain=$ndk_home/toolchains/llvm/prebuilt/$HOST
249226

250227
for arch in $archs; do
251228
case $arch in
@@ -341,26 +318,10 @@ for arch in $archs; do
341318
quiet_pushd ${build_dir}/$arch/curl
342319
run ninja -j$parallel_jobs install
343320
quiet_popd
344-
345321
quiet_popd
346322

347323
header "Building Android SDK for ${compiler_target_host}"
348324
quiet_pushd ${source_dir}/swift-project
349-
# TODO: need to selectively apply patches based on release or not release
350-
git apply $patch_dir/swift-android.patch || true
351-
git apply -C1 $patch_dir/swift-android-ci.patch || true
352-
353-
# need to un-apply libandroid-spawn since we don't need it for API ???+
354-
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
355-
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
356-
# fix for Process.swift:953:57: error: value of optional type 'posix_spawnattr_t?' (aka 'Optional<OpaquePointer>') must be unwrapped to a value of type 'posix_spawnattr_t' (aka 'OpaquePointer')
357-
perl -pi -e 's%canImport\(Darwin\) \|\| os\(Android\) \|\| os\(OpenBSD\)%canImport\(Darwin\) || os\(AndroidXXX\) || os\(OpenBSD\)%g' swift-corelibs-foundation/Sources/Foundation/Process.swift
358-
359-
git apply $patch_dir/swift-android-ci-release.patch || true
360-
git apply $patch_dir/swift-android-testing-release.patch || true
361-
362-
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
363-
364325
# TODO: only for release (for some reason)
365326
LSP_BUILD="--sourcekit-lsp"
366327

@@ -371,11 +332,9 @@ for arch in $archs; do
371332
RelWithDebInfo) build_type_flag="--release-debuginfo" ;;
372333
esac
373334

374-
#./swift/utils/build-script --help
375-
376-
#--reconfigure \
377335
./swift/utils/build-script \
378336
$build_type_flag \
337+
--reconfigure \
379338
--no-assertions \
380339
--android \
381340
--android-ndk $ndk_home \
@@ -408,6 +367,5 @@ for arch in $archs; do
408367
echo "built: ${swiftc}"
409368

410369
quiet_popd
411-
412370
done
413371

0 commit comments

Comments
 (0)