Skip to content

Commit d87d8a0

Browse files
authored
Refactor Android build workflow and environment variables
Updated paths to ignore and modified environment variable settings for Android NDK and build directories.
1 parent 258051c commit d87d8a0

File tree

1 file changed

+109
-67
lines changed

1 file changed

+109
-67
lines changed

.github/workflows/android.yml

Lines changed: 109 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ on:
44
pull_request:
55
push:
66
paths-ignore:
7-
- '.azure/azure-pipelines-alpine.yml'
8-
- '.azure/azure-pipelines-mac.yml'
9-
- '.azure/azure-pipelines-vcpkg.yml'
10-
- '.azure/azure-pipelines-win.yml'
11-
- '.azure/Dockerfile.azure-alpine'
12-
- '.circleci/config.yml'
7+
- '.azure/**'
8+
- '.github/workflows/api_doc_build.yml'
9+
- '.github/workflows/codeql-analysis.yml'
10+
- '.github/workflows/codespell.yml'
1311
- '.github/workflows/linux.yml'
1412
- '.github/workflows/sonarcloud.yml'
13+
- '.github/workflows/solaris.yml'
14+
- '.github/workflows/windows.yml'
15+
- '.github/workflows/ios.yml'
1516
- '.cirrus.yml'
1617
- 'README.md'
1718
schedule:
@@ -34,11 +35,47 @@ env:
3435
FLAC_VERSION: '1.4.3'
3536
PCRE_VERSION: '8.45'
3637

38+
# Android NDK sources and standalone toolchain is put here
39+
DEV: '${{ github.workspace }}/android-build-root'
40+
41+
# This is a symlink pointing to the real Android NDK
42+
# Must be the same as $ANDROID_NDK_HOME see:
43+
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md
44+
# We cannot use $ANDROID_NDK_HOME because this is an environment variable, but here, we need a compile-time constant.
45+
NDK: '/usr/local/lib/android/sdk/ndk/27.3.13750724'
46+
47+
# All the built binaries, libs and their headers will be installed here
48+
PREFIX: '${{ env.DEV }}/opt/android'
49+
50+
# Prevent installing to lib64/
51+
# This becomes important, if you would build on e.g. openSUSE
52+
LIBPATH0: '${{ env.PREFIX }}/lib'
53+
54+
# The path of standalone NDK toolchain
55+
# Refer to https://developer.android.com/ndk/guides/standalone_toolchain.html
56+
NDK_TOOLCHAIN: '${{ env.NDK }}/toolchains/llvm/prebuilt/linux-x86_64/'
57+
58+
# Don't mix up .pc files from your host and build target
59+
PKG_CONFIG_PATH: '${{ envLIBPATH0}}/pkgconfig'
60+
# setting PKG_CONFIG_PATH alone does not seem to be enough to avoid mixing up with the host, also set PKG_CONFIG_LIBDIR
61+
PKG_CONFIG_LIBDIR: '${{ env.PKG_CONFIG_PATH }}'
62+
3763
# Set Android target API level
64+
# when compiling with clang use at least 28 as this makes sure that android provides the posix_spawn functions, so the compilation of gettext will (should) work out of the box
65+
# it's probably a bug of gettext, if posix_spawn is not available it replaces it with its own implementation. Autotools of gettext set HAVE_POSIX_SPAWN==0 (which is correct) but for some reason REPLACE_POSIX_SPAWN==0 (which is wrong, as it should be 1).
66+
#
67+
# NOTE: API 24 is required because it provides fseeko() and ftello() required by libflac
3868
ANDROID_API: '24'
39-
69+
70+
# Tell configure what flags Android requires.
71+
# Turn Wimplicit-function-declaration into errors. Else autotools will be fooled when checking for available functions (that in fact are NOT available) and compilation will fail later on.
72+
CFLAGS: "-fPIE -fPIC -I${{ env.PREFIX }}/include --sysroot=${{ env.NDK_TOOLCHAIN }}/sysroot -I${{ env.NDK_TOOLCHAIN }}/sysroot/usr/include -Werror=implicit-function-declaration"
73+
CXXFLAGS: ${{ env.CFLAGS }}
74+
CPPFLAGS: ${{ env.CXXFLAGS }}
4075
DEBIAN_FRONTEND: 'noninteractive'
4176

77+
ARTIFACT_NAME: 'fluidsynth-android${{ env.ANDROID_API }}'
78+
4279
permissions:
4380
contents: read
4481

@@ -82,7 +119,7 @@ jobs:
82119
- name: Setup build directories
83120
run: |
84121
set -ex
85-
mkdir -p ${{ github.workspace }}/android-build-root
122+
mkdir -p ${{ env.DEV }}
86123
87124
- name: Update apt
88125
run: sudo apt-get update -y
@@ -96,13 +133,13 @@ jobs:
96133
run: |
97134
set -ex
98135
99-
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-${ICONV_VERSION}.tar.gz
136+
wget http://ftpmirror.gnu.org/gnu/libiconv/libiconv-${ICONV_VERSION}.tar.gz
100137
tar zxf libiconv-${ICONV_VERSION}.tar.gz
101138
102139
wget -O libffi-${FFI_VERSION}.tar.gz https://github.com/libffi/libffi/archive/${FFI_VERSION}.tar.gz
103140
tar zxf libffi-${FFI_VERSION}.tar.gz
104141
105-
wget http://ftp.gnu.org/pub/gnu/gettext/gettext-${GETTEXT_VERSION}.tar.gz
142+
wget http://ftpmirror.gnu.org/gnu/gettext/gettext-${GETTEXT_VERSION}.tar.gz
106143
tar zxf gettext-${GETTEXT_VERSION}.tar.gz
107144
108145
wget http://ftp.gnome.org/pub/gnome/sources/glib/${GLIB_VERSION}/glib-${GLIB_VERSION}.${GLIB_EXTRAVERSION}.tar.xz
@@ -132,19 +169,19 @@ jobs:
132169
wget -O pcre-${PCRE_VERSION}.tar.bz2 https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.bz2/download
133170
tar jxf pcre-${PCRE_VERSION}.tar.bz2
134171
cd pcre-${PCRE_VERSION}
135-
# CMake checks for existence of strtoq() using the C compiler - and yes, it does exist!
172+
# CMake checks for the existence of strtoq() using the C compiler - and yes, it does exist!
136173
# Later on, it's actually used by the C++ compiler, where it does not exist.
137174
# Rename the function so CMake won't find it.
138175
sed -i 's/strtoq/strtoqqqq/g' CMakeLists.txt
139-
working-directory: ${{ github.workspace }}/android-build-root
176+
working-directory: ${{ env.DEV }}
140177

141178
- name: Cache fluidsynth dependency libraries
142179
id: cache-deps
143180
if: github.event_name != 'schedule'
144181
uses: actions/cache@v4
145182
with:
146-
key: ${{ matrix.arch }}-${{ env.ANDROID_API }}-android-deps-${{ env.GLIB_VERSION }}-${{ env.OBOE_VERSION }}-${{ env.SNDFILE_VERSION }}-v1
147-
path: ${{ github.workspace }}/android-build-root/opt/android
183+
key: ${{ matrix.arch }}-android${{ env.ANDROID_API }}-${{ env.NDK }}-${{ env.DEV }}/*.tar.*
184+
path: ${{ env.PREFIX }}
148185

149186
- name: Install build tools
150187
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -156,58 +193,37 @@ jobs:
156193
run: |
157194
set -e
158195
159-
# Android NDK path
160-
echo "NDK=/usr/local/lib/android/sdk/ndk/27.3.13750724" >> $GITHUB_ENV
161-
162-
# Build root directory
163-
echo "DEV=${{ github.workspace }}/android-build-root" >> $GITHUB_ENV
164-
165-
# Install prefix
166-
echo "PREFIX=${{ github.workspace }}/android-build-root/opt/android" >> $GITHUB_ENV
167-
168-
# Library path
169-
echo "LIBPATH0=${{ github.workspace }}/android-build-root/opt/android/lib" >> $GITHUB_ENV
170-
171-
# NDK toolchain path
172-
echo "NDK_TOOLCHAIN=/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64" >> $GITHUB_ENV
173-
174-
# PKG_CONFIG paths
175-
echo "PKG_CONFIG_PATH=${{ github.workspace }}/android-build-root/opt/android/lib/pkgconfig" >> $GITHUB_ENV
176-
echo "PKG_CONFIG_LIBDIR=${{ github.workspace }}/android-build-root/opt/android/lib/pkgconfig" >> $GITHUB_ENV
177-
178196
# The cross-compile toolchain we use
179197
ANDROID_TARGET="${{ matrix.arch }}-linux-android${{ matrix.android_target_abi }}"
180198
echo "ANDROID_TARGET=$ANDROID_TARGET" >> $GITHUB_ENV
181199
182200
ANDROID_TARGET_API="${{ matrix.android_arch }}-linux-android${{ matrix.android_target_abi }}${ANDROID_API}"
183201
echo "ANDROID_TARGET_API=$ANDROID_TARGET_API" >> $GITHUB_ENV
184202
185-
# Compiler flags
186-
echo "CFLAGS=-fPIE -fPIC -I${{ github.workspace }}/android-build-root/opt/android/include --sysroot=/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -Werror=implicit-function-declaration" >> $GITHUB_ENV
187-
echo "CXXFLAGS=-fPIE -fPIC -I${{ github.workspace }}/android-build-root/opt/android/include --sysroot=/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -Werror=implicit-function-declaration" >> $GITHUB_ENV
188-
echo "CPPFLAGS=-fPIE -fPIC -I${{ github.workspace }}/android-build-root/opt/android/include --sysroot=/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot -I/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include -Werror=implicit-function-declaration" >> $GITHUB_ENV
189-
203+
# Add the standalone toolchain to the search path.
204+
echo "${{ env.PREFIX }}/bin" >> $GITHUB_PATH
205+
echo "${{ env.PREFIX }}/lib" >> $GITHUB_PATH
206+
echo "${{ env.PREFIX }}/include" >> $GITHUB_PATH
207+
echo "${{ env.NDK_TOOLCHAIN }}/bin" >> $GITHUB_PATH
208+
190209
# Linker flags
191-
LIBPATH1="/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib"
192-
LIBPATH2="/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${{ matrix.arch }}-linux-android${{ matrix.android_target_abi }}/${ANDROID_API}"
193-
LIBPATH3="/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/${{ matrix.arch }}-linux-android${{ matrix.android_target_abi }}"
194-
LIBPATH0="${{ github.workspace }}/android-build-root/opt/android/lib"
210+
LIBPATH1="${{ env.NDK_TOOLCHAIN }}/sysroot/usr/lib"
211+
LIBPATH2="${{ env.NDK_TOOLCHAIN }}/sysroot/usr/lib/${{ matrix.arch }}-linux-android${{ matrix.android_target_abi }}/${ANDROID_API}"
212+
LIBPATH3="${{ env.NDK_TOOLCHAIN }}/sysroot/usr/lib/${{ matrix.arch }}-linux-android${{ matrix.android_target_abi }}"
213+
214+
# Add max. page size to linker flag, see https://developer.android.com/guide/practices/page-sizes
195215
echo "LDFLAGS=-pie -Wl,-z,max-page-size=16384 -Wl,-rpath-link=${LIBPATH1} -L${LIBPATH1} -Wl,-rpath-link=${LIBPATH2} -L${LIBPATH2} -Wl,-rpath-link=${LIBPATH3} -L${LIBPATH3} -Wl,-rpath-link=${LIBPATH0} -L${LIBPATH0}" >> $GITHUB_ENV
196216
197-
# Toolchain binaries
217+
# Tell configure what tools to use.
198218
echo "AR=llvm-ar" >> $GITHUB_ENV
199-
echo "AS=$ANDROID_TARGET_API-clang" >> $GITHUB_ENV
200-
echo "CC=$ANDROID_TARGET_API-clang" >> $GITHUB_ENV
201-
echo "CXX=$ANDROID_TARGET_API-clang++" >> $GITHUB_ENV
219+
echo "AS=${ANDROID_TARGET_API}-clang" >> $GITHUB_ENV
220+
echo "CC=${ANDROID_TARGET_API}-clang" >> $GITHUB_ENV
221+
echo "CXX=${ANDROID_TARGET_API}-clang++" >> $GITHUB_ENV
202222
echo "LD=ld.lld" >> $GITHUB_ENV
203223
echo "STRIP=llvm-strip" >> $GITHUB_ENV
204224
echo "RANLIB=llvm-ranlib" >> $GITHUB_ENV
205225
206-
# Add to PATH
207-
echo "/usr/local/lib/android/sdk/ndk/27.3.13750724/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
208-
echo "${{ github.workspace }}/android-build-root/opt/android/bin" >> $GITHUB_PATH
209-
210-
- name: Compile libiconv
226+
- name: Compile libiconv-${{ env.ICONV_VERSION }}
211227
if: steps.cache-deps.outputs.cache-hit != 'true'
212228
run: |
213229
set -ex
@@ -229,20 +245,32 @@ jobs:
229245
make -j$((`nproc`+1))
230246
make install
231247
popd
232-
working-directory: ${{ github.workspace }}/android-build-root
233-
248+
working-directory: ${{ env.DEV }}
249+
250+
- name: libiconv config.log
251+
if: ${{ failure() && env.CACHE_RESTORED != 'true' }}
252+
working-directory: ${{ env.DEV }}
253+
run: |
254+
set -ex
255+
pushd "libiconv-${ICONV_VERSION}"
256+
cat config.log
257+
popd
258+
234259
- name: Compile libffi
235260
if: steps.cache-deps.outputs.cache-hit != 'true'
236261
run: |
237262
set -ex
238263
239264
pushd libffi-${FFI_VERSION}
240265
NOCONFIGURE=true autoreconf -v -i
266+
# install headers into the conventional ${PREFIX}/include rather than ${PREFIX}/lib/libffi-3.2.1/include.
267+
#sed -e '/^includesdir/ s/$(libdir).*$/$(includedir)/' -i include/Makefile.in
268+
#sed -e '/^includedir/ s/=.*$/=@includedir@/' -e 's/^Cflags: -I${includedir}/Cflags:/' -i libffi.pc.in
241269
./configure --host=${{ matrix.autotools_target }} --prefix=${PREFIX} --libdir=${LIBPATH0} --enable-static --disable-shared
242270
make -j$((`nproc`+1))
243271
make install
244272
popd
245-
working-directory: ${{ github.workspace }}/android-build-root
273+
working-directory: ${{ env.DEV }}
246274

247275
- name: Compile gettext
248276
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -270,7 +298,7 @@ jobs:
270298
make -j$((`nproc`+1))
271299
make install
272300
popd
273-
working-directory: ${{ github.workspace }}/android-build-root
301+
working-directory: ${{ env.DEV }}
274302

275303
- name: Compile pcre
276304
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -304,7 +332,7 @@ jobs:
304332
make install
305333
popd
306334
popd
307-
working-directory: ${{ github.workspace }}/android-build-root
335+
working-directory: ${{ env.DEV }}
308336

309337
- name: Compile glib (meson)
310338
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -349,12 +377,26 @@ jobs:
349377
EOF
350378
351379
cat cross_file.ini
352-
380+
381+
# When CC and CXX are set, then meson detects them as host compiler (not cross compiler),
382+
# so they tries to run arm binaries in x86. That's why sanity check is failing, and that's
383+
# why we have to use env -i.
384+
# And we must explicitly set PKG_CONFIG_LIBDIR, because pkg_config_libdir is only recognized by meson >= 0.54
353385
env -i bash -c "export PATH && export PKG_CONFIG_LIBDIR=${PKG_CONFIG_LIBDIR} && meson setup build --cross-file cross_file.ini --prefix=${PREFIX}"
354386
ninja -C build
355387
ninja -C build install
356388
popd
357-
working-directory: ${{ github.workspace }}/android-build-root
389+
working-directory: ${{ env.DEV }}
390+
391+
- name: Meson LOG
392+
if: ${{ failure() && env.CACHE_RESTORED != 'true' }}
393+
working-directory: ${{ env.DEV }}
394+
shell: bash
395+
run: |
396+
pushd glib-${GLIB_VERSION}.${GLIB_EXTRAVERSION}
397+
ls -la build
398+
cat build/meson-logs/meson-log.txt
399+
popd
358400
359401
- name: Compile libogg
360402
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -388,7 +430,7 @@ jobs:
388430
make install
389431
popd
390432
popd
391-
working-directory: ${{ github.workspace }}/android-build-root
433+
working-directory: ${{ env.DEV }}
392434

393435
- name: Compile libvorbis
394436
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -422,7 +464,7 @@ jobs:
422464
make install
423465
popd
424466
popd
425-
working-directory: ${{ github.workspace }}/android-build-root
467+
working-directory: ${{ env.DEV }}
426468

427469
- name: Compile flac
428470
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -456,7 +498,7 @@ jobs:
456498
make install
457499
popd
458500
popd
459-
working-directory: ${{ github.workspace }}/android-build-root
501+
working-directory: ${{ env.DEV }}
460502

461503
- name: Compile opus
462504
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -490,7 +532,7 @@ jobs:
490532
make install
491533
popd
492534
popd
493-
working-directory: ${{ github.workspace }}/android-build-root
535+
working-directory: ${{ env.DEV }}
494536

495537
- name: Compile libsndfile
496538
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -524,7 +566,7 @@ jobs:
524566
make install
525567
popd
526568
popd
527-
working-directory: ${{ github.workspace }}/android-build-root
569+
working-directory: ${{ env.DEV }}
528570

529571
- name: Compile oboe
530572
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -558,7 +600,7 @@ jobs:
558600
cp liboboe.* ${PREFIX}/lib/ && cp -ur ../include/oboe ${PREFIX}/include
559601
popd
560602
popd
561-
working-directory: ${{ github.workspace }}/android-build-root
603+
working-directory: ${{ env.DEV }}
562604

563605
- name: Create fake oboe.pc
564606
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -579,7 +621,7 @@ jobs:
579621
EOF
580622
581623
cat ${PKG_CONFIG_PATH}/oboe-1.0.pc
582-
working-directory: ${{ github.workspace }}/android-build-root
624+
working-directory: ${{ env.DEV }}
583625

584626
- name: Compile libinstpatch
585627
if: steps.cache-deps.outputs.cache-hit != 'true'
@@ -613,7 +655,7 @@ jobs:
613655
make install
614656
popd
615657
popd
616-
working-directory: ${{ github.workspace }}/android-build-root
658+
working-directory: ${{ env.DEV }}
617659

618660
- name: Compile fluidsynth
619661
run: |
@@ -720,7 +762,7 @@ jobs:
720762
ls libvorbisfile.so
721763
ls libpcre.so
722764
ls libpcreposix.so
723-
working-directory: ${{ github.workspace }}/android-build-root/opt/android/lib
765+
working-directory: ${{ env.DEV }}/opt/android/lib
724766

725767
- name: Assert 16K page alignment
726768
run: |

0 commit comments

Comments
 (0)