Skip to content

Commit 57e06fe

Browse files
committed
1 parent b583ff8 commit 57e06fe

File tree

5 files changed

+67
-41
lines changed

5 files changed

+67
-41
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ jobs:
6161
df -h
6262
- name: Checkout repository
6363
uses: actions/checkout@v4
64-
- name: Install Dependencies
65-
run: |
66-
sudo apt install -q ninja-build patchelf
6764
- name: Build Android SDK in Docker
65+
continue-on-error: true
6866
working-directory: swift-ci/sdks/android
6967
run: |
7068
BUILD_VERSION=${{ matrix.swift-version }} TARGET_ARCHS=${{ matrix.arch }} ./build
69+
- name: Install Dependencies
70+
run: |
71+
sudo apt install -q ninja-build patchelf
7172
- name: Build Android SDK
7273
working-directory: swift-ci/sdks/android
7374
run: |

swift-ci/sdks/android/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ RUN apt-get -q update \
4242
uuid-runtime \
4343
tzdata \
4444
curl \
45+
unzip \
4546
&& rm -rf /var/lib/apt-lists/*
4647

4748
# Install Swift
@@ -60,12 +61,18 @@ ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
6061

6162
COPY scripts/install-swift.sh /scripts/install-swift.sh
6263
RUN chmod ugo+x /scripts/install-swift.sh
63-
6464
RUN /scripts/install-swift.sh
65-
6665
ENV PATH="/usr/local/swift/bin:${PATH}"
6766

67+
68+
ARG NDK_VERSION=android-ndk-r27c
69+
70+
ENV NDK_VERSION=$NDK_VERSION
71+
72+
COPY scripts/install-ndk.sh /scripts/install-ndk.sh
73+
RUN chmod ugo+x /scripts/install-ndk.sh
6874
RUN /scripts/install-ndk.sh
75+
ENV ANDROID_NDK_HOME="/usr/local/ndk/${NDK_VERSION}"
6976

7077
ENV SWIFT_VERSION=$SWIFT_VERSION \
7178
LIBXML2_VERSION=$LIBXML2_VERSION \

swift-ci/sdks/android/build-local

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,41 +74,5 @@ if [[ ! -d ${SDKROOT}/src ]]; then
7474
scripts/fetch-source.sh --source-dir ${SDKROOT}/src --swift-tag ${SWIFT_TAG}
7575
fi
7676

77-
# fetch and apply the patches
78-
PATCHDIR=${SDKROOT}/patches
79-
if [[ ! -d ${PATCHDIR} ]]; then
80-
git clone https://github.com/finagolfin/swift-android-sdk.git ${PATCHDIR}
81-
82-
# TODO: need to selectively apply patches based on release or not release
83-
pushd ${SDKROOT}/src/swift-project
84-
echo "Applying patches"
85-
86-
# patch the patch, which seems to only be needed for an API less than 28
87-
# https://github.com/finagolfin/swift-android-sdk/blob/main/swift-android.patch#L110
88-
perl -pi -e 's/#if os\(Windows\)/#if os\(Android\)/g' $PATCHDIR/swift-android.patch
89-
90-
# remove the need to link in android-execinfo
91-
perl -pi -e 's/dispatch android-execinfo/dispatch/g' $PATCHDIR/swift-android.patch
92-
93-
git apply -v $PATCHDIR/swift-android.patch
94-
# swift-android-ci.patch is not needed, since it is only used for llbuild, etc.
95-
#git apply -C1 $PATCHDIR/swift-android-ci.patch
96-
#git apply -v $PATCHDIR/swift-android-ci-release.patch
97-
if [ "${BUILD_VERSION}" = 'release' ]; then
98-
git apply -v $PATCHDIR/swift-android-testing-release.patch
99-
else
100-
git apply -v $PATCHDIR/swift-android-testing-except-release.patch
101-
fi
102-
103-
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
104-
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
105-
perl -pi -e 's/os\(Android\)/os\(AndroidDISABLED\)/g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
106-
107-
# need to un-apply libandroid-spawn since we don't need it for API28+
108-
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
109-
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
110-
popd
111-
fi
112-
11377
./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} ${@}
11478

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,53 @@ function run() {
238238
"$@"
239239
}
240240

241+
header "Patching Sources"
242+
243+
quiet_pushd ${source_dir}
244+
PATCHDIR="${resource_dir}/patches"
245+
patch=$(realpath "${PATCHDIR}/swift-android.patch")
246+
247+
# patch the patch, which seems to only be needed for an API less than 28
248+
# https://github.com/finagolfin/swift-android-sdk/blob/main/swift-android.patch#L110
249+
perl -pi -e 's/#if os\(Windows\)/#if os\(Android\)/g' $patch
250+
251+
# remove the need to link in android-execinfo
252+
perl -pi -e 's/dispatch android-execinfo/dispatch/g' $patch
253+
254+
if git apply --reverse --check "$patch" >/dev/null 2>&1; then
255+
echo "already patched"
256+
elif git apply "$patch" >/dev/null 2>&1; then
257+
echo "done"
258+
else
259+
echo "failed"
260+
exit 1
261+
fi
262+
263+
if [ "${BUILD_VERSION}" = 'release' ]; then
264+
testing_patch=$(realpath "${PATCHDIR}/swift-android-testing-release.patch")
265+
else
266+
testing_patch=$(realpath "${PATCHDIR}/swift-android-testing-except-release.patch")
267+
fi
268+
269+
if git apply --reverse --check "$testing_patch" >/dev/null 2>&1; then
270+
echo "already patched"
271+
elif git apply "$testing_patch" >/dev/null 2>&1; then
272+
echo "done"
273+
else
274+
echo "failed"
275+
exit 1
276+
fi
277+
278+
perl -pi -e 's%String\(cString: getpass%\"fake\" //%' swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift
279+
# disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport)
280+
perl -pi -e 's/os\(Android\)/os\(AndroidDISABLED\)/g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift
281+
282+
# need to un-apply libandroid-spawn since we don't need it for API28+
283+
perl -pi -e 's/MATCHES "Android"/MATCHES "AndroidDISABLED"/g' llbuild/lib/llvm/Support/CMakeLists.txt
284+
perl -pi -e 's/ STREQUAL Android\)/ STREQUAL AndroidDISABLED\)/g' swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
285+
286+
quiet_popd
287+
241288
for arch in $archs; do
242289
# enable short-circuiting the individual builds
243290
if [[ ! -z "$SWIFT_ANDROID_ARCHIVEONLY" ]]; then

swift-ci/sdks/android/scripts/install-ndk.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ set -e
1010

1111
echo "Installing Android NDK"
1212

13+
mkdir -p /usr/local/ndk
14+
pushd /usr/local/ndk >/dev/null
15+
NDKFILE=${NDK_VERSION}-linux.zip
16+
curl -fsSL "https://dl.google.com/android/repository/${NDKFILE}" -o ${NDKFILE}
17+
unzip -q ${NDKFILE}
18+
rm ${NDKFILE}
19+
popd >/dev/null
1320

0 commit comments

Comments
 (0)