diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index a2611bf37..599854a92 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -19,18 +19,36 @@ jobs: run: ./generator/test.sh lib: - runs-on: ubuntu-20.04 - container: - image: google/dart:latest + strategy: + matrix: + os: + - windows-2019 + - macos-10.15 + - ubuntu-20.04 + dart: + - 2.10.5 + # - 2.9.3 - generator stuck. I remember there was an issue in some dependency but don't remember which one. + - 2.8.4 + - 2.7.2 + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v1 + # Note: dart-sdk from flutter doesn't work on linux, see https://github.com/flutter/flutter/issues/74599 + # - uses: subosito/flutter-action@v1 + # with: + # flutter-version: 1.22.x + # - run: flutter --version + - uses: cedx/setup-dart@v2 + with: + version: ${{ matrix.dart }} + - run: dart --version + - uses: actions/checkout@v2 - name: Install ObjectBox C-API run: ./install.sh - - run: pub get + - run: ./tool/pub.sh get - name: Generate ObjectBox models - run: pub run build_runner build + run: ./tool/pub.sh run build_runner build - name: Run tests - run: pub run test + run: ./tool/pub.sh run test valgrind: runs-on: ubuntu-20.04 @@ -47,4 +65,4 @@ jobs: run: | apt update apt install -y valgrind - - run: ./tool/valgrind.sh \ No newline at end of file + - run: ./tool/valgrind.sh diff --git a/lib/src/bindings/bindings.dart b/lib/src/bindings/bindings.dart index e75223fa0..e0e965a3f 100644 --- a/lib/src/bindings/bindings.dart +++ b/lib/src/bindings/bindings.dart @@ -11,8 +11,18 @@ ObjectBoxC loadObjectBoxLib() { var libName = 'objectbox'; if (Platform.isWindows) { libName += '.dll'; + try { + lib = DynamicLibrary.open(libName); + } on ArgumentError { + lib = DynamicLibrary.open('lib/' + libName); + } } else if (Platform.isMacOS) { libName = 'lib' + libName + '.dylib'; + try { + lib = DynamicLibrary.open(libName); + } on ArgumentError { + lib = DynamicLibrary.open('/usr/local/lib/' + libName); + } } else if (Platform.isIOS) { // this works in combination with `'OTHER_LDFLAGS' => '-framework ObjectBox'` in objectbox_flutter_libs.podspec lib = DynamicLibrary.process(); diff --git a/lib/src/bindings/flatbuffers.dart b/lib/src/bindings/flatbuffers.dart index 0fb0cded2..bc61549d3 100644 --- a/lib/src/bindings/flatbuffers.dart +++ b/lib/src/bindings/flatbuffers.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; import 'package:ffi/ffi.dart' as f; import 'dart:ffi'; +import 'dart:io' show Platform; import '../../flatbuffers/flat_buffers.dart' as fb; @@ -80,8 +81,30 @@ class _Allocator extends fb.Allocator { @override void clear(ByteData data, bool _) { - _memset ??= DynamicLibrary.process().lookupFunction< - Void Function(Pointer, Int32, IntPtr), _dart_memset>('memset'); + if (_memset == null) { + try { + DynamicLibrary lib; + if (Platform.isWindows) { + // DynamicLibrary.process() is not available on Windows, let's load a + // lib that defines 'memset()' it - should be mscvr100 or mscvrt DLL. + // mscvr100.dll is in the frequently installed MSVC Redistributable. + lib = DynamicLibrary.open('msvcr100.dll'); + } else { + lib = DynamicLibrary.process(); + } + _memset = lib.lookupFunction< + Void Function(Pointer, Int32, IntPtr), + _dart_memset>('memset'); + } catch (_) { + // fall back if we can't load a native memset() + _memset = (Pointer ptr, int byte, int size) { + final bytes = ptr.cast(); + for (var i = 0; i < size; i++) { + bytes[i] = byte; + } + }; + } + } _memset(_allocs[data].cast(), 0, data.lengthInBytes); } } diff --git a/lib/src/query/query.dart b/lib/src/query/query.dart index ad0fc906e..ec234d7c6 100644 --- a/lib/src/query/query.dart +++ b/lib/src/query/query.dart @@ -754,7 +754,7 @@ class Query { try { final idArray = idArrayPtr.ref; return idArray.count == 0 - ? List.empty() + ? List.filled(0, 0) : idArray.ids.asTypedList(idArray.count).toList(growable: false); } finally { C.id_array_free(idArrayPtr); diff --git a/pubspec.yaml b/pubspec.yaml index 4507d2341..1856ea771 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,8 @@ description: ObjectBox is a super-fast NoSQL ACID compliant object database. environment: # sdk: '>=2.12.0-0 <3.0.0' - sdk: '>=2.6.0 <3.0.0' + # min 2.7.0 because of ffigen + sdk: '>=2.7.0 <3.0.0' dependencies: collection: ^1.14.11 @@ -20,8 +21,8 @@ dev_dependencies: build_runner: ^1.0.0 objectbox_generator: path: generator - pedantic: ^1.10.0-nullsafety.0 - test: ^1.16.0-nullsafety.0 + pedantic: ^1.9.0 + test: ^1.0.0 ffigen: ^1.1.0 flat_buffers: 1.12.0 diff --git a/tool/pub.sh b/tool/pub.sh new file mode 100755 index 000000000..b9ed4b573 --- /dev/null +++ b/tool/pub.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +# forward all arguments to an available version of `pub` + +if [[ `command -v pub` ]]; then + pub "$@" +elif [[ `command -v pub.bat` ]]; then + pub.bat "$@" +else + dart pub "$@" +fi