Add android native library build support (#1835)

This commit is contained in:
Thad House 2021-07-21 14:47:45 -07:00 коммит произвёл GitHub
Родитель 8d82207cbb
Коммит acdebe43a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 65 добавлений и 4 удалений

Просмотреть файл

@ -283,6 +283,23 @@ stages:
tls: openssl
ubuntuVersion: 18.04
extraBuildArgs: -DisableLogs -ToolchainFile cmake/toolchains/arm-pi-gnueabihf.toolchain.cmake
- template: ./templates/build-config-user.yml
parameters:
image: ubuntu-latest
platform: android
arch: arm64
tls: openssl
extraBuildArgs: -DisableLogs
- template: ./templates/build-config-user.yml
parameters:
image: ubuntu-latest
platform: android
arch: x64
tls: openssl
extraBuildArgs: -DisableLogs
- template: ./templates/build-config-user.yml
parameters:
image: ubuntu-latest

Просмотреть файл

@ -488,6 +488,22 @@ if(QUIC_TLS STREQUAL "openssl")
set(OPENSSL_CONFIG_CMD ${CMAKE_CURRENT_SOURCE_DIR}/submodules/openssl/config)
endif()
list(APPEND OPENSSL_CONFIG_FLAGS -isysroot ${CMAKE_OSX_SYSROOT})
elseif(ANDROID)
message(STATUS "${ANDROID_ABI}")
if(ANDROID_ABI STREQUAL "arm64-v8a")
set(OPENSSL_BUILD_TYPE android-arm64)
elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
set(OPENSSL_BUILD_TYPE android-arm)
elseif(ANDROID_ABI STREQUAL "x86")
set(OPENSSL_BUILD_TYPE android-x86)
elseif(ANDROID_ABI STREQUAL "x86_64")
set(OPENSSL_BUILD_TYPE android-x86_64)
else()
message(FATAL_ERROR "Unknown android abi type")
endif()
set(OPENSSL_CONFIG_CMD ${CMAKE_CURRENT_SOURCE_DIR}/submodules/openssl/Configure
${OPENSSL_BUILD_TYPE}
-D__ANDROID_API__=29)
else()
set(OPENSSL_CONFIG_CMD ${CMAKE_CURRENT_SOURCE_DIR}/submodules/openssl/config
CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER})

Просмотреть файл

@ -108,7 +108,7 @@ param (
[string]$Arch = "",
[Parameter(Mandatory = $false)]
[ValidateSet("uwp", "windows", "linux", "macos")] # For future expansion
[ValidateSet("uwp", "windows", "linux", "macos", "android")] # For future expansion
[string]$Platform = "",
[Parameter(Mandatory = $false)]
@ -346,6 +346,20 @@ function CMake-Generate {
if ($UseSystemOpenSSLCrypto) {
$Arguments += " -DQUIC_USE_SYSTEM_LIBCRYPTO=on"
}
if ($Platform -eq "android") {
$env:PATH = "$env:ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$env:PATH"
switch ($Arch) {
"x86" { $Arguments += " -DANDROID_ABI=x86"}
"x64" { $Arguments += " -DANDROID_ABI=x86_64" }
"arm" { $Arguments += " -DANDROID_ABI=armeabi-v7a" }
"arm64" { $Arguments += " -DANDROID_ABI=arm64-v8a" }
}
$Arguments += " -DANDROID_PLATFORM=android-29"
$NDK = $env:ANDROID_NDK_HOME
$NdkToolchainFile = "$NDK/build/cmake/android.toolchain.cmake"
$Arguments += " -DANDROID_NDK=$NDK"
$Arguments += " -DCMAKE_TOOLCHAIN_FILE=$NdkToolchainFile"
}
$Arguments += " -DQUIC_LIBRARY_NAME=$LibraryName"
$Arguments += " ../../.."

Просмотреть файл

@ -30,7 +30,7 @@ param (
[string]$Arch = "",
[Parameter(Mandatory = $false)]
[ValidateSet("uwp", "windows", "linux", "macos", "")] # For future expansion
[ValidateSet("uwp", "windows", "linux", "macos", "android", "")] # For future expansion
[string]$Platform = "",
[Parameter(Mandatory = $false)]
@ -44,6 +44,15 @@ param (
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
if ($Platform -eq "android") {
if (!$IsLinux) {
Write-Error "Can only build android on linux"
}
if ($Arch -eq "") {
$Arch = "arm64"
}
}
if ("" -eq $Arch) {
if ($IsMacOS) {
$RunningArch = uname -m

Просмотреть файл

@ -26,7 +26,7 @@ if(QUIC_ENABLE_LOGGING)
endif()
endif()
if (NOT MSVC AND NOT APPLE)
if (NOT MSVC AND NOT APPLE AND NOT ANDROID)
find_library(ATOMIC NAMES atomic libatomic.so.1)
if (ATOMIC)
message(STATUS "Found libatomic: ${ATOMIC}")

Просмотреть файл

@ -591,7 +591,7 @@ CxPlatThreadCreate(
#endif // !CXPLAT_USE_CUSTOM_THREAD_CONTEXT
#ifndef __GLIBC__
#if !defined(__GLIBC__) && !defined(__ANDROID__)
if (Status == QUIC_STATUS_SUCCESS) {
if (Config->Flags & CXPLAT_THREAD_FLAG_SET_AFFINITIZE) {
cpu_set_t CpuSet;
@ -619,6 +619,7 @@ CxPlatSetCurrentThreadProcessorAffinity(
_In_ uint16_t ProcessorIndex
)
{
#ifndef __ANDROID__
cpu_set_t CpuSet;
pthread_t Thread = pthread_self();
CPU_ZERO(&CpuSet);
@ -632,6 +633,10 @@ CxPlatSetCurrentThreadProcessorAffinity(
}
return QUIC_STATUS_SUCCESS;
#else
UNREFERENCED_PARAMETER(ProcessorIndex);
return QUIC_STATUS_SUCCESS;
#endif
}
#elif defined(CX_PLATFORM_DARWIN)