Skip to content

Commit

Permalink
package:objective_c (#1061)
Browse files Browse the repository at this point in the history
* Initial commit of package:objective_c

* Fix some of the PR health warnings

* Remove the objective_c dep from ffigen. Need to separate those tests

* Disable analysis and move tests

* Fix tests

* Workflows

* Fix analysis

* Fix analysis

* Fix analysis

* Fix analysis

* Fix analysis

* Fix analysis

* Fix tests

* Fix tests and address comments

* Improve ffigen's CHANGELOG entry

* Gather objective_c coverage during ffigen tests

* Daco's comments

* Move objc_msgSend into package:objective_c

* Changelog

* Fix analysis

* Update changelog
  • Loading branch information
liamappelbe authored Apr 11, 2024
1 parent 695c065 commit ffc493d
Show file tree
Hide file tree
Showing 96 changed files with 78,607 additions and 109,518 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/objective_c.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: "package:objective_c"
about: "Create a bug or file a feature request against package:objective_c."
labels: "package:objective_c"
---

39 changes: 21 additions & 18 deletions .github/workflows/ffigen.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: ffigen

on:
# Run on PRs and pushes to the default branch.
# Run on PRs and pushes to the default branch, in either the ffigen directory,
# or the objective_c directory.
push:
branches: [main, stable]
paths:
- '.github/workflows/ffigen.yml'
- 'pkgs/ffigen/**'
- 'pkgs/objective_c/**'
pull_request:
branches: [main, stable]
paths:
- '.github/workflows/ffigen.yml'
- 'pkgs/ffigen/**'
- 'pkgs/objective_c/**'
schedule:
- cron: "0 0 * * 0"

Expand All @@ -27,25 +30,22 @@ jobs:
working-directory: pkgs/ffigen/
strategy:
fail-fast: false
matrix:
sdk: [dev]
# sdk: [3.3.0]
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
sdk: ${{ matrix.sdk }}
flutter-version: 3.19.0
channel: 'stable'
- id: install
name: Install dependencies
run: dart pub get && dart pub get --directory="example/shared_bindings"
run: flutter pub get && flutter pub get --directory="example/shared_bindings"
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'
run: flutter analyze --fatal-infos

test-linux:
needs: analyze
Expand All @@ -55,11 +55,12 @@ jobs:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
sdk: dev #3.3.0
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: dart pub get
run: flutter pub get
- name: Install libclang-14-dev
run: sudo apt-get install libclang-14-dev
- name: Build test dylib and bindings
Expand All @@ -76,11 +77,12 @@ jobs:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
sdk: dev #3.3.0
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: dart pub get
run: flutter pub get
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
Expand Down Expand Up @@ -109,11 +111,12 @@ jobs:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
sdk: dev #3.3.0
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: dart pub get
run: flutter pub get
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ffigen_weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:
working-directory: pkgs/ffigen/
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
sdk: dev #3.3.0
flutter-version: 3.19.0
channel: 'stable'
- name: Install dependencies
run: dart pub get
run: flutter pub get
- name: Build test dylib and bindings
run: dart test/setup.dart
- name: Run VM tests
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
# Remove paths after https://github.com/bmw-tech/dart_apitool/issues/177 is addressed.
paths:
- "pkgs/ffi/**"
- "pkgs/ffigen/**"
- "pkgs/native_assets_builder/**"
- "pkgs/native_assets_cli/**"
- "pkgs/native_toolchain_c/**"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches: [ main ]
# Merge back into health.yaml after https://github.com/bmw-tech/dart_apitool/issues/177 is addressed.
paths:
- "pkgs/ffigen/**"
- "pkgs/jni/**"
- "pkgs/jnigen/**"
types: [opened, synchronize, reopened, labeled, unlabeled]
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/objective_c.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: objective_c

on:
# Run on PRs and pushes to the default branch.
push:
branches: [main, stable]
paths:
- '.github/workflows/objective_c.yml'
- 'pkgs/objective_c/**'
pull_request:
branches: [main, stable]
paths:
- '.github/workflows/objective_c.yml'
- 'pkgs/objective_c/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

jobs:
# Check code formatting and static analysis.
analyze:
runs-on: macos-latest
defaults:
run:
working-directory: pkgs/objective_c/
strategy:
fail-fast: false
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: 3.19.0
channel: 'stable'
- id: install
name: Install dependencies
run: flutter pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: flutter analyze --fatal-infos
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ building and bundling.
| --- | --- | --- |
| [ffi](pkgs/ffi/) | Utilities for working with Foreign Function Interface (FFI) code. | [![pub package](https://img.shields.io/pub/v/ffi.svg)](https://pub.dev/packages/ffi) |
| [ffigen](pkgs/ffigen/) | Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift files. | [![pub package](https://img.shields.io/pub/v/ffigen.svg)](https://pub.dev/packages/ffigen) |
| [objective_c](pkgs/objective_c/) | A library to access Objective C from Flutter that acts as a support library for package:ffigen. | [![pub package](https://img.shields.io/pub/v/objective_c.svg)](https://pub.dev/packages/objective_c) |
| [jni](pkgs/jni/) | A library to access JNI from Dart and Flutter that acts as a support library for `package:jnigen`. | [![pub package](https://img.shields.io/pub/v/jni.svg)](https://pub.dev/packages/jni) |
| [jnigen](pkgs/jnigen/) | A Dart bindings generator for Java and Kotlin that uses JNI under the hood to interop with Java virtual machine. | [![pub package](https://img.shields.io/pub/v/jnigen.svg)](https://pub.dev/packages/jnigen) |
| [native_assets_builder](pkgs/native_assets_builder/) | This package is the backend that invokes build hooks. | [![pub package](https://img.shields.io/pub/v/native_assets_builder.svg)](https://pub.dev/packages/native_assets_builder) |
Expand Down
15 changes: 15 additions & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
- Add `retainAndReturnPointer` method to ObjC objects and blocks, and add
`castFromPointer` method to blocks.
- Add `-Wno-nullability-completeness` as default compiler option for MacOS.
- __Breaking change__: Use `package:objective_c` in ObjC bindings.
- ObjC packages will have a flutter dependency (until
https://github.com/dart-lang/native/issues/1068 is fixed).
- ObjC class methods don't need the ubiquitous `lib` argument anymore. In
fact, ffigen won't even generate the native library class (unless it needs
to bind top level functions without using `@Native`). It is still necessary
to `DynamicLibrary.open` the dylib though, to load the classes and methods.
- Adapting to this change:
- Update ffigen and re-run the code generation. If the generated code no
longer contains the native library class, it means it isn't needed
anymore. So `final lib = FooNativeLib(DynamicLibrary.open('foo.dylib'));`
must be changed to `DynamicLibrary.open('foo.dylib');`.
- Regardless of whether the native library class still exists, delete the
`lib` parameter from all ObjC object constructors and static method calls
and block constructors.

## 11.0.0

Expand Down
8 changes: 6 additions & 2 deletions pkgs/ffigen/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ analyzer:
todo: ignore
exclude:
- 'test/**_expected*'
# Goldens cannot be generated outside MacOS causing analysis errors.
- test/native_objc_test/**

# Exclude anything that uses package:objective_c, due to flutter dependency.
# https://github.com/dart-lang/native/issues/1068
- example/objective_c/**
- example/swift/**
- test_flutter/native_objc_test/**
language:
strict-casts: true
strict-inference: true
Expand Down
Loading

0 comments on commit ffc493d

Please sign in to comment.