Stable: check Android support in CI, too
This commit is contained in:
parent
6bce2fe9c9
commit
3eb1b40ade
25
.github/workflows/ci.yml
vendored
25
.github/workflows/ci.yml
vendored
@ -154,3 +154,28 @@ jobs:
|
|||||||
env CPPFLAGS="-DDEV_MODE=1" ./configure --disable-dependency-tracking --host=powerpc-linux-gnu
|
env CPPFLAGS="-DDEV_MODE=1" ./configure --disable-dependency-tracking --host=powerpc-linux-gnu
|
||||||
make -j $(nproc)
|
make -j $(nproc)
|
||||||
make clean > /dev/null
|
make clean > /dev/null
|
||||||
|
|
||||||
|
android:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Update packages list
|
||||||
|
run: sudo apt-get update
|
||||||
|
|
||||||
|
- name: Install base dependencies
|
||||||
|
run: sudo apt-get install -y libtool autoconf automake unzip
|
||||||
|
|
||||||
|
- name: Autogen
|
||||||
|
run: ./autogen.sh -s
|
||||||
|
|
||||||
|
- name: Install Android NDK
|
||||||
|
run: |
|
||||||
|
mkdir /tmp/android && cd /tmp/android
|
||||||
|
curl -o ndk.zip -L https://dl.google.com/android/repository/android-ndk-r24-beta2-linux.zip
|
||||||
|
unzip ndk.zip && rm -f *.zip && mv android-ndk* ndk
|
||||||
|
|
||||||
|
- name: Android compilation
|
||||||
|
run: |
|
||||||
|
env ANDROID_NDK_HOME=/tmp/android/ndk ./dist-build/android-x86.sh
|
||||||
|
env ANDROID_NDK_HOME=/tmp/android/ndk ./dist-build/android-armv8-a.sh
|
||||||
|
144
dist-build/android-aar.sh
Executable file
144
dist-build/android-aar.sh
Executable file
@ -0,0 +1,144 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# Create an AAR with libsodium in all combinations of static | shared | minimal | full.
|
||||||
|
#
|
||||||
|
# The x86 static library will not work due to text relocation rules, so static x86 versions are limited to shared libraries.
|
||||||
|
# To simplify linking, library variants have distinct names: sodium, sodium-static, sodium-minimal and sodium-minimal-static.
|
||||||
|
|
||||||
|
SODIUM_VERSION="1.0.18.0"
|
||||||
|
NDK_VERSION=$(grep "Pkg.Revision = " <"${ANDROID_NDK_HOME}/source.properties" | cut -f 2 -d '=' | cut -f 2 -d' ' | cut -f 1 -d'.')
|
||||||
|
DEST_PATH=$(mktemp -d)
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/../" || exit
|
||||||
|
|
||||||
|
make_abi_json() {
|
||||||
|
echo "{\"abi\":\"${NDK_ARCH}\",\"api\":${SDK_VERSION},\"ndk\":${NDK_VERSION},\"stl\":\"none\"}" >"$1/abi.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_prefab_json() {
|
||||||
|
echo "{\"name\":\"sodium\",\"schema_version\":1,\"dependencies\":[],\"version\":\"$SODIUM_VERSION\"}" >"$1/prefab.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_manifest() {
|
||||||
|
echo "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"com.android.ndk.thirdparty.sodium\" android:versionCode=\"1\" android:versionName=\"1.0\">
|
||||||
|
<uses-sdk android:minSdkVersion=\"19\" android:targetSdkVersion=\"21\"/>
|
||||||
|
</manifest>" >"${1}/AndroidManifest.xml"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_prefab_structure() {
|
||||||
|
mkdir "$DEST_PATH"
|
||||||
|
|
||||||
|
for variant_dirs in "prefab" "prefab/modules" "META-INF"; do
|
||||||
|
mkdir "${DEST_PATH}/${variant_dirs}"
|
||||||
|
done
|
||||||
|
|
||||||
|
make_prefab_json "${DEST_PATH}/prefab"
|
||||||
|
make_manifest "${DEST_PATH}"
|
||||||
|
cp "LICENSE" "${DEST_PATH}/META-INF"
|
||||||
|
|
||||||
|
for variant in \
|
||||||
|
"prefab/modules/sodium" "prefab/modules/sodium-static" \
|
||||||
|
"prefab/modules/sodium-minimal" "prefab/modules/sodium-minimal-static"; do
|
||||||
|
mkdir "${DEST_PATH}/${variant}"
|
||||||
|
|
||||||
|
if [ "$variant" = "prefab/modules/sodium-minimal" ]; then
|
||||||
|
echo "{\"library_name\":\"libsodium\"}" >"${DEST_PATH}/${variant}/module.json"
|
||||||
|
else
|
||||||
|
echo "{}" >"${DEST_PATH}/${variant}/module.json"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir "${DEST_PATH}/${variant}/libs"
|
||||||
|
|
||||||
|
for arch in "arm64-v8a" "armeabi-v7a" "x86" "x86_64"; do
|
||||||
|
mkdir "$DEST_PATH/${variant}/libs/android.${arch}"
|
||||||
|
mkdir "$DEST_PATH/${variant}/libs/android.${arch}/include"
|
||||||
|
NDK_ARCH="$arch"
|
||||||
|
if [ $arch = "arm64-v8a" ] || [ $arch = "x86_64" ]; then
|
||||||
|
SDK_VERSION="21"
|
||||||
|
else
|
||||||
|
SDK_VERSION="19"
|
||||||
|
fi
|
||||||
|
|
||||||
|
make_abi_json "$DEST_PATH/${variant}/libs/android.${arch}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
copy_libs() {
|
||||||
|
SRC_DIR="libsodium-android-${1}"
|
||||||
|
|
||||||
|
SHARED_DEST_DIR="${DEST_PATH}/prefab/modules/sodium${3}/libs/android.${2}"
|
||||||
|
STATIC_DEST_DIR="${DEST_PATH}/prefab/modules/sodium${3}-static/libs/android.${2}"
|
||||||
|
|
||||||
|
cp -r "${SRC_DIR}/include" "$SHARED_DEST_DIR"
|
||||||
|
cp -r "${SRC_DIR}/include" "$STATIC_DEST_DIR"
|
||||||
|
cp "${SRC_DIR}/lib/libsodium.so" "${SHARED_DEST_DIR}/libsodium.so"
|
||||||
|
cp "${SRC_DIR}/lib/libsodium.a" "${STATIC_DEST_DIR}/libsodium${3}-static.a"
|
||||||
|
|
||||||
|
rm -r "$SRC_DIR"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_all() {
|
||||||
|
dist-build/android-armv7-a.sh
|
||||||
|
dist-build/android-armv8-a.sh
|
||||||
|
dist-build/android-x86_64.sh
|
||||||
|
dist-build/android-x86.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
make_prefab_structure
|
||||||
|
|
||||||
|
build_all
|
||||||
|
|
||||||
|
copy_libs "armv7-a" "armeabi-v7a" "-minimal"
|
||||||
|
copy_libs "armv8-a+crypto" "arm64-v8a" "-minimal"
|
||||||
|
copy_libs "i686" "x86" "-minimal"
|
||||||
|
copy_libs "westmere" "x86_64" "-minimal"
|
||||||
|
|
||||||
|
LIBSODIUM_FULL_BUILD="Y"
|
||||||
|
export LIBSODIUM_FULL_BUILD
|
||||||
|
|
||||||
|
build_all
|
||||||
|
|
||||||
|
copy_libs "armv7-a" "armeabi-v7a"
|
||||||
|
copy_libs "armv8-a+crypto" "arm64-v8a"
|
||||||
|
copy_libs "i686" "x86"
|
||||||
|
copy_libs "westmere" "x86_64"
|
||||||
|
|
||||||
|
AAR_PATH="$(pwd)/libsodium-${SODIUM_VERSION}.aar"
|
||||||
|
cd "$DEST_PATH" || exit
|
||||||
|
rm "$AAR_PATH"
|
||||||
|
zip -9 -r "$AAR_PATH" META-INF prefab AndroidManifest.xml
|
||||||
|
cd .. || exit
|
||||||
|
rm -r "$DEST_PATH"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Congrats you have built an AAR containing libsodium! To use it with
|
||||||
|
gradle or cmake (as set by default for Android Studio projects):
|
||||||
|
|
||||||
|
- Edit the app/build.gradle file to add:
|
||||||
|
|
||||||
|
android {
|
||||||
|
buildFeatures {
|
||||||
|
prefab true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
and
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(dir:'path/to/aar/',include:['libsodium-$SODIUM_VERSION.aar'])
|
||||||
|
}
|
||||||
|
|
||||||
|
Optionally, store multiple AAR files in the same folder and include '*.aar'
|
||||||
|
|
||||||
|
- Edit your module's CMakeLists.txt file to add:
|
||||||
|
|
||||||
|
find_package(sodium REQUIRED CONFIG)
|
||||||
|
|
||||||
|
- Then, specify 'sodium::x' as an item in the relevant 'target_link_libraries' statement.
|
||||||
|
The first part is the AAR name and should be 'sodium'.
|
||||||
|
The second part ('x', to be replaced) should be set to:
|
||||||
|
- 'sodium' for the full shared library,
|
||||||
|
- 'sodium-static' for the full static library
|
||||||
|
- 'sodium-minimal' for the minimal shared library, or
|
||||||
|
- 'sodium-minimal-static' for the minimal static library."
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
export TARGET_ARCH=armv7-a
|
export TARGET_ARCH=armv7-a
|
||||||
export CFLAGS="-Os -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -marm -march=${TARGET_ARCH}"
|
export CFLAGS="-Os -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -marm -march=${TARGET_ARCH}"
|
||||||
ARCH=arm HOST_COMPILER=arm-linux-androideabi "$(dirname "$0")/android-build.sh"
|
ARCH=arm HOST_COMPILER=armv7a-linux-androideabi "$(dirname "$0")/android-build.sh"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
export TARGET_ARCH=armv8-a
|
export TARGET_ARCH=armv8-a+crypto
|
||||||
export CFLAGS="-Os -march=${TARGET_ARCH}"
|
export CFLAGS="-Os -march=${TARGET_ARCH}"
|
||||||
NDK_PLATFORM=android-21 ARCH=arm64 HOST_COMPILER=aarch64-linux-android "$(dirname "$0")/android-build.sh"
|
NDK_PLATFORM=android-21 ARCH=arm64 HOST_COMPILER=aarch64-linux-android "$(dirname "$0")/android-build.sh"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
|
|
||||||
if [ -z "$NDK_PLATFORM" ]; then
|
if [ -z "$NDK_PLATFORM" ]; then
|
||||||
export NDK_PLATFORM="android-16"
|
export NDK_PLATFORM="android-19"
|
||||||
fi
|
fi
|
||||||
export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
|
export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}"
|
||||||
export NDK_API_VERSION=$(echo "$NDK_PLATFORM" | sed 's/^android-//')
|
export NDK_API_VERSION="$(echo "$NDK_PLATFORM" | sed 's/^android-//')"
|
||||||
export NDK_API_VERSION_COMPAT=$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')
|
export NDK_API_VERSION_COMPAT="$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')"
|
||||||
|
|
||||||
if [ -z "$ANDROID_NDK_HOME" ]; then
|
if [ -z "$ANDROID_NDK_HOME" ]; then
|
||||||
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
|
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
|
||||||
@ -18,20 +18,19 @@ if [ ! -f ./configure ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "x$TARGET_ARCH" = 'x' ] || [ "x$ARCH" = 'x' ] || [ "x$HOST_COMPILER" = 'x' ]; then
|
if [ -z "$TARGET_ARCH" ] || [ -z "$ARCH" ] || [ -z "$HOST_COMPILER" ]; then
|
||||||
echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
|
echo "You shouldn't use android-build.sh directly, use android-[arch].sh instead" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export MAKE_TOOLCHAIN="${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py"
|
|
||||||
|
|
||||||
export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
|
export PREFIX="$(pwd)/libsodium-android-${TARGET_ARCH}"
|
||||||
export TOOLCHAIN_DIR="$(pwd)/android-toolchain-${TARGET_ARCH}"
|
export TOOLCHAIN_OS_DIR="$(uname | tr '[:upper:]' '[:lower:]')-x86_64/"
|
||||||
|
export TOOLCHAIN_DIR="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}"
|
||||||
|
echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}/${HOST_COMPILER}"
|
||||||
|
|
||||||
export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
|
export PATH="${PATH}:${TOOLCHAIN_DIR}/bin"
|
||||||
|
SDK_VERSION_NUM=$(echo $NDK_PLATFORM | cut -d'-' -f2)
|
||||||
export CC=${CC:-"${HOST_COMPILER}-clang"}
|
export CC=${CC:-"${HOST_COMPILER}${SDK_VERSION_NUM}-clang"}
|
||||||
|
|
||||||
rm -rf "${TOOLCHAIN_DIR}" "${PREFIX}"
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Warnings related to headers being present but not usable are due to functions"
|
echo "Warnings related to headers being present but not usable are due to functions"
|
||||||
@ -47,9 +46,6 @@ else
|
|||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
|
|
||||||
env - PATH="$PATH" \
|
|
||||||
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION_COMPAT" \
|
|
||||||
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
|
|
||||||
|
|
||||||
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
|
if [ -z "$LIBSODIUM_FULL_BUILD" ]; then
|
||||||
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
|
export LIBSODIUM_ENABLE_MINIMAL_FLAG="--enable-minimal"
|
||||||
@ -59,28 +55,27 @@ fi
|
|||||||
|
|
||||||
./configure \
|
./configure \
|
||||||
--disable-soname-versions \
|
--disable-soname-versions \
|
||||||
|
--disable-pie \
|
||||||
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
||||||
--host="${HOST_COMPILER}" \
|
--host="${HOST_COMPILER}" \
|
||||||
--prefix="${PREFIX}" \
|
--prefix="${PREFIX}" \
|
||||||
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
||||||
|
|
||||||
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
||||||
egrep '^#define ' config.log | sort -u > config-def-compat.log
|
egrep '^#define ' config.log | sort -u >config-def-compat.log
|
||||||
echo
|
echo
|
||||||
echo "Configuring again for platform [${NDK_PLATFORM}]"
|
echo "Configuring again for platform [${NDK_PLATFORM}]"
|
||||||
echo
|
echo
|
||||||
env - PATH="$PATH" \
|
|
||||||
"$MAKE_TOOLCHAIN" --force --api="$NDK_API_VERSION" \
|
|
||||||
--arch="$ARCH" --install-dir="$TOOLCHAIN_DIR" || exit 1
|
|
||||||
|
|
||||||
./configure \
|
./configure \
|
||||||
--disable-soname-versions \
|
--disable-soname-versions \
|
||||||
|
--disable-pie \
|
||||||
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
${LIBSODIUM_ENABLE_MINIMAL_FLAG} \
|
||||||
--host="${HOST_COMPILER}" \
|
--host="${HOST_COMPILER}" \
|
||||||
--prefix="${PREFIX}" \
|
--prefix="${PREFIX}" \
|
||||||
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
|
||||||
|
|
||||||
egrep '^#define ' config.log | sort -u > config-def.log
|
grep -E '^#define ' config.log | sort -u >config-def.log
|
||||||
if ! cmp config-def.log config-def-compat.log; then
|
if ! cmp config-def.log config-def-compat.log; then
|
||||||
echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
|
echo "Platform [${NDK_PLATFORM}] is not backwards-compatible with [${NDK_PLATFORM_COMPAT}]" >&2
|
||||||
diff -u config-def.log config-def-compat.log >&2
|
diff -u config-def.log config-def-compat.log >&2
|
||||||
@ -89,10 +84,9 @@ if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
|
|||||||
rm -f config-def.log config-def-compat.log
|
rm -f config-def.log config-def-compat.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
|
NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
|
||||||
PROCESSORS=${NPROCESSORS:-3}
|
PROCESSORS=${NPROCESSORS:-3}
|
||||||
|
|
||||||
make clean && \
|
make clean &&
|
||||||
make -j${PROCESSORS} install && \
|
make -j${PROCESSORS} install &&
|
||||||
echo "libsodium has been installed into ${PREFIX}"
|
echo "libsodium has been installed into ${PREFIX}"
|
||||||
|
Loading…
Reference in New Issue
Block a user