Skip to content

Commit ae612f2

Browse files
committed
1 parent db2c0db commit ae612f2

File tree

4 files changed

+67
-46
lines changed

4 files changed

+67
-46
lines changed

swift-ci/sdks/android/build-docker

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ ANDROID_NDK_VERSION=android-ndk-r27c
3333
$DOCKER build --build-arg OS_ARCH_SUFFIX=$OS_ARCH_SUFFIX --build-arg SWIFT_TOOLCHAIN_URL=$SWIFT_TOOLCHAIN_URL --build-arg ANDROID_NDK_VERSION=$ANDROID_NDK_VERSION -t swift-android .
3434

3535
# Check-out the sources
36-
scripts/fetch-source.sh --source-dir source --swift-tag ${SWIFT_TAG}
36+
./scripts/fetch-source.sh --source-dir source --swift-tag ${SWIFT_TAG}
37+
38+
./scripts/patch-sources.sh source
3739

3840
mkdir -p products
3941

swift-ci/sdks/android/build-local

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ mkdir -p ${SDKROOT}/products
5353

5454
./scripts/fetch-source.sh --source-dir ${SDKROOT}/src --swift-tag ${SWIFT_TAG}
5555

56+
./scripts/patch-sources.sh ${SDKROOT}/src
57+
5658
./scripts/build.sh --products-dir ${SDKROOT}/products --source-dir ${SDKROOT}/src --build-dir ${SDKROOT}/build --ndk-home ${ANDROID_NDK_HOME} --android-api ${ANDROID_API} --host-toolchain ${HOST_TOOLCHAIN} --archs ${TARGET_ARCHS} ${@}
5759

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ if ! swiftc=$(which swiftc); then
165165
exit 1
166166
fi
167167

168-
script_dir=$(dirname -- "${BASH_SOURCE[0]}")
169-
resource_dir=$(realpath "${script_dir}/../resources")
170-
patches_dir="${resource_dir}/patches"
171-
172168
# Find the version numbers of the various dependencies
173169
function describe {
174170
pushd $1 >/dev/null 2>&1
@@ -235,47 +231,6 @@ function run() {
235231
"$@"
236232
}
237233

238-
header "Patching Sources"
239-
240-
quiet_pushd ${source_dir}/swift-project
241-
swift_android_patch="${patches_dir}/swift-android.patch"
242-
243-
# patch the patch, which seems to only be needed for an API less than 28
244-
# https://github.com/finagolfin/swift-android-sdk/blob/main/swift-android.patch#L110
245-
perl -pi -e 's/#if os\(Windows\)/#if os\(Android\)/g' $swift_android_patch
246-
247-
# remove the need to link in android-execinfo
248-
perl -pi -e 's/dispatch android-execinfo/dispatch/g' $swift_android_patch
249-
250-
if [ "${BUILD_VERSION}" = 'release' ]; then
251-
testing_patch="${patches_dir}/swift-android-testing-release.patch"
252-
else
253-
testing_patch="${patches_dir}/swift-android-testing-except-release.patch"
254-
fi
255-
256-
for patch in "$swift_android_patch" "$testing_patch"; do
257-
echo "applying patch $patch in $PWD"
258-
259-
if git apply -C1 --reverse --check "$patch" >/dev/null 2>&1 ; then
260-
echo "already patched"
261-
elif git apply -C1 "$patch" ; then
262-
echo "done"
263-
else
264-
echo "failed to apply patch $patch in $PWD"
265-
exit 1
266-
fi
267-
done
268-
269-
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
270-
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
271-
perl -pi -e 's/os\(Android\)/os\(AndroidDISABLED\)/g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
272-
273-
# need to un-apply libandroid-spawn since we don't need it for API28+
274-
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
275-
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
276-
277-
quiet_popd
278-
279234
for arch in $archs; do
280235
# enable short-circuiting the individual builds
281236
if [[ ! -z "$SWIFT_ANDROID_ARCHIVEONLY" ]]; then
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Swift Android SDK: Patch Sources
3+
set -e
4+
5+
source_dir=$1
6+
7+
if [[ ! -d "${source_dir}" ]]; then
8+
echo "$0: source_dir ${source_dir} does not exist"
9+
exit 1
10+
fi
11+
12+
script_dir=$(dirname -- "${BASH_SOURCE[0]}")
13+
resource_dir=$(realpath "${script_dir}/../resources")
14+
patches_dir="${resource_dir}/patches"
15+
16+
if [[ ! -d "${patches_dir}" ]]; then
17+
echo "$0: patches_dir ${patches_dir} does not exist"
18+
exit 1
19+
fi
20+
21+
if [[ "${BUILD_VERSION}" == "" ]]; then
22+
echo "$0: BUILD_VERSION environment is not set"
23+
exit 1
24+
fi
25+
26+
cd ${source_dir}/swift-project
27+
swift_android_patch="${patches_dir}/swift-android.patch"
28+
29+
# patch the patch, which seems to only be needed for an API less than 28
30+
# https://github.com/finagolfin/swift-android-sdk/blob/main/swift-android.patch#L110
31+
perl -pi -e 's/#if os\(Windows\)/#if os\(Android\)/g' $swift_android_patch
32+
33+
# remove the need to link in android-execinfo
34+
perl -pi -e 's/dispatch android-execinfo/dispatch/g' $swift_android_patch
35+
36+
if [ "${BUILD_VERSION}" = 'release' ]; then
37+
testing_patch="${patches_dir}/swift-android-testing-release.patch"
38+
else
39+
testing_patch="${patches_dir}/swift-android-testing-except-release.patch"
40+
fi
41+
42+
for patch in "$swift_android_patch" "$testing_patch"; do
43+
echo "applying patch $patch in $PWD"
44+
45+
if git apply -C1 --reverse --check "$patch" >/dev/null 2>&1 ; then
46+
echo "already patched"
47+
elif git apply -C1 "$patch" ; then
48+
echo "done"
49+
else
50+
echo "failed to apply patch $patch in $PWD"
51+
exit 1
52+
fi
53+
done
54+
55+
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
56+
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
57+
perl -pi -e 's/os\(Android\)/os\(AndroidDISABLED\)/g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
58+
59+
# need to un-apply libandroid-spawn since we don't need it for API28+
60+
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
61+
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
62+

0 commit comments

Comments
 (0)