From e72eb82163aa61872287ed62cb0a3ea37d6243b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Cig=C3=A1nek?= Date: Tue, 17 Dec 2024 16:45:28 +0100 Subject: [PATCH] ci: Test dart bindings on linux and windows --- .github/workflows/ci.yml | 179 ++++++++++++++++++-------------- bindings/dart/lib/bindings.dart | 24 ++--- 2 files changed, 111 insertions(+), 92 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f53cc8085..9744d9b02 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/gradle-build-action@v2.4.2 - - - 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/gradle-build-action@v2.4.2 + + # - 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 @@ -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 @@ -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 diff --git a/bindings/dart/lib/bindings.dart b/bindings/dart/lib/bindings.dart index 548c5b0f3..f8eeaaff6 100644 --- a/bindings/dart/lib/bindings.dart +++ b/bindings/dart/lib/bindings.dart @@ -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`. @@ -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;