Skip to content

Commit 67249ef

Browse files
committed
feat: add android for ci
1 parent f2cf1af commit 67249ef

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

.github/workflows/build.yml

+69-1
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,76 @@ jobs:
241241
name: MAA-macos-${{ matrix.arch }}
242242
path: "install"
243243

244+
android:
245+
needs: meta
246+
runs-on: ubuntu-latest
247+
strategy:
248+
matrix:
249+
include:
250+
- os: ubuntu
251+
arch: arm64-android
252+
- os: ubuntu
253+
arch: x64-android
254+
fail-fast: false
255+
256+
steps:
257+
- uses: actions/checkout@v3
258+
with:
259+
submodules: true
260+
261+
- name: Install Packages
262+
run: |
263+
sudo apt-get update -y
264+
sudo apt-get install -y ninja-build python3-pyelftools elfutils patchelf nasm
265+
266+
- uses: nttld/setup-ndk@v1
267+
id: setup-ndk
268+
with:
269+
ndk-version: r27
270+
271+
- name: Setup ccache
272+
uses: Chocobo1/setup-ccache-action@v1
273+
with:
274+
remove_stale_cache: false
275+
276+
- name: Bootstrap MaaDeps
277+
env:
278+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
279+
run: |
280+
python3 tools/maadeps-download.py ${{ matrix.arch }}
281+
282+
- name: Build MAA
283+
run: |
284+
cmake --preset 'NinjaMulti' \
285+
-DCMAKE_TOOLCHAIN_FILE=${{ steps.setup-ndk.outputs.ndk-path}}/build/cmake/android.toolchain.cmake \
286+
-DANDROID_ABI=${{ matrix.abi }} \
287+
-DANDROID_PLATFORM=android-23 \
288+
-DMAADEPS_TRIPLET='maa-${{ matrix.arch }}' \
289+
-DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}'
290+
291+
cmake --build build --preset 'NinjaMulti - Release' -j 16
292+
293+
- name: Install
294+
shell: bash
295+
if: always()
296+
run: |
297+
cmake --install build --prefix install
298+
299+
cp -r docs install
300+
cp README*.md install
301+
302+
cp -r sample install
303+
304+
cp -r LICENSE.md install
305+
306+
- uses: actions/upload-artifact@v3
307+
if: always()
308+
with:
309+
name: MAA-android-${{ matrix.arch_name }}
310+
path: "install"
311+
244312
nuget_pack:
245-
needs: [meta, windows, ubuntu, macos]
313+
needs: [meta, windows, ubuntu, macos, android]
246314
runs-on: ubuntu-latest
247315
steps:
248316
- uses: nuget/setup-nuget@v2

source/include/Utils/Time.hpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#pragma once
22

3-
#ifdef __APPLE__
3+
#if defined(__APPLE__) || defined(__ANDROID__)
4+
#define MAA_USE_POSIX_TIME
5+
#endif
6+
7+
#ifdef MAA_USE_POSIX_TIME
48
#include <fcntl.h>
59
#include <sys/time.h>
610
#include <time.h>
@@ -18,10 +22,9 @@ MAA_NS_BEGIN
1822

1923
inline std::string format_now()
2024
{
21-
#ifndef __APPLE__ // Clang lacks of std::chrono::current_zone, 2024/08/24
22-
return std::format(
23-
"{}",
24-
std::chrono::current_zone()->to_local(std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now())));
25+
#ifndef MAA_USE_POSIX_TIME
26+
return std::format("{}", std::chrono::current_zone()->to_local(
27+
std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now())));
2528
#else
2629
timeval tv = {};
2730
gettimeofday(&tv, nullptr);
@@ -41,8 +44,9 @@ inline std::string format_now()
4144

4245
inline std::string format_now_for_filename()
4346
{
44-
#ifndef __APPLE__ // Clang lacks of std::chrono::current_zone, 2024/08/24
45-
return std::format("{:%Y.%m.%d-%H.%M.%S}", std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
47+
#ifndef MAA_USE_POSIX_TIME
48+
return std::format("{:%Y.%m.%d-%H.%M.%S}",
49+
std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
4650
#else
4751
timeval tv = {};
4852
gettimeofday(&tv, nullptr);
@@ -66,4 +70,4 @@ inline duration_t duration_since(const std::chrono::steady_clock::time_point& st
6670
return std::chrono::duration_cast<duration_t>(std::chrono::steady_clock::now() - start_time);
6771
}
6872

69-
MAA_NS_END
73+
MAA_NS_END

0 commit comments

Comments
 (0)