Skip to content

Commit

Permalink
fix: ensure compatibility with Dart 2.19 (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Feb 18, 2023
1 parent a6c68f5 commit caf9bc9
Show file tree
Hide file tree
Showing 52 changed files with 981 additions and 535 deletions.
33 changes: 25 additions & 8 deletions .github/workflows/ci.yaml
Expand Up @@ -15,9 +15,9 @@ on:
- cron: '0 0 * * *'

env:
flutter-version-stable: 3.3.3
flutter-version-beta: beta
dart-version-stable: 2.18.2
# Temporarily use a beta version of Flutter to work around a bug in the stable version.
flutter-channel: beta
dart-version-stable: 2.19.1
dart-version-beta: beta
melos-version: 3.0.0-dev.0

Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter-version-stable }}
channel: ${{ env.flutter-channel }}

- name: Setup Dart
uses: dart-lang/setup-dart@v1
Expand Down Expand Up @@ -154,12 +154,20 @@ jobs:
fail-fast: false
matrix:
embedder: [standalone, flutter]
os: [iOS, macOS, Android, Ubuntu, Windows]
os:
- iOS
- macOS
- Android
- Ubuntu
- Windows
exclude:
- embedder: standalone
os: iOS
- embedder: standalone
os: Android
# TODO: Get macOS tests to launch again in CI
- embedder: flutter
os: macOS
# Flutter + Ubuntu is flaky, likely because of a bug in CBL C, so we allow it to fail for now.
continue-on-error:
${{ matrix.embedder == 'flutter' && matrix.os == 'Ubuntu' }}
Expand Down Expand Up @@ -204,7 +212,7 @@ jobs:
if: matrix.embedder == 'flutter'
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter-version-stable }}
channel: ${{ env.flutter-channel }}

- name: Configure flutter
if: matrix.embedder == 'flutter'
Expand Down Expand Up @@ -265,7 +273,16 @@ jobs:
fail-fast: false
matrix:
embedder: [flutter]
os: [iOS, macOS, Android, Ubuntu, Windows]
os:
- iOS
- macOS
- Android
- Ubuntu
- Windows
exclude:
# TODO: Get macOS tests to launch again in CI
- embedder: flutter
os: macOS
runs-on: >-
${{ fromJSON('{
"iOS":"macos-11",
Expand All @@ -291,7 +308,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.flutter-version-stable }}
channel: ${{ env.flutter-channel }}

- name: Configure flutter
shell: bash
Expand Down
8 changes: 3 additions & 5 deletions .vscode/launch.json
Expand Up @@ -16,8 +16,7 @@
"cwd": "packages/cbl_e2e_tests_flutter",
"request": "launch",
"type": "dart",
"program": "integration_test/e2e_test.dart",
"toolArgs": ["--no-pub"]
"program": "integration_test/e2e_test.dart"
},
{
"name": "cbl_e2e_tests_standalone_dart (test)",
Expand All @@ -31,16 +30,15 @@
"cwd": "packages/cbl_flutter_prebuilt_e2e_tests",
"request": "launch",
"type": "dart",
"program": "integration_test/e2e_test.dart",
"toolArgs": ["--no-pub"]
"program": "integration_test/e2e_test.dart"
},
{
"name": "cbl_sentry (test)",
"templateFor": "packages/cbl_sentry/test",
"type": "dart",
"request": "launch",
"customTool": "${workspaceFolder}/tools/flutter-test-wrapper.sh",
"customToolReplacesArgs": 3,
"customToolReplacesArgs": 3
}
]
}
1 change: 0 additions & 1 deletion all_lint_rules.yaml
Expand Up @@ -74,7 +74,6 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- join_return_with_assignment
- leading_newlines_in_multiline_strings
Expand Down
11 changes: 9 additions & 2 deletions native/couchbase-lite-dart/include/CBL+Dart.h
Expand Up @@ -18,6 +18,12 @@
* C API is integrated with the garbage collection of Dart objects.
*/

enum CBLDartInitializeResult {
CBLDartInitializeResult_kSuccess,
CBLDartInitializeResult_kIncompatibleDartVM,
CBLDartInitializeResult_kCBLInitError,
};

/**
* Initializes the native libraries.
*
Expand All @@ -26,8 +32,9 @@
* NOOPs.
*/
CBLDART_EXPORT
bool CBLDart_Initialize(void *dartInitializeDlData, void *cblInitContext,
CBLError *errorOut);
CBLDartInitializeResult CBLDart_Initialize(void *dartInitializeDlData,
void *cblInitContext,
CBLError *errorOut);

// === Dart Native ============================================================

Expand Down
3 changes: 2 additions & 1 deletion native/couchbase-lite-dart/src/AsyncCallback.cpp
Expand Up @@ -52,6 +52,7 @@ AsyncCallbackRegistry::AsyncCallbackRegistry() {}

AsyncCallback::AsyncCallback(uint32_t id, Dart_Port sendPort, bool debug)
: id_(id), debug_(debug), sendPort_(sendPort) {
assert(sendPort != ILLEGAL_PORT);
AsyncCallbackRegistry::instance.registerCallback(*this);
}

Expand Down Expand Up @@ -132,7 +133,7 @@ bool AsyncCallback::sendRequest(Dart_CObject *request) {
inline void AsyncCallback::debugLog(const char *message) {
#ifdef DEBUG
if (debug_) {
printf("AsyncCallback #%d -> %s\n", id_, message);
printf("AsyncCallback #%d (native) -> %s\n", id_, message);
}
#endif
}
Expand Down
23 changes: 13 additions & 10 deletions native/couchbase-lite-dart/src/CBL+Dart.cpp
Expand Up @@ -12,28 +12,31 @@
static std::mutex initializeMutex;
static bool initialized = false;

bool CBLDart_Initialize(void *dartInitializeDlData, void *cblInitContext,
CBLError *errorOut) {
CBLDartInitializeResult CBLDart_Initialize(void *dartInitializeDlData,
void *cblInitContext,
CBLError *errorOut) {
std::scoped_lock lock(initializeMutex);

if (initialized) {
// Only initialize libraries once.
return true;
return CBLDartInitializeResult_kSuccess;
}

#ifdef __ANDROID__
// Initialize the Couchbase Lite library.
if (!CBL_Init(*reinterpret_cast<CBLInitContext *>(cblInitContext),
errorOut)) {
return false;
return CBLDartInitializeResult_kCBLInitError;
}
#endif

// Initialize the Dart API for this dynamic library.
Dart_InitializeApiDL(dartInitializeDlData);
if (Dart_InitializeApiDL(dartInitializeDlData) != 0) {
return CBLDartInitializeResult_kIncompatibleDartVM;
}

initialized = true;
return true;
return CBLDartInitializeResult_kSuccess;
}

// === Dart Native ============================================================
Expand Down Expand Up @@ -622,11 +625,11 @@ static bool CBLDart_ReplicatorFilterWrapper(CBLDart::AsyncCallback *callback,
Dart_CObject document_;
CBLDart_CObject_SetPointer(&document_, document);

Dart_CObject isDeleted_;
isDeleted_.type = Dart_CObject_kInt32;
isDeleted_.value.as_int32 = flags;
Dart_CObject flags_;
flags_.type = Dart_CObject_kInt32;
flags_.value.as_int32 = flags;

Dart_CObject *argsValues[] = {&document_, &isDeleted_};
Dart_CObject *argsValues[] = {&document_, &flags_};

Dart_CObject args;
args.type = Dart_CObject_kArray;
Expand Down

0 comments on commit caf9bc9

Please sign in to comment.