Skip to content

Commit

Permalink
Mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Apr 24, 2024
1 parent 3462a57 commit 811c2f9
Show file tree
Hide file tree
Showing 27 changed files with 40 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/objective_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
channel: 'stable'
- name: Install dependencies
run: flutter pub get
- name: Build test dylib
run: dart test/setup.dart
- name: Run VM tests
run: dart test
- name: Collect coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void main() {
group('Automatic reference counting', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib =
File('test/native_objc_test/automated_ref_count_test.dylib');
verifySetupFile(dylib);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/bad_method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
group('bad_method_test', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/bad_method_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/cast_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void main() {
group('cast', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/cast_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/category_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
group('categories', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/category_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/forward_decl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
group('forward decl', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/forward_decl_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
group('inheritedInstancetype', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib =
File('test/native_objc_test/inherited_instancetype_test.dylib');
verifySetupFile(dylib);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/is_instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
group('isInstance', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/is_instance_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
group('method calls', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/method_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/native_objc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
group('native_objc_test', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/native_objc_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() {
group('Nullable inheritance', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib =
File('test/native_objc_test/nullable_inheritance_test.dylib');
verifySetupFile(dylib);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/nullable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void main() {
group('Nullability', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/nullable_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
group('properties', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/property_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/rename_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
group('rename_test', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/rename_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void main() {
group('static functions', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/static_func_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/static_func_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void main() {
group('static functions', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/static_func_test.dylib');
verifySetupFile(dylib);
lib = StaticFuncTestObjCLibrary(DynamicLibrary.open(dylib.absolute.path));
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
group('string', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/string_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/swift_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
group('swift_class_test', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/swift_class_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
1 change: 1 addition & 0 deletions pkgs/ffigen/test/native_objc_test/typedef_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
group('typedef', () {
setUpAll(() {
logWarnings();
DynamicLibrary.open('../objective_c/test/objective_c.dylib');
final dylib = File('test/native_objc_test/typedef_test.dylib');
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/objective_c/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MainApp extends StatelessWidget {
return MaterialApp(
home: Scaffold(
body: Center(
child: Text(NSString('Hello World! ${hello()}').toString()),
child: Text(NSString('Hello World!').toString()),
),
),
);
Expand Down
3 changes: 2 additions & 1 deletion pkgs/objective_c/ffigen_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ headers:
entry-points:
- 'src/include/dart_api_dl.h'
- 'src/objective_c.h'
- 'src/objective_c_runtime.h'
- 'src/objective_c_runtime_types.h'
- 'src/objective_c_runtime_functions.h'
ffi-native:
assetId: 'objective_c.framework/objective_c'
exclude-all-by-default: true
Expand Down
26 changes: 13 additions & 13 deletions pkgs/objective_c/lib/src/c_bindings_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ external int Dart_InitializeApiDL(
ffi.Pointer<ffi.Void> data,
);

@ffi.Native<ffi.Void Function(ffi.Pointer<ObjCBlock>)>(isLeaf: true)
external void disposeObjCBlockWithClosure(
ffi.Pointer<ObjCBlock> block,
);

@ffi.Native<ffi.Pointer<ObjCSelector> Function(ffi.Pointer<ffi.Char>)>(
symbol: "sel_registerName", isLeaf: true)
external ffi.Pointer<ObjCSelector> registerName(
Expand Down Expand Up @@ -84,19 +89,6 @@ external void blockRelease(
ffi.Pointer<ObjCBlock> object,
);

@ffi.Native<ffi.Void Function(ffi.Pointer<ObjCBlock>)>(isLeaf: true)
external void disposeObjCBlockWithClosure(
ffi.Pointer<ObjCBlock> block,
);

typedef ObjCSelector = _ObjCSelector;

final class _ObjCSelector extends ffi.Opaque {}

typedef ObjCObject = _ObjCObject;

final class _ObjCObject extends ffi.Opaque {}

typedef ObjCBlock = _ObjCBlock;

final class _ObjCBlock extends ffi.Struct {
Expand Down Expand Up @@ -139,3 +131,11 @@ final class _ObjCBlockDesc extends ffi.Struct {

external ffi.Pointer<ffi.Char> signature;
}

typedef ObjCSelector = _ObjCSelector;

final class _ObjCSelector extends ffi.Opaque {}

typedef ObjCObject = _ObjCObject;

final class _ObjCObject extends ffi.Opaque {}
2 changes: 2 additions & 0 deletions pkgs/objective_c/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ add_library(objective_c SHARED
"include/dart_api_dl.c"
)

target_link_options(objective_c PRIVATE "-undefined dynamic_lookup")

set_target_properties(objective_c PROPERTIES
PUBLIC_HEADER objective_c.h
OUTPUT_NAME "objective_c"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/objective_c/src/objective_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "include/dart_api_dl.h"
#include "objective_c.h"
#include "objective_c_runtime.h"
#include "objective_c_runtime_types.h"

// Dispose helper for ObjC blocks that wrap a Dart closure. For these blocks,
// the target is an int ID, and the dispose_port is listening for these IDs.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/objective_c/src/objective_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef OBJECTIVE_C_SRC_OBJECTIVE_C_H_
#define OBJECTIVE_C_SRC_OBJECTIVE_C_H_

#include "objective_c_runtime.h"
#include "objective_c_runtime_types.h"

// Dispose helper for ObjC blocks that wrap a Dart closure.
void disposeObjCBlockWithClosure(ObjCBlock* block);
Expand Down
54 changes: 0 additions & 54 deletions pkgs/objective_c/src/objective_c_runtime.h

This file was deleted.

4 changes: 0 additions & 4 deletions pkgs/objective_c/test/nsstring_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ void main() {
expect(ns2.toString(), s);
});
}

test('hello', () {
expect(hello(), 123);
});
});
}

0 comments on commit 811c2f9

Please sign in to comment.