Skip to content

Multi-platform & multi-version CI #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,4 +65,4 @@ jobs:
run: |
apt update
apt install -y valgrind
- run: ./tool/valgrind.sh
- run: ./tool/valgrind.sh
10 changes: 10 additions & 0 deletions lib/src/bindings/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 25 additions & 2 deletions lib/src/bindings/flatbuffers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -80,8 +81,30 @@ class _Allocator extends fb.Allocator {

@override
void clear(ByteData data, bool _) {
_memset ??= DynamicLibrary.process().lookupFunction<
Void Function(Pointer<Void>, 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<Void>, Int32, IntPtr),
_dart_memset>('memset');
} catch (_) {
// fall back if we can't load a native memset()
_memset = (Pointer<Void> ptr, int byte, int size) {
final bytes = ptr.cast<Uint8>();
for (var i = 0; i < size; i++) {
bytes[i] = byte;
}
};
}
}
_memset(_allocs[data].cast<Void>(), 0, data.lengthInBytes);
}
}
2 changes: 1 addition & 1 deletion lib/src/query/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ class Query<T> {
try {
final idArray = idArrayPtr.ref;
return idArray.count == 0
? List<int>.empty()
? List<int>.filled(0, 0)
: idArray.ids.asTypedList(idArray.count).toList(growable: false);
} finally {
C.id_array_free(idArrayPtr);
Expand Down
7 changes: 4 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions tool/pub.sh
Original file line number Diff line number Diff line change
@@ -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