Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add android native library build support #1835

Merged
merged 4 commits into from
Jul 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add android native library build support
ThadHouse committed Jul 21, 2021
commit e1aff790f28219dee3d8e2cf0c2891634ccc9fba
8 changes: 8 additions & 0 deletions .azure/azure-pipelines.ci.yml
Original file line number Diff line number Diff line change
@@ -283,6 +283,14 @@ 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

- template: ./templates/build-config-user.yml
parameters:
image: ubuntu-latest
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
19 changes: 18 additions & 1 deletion scripts/build.ps1
Original file line number Diff line number Diff line change
@@ -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)]
@@ -250,6 +250,10 @@ function Log($msg) {
Write-Host "[$(Get-Date)] $msg"
}

if ($Platform -eq "android") {
$DisableLogs = $true
}

# Executes cmake with the given arguments.
function CMake-Execute([String]$Arguments) {
Log "cmake $($Arguments)"
@@ -346,6 +350,19 @@ function CMake-Generate {
if ($UseSystemOpenSSLCrypto) {
$Arguments += " -DQUIC_USE_SYSTEM_LIBCRYPTO=on"
}
if ($Platform -eq "android") {
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 += " ../../.."

6 changes: 5 additions & 1 deletion scripts/get-buildconfig.ps1
Original file line number Diff line number Diff line change
@@ -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,10 @@ param (
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'

if ($Platform -eq "android" -and $Arch -eq "") {
$Arch = "arm64"
}

if ("" -eq $Arch) {
if ($IsMacOS) {
$RunningArch = uname -m
2 changes: 1 addition & 1 deletion src/inc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}")
7 changes: 6 additions & 1 deletion src/platform/platform_posix.c
Original file line number Diff line number Diff line change
@@ -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)