Skip to content

Commit ffc493d

Browse files
authored
package:objective_c (#1061)
* 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
1 parent 695c065 commit ffc493d

File tree

96 files changed

+78607
-109518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+78607
-109518
lines changed

.github/ISSUE_TEMPLATE/objective_c.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
name: "package:objective_c"
3+
about: "Create a bug or file a feature request against package:objective_c."
4+
labels: "package:objective_c"
5+
---
6+

.github/workflows/ffigen.yml

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: ffigen
22

33
on:
4-
# Run on PRs and pushes to the default branch.
4+
# Run on PRs and pushes to the default branch, in either the ffigen directory,
5+
# or the objective_c directory.
56
push:
67
branches: [main, stable]
78
paths:
89
- '.github/workflows/ffigen.yml'
910
- 'pkgs/ffigen/**'
11+
- 'pkgs/objective_c/**'
1012
pull_request:
1113
branches: [main, stable]
1214
paths:
1315
- '.github/workflows/ffigen.yml'
1416
- 'pkgs/ffigen/**'
17+
- 'pkgs/objective_c/**'
1518
schedule:
1619
- cron: "0 0 * * 0"
1720

@@ -27,25 +30,22 @@ jobs:
2730
working-directory: pkgs/ffigen/
2831
strategy:
2932
fail-fast: false
30-
matrix:
31-
sdk: [dev]
32-
# sdk: [3.3.0]
3333
steps:
3434
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
35-
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
35+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
3636
with:
37-
sdk: ${{ matrix.sdk }}
37+
flutter-version: 3.19.0
38+
channel: 'stable'
3839
- id: install
3940
name: Install dependencies
40-
run: dart pub get && dart pub get --directory="example/shared_bindings"
41+
run: flutter pub get && flutter pub get --directory="example/shared_bindings"
4142
- name: Check formatting
4243
run: dart format --output=none --set-exit-if-changed .
4344
if: always() && steps.install.outcome == 'success'
4445
- name: Build test dylib and bindings
4546
run: dart test/setup.dart
4647
- name: Analyze code
47-
run: dart analyze --fatal-infos
48-
if: always() && steps.install.outcome == 'success'
48+
run: flutter analyze --fatal-infos
4949

5050
test-linux:
5151
needs: analyze
@@ -55,11 +55,12 @@ jobs:
5555
working-directory: pkgs/ffigen/
5656
steps:
5757
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
58-
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
58+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
5959
with:
60-
sdk: dev #3.3.0
60+
flutter-version: 3.19.0
61+
channel: 'stable'
6162
- name: Install dependencies
62-
run: dart pub get
63+
run: flutter pub get
6364
- name: Install libclang-14-dev
6465
run: sudo apt-get install libclang-14-dev
6566
- name: Build test dylib and bindings
@@ -76,11 +77,12 @@ jobs:
7677
working-directory: pkgs/ffigen/
7778
steps:
7879
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
79-
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
80+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
8081
with:
81-
sdk: dev #3.3.0
82+
flutter-version: 3.19.0
83+
channel: 'stable'
8284
- name: Install dependencies
83-
run: dart pub get
85+
run: flutter pub get
8486
- name: Build test dylib and bindings
8587
run: dart test/setup.dart
8688
- name: Run VM tests
@@ -109,11 +111,12 @@ jobs:
109111
working-directory: pkgs/ffigen/
110112
steps:
111113
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
112-
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
114+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
113115
with:
114-
sdk: dev #3.3.0
116+
flutter-version: 3.19.0
117+
channel: 'stable'
115118
- name: Install dependencies
116-
run: dart pub get
119+
run: flutter pub get
117120
- name: Build test dylib and bindings
118121
run: dart test/setup.dart
119122
- name: Run VM tests

.github/workflows/ffigen_weekly.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ jobs:
2020
working-directory: pkgs/ffigen/
2121
steps:
2222
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
23-
- uses: dart-lang/setup-dart@fedb1266e91cf51be2fdb382869461a434b920a3
23+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
2424
with:
25-
sdk: dev #3.3.0
25+
flutter-version: 3.19.0
26+
channel: 'stable'
2627
- name: Install dependencies
27-
run: dart pub get
28+
run: flutter pub get
2829
- name: Build test dylib and bindings
2930
run: dart test/setup.dart
3031
- name: Run VM tests

.github/workflows/health.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
# Remove paths after https://github.com/bmw-tech/dart_apitool/issues/177 is addressed.
66
paths:
77
- "pkgs/ffi/**"
8-
- "pkgs/ffigen/**"
98
- "pkgs/native_assets_builder/**"
109
- "pkgs/native_assets_cli/**"
1110
- "pkgs/native_toolchain_c/**"

.github/workflows/health_jnigen.yaml .github/workflows/health_flutter.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches: [ main ]
55
# Merge back into health.yaml after https://github.com/bmw-tech/dart_apitool/issues/177 is addressed.
66
paths:
7+
- "pkgs/ffigen/**"
78
- "pkgs/jni/**"
89
- "pkgs/jnigen/**"
910
types: [opened, synchronize, reopened, labeled, unlabeled]

.github/workflows/objective_c.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: objective_c
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [main, stable]
7+
paths:
8+
- '.github/workflows/objective_c.yml'
9+
- 'pkgs/objective_c/**'
10+
pull_request:
11+
branches: [main, stable]
12+
paths:
13+
- '.github/workflows/objective_c.yml'
14+
- 'pkgs/objective_c/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
jobs:
22+
# Check code formatting and static analysis.
23+
analyze:
24+
runs-on: macos-latest
25+
defaults:
26+
run:
27+
working-directory: pkgs/objective_c/
28+
strategy:
29+
fail-fast: false
30+
steps:
31+
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
32+
- uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
33+
with:
34+
flutter-version: 3.19.0
35+
channel: 'stable'
36+
- id: install
37+
name: Install dependencies
38+
run: flutter pub get
39+
- name: Check formatting
40+
run: dart format --output=none --set-exit-if-changed .
41+
if: always() && steps.install.outcome == 'success'
42+
- name: Analyze code
43+
run: flutter analyze --fatal-infos
44+
if: always() && steps.install.outcome == 'success'

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ building and bundling.
1111
| --- | --- | --- |
1212
| [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) |
1313
| [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) |
14+
| [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) |
1415
| [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) |
1516
| [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) |
1617
| [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) |

pkgs/ffigen/CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
- Add `retainAndReturnPointer` method to ObjC objects and blocks, and add
77
`castFromPointer` method to blocks.
88
- Add `-Wno-nullability-completeness` as default compiler option for MacOS.
9+
- __Breaking change__: Use `package:objective_c` in ObjC bindings.
10+
- ObjC packages will have a flutter dependency (until
11+
https://github.com/dart-lang/native/issues/1068 is fixed).
12+
- ObjC class methods don't need the ubiquitous `lib` argument anymore. In
13+
fact, ffigen won't even generate the native library class (unless it needs
14+
to bind top level functions without using `@Native`). It is still necessary
15+
to `DynamicLibrary.open` the dylib though, to load the classes and methods.
16+
- Adapting to this change:
17+
- Update ffigen and re-run the code generation. If the generated code no
18+
longer contains the native library class, it means it isn't needed
19+
anymore. So `final lib = FooNativeLib(DynamicLibrary.open('foo.dylib'));`
20+
must be changed to `DynamicLibrary.open('foo.dylib');`.
21+
- Regardless of whether the native library class still exists, delete the
22+
`lib` parameter from all ObjC object constructors and static method calls
23+
and block constructors.
924

1025
## 11.0.0
1126

pkgs/ffigen/analysis_options.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ analyzer:
99
todo: ignore
1010
exclude:
1111
- 'test/**_expected*'
12-
# Goldens cannot be generated outside MacOS causing analysis errors.
13-
- test/native_objc_test/**
12+
13+
# Exclude anything that uses package:objective_c, due to flutter dependency.
14+
# https://github.com/dart-lang/native/issues/1068
15+
- example/objective_c/**
16+
- example/swift/**
17+
- test_flutter/native_objc_test/**
1418
language:
1519
strict-casts: true
1620
strict-inference: true

0 commit comments

Comments
 (0)