Skip to content

[pigeon] Add macOS Obj-C support #4267

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

Merged
merged 13 commits into from
Jun 21, 2023
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
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 10.1.0

* [objc] Adds macOS support to facilitate code sharing with existing iOS plugins.

## 10.0.1

* Requires `analyzer 5.13.0` and replaces use of deprecated APIs.
Expand Down
5 changes: 2 additions & 3 deletions packages/pigeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ host platform type-safe, easier and faster.
## Supported Platforms

Currently Pigeon supports generating:
* Kotlin and Java code for Android,
* Swift and Objective-C code for iOS
* Swift code for macOS
* Kotlin and Java code for Android
* Swift and Objective-C code for iOS and macOS
* C++ code for Windows

## Runtime Requirements
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '10.0.1';
const String pigeonVersion = '10.1.0';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
5 changes: 5 additions & 0 deletions packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,12 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
void writeFileImports(
ObjcOptions generatorOptions, Root root, Indent indent) {
indent.writeln('#import "${generatorOptions.headerIncludePath}"');
indent.newln();
indent.writeln('#if TARGET_OS_OSX');
indent.writeln('#import <FlutterMacOS/FlutterMacOS.h>');
indent.writeln('#else');
indent.writeln('#import <Flutter/Flutter.h>');
indent.writeln('#endif');
indent.newln();

indent.writeln('#if !__has_feature(objc_arc)');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TargetGenerator _getTarget() {
if (Platform.isAndroid) {
return TargetGenerator.java;
}
if (Platform.isIOS) {
if (Platform.isIOS || Platform.isMacOS) {
return TargetGenerator.objc;
}
throw UnimplementedError('Unsupported target.');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/dgph
**/xcuserdata/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
Loading