Skip to content

Commit

Permalink
Add android
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-keller committed Jun 19, 2024
1 parent 2fc501b commit b0322f1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
87 changes: 51 additions & 36 deletions .github/workflows/cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/surrealdb/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b0322f1

Please sign in to comment.