From 29e1026ee1cb11df3fe1eaed60c235f4112577f5 Mon Sep 17 00:00:00 2001 From: james58899 Date: Wed, 5 Jun 2024 05:17:16 +0000 Subject: [PATCH] Build android --- .github/workflows/build.yml | 43 ++++++++++++++++++++++++++++++++++- .github/workflows/release.yml | 10 +++++++- Cargo.toml | 2 +- src/main.rs | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b199eb1..daf7d3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,6 +23,10 @@ on: required: false type: boolean default: false + skip-android: + required: false + type: boolean + default: false env: CARGO_TERM_COLOR: always @@ -57,7 +61,7 @@ jobs: env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: "aarch64-linux-gnu-gcc" CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: "arm-linux-gnueabihf-gcc" - run: cargo build --verbose --release --target=${{ matrix.target }} + run: cargo build --verbose --release --target=${{ matrix.target }} - uses: actions/upload-artifact@v4 with: name: hath-rust-${{ matrix.target }} @@ -161,3 +165,40 @@ jobs: with: name: hath-rust-universal-apple-darwin path: target/release/hath-rust + build-android: + runs-on: ubuntu-latest + if: inputs.skip-android != true + strategy: + fail-fast: false + matrix: + target: ["aarch64-linux-android", "armv7-linux-androideabi", "i686-linux-android", "x86_64-linux-android"] + steps: + - uses: actions/checkout@v4 + - name: Install Android NDK + uses: nttld/setup-ndk@v1 + with: + ndk-version: r26d + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} + - name: Install toolchain + run: | + rustup update + rustup target add ${{ matrix.target }} + - name: Build + env: + CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER: "aarch64-linux-android21-clang" + CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER: "armv7a-linux-androideabi21-clang" + CARGO_TARGET_I686_LINUX_ANDROID_LINKER: "i686-linux-android21-clang" + CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER: "x86_64-linux-android21-clang" + run: cargo build --verbose --release --target=${{ matrix.target }} + - uses: actions/upload-artifact@v4 + with: + name: hath-rust-${{ matrix.target }} + path: target/${{ matrix.target }}/release/hath-rust diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05fccfd..afed27b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,6 +28,10 @@ jobs: mv artifacts/hath-rust-x86_64-pc-windows-msvc/hath-rust.exe hath-rust-x86_64-pc-windows-msvc.exe mv artifacts/hath-rust-i686-pc-windows-msvc/hath-rust.exe hath-rust-i686-pc-windows-msvc.exe mv artifacts/hath-rust-universal-apple-darwin/hath-rust hath-rust-universal-apple-darwin + mv artifacts/hath-rust-aarch64-linux-android/hath-rust hath-rust-aarch64-linux-android + mv artifacts/hath-rust-armv7-linux-androideabi/hath-rust hath-rust-armv7-linux-androideabi + mv artifacts/hath-rust-i686-linux-android/hath-rust hath-rust-i686-linux-android + mv artifacts/hath-rust-x86_64-linux-android/hath-rust hath-rust-x86_64-linux-android - name: Create release uses: softprops/action-gh-release@v2 with: @@ -42,4 +46,8 @@ jobs: hath-rust-armv7-unknown-linux-musleabihf hath-rust-x86_64-pc-windows-msvc.exe hath-rust-i686-pc-windows-msvc.exe - hath-rust-universal-apple-darwin \ No newline at end of file + hath-rust-universal-apple-darwin + hath-rust-aarch64-linux-android + hath-rust-armv7-linux-androideabi + hath-rust-i686-linux-android + hath-rust-x86_64-linux-android \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6d1c74b..8b01214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ unicode-segmentation = "1.11.0" [target.'cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))'.dependencies] cpufeatures = "0.2" -[target.'cfg(not(any(target_env = "msvc", target_os = "macos")))'.dependencies] +[target.'cfg(not(any(target_env = "msvc", target_os = "macos", target_os = "android")))'.dependencies] tikv-jemallocator = { version = "0.5", features = ["background_threads", "unprefixed_malloc_on_supported_platforms"] } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/src/main.rs b/src/main.rs index edc1cb5..4019bfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ mod rpc; mod server; mod util; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(any(target_env = "msvc", target_os = "android")))] #[global_allocator] static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;