Skip to content

Commit

Permalink
Add android15 15KB page size support
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Dec 11, 2024
1 parent 775b752 commit ddc66fb
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 52 deletions.
118 changes: 84 additions & 34 deletions 1k/1kiss.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ class _1kiss {
$stringAsStream.Position = 0
return (Get-FileHash -InputStream $stringAsStream -Algorithm MD5).Hash
}

[void] insert([ref]$arr, $item) {
if($item -and !$arr.Value.Contains($item)) {
$arr.Value += $item
}
}
}
$1k = [_1kiss]::new()

Expand Down Expand Up @@ -236,6 +242,8 @@ $channels = @{}
# refer to: https://developer.android.com/studio#command-line-tools-only
$cmdlinetools_rev = '11076708' # 12.0

$ndk_r23d_rev = '12186248'

$android_sdk_tools = @{
'build-tools' = '34.0.0'
'platforms' = 'android-34'
Expand Down Expand Up @@ -729,8 +737,10 @@ function download_and_expand($url, $out, $dest) {
}

function resolve_path ($path) { if ($1k.isabspath($path)) { $path } else { Join-Path $external_prefix $path } }
function fetch_pkg($url, $exrep = $null) {
$name = Split-Path $url -Leaf
function fetch_pkg($url, $exrep = $null, $name = $null) {
if(!$name) {
$name = Split-Path $url.Split('?')[0] -Leaf
}
$out = Join-Path $external_prefix $name
$dest = $external_prefix

Expand Down Expand Up @@ -1130,7 +1140,10 @@ function setup_android_sdk() {

$my_sdk_root = Join-Path $external_prefix 'adt/sdk'

$sdk_dirs = @("$env:ANDROID_HOME", "$env:ANDROID_SDK_ROOT", $my_sdk_root)
$sdk_dirs = @()
$1k.insert([ref]$sdk_dirs, $env:ANDROID_HOME)
$1k.insert([ref]$sdk_dirs, $env:ANDROID_SDK_ROOT)
$1k.insert([ref]$sdk_dirs, $my_sdk_root)

$ndk_minor_base = [int][char]'a'

Expand Down Expand Up @@ -1219,34 +1232,57 @@ function setup_android_sdk() {
$matchInfos = (exec_prog -prog $sdkmanager_prog -params "--sdk_root=$sdk_root", '--list' | Select-String 'ndk;')
if ($null -ne $matchInfos -and $matchInfos.Count -gt 0) {
$1k.println("Not found suitable android ndk, installing ...")
# for android 15 16KB page size support, ndk-r23d only available on ci.android.com, refer:
# - https://developer.android.com/about/versions/15/behavior-changes-all#16-kb
# - https://developer.android.google.cn/about/versions/15/behavior-changes-all?hl=zh-cn#16-kb
# IF fail, you can visit download url by browser:
# - https://ci.android.com/builds/submitted/12186248/win64/latest/android-ndk-12186248-windows-x86_64.zip
# - https://ci.android.com/builds/submitted/12186248/linux/latest/android-ndk-12186248-linux-x86_64.zip
# - https://ci.android.com/builds/submitted/12186248/darwin_mac/latest/android-ndk-12186248-darwin-x86_64.zip
$ndk_loc = Join-Path $sdk_root 'ndk'
if ($ndk_ver -eq 'r23d') {
$_artifact = @("android-ndk-${ndk_r23d_rev}-windows-x86_64.zip",
"android-ndk-${ndk_r23d_rev}-linux-x86_64.zip",
"android-ndk-${ndk_r23d_rev}-darwin-x86_64.zip").Get($HOST_OS)
$_target_os = @('win64', 'linux', 'darwin_mac').Get($HOST_OS)
. (Join-Path $myRoot 'resolv-url.ps1') -artifact $_artifact -target $_target_os -build_id $ndk_r23d_rev -manifest gcloud -out_var 'artifact_info'
$artifact_url = $artifact_info[0].messageData
$full_ver = "23.3.${ndk_r23d_rev}"
$1k.println("Installing ndk-r23d from ci.android.com ...")
$ndk_root = Join-Path $ndk_loc $full_ver
fetch_pkg -url $artifact_url -exrep "android-ndk-r23d-canary=$ndk_root" -name $_artifact
if (!$1k.isdir($ndk_root)) { throw "Install ndk-r23d fail, please try again" }
}
else {
# install ndk by android sdk manager
$ndks = @{}
foreach ($matchInfo in $matchInfos) {
$fullVer = $matchInfo.Line.Trim().Split(' ')[0] # "ndk;23.2.8568313"
$verNums = $fullVer.Split(';')[1].Split('.')
$ndkVer = 'r'
$ndkVer += $verNums[0]

$ndk_minor = [int]$verNums[1]
if ($ndk_minor -gt 0) {
$ndkVer += [char]($ndk_minor_base + $ndk_minor)
}
if (!$ndks.Contains($ndkVer)) {
$ndks.Add($ndkVer, $fullVer)
}
}

$ndks = @{}
foreach ($matchInfo in $matchInfos) {
$fullVer = $matchInfo.Line.Trim().Split(' ')[0] # "ndk;23.2.8568313"
$verNums = $fullVer.Split(';')[1].Split('.')
$ndkVer = 'r'
$ndkVer += $verNums[0]
$ndkFullVer = $ndks[$ndk_ver]

$ndk_minor = [int]$verNums[1]
if ($ndk_minor -gt 0) {
$ndkVer += [char]($ndk_minor_base + $ndk_minor)
((1..10 | ForEach-Object { "yes"; Start-Sleep -Milliseconds 100 }) | . $sdkmanager_prog --licenses --sdk_root=$sdk_root) | Out-Host
if (!$ndkOnly) {
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", 'platform-tools', 'cmdline-tools;latest', "platforms;$($android_sdk_tools['platforms'])", "build-tools;$($android_sdk_tools['build-tools'])", $ndkFullVer | Out-Host
}
if (!$ndks.Contains($ndkVer)) {
$ndks.Add($ndkVer, $fullVer)
else {
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", $ndkFullVer | Out-Host
}
$full_ver = $ndkFullVer.Split(';')[1]
$ndk_root = (Resolve-Path -Path "$ndk_loc/$full_ver").Path
}

$ndkFullVer = $ndks[$ndk_ver]

((1..10 | ForEach-Object { "yes"; Start-Sleep -Milliseconds 100 }) | . $sdkmanager_prog --licenses --sdk_root=$sdk_root) | Out-Host
if (!$ndkOnly) {
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", 'platform-tools', 'cmdline-tools;latest', "platforms;$($android_sdk_tools['platforms'])", "build-tools;$($android_sdk_tools['build-tools'])", $ndkFullVer | Out-Host
}
else {
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", $ndkFullVer | Out-Host
}
$fullVer = $ndkFullVer.Split(';')[1]
$ndk_root = (Resolve-Path -Path "$sdk_root/ndk/$fullVer").Path
}
}

Expand Down Expand Up @@ -1888,21 +1924,35 @@ if (!$setupOnly) {
# apply additional build options
$BUILD_ALL_OPTIONS += "--parallel", "$($options.j)"

if ($options.t) { $cmake_target = $options.t }
if ($cmake_target) { $BUILD_ALL_OPTIONS += '--target', $cmake_target }

$1k.println("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)

# forward non-cmake args to underlaying build toolchain, must at last
$forward_options = @()
if (($cmake_generator -eq 'Xcode') -and !$BUILD_ALL_OPTIONS.Contains('--verbose')) {
$BUILD_ALL_OPTIONS += '--', '-quiet'
$forward_options += '--', '-quiet'
}
$1k.println("cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS")
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS | Out-Host
if (!$?) {
Set-Location $stored_cwd
exit $LASTEXITCODE
}

if ($options.t) { $cmake_target = $options.t }
if ($cmake_target) {
$cmake_targets = $cmake_target.Split(',') | Sort-Object | Get-Unique
foreach ($target in $cmake_targets) {
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS --target $target $forward_options | Out-Host
if (!$?) {
Set-Location $stored_cwd
exit $LASTEXITCODE
}
}
}
else {
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS $forward_options | Out-Host
if (!$?) {
Set-Location $stored_cwd
exit $LASTEXITCODE
}
}

if ($options.i) {
$install_args = @($BUILD_DIR, '--config', $optimize_flag)
cmake --install $install_args | Out-Host
Expand Down
2 changes: 1 addition & 1 deletion 1k/fetch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function(_1kfetch_init)
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
endif()

execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/resolv-uri.ps1
execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/resolv-url.ps1
-name "1kdist"
-manifest ${_1kfetch_manifest}
OUTPUT_VARIABLE _1kdist_url
Expand Down
6 changes: 6 additions & 0 deletions 1k/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ if ($Global:is_axmol_app -or $Global:is_axmol_engine) {
$manifest['emsdk'] = '3.1.66~3.1.67+'
$manifest['jdk'] = '17.0.10~17.0.12+'
$manifest['vs'] = '16.0+'

# for android 15 16KB page size support, ndk-r23d only available on ci.android.com, refer:
# - https://developer.android.com/about/versions/15/behavior-changes-all#16-kb
# - https://developer.android.google.cn/about/versions/15/behavior-changes-all?hl=zh-cn#16-kb
# r23d rev: 23.3.12186248
# $manifest['ndk'] = 'r23d'
}

# android sdk tools
Expand Down
5 changes: 5 additions & 0 deletions 1k/platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(PLATFORM_NAME android)
set(ARCH_ALIAS ${ANDROID_ABI})

# refer
# - https://developer.android.com/about/versions/15/behavior-changes-all#16-kb
# - https://developer.android.google.cn/about/versions/15/behavior-changes-all?hl=zh-cn#16-kb
set(_16KPAGE_SIZE_LD_FLAGS "-Wl,-z,max-page-size=16384")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
set(PLATFORM_NAME linux)
Expand Down
17 changes: 0 additions & 17 deletions 1k/resolv-uri.ps1

This file was deleted.

61 changes: 61 additions & 0 deletions 1k/resolv-url.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# resolve artifact url
param(
[Alias('artifact')]
$name,
$manifest,
$target,
$build_id,
$branch,
$out_var
)

$artifact_url = $null

if ($manifest -eq 'gcloud') {
function Get-LatestGoodBuild {
param (
[string]$branch,
[string]$target
)

$apiURL = "https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds?branches=$([uri]::EscapeDataString($branch))&buildAttemptStatus=complete&buildType=submitted&maxResults=1&successful=true&target=$([uri]::EscapeDataString($target))"
$body = Invoke-WebRequest -Uri $apiURL
$buildData = $body | ConvertFrom-Json
if ($buildData.builds.Count -eq 0) {
throw "No build ID is found"
}
return $buildData.builds[0].buildId
}

# Validate input parameters
$artifact = $name
if (-not $target) { throw "Missing target." }
if (-not $artifact) { throw "Missing artifact." }
if (-not $build_id -and -not $branch) { throw "Missing build_id or branch." }
if (-not $build_id -and $branch) {
$build_id = Get-LatestGoodBuild -branch $branch -target $target
}

$artifact_url = "https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds/$([uri]::EscapeDataString($build_id))/$([uri]::EscapeDataString($target))/attempts/latest/artifacts/$([uri]::EscapeDataString($artifact))/url"
}
else {
if (Test-Path $manifest -PathType Leaf) {
$mirror = if (!(Test-Path (Join-Path $PSScriptRoot '.gitee') -PathType Leaf)) { 'github' } else { 'gitee' }

$manifest_map = ConvertFrom-Json (Get-Content $manifest -raw)
$ver = $manifest_map.versions.PSObject.Properties[$name].Value
$mirror_current = $manifest_map.mirrors.PSObject.Properties[$mirror].Value.PSObject.Properties
$url_base = "https://$($mirror_current['host'].Value)/"
$url_path = $mirror_current[$name].Value

$artifact_url = "$url_base$url_path#$ver"
}
}

if($artifact_url) {
if(!$out_var) {
Write-Host $artifact_url -NoNewline
} else {
Write-Information $artifact_url -InformationVariable $out_var
}
}
1 change: 1 addition & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ if (AX_ENABLE_AUDIO)
target_compile_definitions(3rdparty INTERFACE AL_LIBTYPE_STATIC=1)
elseif(ANDROID)
set(ANDROID_SHARED_LOADS "${ANDROID_SHARED_LOADS}System.loadLibrary(\"openal\");" CACHE INTERNAL "Android Shared Loads" )
target_link_options(OpenAL PRIVATE "${_16KPAGE_SIZE_LD_FLAGS}")
endif()
endif()

Expand Down
2 changes: 2 additions & 0 deletions cmake/Modules/AXBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ function(ax_setup_app_config app_name)
if (_win32_console_app)
set_source_files_properties(proj.win32/main.cpp PROPERTIES COMPILE_DEFINITIONS _CONSOLE=1)
endif()
elseif(ANDROID)
target_link_options(${APP_NAME} PRIVATE "${_16KPAGE_SIZE_LD_FLAGS}")
endif()
# auto mark code files for IDE when mark app
if(XCODE OR VS)
Expand Down
1 change: 1 addition & 0 deletions core/platform/android/libaxmol/axutils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class axutils {
options.add('"-DANDROID_STL=c++_shared"')
options.add('"-DANDROID_TOOLCHAIN=clang"')
options.add('"-DANDROID_ARM_NEON=TRUE"')
options.add('"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"')
options.add("\"-D_AX_ANDROID_PROJECT_DIR=${androidProjDir}\"")
rets[3] = options
}
Expand Down

0 comments on commit ddc66fb

Please sign in to comment.