From ddc66fb0784134da182a9f0fbbd051c787983ca8 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 12 Dec 2024 01:05:56 +0800 Subject: [PATCH] Add android15 15KB page size support --- 1k/1kiss.ps1 | 118 +++++++++++++----- 1k/fetch.cmake | 2 +- 1k/manifest.ps1 | 6 + 1k/platforms.cmake | 5 + 1k/resolv-uri.ps1 | 17 --- 1k/resolv-url.ps1 | 61 +++++++++ 3rdparty/CMakeLists.txt | 1 + cmake/Modules/AXBuildHelpers.cmake | 2 + core/platform/android/libaxmol/axutils.gradle | 1 + 9 files changed, 161 insertions(+), 52 deletions(-) delete mode 100644 1k/resolv-uri.ps1 create mode 100644 1k/resolv-url.ps1 diff --git a/1k/1kiss.ps1 b/1k/1kiss.ps1 index 6b510e240f40..7d297b748144 100644 --- a/1k/1kiss.ps1 +++ b/1k/1kiss.ps1 @@ -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() @@ -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' @@ -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 @@ -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' @@ -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 } } @@ -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 diff --git a/1k/fetch.cmake b/1k/fetch.cmake index 6fa0c0804fde..4fb7614260a9 100644 --- a/1k/fetch.cmake +++ b/1k/fetch.cmake @@ -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 diff --git a/1k/manifest.ps1 b/1k/manifest.ps1 index 76e45a659300..e92f155bd5c5 100644 --- a/1k/manifest.ps1 +++ b/1k/manifest.ps1 @@ -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 diff --git a/1k/platforms.cmake b/1k/platforms.cmake index b23239a3d4d9..f290e5a163ed 100644 --- a/1k/platforms.cmake +++ b/1k/platforms.cmake @@ -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) diff --git a/1k/resolv-uri.ps1 b/1k/resolv-uri.ps1 deleted file mode 100644 index 9a956b809858..000000000000 --- a/1k/resolv-uri.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -# fetch repo url by name -param( - $name, - $manifest_file -) - -if(Test-Path $manifest_file -PathType Leaf) { - $mirror = if (!(Test-Path (Join-Path $PSScriptRoot '.gitee') -PathType Leaf)) {'github'} else {'gitee'} - - $manifest_map = ConvertFrom-Json (Get-Content $manifest_file -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 - - Write-Host "$url_base$url_path#$ver" -NoNewline -} diff --git a/1k/resolv-url.ps1 b/1k/resolv-url.ps1 new file mode 100644 index 000000000000..ac4a1e889ff8 --- /dev/null +++ b/1k/resolv-url.ps1 @@ -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 + } +} diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index dda1029e22ad..375c0d2e5a32 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -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() diff --git a/cmake/Modules/AXBuildHelpers.cmake b/cmake/Modules/AXBuildHelpers.cmake index 6ef8a263edac..141b2467da51 100644 --- a/cmake/Modules/AXBuildHelpers.cmake +++ b/cmake/Modules/AXBuildHelpers.cmake @@ -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) diff --git a/core/platform/android/libaxmol/axutils.gradle b/core/platform/android/libaxmol/axutils.gradle index a3a3cc66c364..4878330287de 100644 --- a/core/platform/android/libaxmol/axutils.gradle +++ b/core/platform/android/libaxmol/axutils.gradle @@ -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 }