Skip to content

Commit

Permalink
Add android native library build support (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse authored Jul 21, 2021
1 parent 8d82207 commit acdebe4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .azure/azure-pipelines.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
16 changes: 15 additions & 1 deletion scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 += " ../../.."

Expand Down
11 changes: 10 additions & 1 deletion scripts/get-buildconfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/inc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
7 changes: 6 additions & 1 deletion src/platform/platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -619,6 +619,7 @@ CxPlatSetCurrentThreadProcessorAffinity(
_In_ uint16_t ProcessorIndex
)
{
#ifndef __ANDROID__
cpu_set_t CpuSet;
pthread_t Thread = pthread_self();
CPU_ZERO(&CpuSet);
Expand All @@ -632,6 +633,10 @@ CxPlatSetCurrentThreadProcessorAffinity(
}

return QUIC_STATUS_SUCCESS;
#else
UNREFERENCED_PARAMETER(ProcessorIndex);
return QUIC_STATUS_SUCCESS;
#endif
}

#elif defined(CX_PLATFORM_DARWIN)
Expand Down

0 comments on commit acdebe4

Please sign in to comment.