diff --git a/packages/mixin_logger/CHANGELOG.md b/packages/mixin_logger/CHANGELOG.md index bb55e158..526b54a7 100644 --- a/packages/mixin_logger/CHANGELOG.md +++ b/packages/mixin_logger/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.1.4 +* support Swift Package Manager on iOS + ## 0.1.3 * support android 15 16k page size diff --git a/packages/mixin_logger/ios/mixin_logger/Package.swift b/packages/mixin_logger/ios/mixin_logger/Package.swift new file mode 100644 index 00000000..9669d852 --- /dev/null +++ b/packages/mixin_logger/ios/mixin_logger/Package.swift @@ -0,0 +1,29 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "mixin_logger", + platforms: [ + .iOS("12.0") + ], + products: [ + // `mixin_logger` is an FFI plugin whose Dart bindings load the native + // code from a dynamic framework, so the product is built as a dynamic + // library rather than being statically linked into the app binary. + // + // The product is named `mixin-logger` (with a hyphen) because Flutter's + // generated `FlutterGeneratedPluginSwiftPackage` references plugin + // products by the package name with underscores replaced by hyphens. + // The framework SPM builds is therefore `mixin-logger.framework`; the + // Dart loader in `lib/src/write_to_file_ffi.dart` accepts both this name + // and the CocoaPods `mixin_logger.framework` name. + .library(name: "mixin-logger", type: .dynamic, targets: ["mixin_logger"]) + ], + targets: [ + .target( + name: "mixin_logger" + ) + ] +) diff --git a/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/include/mixin_logger/mixin_logger.h b/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/include/mixin_logger/mixin_logger.h new file mode 100644 index 00000000..fa2dd5df --- /dev/null +++ b/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/include/mixin_logger/mixin_logger.h @@ -0,0 +1,35 @@ +#include +#include +#include + +#if _WIN32 +#include +#else + +#include +#include + +#endif + +#if _WIN32 +#define FFI_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FFI_PLUGIN_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { // only need to export C interface if +// used by C++ source code +#endif + + +FFI_PLUGIN_EXPORT intptr_t +mixin_logger_init(const char *dir, intptr_t max_file_size, intptr_t max_file_count, const char *file_leading); + +FFI_PLUGIN_EXPORT intptr_t mixin_logger_set_file_leading(const char *file_leading); + +FFI_PLUGIN_EXPORT intptr_t mixin_logger_write_log(const char *log); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/mixin_logger.cpp b/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/mixin_logger.cpp new file mode 100644 index 00000000..0fcc59f1 --- /dev/null +++ b/packages/mixin_logger/ios/mixin_logger/Sources/mixin_logger/mixin_logger.cpp @@ -0,0 +1,8 @@ +// Relative import to be able to reuse the C sources. +// +// Swift Package Manager (like CocoaPods) does not support referencing source +// files outside of the package directory, so this forwarder relatively imports +// the shared implementation in `../src` so that the C sources can be shared +// among all target platforms. See the comment in ../mixin_logger.podspec for +// more information about the equivalent CocoaPods setup. +#include "../../../../src/mixin_logger.cpp" diff --git a/packages/mixin_logger/lib/src/write_to_file_ffi.dart b/packages/mixin_logger/lib/src/write_to_file_ffi.dart index 0fe1525c..deedef9c 100644 --- a/packages/mixin_logger/lib/src/write_to_file_ffi.dart +++ b/packages/mixin_logger/lib/src/write_to_file_ffi.dart @@ -11,7 +11,19 @@ const String _libName = 'mixin_logger'; /// The dynamic library in which the symbols for [MixinLoggerBindings] can be found. final DynamicLibrary _dylib = () { if (Platform.isMacOS || Platform.isIOS) { - return DynamicLibrary.open('$_libName.framework/$_libName'); + // The native code ships as a dynamic framework. With CocoaPods the + // framework is named after the pod (`mixin_logger`); with Swift Package + // Manager it is named after the SPM product (`mixin-logger`, because + // Flutter references plugin products with underscores replaced by + // hyphens). Try both so the plugin loads with either integration. + for (final framework in const ['mixin_logger', 'mixin-logger']) { + try { + return DynamicLibrary.open('$framework.framework/$framework'); + } catch (_) { + continue; + } + } + throw UnsupportedError('Failed to load the $_libName dynamic library.'); } if (Platform.isAndroid || Platform.isLinux) { return DynamicLibrary.open('lib$_libName.so'); diff --git a/packages/mixin_logger/pubspec.yaml b/packages/mixin_logger/pubspec.yaml index 0610d4ce..09403c0e 100644 --- a/packages/mixin_logger/pubspec.yaml +++ b/packages/mixin_logger/pubspec.yaml @@ -1,7 +1,7 @@ name: mixin_logger resolution: workspace description: Simple logger tool for flutter, make it easy to save your app log to file. -version: 0.1.3 +version: 0.1.4 homepage: https://github.com/MixinNetwork/flutter-plugins environment: