-
Notifications
You must be signed in to change notification settings - Fork 283
mixin_logger: support Swift Package Manager on iOS #487
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| ## 0.1.4 | ||
| * support Swift Package Manager on iOS | ||
|
|
||
| ## 0.1.3 | ||
| * support android 15 16k page size | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| ) | ||
| ] | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include <stdint.h> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving this as-is intentionally: this header is a verbatim copy of the canonical |
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #if _WIN32 | ||
| #include <windows.h> | ||
| #else | ||
|
|
||
| #include <pthread.h> | ||
| #include <unistd.h> | ||
|
|
||
| #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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.'); | ||
|
Comment on lines
+19
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed — the loader now preserves the last |
||
| } | ||
| if (Platform.isAndroid || Platform.isLinux) { | ||
| return DynamicLibrary.open('lib$_libName.so'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — aligned the SPM minimum to iOS 11.0 to match
mixin_logger.podspec. Fixed in d135200.