Skip to content

Commit 73ebe28

Browse files
committed
Swift Androd build
1 parent 652b8b8 commit 73ebe28

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

.github/workflows/pull_request.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535
run: ./build
3636

3737
android-build:
38-
#name: Build Android ${{ matrix.arch }} SDK
39-
#strategy:
40-
#fail-fast: false
41-
#matrix:
42-
# arch: [armv7,aarch64,x86_64]
43-
name: Build Android SDK
38+
name: Build Android ${{ matrix.arch }} SDK
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
arch: ['x86_64', 'armv7,aarch64,x86_64']
43+
#name: Build Android SDK
4444
runs-on: ubuntu-24.04
4545
steps:
4646
- name: Checkout repository
@@ -79,13 +79,13 @@ jobs:
7979
cd ${{ runner.temp }}
8080
git clone https://github.com/apple/swift-algorithms.git
8181
cd swift-algorithms
82-
${{ steps.paths.outputs.swift-path }} build --build-tests --swift-sdk x86_64-unknown-linux-android
82+
${{ steps.paths.outputs.swift-path }} build --build-tests --swift-sdk x86_64-unknown-linux-android28
8383
- name: Test swift-algorithms on Android
8484
uses: skiptools/swift-android-action@main
8585
with:
8686
#package-path: ${{ runner.temp }}/DemoProject
8787
package-path: ${{ runner.temp }}/swift-algorithms
88-
installed-sdk: x86_64-unknown-linux-android
88+
installed-sdk: x86_64-unknown-linux-android28
8989
installed-swift: ${{ steps.paths.outputs.swift-root }}
9090
- name: Build Demo Project
9191
if: false
@@ -101,4 +101,4 @@ jobs:
101101
echo 'import FoundationNetworking' >> Sources/DemoProject/DemoProject.swift
102102
echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift
103103
echo 'import Android' >> Sources/DemoProject/DemoProject.swift
104-
${{ steps.paths.outputs.swift-path }} build --build-tests --swift-sdk x86_64-unknown-linux-android
104+
${{ steps.paths.outputs.swift-path }} build --build-tests --swift-sdk x86_64-unknown-linux-android28

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

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -395,19 +395,13 @@ done
395395
# Now generate the bundle
396396
groupstart "Bundling SDK"
397397

398-
sdk_name=swift-${swift_version}-android-${android_api}-${android_sdk_version}
399-
#sdk_base=android-27c-sysroot
400-
#sdk_base=swift-unknown-android
401-
#sdk_base=linux-android
402398
sdk_base=swift-android
403-
#sdk_root="${sdk_base}-${android_sdk_version}.sdk"
404-
sdk_root="${sdk_base}.sdk"
399+
sdk_staging="sdk_staging"
405400

406401
bundle="${sdk_name}.artifactbundle"
407402

408-
rm -rf "${build_dir}/$bundle"
409-
mkdir -p "${build_dir}/$bundle/$sdk_name/$sdk_base"
410-
403+
rm -rf ${build_dir}/$bundle
404+
mkdir -p ${build_dir}/$bundle
411405
quiet_pushd ${build_dir}/$bundle
412406

413407
# First the info.json, for SwiftPM
@@ -418,7 +412,7 @@ cat > info.json <<EOF
418412
"$sdk_name": {
419413
"variants": [
420414
{
421-
"path": "$sdk_name/$sdk_base"
415+
"path": "$sdk_base"
422416
}
423417
],
424418
"version": "${android_sdk_version}",
@@ -428,14 +422,15 @@ cat > info.json <<EOF
428422
}
429423
EOF
430424

431-
quiet_pushd "$sdk_name/$sdk_base"
432-
433-
#ndk_sysroot_path="ndk-sysroot"
434-
ndk_sysroot_path="android-27c-sysroot"
425+
mkdir -p $sdk_base
426+
quiet_pushd $sdk_base
435427

436-
cp -a ${ndk_toolchain}/sysroot ${ndk_sysroot_path}
428+
#sysroot_path="ndk-sysroot"
429+
#sysroot_path="android-27c-sysroot"
430+
sysroot_path="sysroot"
431+
cp -a ${ndk_toolchain}/sysroot ${sysroot_path}
437432

438-
cat > $ndk_sysroot_path/SDKSettings.json <<EOF
433+
cat > $sysroot_path/SDKSettings.json <<EOF
439434
{
440435
"DisplayName": "Swift Android SDK",
441436
"Version": "${android_sdk_version}",
@@ -444,13 +439,13 @@ cat > $ndk_sysroot_path/SDKSettings.json <<EOF
444439
}
445440
EOF
446441

447-
cp -a ${build_dir}/sdk_root sdk_root
442+
cp -a ${build_dir}/sdk_root ${sdk_staging}
448443
# Copy necessary headers and libraries from the toolchain and NDK clang resource directories
449-
mkdir -pv $ndk_sysroot_path/usr/lib/swift/clang/lib
450-
cp -rv $host_toolchain/lib/clang/*/include $ndk_sysroot_path/usr/lib/swift/clang
444+
mkdir -p $sysroot_path/usr/lib/swift/clang/lib
445+
cp -r $host_toolchain/lib/clang/*/include $sysroot_path/usr/lib/swift/clang
451446

452447
for arch in $archs; do
453-
quiet_pushd sdk_root/${arch}/usr
448+
quiet_pushd ${sdk_staging}/${arch}/usr
454449
rm -r bin
455450
rm -r include/*
456451
cp -r ${source_dir}/swift-project/swift/lib/ClangImporter/SwiftBridging/{module.modulemap,swift} include/
@@ -473,16 +468,16 @@ for arch in $archs; do
473468
ln -s ../swift/clang lib/swift_static-$arch/clang
474469
quiet_popd
475470

476-
# now sync the massaged sdk_root into the ndk_sysroot_path
477-
rsync -a sdk_root/${arch}/usr ${ndk_sysroot_path}
471+
# now sync the massaged sdk_root into the sysroot_path
472+
rsync -a ${sdk_staging}/${arch}/usr ${sysroot_path}
478473
done
479474

480-
rm -r ${ndk_sysroot_path}/usr/share/{doc,man}
481-
rm -r ${ndk_sysroot_path}/usr/{include,lib}/{i686,riscv64}-linux-android
482-
rm -r sdk_root
475+
rm -r ${sysroot_path}/usr/share/{doc,man}
476+
rm -r ${sysroot_path}/usr/{include,lib}/{i686,riscv64}-linux-android
477+
rm -r ${sdk_staging}
483478

484479
# validate that some expected paths exist
485-
quiet_pushd ${ndk_sysroot_path}/usr
480+
quiet_pushd ${sysroot_path}/usr
486481
ls lib/swift/android
487482
ls lib/swift/android/*
488483
ls lib/swift/android/*/swiftrt.o
@@ -507,7 +502,9 @@ EOF
507502
first=true
508503
# create targets for the supported API and higher,
509504
# as well as a blank API, which will be the NDK default
510-
for api in "" $(eval echo "{$android_api..36}"); do
505+
# FIXME: building against blank API doesn't work: ld.lld: error: cannot open crtbegin_dynamic.o: No such file or directory
506+
#for api in "" $(eval echo "{$android_api..36}"); do
507+
for api in $(eval echo "{$android_api..36}"); do
511508
for arch in $archs; do
512509
if [[ "$first" == "true" ]]; then
513510
first=false
@@ -518,9 +515,9 @@ EOF
518515
fi
519516
cat >> swift-sdk.json <<EOF
520517
"${arch}-unknown-linux-android${api}": {
521-
"sdkRootPath": "${ndk_sysroot_path}",
522-
"swiftResourcesPath": "${ndk_sysroot_path}/usr/lib/swift",
523-
"swiftStaticResourcesPath": "${ndk_sysroot_path}/usr/lib/swift_static-${arch}",
518+
"sdkRootPath": "${sysroot_path}",
519+
"swiftResourcesPath": "${sysroot_path}/usr/lib/swift",
520+
"swiftStaticResourcesPath": "${sysroot_path}/usr/lib/swift_static-${arch}",
524521
"toolsetPaths": [ "swift-toolset.json" ]
525522
EOF
526523
done

0 commit comments

Comments
 (0)