]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
android: add CI jobs, buildinfo, cmake docs, disable `CURL_USE_PKGCONFIG` by default
authorViktor Szakats <commit@vsz.me>
Wed, 15 Jan 2025 14:46:32 +0000 (15:46 +0100)
committerViktor Szakats <commit@vsz.me>
Thu, 16 Jan 2025 23:44:11 +0000 (00:44 +0100)
- GHA/non-native: add Android builds, both cmake and autotools,
  both NDK 21 (oldest available) and 35 (newest available)
  https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
  It comes with a maintenance burden to bump the oldest/latest values
  with CI runner updates.

- cmake: disable `CURL_USE_PKGCONFIG` by default for Android.
  To avoid picking up system package by default.

- build: add `ANDROID-<NDK-LEVEL>` flag to `buildinfo.txt`.
  Also detect NDK level with the CMake built-in build method:
  https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android

- INSTALL.md: add CMake build instructions for Android.

- INSTALL.md: make NDK levels consistent in `./configure` example.

Closes #16014

.github/workflows/non-native.yml
CMake/curl-config.cmake.in
CMakeLists.txt
acinclude.m4
docs/INSTALL-CMAKE.md
docs/INSTALL.md

index ccaaba337f990311d7925aaab89249bd39879151..5d378a11541e1190ff06841c6ae8506f954f39ff 100644 (file)
@@ -224,6 +224,80 @@ jobs:
             time gmake -j3 examples
             echo '::endgroup::'
 
+  android:
+    name: "Android ${{ matrix.platform }} (${{ matrix.build == 'cmake' && 'CM' || 'AM' }}, arm64)"
+    runs-on: 'ubuntu-24.04'
+    timeout-minutes: 5
+    strategy:
+      matrix:
+        platform: ['21', '35']
+        build: [autotools, cmake]
+      fail-fast: false
+    steps:
+      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
+
+      - name: 'configure'
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake -B bld \
+              -DANDROID_ABI=arm64-v8a \
+              -DANDROID_PLATFORM=android-${{ matrix.platform }} \
+              -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake" \
+              -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \
+              -DCURL_WERROR=ON \
+              -DCURL_ENABLE_SSL=OFF \
+              -DCURL_USE_LIBPSL=OFF
+          else
+            autoreconf -fi
+            TOOLCHAIN="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64"
+            mkdir bld && cd bld && ../configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror \
+              CC="$TOOLCHAIN/bin/aarch64-linux-android${{ matrix.platform }}-clang" \
+              AR="$TOOLCHAIN/bin/llvm-ar" \
+              RANLIB="$TOOLCHAIN/bin/llvm-ranlib" \
+              --host=aarch64-linux-android${{ matrix.platform }} \
+              --without-ssl \
+              --without-libpsl
+          fi
+
+      - name: 'configure log'
+        if: ${{ !cancelled() }}
+        run: cat bld/config.log bld/CMakeFiles/CMake*.yaml 2>/dev/null || true
+
+      - name: 'curl_config.h'
+        run: |
+          echo '::group::raw'; cat bld/lib/curl_config.h || true; echo '::endgroup::'
+          grep -F '#define' bld/lib/curl_config.h | sort || true
+
+      - name: 'build'
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld
+          else
+            make -j5 -C bld
+          fi
+
+      - name: 'curl info'
+        run: |
+          find . -type f \( -name curl -o -name '*.so' -o -name '*.a' \) -exec file '{}' \;
+
+      - name: 'build tests'
+        if: ${{ matrix.build == 'cmake' }}  # skip for autotools to save time
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld --target testdeps
+          else
+            make -j5 -C bld -C tests
+          fi
+
+      - name: 'build examples'
+        if: ${{ matrix.build == 'cmake' }}  # skip for autotools to save time
+        run: |
+          if [ '${{ matrix.build }}' = 'cmake' ]; then
+            cmake --build bld --target curl-examples
+          else
+            make -j5 -C bld examples
+          fi
+
   amiga:
     name: "AmigaOS (${{ matrix.build == 'cmake' && 'CM' || 'AM' }}, AmiSSL, gcc, m68k)"
     runs-on: 'ubuntu-24.04'
index e9f3688ce4785a4252314ec7db0dfb7472d9fd7c..88db0f49341b344c2be660b8f4228e0d21d94594 100644 (file)
@@ -23,7 +23,8 @@
 ###########################################################################
 @PACKAGE_INIT@
 
-if(UNIX OR VCPKG_TOOLCHAIN OR (MINGW AND NOT CMAKE_CROSSCOMPILING))  # Keep in sync with root CMakeLists.txt
+# Keep condition in sync with CMake/curl-config.cmake.in
+if((UNIX AND NOT ANDROID) OR VCPKG_TOOLCHAIN OR (MINGW AND NOT CMAKE_CROSSCOMPILING))
   set(_curl_use_pkgconfig_default ON)
 else()
   set(_curl_use_pkgconfig_default OFF)
index e21e7347686a9f9e232c63d2bf3857c1073e6254..c7e6b04e16d669c17d00061a846c9567f0142204 100644 (file)
@@ -98,6 +98,11 @@ elseif(DOS AND CMAKE_COMPILER_IS_GNUCC)  # DJGPP
   set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
 endif()
 
+# Fill platform level variable when using CMake's built-in Android configuration
+if(ANDROID AND NOT DEFINED ANDROID_PLATFORM_LEVEL AND NOT CMAKE_SYSTEM_VERSION EQUAL 1)
+  set(ANDROID_PLATFORM_LEVEL "${CMAKE_SYSTEM_VERSION}")
+endif()
+
 set(_target_flags "")
 if(APPLE)
   set(_target_flags "${_target_flags} APPLE")
@@ -108,6 +113,9 @@ endif()
 if(BSD)
   set(_target_flags "${_target_flags} BSD")
 endif()
+if(ANDROID)
+  set(_target_flags "${_target_flags} ANDROID-${ANDROID_PLATFORM_LEVEL}")
+endif()
 if(WIN32)
   set(_target_flags "${_target_flags} WIN32")
 endif()
@@ -304,7 +312,8 @@ else()
 endif()
 
 # Override to force-disable or force-enable the use of pkg-config.
-if(UNIX OR VCPKG_TOOLCHAIN OR (MINGW AND NOT CMAKE_CROSSCOMPILING))  # Keep in sync with CMake/curl-config.cmake.in
+# Keep condition in sync with CMake/curl-config.cmake.in
+if((UNIX AND NOT ANDROID) OR VCPKG_TOOLCHAIN OR (MINGW AND NOT CMAKE_CROSSCOMPILING))
   set(_curl_use_pkgconfig_default ON)
 else()
   set(_curl_use_pkgconfig_default OFF)
index d368a1db3133acf0ffd2acbf55737e8ea49d561b..21b6d0c40682bcb0ef8536b12f2444c4652ff5d8 100644 (file)
@@ -1539,6 +1539,15 @@ AC_DEFUN([CURL_PREPARE_BUILDINFO], [
   if test "$curl_cv_winuwp" = 'yes'; then
     curl_pflags="${curl_pflags} UWP"
   fi
+  case $host in
+    *-*-android*)
+      curl_pflags="${curl_pflags} ANDROID"
+      ANDROID_PLATFORM_LEVEL=`echo "$host_os" | $SED -ne 's/.*android\(@<:@0-9@:>@*\).*/\1/p'`
+      if test -n "${ANDROID_PLATFORM_LEVEL}"; then
+        curl_pflags="${curl_pflags}-${ANDROID_PLATFORM_LEVEL}"
+      fi
+      ;;
+  esac
   if test "$curl_cv_cygwin" = 'yes'; then
     curl_pflags="${curl_pflags} CYGWIN"
   fi
index b42dc7f7cfc809b3b02274a3ef623539a056a097..8b6ca622f092566f7bfc6fd5078c274f6a01288a 100644 (file)
@@ -280,7 +280,7 @@ Details via CMake
 - `CURL_USE_LIBUV`:                         Use libuv for event-based tests. Default: `OFF`
 - `CURL_USE_MBEDTLS`:                       Enable mbedTLS for SSL/TLS. Default: `OFF`
 - `CURL_USE_OPENSSL`:                       Enable OpenSSL for SSL/TLS. Default: `ON` if no other TLS backend was enabled.
-- `CURL_USE_PKGCONFIG`:                     Enable `pkg-config` to detect dependencies. Default: `ON` for Unix, vcpkg, MinGW if not cross-compiling.
+- `CURL_USE_PKGCONFIG`:                     Enable `pkg-config` to detect dependencies. Default: `ON` for Unix (except Android), vcpkg, MinGW if not cross-compiling.
 - `CURL_USE_RUSTLS`:                        Enable Rustls for SSL/TLS. Default: `OFF`
 - `CURL_USE_SCHANNEL`:                      Enable Windows native SSL/TLS (Schannel). Default: `OFF`
 - `CURL_USE_SECTRANSP`:                     Enable Apple OS native SSL/TLS (Secure Transport). Default: `OFF`
index e8300f589a18e5bee22d5fd67838c27810e5d78c..a6732cffcdd487c3b85069d7fc750a8f2b1c326f 100644 (file)
@@ -401,14 +401,26 @@ In all above, the built libraries and executables can be found in the
 
 # Android
 
-When building curl for Android it is recommended to use a Linux/macOS
-environment since using curl's `configure` script is the easiest way to build
-curl for Android. Before you can build curl for Android, you need to install
-the Android NDK first. This can be done using the SDK Manager that is part of
-Android Studio. Once you have installed the Android NDK, you need to figure
-out where it has been installed and then set up some environment variables
-before launching `configure`. On macOS, those variables could look like this
-to compile for `aarch64` and API level 29:
+When building curl for Android you can you CMake or curl's `configure` script.
+
+Before you can build curl for Android, you need to install the Android NDK
+first. This can be done using the SDK Manager that is part of Android Studio.
+Once you have installed the Android NDK, you need to figure out where it has
+been installed and then set up some environment variables before launching
+the build.
+
+Examples to compile for `aarch64` and API level 29:
+
+with CMake, where `ANDROID_NDK_HOME` points into your NDK:
+
+    cmake . \
+      -DANDROID_ABI=arm64-v8a \
+      -DANDROID_PLATFORM=android-29 \
+      -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
+      -DCURL_ENABLE_SSL=OFF \
+      -DCURL_USE_LIBPSL=OFF
+
+with `configure`, on macOS:
 
 ```bash
 export ANDROID_NDK_HOME=~/Library/Android/sdk/ndk/25.1.8937393 # Point into your NDK.
@@ -416,8 +428,8 @@ export HOST_TAG=darwin-x86_64 # Same tag for Apple Silicon. Other OS values here
 export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG
 export AR=$TOOLCHAIN/bin/llvm-ar
 export AS=$TOOLCHAIN/bin/llvm-as
-export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
-export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
+export CC=$TOOLCHAIN/bin/aarch64-linux-android29-clang
+export CXX=$TOOLCHAIN/bin/aarch64-linux-android29-clang++
 export LD=$TOOLCHAIN/bin/ld
 export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
 export STRIP=$TOOLCHAIN/bin/llvm-strip