From: Viktor Szakats Date: Wed, 15 Jan 2025 14:46:32 +0000 (+0100) Subject: android: add CI jobs, buildinfo, cmake docs, disable `CURL_USE_PKGCONFIG` by default X-Git-Tag: curl-8_12_0~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56a74fac47a27cfbfe2f49976938dab7a1b9b4f2;p=thirdparty%2Fcurl.git android: add CI jobs, buildinfo, cmake docs, disable `CURL_USE_PKGCONFIG` by default - 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-` 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 --- diff --git a/.github/workflows/non-native.yml b/.github/workflows/non-native.yml index ccaaba337f..5d378a1154 100644 --- a/.github/workflows/non-native.yml +++ b/.github/workflows/non-native.yml @@ -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' diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in index e9f3688ce4..88db0f4934 100644 --- a/CMake/curl-config.cmake.in +++ b/CMake/curl-config.cmake.in @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index e21e734768..c7e6b04e16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/acinclude.m4 b/acinclude.m4 index d368a1db31..21b6d0c406 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index b42dc7f7cf..8b6ca622f0 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -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` diff --git a/docs/INSTALL.md b/docs/INSTALL.md index e8300f589a..a6732cffcd 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -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