Skip to content

Commit

Permalink
🚀 Update according to new Flutter SDKs and FRB (#72)
Browse files Browse the repository at this point in the history
- The old FRB causes conflicts with other FRBs.
- Dependency constraints are conflicted with major versions.
- `ZipEncoder` is outdated and its implementation is missing arguments.
- Fixes the empty `sha` mod to avoid producing invalid bridges.
- Removes redundant public constants from Rust.
- Corrects the dynamic library paths for Desktops.
- Adds the script to build Windows libraries on Windows.
  • Loading branch information
AlexV525 authored Dec 29, 2023
1 parent 94063af commit 6abb27b
Show file tree
Hide file tree
Showing 32 changed files with 11,235 additions and 9,620 deletions.
6 changes: 1 addition & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- 'lib/bridge/ffi/ffi_bridge.dart'
- 'lib/protobuf/**.dart'
- 'rust/bridge/ffi/**.dart'
- 'packages/**/**.g.dart'
- 'packages/**/**.freezed.dart'
- 'packages/**/bridge_generated.dart'
- 'packages/**/types.pb*.dart'
# - 'packages/**/test/**.dart'

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Expand All @@ -26,7 +22,7 @@ linter:
prefer_final_in_for_each: true
prefer_final_locals: true
prefer_single_quotes: true
require_trailing_commas: true
require_trailing_commas: false
sort_constructors_first: true
sort_unnamed_constructors_first: true
unnecessary_await_in_return: true
Expand Down
1 change: 1 addition & 0 deletions packages/agent_dart/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tar.gz
10 changes: 5 additions & 5 deletions packages/agent_dart/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(LibraryVersion "library_name-v0.0.0") # generated; do not edit
set(LibraryVersion "agent_dart-v0.0.0") # generated; do not edit

# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
Expand All @@ -21,17 +21,17 @@ if(NOT EXISTS ${ArchivePath})
endif()

# Extract the binaries, overriding any already present.
file(REMOVE_RECURSE ${LibRoot})
file(MAKE_DIRECTORY ${LibRoot})
file(REMOVE_RECURSE "linux-arm64")
file(REMOVE_RECURSE "linux-x64")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${ArchivePath}
WORKING_DIRECTORY ${LibRoot}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

# List of absolute paths to libraries that should be bundled with the plugin.
# This list could contain prebuilt libraries, or libraries created by an
# external build triggered from this build file.
set(agent_dart_bundled_libraries
"${LibRoot}/${FLUTTER_TARGET_PLATFORM}/libagent_dart.so"
"${FLUTTER_TARGET_PLATFORM}/lib${PROJECT_NAME}.so"
PARENT_SCOPE
)
12 changes: 6 additions & 6 deletions packages/agent_dart/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(LibraryVersion "library_name-v0.0.0") # generated; do not edit
set(LibraryVersion "agent_dart-v0.0.0") # generated; do not edit

# TODO Remove this workaround once Flutter supports Windows ARM.
# https://github.com/flutter/flutter/issues/116196
Expand All @@ -11,7 +11,7 @@ set(FLUTTER_TARGET_PLATFORM windows-x64)
cmake_minimum_required(VERSION 3.14)

# Project-level configuration.
set(PROJECT_NAME "flutter_agent_dart")
set(PROJECT_NAME "agent_dart")
project(${PROJECT_NAME} LANGUAGES CXX)

# Download the binaries if they are not already present.
Expand All @@ -26,17 +26,17 @@ if(NOT EXISTS ${ArchivePath})
endif()

# Extract the binaries, overriding any already present.
file(REMOVE_RECURSE ${LibRoot})
file(MAKE_DIRECTORY ${LibRoot})
file(REMOVE_RECURSE "windows-arm64")
file(REMOVE_RECURSE "windows-x64")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${ArchivePath}
WORKING_DIRECTORY ${LibRoot}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

# List of absolute paths to libraries that should be bundled with the plugin.
# This list could contain prebuilt libraries, or libraries created by an
# external build triggered from this build file.
set(flutter_agent_dart_bundled_libraries
"${LibRoot}/${FLUTTER_TARGET_PLATFORM}/agent_dart.dll"
"${FLUTTER_TARGET_PLATFORM}/${PROJECT_NAME}.dll"
PARENT_SCOPE
)
2 changes: 1 addition & 1 deletion packages/agent_dart_base/lib/agent_dart_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export 'identity/identity.dart';
// principal;
export 'principal/principal.dart';
export 'principal/utils/utils.dart';
export 'src/ffi.dart';
export 'src/ffi.dart' hide AbiExtension;
// utils
export 'utils/base64.dart';
export 'utils/bech32.dart';
Expand Down
6 changes: 5 additions & 1 deletion packages/agent_dart_base/lib/archiver/encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SingingBlockZipFileEncoder extends ZipFileEncoder {
int? level,
bool followLinks = true,
DateTime? modified,
void Function(double)? onProgress,
}) {
final dirPath = dir.path;
final zipPath = filename ?? '$dirPath.zip';
Expand Down Expand Up @@ -107,9 +108,12 @@ class SingingBlockZipFileEncoder extends ZipFileEncoder {
bool includeDirName = true,
int? level,
bool followLinks = true,
void Function(double)? onProgress,
}) async {
final List files = dir.listSync(recursive: true, followLinks: followLinks);
final futures = <Future<void>>[];
final amount = files.length;
int current = 0;
for (final file in files) {
if (file is! File) {
continue;
Expand All @@ -122,7 +126,7 @@ class SingingBlockZipFileEncoder extends ZipFileEncoder {
f,
includeDirName ? ('$dirName/$relativePath') : relativePath,
level,
),
).then((_) => onProgress?.call(++current / amount)),
);
}
await Future.wait(futures);
Expand Down
83 changes: 37 additions & 46 deletions packages/agent_dart_base/lib/src/ffi/io.dart
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
// lib/src/ffi/io.dart
import 'dart:ffi';
import 'dart:io';
import 'dart:io' show Platform;

import 'package:agent_dart_ffi/agent_dart_ffi.dart';
import 'package:flutter/foundation.dart';
import 'package:agent_dart_base/agent_dart_base.dart' show AgentDartImpl;

const libName = 'agent_dart';
const dyLib = 'lib$libName.dylib';
const androidLibName = 'lib$libName.so';
const linuxLibName = 'lib$libName.so';

DynamicLibrary createLibraryImpl() {
// print(Platform.environment['FLUTTER_TEST']);
// if (Platform.environment['FLUTTER_TEST'] == null) {
// if (Platform.isIOS || Platform.isMacOS) {
// return DynamicLibrary.executable();
// } else if (Platform.isWindows) {
// return DynamicLibrary.open('$libName.dll');
// } else {
// return DynamicLibrary.open(androidLibName);
// }
// } else {
// if (Platform.isAndroid) {
// return DynamicLibrary.open(androidLibName);
// }
// if (Platform.isIOS) {
// return DynamicLibrary.executable();
// }

// if (Platform.isMacOS) {
// return DynamicLibrary.open(
// '../../platform-build/dylib/x86_64-apple-darwin/$dyLib',
// );
// }
// if (Platform.isLinux) {
// return DynamicLibrary.open(
// 'target/x86_64-unknown-linux-gnu/$linuxLibName');
// }
// if (Platform.isWindows) {
// return DynamicLibrary.open('$libName.dll');
// }
// return DynamicLibrary.open('target/x86_64-apple-darwin/release/$dyLib');
// }
if (Platform.isAndroid) {
return DynamicLibrary.open('lib$libName.so');
}
if (Platform.isIOS || Platform.isMacOS) {
return DynamicLibrary.executable();
} else if (Platform.isWindows) {
return DynamicLibrary.open('$libName.dll');
} else {
return DynamicLibrary.open(androidLibName);
return DynamicLibrary.process();
}
if (Platform.isLinux) {
if (kReleaseMode) {
return DynamicLibrary.open('lib$libName.dylib');
}
return DynamicLibrary.open(
'linux/flutter/ephemeral/.plugin_symlinks/'
'agent_dart/linux/'
'linux-${Abi.current().architecture}/'
'$libName.so',
);
}
if (Platform.isWindows) {
if (kReleaseMode) {
return DynamicLibrary.open('$libName.dll');
}
return DynamicLibrary.open(
'windows/flutter/ephemeral/.plugin_symlinks/'
'agent_dart/windows/'
'windows-${Abi.current().architecture}/'
'$libName.dll',
);
}
throw UnsupportedError('${Abi.current()} is not supported');
}

class AgentDartFFI {
Expand All @@ -56,10 +44,13 @@ class AgentDartFFI {
AgentDartFFI._();

static final AgentDartFFI _instance = AgentDartFFI._();
static String? dylib;

static AgentDartImpl get impl => _instance._impl;
late final AgentDartImpl _impl = AgentDartImpl(
dylib == null ? createLibraryImpl() : DynamicLibrary.open(dylib!),
);
late final AgentDartImpl _impl = AgentDartImpl(createLibraryImpl());
}

extension AbiExtension on Abi {
String get architecture => toString().split('_').last;

String get os => toString().split('_').first;
}
6 changes: 3 additions & 3 deletions packages/agent_dart_base/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
dependencies:
plugin_platform_interface: ^2.0.2
agent_dart_ffi: ^1.0.0
archive: ^3.3.0
archive: ^3.4.9
args: ^2.3.1
basic_utils: ^4.2.2
bip32: ^2.0.0
Expand All @@ -22,7 +22,7 @@ dependencies:
crypto: ^3.0.2
ffi: ^2.0.1
fixnum: ^1.0.1
flutter_rust_bridge: ^1.72.0
flutter_rust_bridge: 1.82.6
http: ^0.13.4
js: ^0.6.4
meta: ^1.7.0
Expand All @@ -33,7 +33,7 @@ dependencies:
recase: ^4.0.0
tuple: ^2.0.0
typed_data: ^1.3.1
uuid: ^3.0.6
uuid: '>=3.0.0 <5.0.0'
validators: ^3.0.0
json_annotation: ^4.8.1
freezed_annotation: ^2.2.0
Expand Down
Loading

0 comments on commit 6abb27b

Please sign in to comment.