Skip to content

Commit

Permalink
ci: Test dart bindings on linux and windows
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Dec 18, 2024
1 parent 1af890c commit e72eb82
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 92 deletions.
179 changes: 100 additions & 79 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,83 +84,99 @@ jobs:
if: matrix.name == 'linux'
run: ${{ matrix.cargo-command }} test --package ouisync-cli --test cli

check_kotlin_bindings:
name: check kotlin bindings
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Add rust targets
run: rustup target add x86_64-linux-android armv7-linux-androideabi aarch64-linux-android

- name: Setup java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Setup gradle
uses: gradle/[email protected]

- name: Install system dependencies
# NOTE: fuse isn't used by the bindings themselves but it's required for the unit tests
# because they use the linux version of the ouisync_service library, not the android one
# and the linux version does currently unconditionally depend on fuse.
run: sudo apt-get install libfuse-dev

# - name: Install NDK
# uses: nttld/setup-ndk@v1
# with:
# ndk-version: r27c
# link-to-sdk: true
# local-cache: true

- name: Cache cargo artifacts
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache gradle artifacts
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('bindings/kotlin/**/*.gradle*', 'bindings/kotlin/**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Create local.properties
working-directory: bindings/kotlin
run: echo "useLocalLib=true" > local.properties

- name: Run spotless
working-directory: bindings/kotlin
run: ./gradlew --stacktrace spotlessCheck
# TODO: The kotlin bindings need to be updated to the new service architecture, disabled for now
# check_kotlin_bindings:
# name: check kotlin bindings
# runs-on: ubuntu-24.04
# steps:
# - uses: actions/checkout@v4

# - name: Add rust targets
# run: rustup target add x86_64-linux-android armv7-linux-androideabi aarch64-linux-android

# - name: Setup java
# uses: actions/setup-java@v3
# with:
# distribution: 'temurin'
# java-version: '17'

# - name: Setup gradle
# uses: gradle/[email protected]

# - name: Install system dependencies
# # NOTE: fuse isn't used by the bindings themselves but it's required for the unit tests
# # because they use the linux version of the ouisync_service library, not the android one
# # and the linux version does currently unconditionally depend on fuse.
# run: sudo apt-get install libfuse-dev

# # - name: Install NDK
# # uses: nttld/setup-ndk@v1
# # with:
# # ndk-version: r27c
# # link-to-sdk: true
# # local-cache: true

# - name: Cache cargo artifacts
# uses: actions/cache@v3
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# target/
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
# restore-keys: |
# ${{ runner.os }}-cargo-

# - name: Cache gradle artifacts
# uses: actions/cache@v3
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('bindings/kotlin/**/*.gradle*', 'bindings/kotlin/**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-

# - name: Create local.properties
# working-directory: bindings/kotlin
# run: echo "useLocalLib=true" > local.properties

# - name: Run spotless
# working-directory: bindings/kotlin
# run: ./gradlew --stacktrace spotlessCheck

# - name: Run lint
# working-directory: bindings/kotlin
# run: ./gradlew --stacktrace lint

# - name: Run unit tests
# working-directory: bindings/kotlin
# run: ./gradlew --stacktrace lib:testDebugUnitTest

# - name: Build the example app
# working-directory: bindings/kotlin
# run: ./gradlew --stacktrace example:assembleDebug

- name: Run lint
working-directory: bindings/kotlin
run: ./gradlew --stacktrace lint
check_dart_bindings:
name: check dart bindings on ${{ matrix.name }}
runs-on: ${{ matrix.os }}

- name: Run unit tests
working-directory: bindings/kotlin
run: ./gradlew --stacktrace lib:testDebugUnitTest
strategy:
matrix:
name: [linux, windows]
include:
- name: linux
os: ubuntu-24.04
cargo-dir: ~/.cargo
ouisync_lib: ../../target/debug/libouisync_service.so

- name: Build the example app
working-directory: bindings/kotlin
run: ./gradlew --stacktrace example:assembleDebug
- name: windows
os: windows-latest
cargo-dir: ~\cargo
ouisync_lib: ..\..\target\debug\ouisync_service.dll

check_dart_bindings:
name: check dart bindings
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

Expand All @@ -173,14 +189,15 @@ jobs:
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
ouisync/target/
${{ matrix.cargo-dir }}/bin/
${{ matrix.cargo-dir }}/registry/index/
${{ matrix.cargo-dir }}/registry/cache/
${{ matrix.cargo-dir }}/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Install system dependencies
if: matrix.name == 'linux'
run: sudo apt-get install libfuse-dev

- name: Get dart dependencies
Expand All @@ -192,17 +209,21 @@ jobs:
run: dart run util/bindgen.dart

- name: Analyze
# analyze should be the same on all platforms so run it on just one to save time
if: matrix.name == 'linux'
working-directory: bindings/dart
run: |
dart analyze lib
dart analyze test
dart analyze example
- name: Building the ouisync service library for tests
- name: Build the ouisync service library for tests
run: cargo build -p ouisync-service --lib

- name: Run tests
working-directory: bindings/dart
env:
RUST_LOG: ouisync=debug,sqlx=warn
OUISYNC_LIB: ${{ matrix.ouisync_lib }}
run: flutter test

24 changes: 11 additions & 13 deletions bindings/dart/lib/bindings.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:ffi';
import 'dart:io';

import 'package:path/path.dart';
import 'package:flutter/foundation.dart' show kReleaseMode;

export 'bindings.g.dart';

/// Callback for `start` and `stop`.
Expand Down Expand Up @@ -87,19 +84,20 @@ DynamicLibrary _defaultLib() {
}

// full path to loadable library
late final String path;
final String path;

if (env.containsKey('OUISYNC_LIB')) {
// user provided library path
path = env['OUISYNC_LIB']!;
} else if (env.containsKey('FLUTTER_TEST')) {
// guess the location of flutter's build output
final String build;
if (Platform.isMacOS) {
build = join(dirname(Platform.script.toFilePath()), 'ouisync');
} else {
build = join('..', '..');
}
path = join(build, 'target', kReleaseMode ? 'release' : 'debug', name);
//} else if (env.containsKey('FLUTTER_TEST')) {
// // guess the location of flutter's build output
// final String build;
// if (Platform.isMacOS) {
// build = join(dirname(Platform.script.toFilePath()), 'ouisync');
// } else {
// build = join('..', '..');
// }
// path = join(build, 'target', kReleaseMode ? 'release' : 'debug', name);
} else {
// assume that the library is available globally by name only
path = name;
Expand Down

0 comments on commit e72eb82

Please sign in to comment.