From b0322f1ef89cdf37f4f29f37d28def5dbe15cb02 Mon Sep 17 00:00:00 2001 From: Emmanuel Keller Date: Wed, 19 Jun 2024 23:30:30 +0100 Subject: [PATCH] Add android --- .github/workflows/cross.yml | 87 +++++++++++-------- .../integration/IntegrationTest.java | 2 +- src/main/java/com/surrealdb/Loader.java | 15 +++- 3 files changed, 63 insertions(+), 41 deletions(-) diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index ff86994..3f1bf5c 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -16,44 +16,46 @@ jobs: target: - x86_64-unknown-linux-gnu - aarch64-unknown-linux-gnu + - x86_64-linux-android + - aarch64-linux-android - x86_64-pc-windows-gnu - steps: - - name: Install dependencies - run: sudo apt-get update + steps: + - name: Install dependencies + run: sudo apt-get update - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - - name: Install cross - run: cargo install cross + - name: Install cross + run: cargo install cross - - name: Cache Rust - uses: Swatinem/rust-cache@v2 + - name: Cache Rust + uses: Swatinem/rust-cache@v2 - - name: Pull cross Docker image - run: docker pull rustembedded/cross:${{ matrix.target }} + - name: Pull cross Docker image + run: docker pull rustembedded/cross:${{ matrix.target }} - - name: Cross compile - run: cross build --target ${{ matrix.target }} --release + - name: Cross compile + run: cross build --target ${{ matrix.target }} --release - - name: Upload so lib - if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu' - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.target }}-build - path: target/${{ matrix.target }}/release/*.so + - name: Upload so lib + if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'aarch64-unknown-linux-gnu' + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }}-build + path: target/${{ matrix.target }}/release/*.so - - name: Upload dll lib - if: matrix.target == 'x86_64-pc-windows-gnu' - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.target }}-build - path: target/${{ matrix.target }}/release/*.dll + - name: Upload dll lib + if: matrix.target == 'x86_64-pc-windows-gnu' + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }}-build + path: target/${{ matrix.target }}/release/*.dll build-macos-intel: runs-on: macos-12 @@ -125,12 +127,25 @@ jobs: - name: Create directories for artifacts run: | + mkdir -p src/main/resources/natives/android_64 + mkdir -p src/main/resources/natives/android_arm64 mkdir -p src/main/resources/natives/linux_64 mkdir -p src/main/resources/natives/linux_arm64 - mkdir -p src/main/resources/natives/windows_64 mkdir -p src/main/resources/natives/osx_64 mkdir -p src/main/resources/natives/osx_arm64 + mkdir -p src/main/resources/natives/windows_64 + - name: Download Linux artifacts + uses: actions/download-artifact@v4 + with: + name: x86_64-linux-android-build + path: src/main/resources/natives/android_64 + + - name: Download AArch64 Linux artifacts + uses: actions/download-artifact@v4 + with: + name: aarch64-linux-android-build + path: src/main/resources/natives/android_arm64 - name: Download Linux artifacts uses: actions/download-artifact@v4 with: @@ -143,12 +158,6 @@ jobs: name: aarch64-unknown-linux-gnu-build path: src/main/resources/natives/linux_arm64 - - name: Download Windows artifacts - uses: actions/download-artifact@v4 - with: - name: x86_64-pc-windows-gnu-build - path: src/main/resources/natives/windows_64 - - name: Download macOS Intel artifacts uses: actions/download-artifact@v4 with: @@ -161,6 +170,12 @@ jobs: name: aarch64-apple-darwin-build path: src/main/resources/natives/osx_arm64 + - name: Download Windows artifacts + uses: actions/download-artifact@v4 + with: + name: x86_64-pc-windows-gnu-build + path: src/main/resources/natives/windows_64 + - name: Build JAR run: ./gradlew jar diff --git a/src/integrationTest/java/com/surrealdb/integration/IntegrationTest.java b/src/integrationTest/java/com/surrealdb/integration/IntegrationTest.java index 62c3dc2..0eacf8c 100644 --- a/src/integrationTest/java/com/surrealdb/integration/IntegrationTest.java +++ b/src/integrationTest/java/com/surrealdb/integration/IntegrationTest.java @@ -15,7 +15,7 @@ void surrealdb_websocket() throws Exception { RuntimeException e = assertThrows(RuntimeException.class, () -> { surreal.connect("ws://localhost:8000"); }); - assertTrue(e.getMessage().startsWith("There was an error processing a remote WS request: IO error: Connection refused ")); + assertTrue(e.getMessage().startsWith("There was an error processing a remote WS request: IO error: Connection refused "), e::getMessage); } } diff --git a/src/main/java/com/surrealdb/Loader.java b/src/main/java/com/surrealdb/Loader.java index ba8e078..583fa30 100644 --- a/src/main/java/com/surrealdb/Loader.java +++ b/src/main/java/com/surrealdb/Loader.java @@ -27,14 +27,21 @@ static void load_native() throws RuntimeException { } private static String get_path() { + final String vendor = System.getProperty("java.vendor").toLowerCase(Locale.ENGLISH); final String arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH); final String name = System.getProperty("os.name").toLowerCase(Locale.ENGLISH); - final boolean intel = arch.contains("x86_64") || arch.contains("amd64"); - final boolean arm = arch.contains("aarch64"); - final boolean linux = name.contains("nix") || name.contains("nux"); + final boolean android = vendor.contains("android"); + final boolean linux = name.contains("linux"); final boolean windows = name.contains("win"); final boolean osx = name.contains("mac"); - if (linux) { + final boolean intel = arch.contains("x86_64") || arch.contains("amd64"); + final boolean arm = arch.contains("aarch64") || arch.contains("arm64"); + if (android) { + if (arm) + return "android_arm64"; + else if (intel) + return "android_64"; + } else if (linux) { if (arm) return "linux_arm64"; else if (intel)