Skip to content

Commit

Permalink
Better isolates (#71)
Browse files Browse the repository at this point in the history
* Better isolates

* fix: windows tests

* fix: windows tests

* chore: updated xcode assets

* fix: disable cache android

* fix: no impeller for ios and macos
  • Loading branch information
jerson authored Jul 6, 2024
1 parent d76b861 commit 237dfa1
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 57 deletions.
26 changes: 2 additions & 24 deletions .github/workflows/tests_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ jobs:
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-android
- uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-android
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand All @@ -35,19 +22,10 @@ jobs:
flutter-version: '3.x'
channel: 'stable'
- run: flutter pub get
- if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
avd-name: PhoneAPI30
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
avd-name: PhoneAPI30
api-level: 29
avd-name: PhoneAPI29
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
run: |
flutter pub get
cd example/ios && pod install
- run: "cd example && flutter test --verbose integration_test/app_test.dart"
- run: "cd example && flutter test --verbose --no-enable-impeller integration_test/app_test.dart"
2 changes: 1 addition & 1 deletion .github/workflows/tests_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
flutter config --enable-macos-desktop
flutter pub get
cd example/macos && pod install
- run: "cd example && flutter test --verbose -d macos integration_test/app_test.dart"
- run: "cd example && flutter test --verbose --no-enable-impeller -d macos integration_test/app_test.dart"
- run: "cd example && flutter test --verbose test/app_test.dart"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.8.2

- Updated Isolate spawn logic to close gracefully

## 3.8.1

- Updated binaries to v1.10.3
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/openpgp/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
openpgp: 8925c86ba4a2663e345e3e6e133d8c4e6f6754a3

PODFILE CHECKSUM: 663715e941f9adb426e33bf9376914006f9ea95b
PODFILE CHECKSUM: 1a782344d33c12ced0182eeab11e8668d253eb48

COCOAPODS: 1.11.3
COCOAPODS: 1.14.3
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -158,7 +158,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -202,10 +202,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down Expand Up @@ -238,6 +240,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -325,7 +328,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -411,7 +414,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -460,7 +463,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

COCOAPODS: 1.12.1
COCOAPODS: 1.14.3
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.8.1"
version: "3.8.2"
package_config:
dependency: transitive
description:
Expand Down
47 changes: 33 additions & 14 deletions lib/bridge/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,40 @@ class Binding {
_library = openLib();
}

static callBridge(IsolateArguments args) async {
static void callBridge(IsolateArguments args) async {
var result = await Binding().call(args.name, args.payload);
args.port.send(result);
}

Future<Uint8List> callAsync(String name, Uint8List payload) async {
final port = ReceivePort();
final port = ReceivePort('${_libraryName}_port');
final args = IsolateArguments(name, payload, port.sendPort);
final completer = new Completer<Uint8List>();

final isolate = await Isolate.spawn(
callBridge,
args,
errorsAreFatal: false,
debugName: '${_libraryName}_isolate',
onError: port.sendPort,
);

port.listen(
(message) async {
if (message is Uint8List) {
completer.complete(message);
} else if (message is List) {
completer.completeError(message.firstOrNull ?? "internal error");
} else {
completer.completeError(message ?? "spawn error");
}
port.close();
},
onDone: () {
isolate.kill(priority: Isolate.beforeNextEvent);
},
);

final isolate = await Isolate.spawn(callBridge, args);

Completer<Uint8List> completer = new Completer();

port.listen((message) async {
completer.complete(message);
port.close();
isolate.kill();
});
return completer.future;
}

Expand All @@ -66,7 +82,7 @@ class Binding {
final result = callable(namePointer, payloadPointer, payload.length);

malloc.free(namePointer);
malloc.free(payloadPointer);
malloc.free(pointer);

handleError(result.ref.error, result);

Expand Down Expand Up @@ -189,8 +205,11 @@ class Binding {

if (Platform.isWindows) {
if (isFlutterTest) {
var ffiFile = Path.canonicalize(
Path.join(r'build\windows\runner\Debug', '$_libraryName.dll'));
var arch =
Platform.resolvedExecutable.contains("x64") ? "x64" : "arm64";

var ffiFile = Path.canonicalize(Path.join(
r'build\windows', arch, r'runner\Debug', '$_libraryName.dll'));
validateTestFFIFile(ffiFile);
return ffi.DynamicLibrary.open(ffiFile);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/openpgp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class OpenPGPException implements Exception {
String cause;

OpenPGPException(this.cause);

@override
String toString() {
return 'OpenPGPException: $cause';
}
}

enum Hash { SHA256, SHA224, SHA384, SHA512 }
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: openpgp
description: library for use OpenPGP with support for android and ios, macOS, linux, windows and web
version: 3.8.1
version: 3.8.2
homepage: https://github.com/jerson/flutter-openpgp

environment:
Expand Down

0 comments on commit 237dfa1

Please sign in to comment.