Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/mixin_logger/CHANGELOG.md
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

Expand Down
29 changes: 29 additions & 0 deletions packages/mixin_logger/ios/mixin_logger/Package.swift
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")
],
Comment on lines +8 to +10

Copy link
Copy Markdown
Contributor Author

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.

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>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 src/include/mixin_logger/mixin_logger.h, mirroring the existing ios/Classes/mixin_logger.h and macos/Classes/mixin_logger.h copies — none of which have an include guard. Adding #pragma once only to this SPM copy would make it diverge from the source of truth. Adding guards consistently would mean editing the shared canonical header used by every platform, which feels out of scope for this iOS SPM change; happy to do that in a separate PR if you'd prefer.

#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"
14 changes: 13 additions & 1 deletion packages/mixin_logger/lib/src/write_to_file_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — the loader now preserves the last DynamicLibrary.open failure and includes the attempted framework paths in the thrown error. Fixed in d135200.

}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open('lib$_libName.so');
Expand Down
2 changes: 1 addition & 1 deletion packages/mixin_logger/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading