From 576c133e261200932c46b7056e2a52603711c6cd Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Mon, 10 Nov 2025 11:01:22 +1100 Subject: [PATCH] [objective_c] Various small fixes --- pkgs/ffigen/CHANGELOG.md | 6 ++++ pkgs/ffigen/lib/ffigen.dart | 9 +++++- pkgs/ffigen/lib/src/config_provider.dart | 3 +- .../lib/src/config_provider/config_types.dart | 2 ++ .../lib/src/config_provider/spec_utils.dart | 1 - .../ffigen/lib/src/config_provider/utils.dart | 15 ++++++++++ .../sub_parsers/api_availability.dart | 1 - pkgs/ffigen/lib/src/header_parser/utils.dart | 1 - pkgs/ffigen/pubspec.yaml | 2 +- .../large_objc_test.dart | 1 - .../unit_tests/api_availability_test.dart | 1 - .../test/unit_tests/sdk_variables_test.dart | 28 +++++++++++++++++++ pkgs/objective_c/CHANGELOG.md | 4 +++ pkgs/objective_c/lib/src/internal.dart | 4 +-- pkgs/objective_c/pubspec.yaml | 4 +-- 15 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 pkgs/ffigen/test/unit_tests/sdk_variables_test.dart diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index 03d0ee82e6..429e331adc 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md @@ -1,3 +1,9 @@ +## 20.1.0 + +- Add `xcodeUri`, `iosSdkUri`, and `macSdkUri`, to mirror `xcodePath`, + `iosSdkPath`, and `macSdkPath`. +- Export some missing elements from the config API. + ## 20.0.0 - __Breaking change__: Completely rewrite the public Dart API for FFIgen. diff --git a/pkgs/ffigen/lib/ffigen.dart b/pkgs/ffigen/lib/ffigen.dart index 737bd33217..efac9fc6ae 100644 --- a/pkgs/ffigen/lib/ffigen.dart +++ b/pkgs/ffigen/lib/ffigen.dart @@ -18,10 +18,13 @@ export 'src/config_provider.dart' show BindingStyle, Categories, + CommentLength, + CommentStyle, CommentType, CompoundDependencies, Declaration, DynamicLibraryBindings, + EnumStyle, Enums, ExternalVersions, FfiGenerator, @@ -42,9 +45,13 @@ export 'src/config_provider.dart' Unions, UnnamedEnums, VarArgFunction, + Version, Versions, YamlConfig, defaultCompilerOpts, iosSdkPath, + iosSdkUri, macSdkPath, - xcodePath; + macSdkUri, + xcodePath, + xcodeUri; diff --git a/pkgs/ffigen/lib/src/config_provider.dart b/pkgs/ffigen/lib/src/config_provider.dart index 31f24a18c4..82e82ce8a9 100644 --- a/pkgs/ffigen/lib/src/config_provider.dart +++ b/pkgs/ffigen/lib/src/config_provider.dart @@ -8,5 +8,6 @@ library; export 'config_provider/config.dart'; export 'config_provider/config_types.dart'; export 'config_provider/path_finder.dart'; -export 'config_provider/utils.dart' show iosSdkPath, macSdkPath, xcodePath; +export 'config_provider/utils.dart' + show iosSdkPath, iosSdkUri, macSdkPath, macSdkUri, xcodePath, xcodeUri; export 'config_provider/yaml_config.dart'; diff --git a/pkgs/ffigen/lib/src/config_provider/config_types.dart b/pkgs/ffigen/lib/src/config_provider/config_types.dart index ac61da7f91..d8fbee7d76 100644 --- a/pkgs/ffigen/lib/src/config_provider/config_types.dart +++ b/pkgs/ffigen/lib/src/config_provider/config_types.dart @@ -15,6 +15,8 @@ import '../code_generator.dart'; import 'config.dart'; import 'path_finder.dart'; +export 'package:pub_semver/pub_semver.dart' show Version; + enum Language { c, objc } class CommentType { diff --git a/pkgs/ffigen/lib/src/config_provider/spec_utils.dart b/pkgs/ffigen/lib/src/config_provider/spec_utils.dart index d8ace53e87..10963e3006 100644 --- a/pkgs/ffigen/lib/src/config_provider/spec_utils.dart +++ b/pkgs/ffigen/lib/src/config_provider/spec_utils.dart @@ -9,7 +9,6 @@ import 'package:glob/glob.dart'; import 'package:logging/logging.dart'; import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as p; -import 'package:pub_semver/pub_semver.dart'; import 'package:quiver/pattern.dart' as quiver; import 'package:yaml/yaml.dart'; diff --git a/pkgs/ffigen/lib/src/config_provider/utils.dart b/pkgs/ffigen/lib/src/config_provider/utils.dart index 296a965572..5a8ce98e1e 100644 --- a/pkgs/ffigen/lib/src/config_provider/utils.dart +++ b/pkgs/ffigen/lib/src/config_provider/utils.dart @@ -62,3 +62,18 @@ String get iosSdkPath => _iosSdk.value; /// /// This is the result of the command `xcrun --show-sdk-path --sdk macosx`. String get macSdkPath => _macSdk.value; + +/// The directory where Xcode's APIs are installed. +/// +/// This is the result of the command `xcode-select -p`. +Uri get xcodeUri => Uri.directory(xcodePath); + +/// The directory within [xcodePath] where the iOS SDK is installed. +/// +/// This is the result of the command `xcrun --show-sdk-path --sdk iphoneos`. +Uri get iosSdkUri => Uri.directory(iosSdkPath); + +/// The directory within [xcodePath] where the macOS SDK is installed. +/// +/// This is the result of the command `xcrun --show-sdk-path --sdk macosx`. +Uri get macSdkUri => Uri.directory(macSdkPath); diff --git a/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart b/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart index e6840ef659..eb5e3a2b53 100644 --- a/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart +++ b/pkgs/ffigen/lib/src/header_parser/sub_parsers/api_availability.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:meta/meta.dart'; -import 'package:pub_semver/pub_semver.dart'; import '../../config_provider/config_types.dart'; import '../../context.dart'; diff --git a/pkgs/ffigen/lib/src/header_parser/utils.dart b/pkgs/ffigen/lib/src/header_parser/utils.dart index eaa56c539c..8b53b2b2d6 100644 --- a/pkgs/ffigen/lib/src/header_parser/utils.dart +++ b/pkgs/ffigen/lib/src/header_parser/utils.dart @@ -6,7 +6,6 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:logging/logging.dart'; -import 'package:pub_semver/pub_semver.dart'; import '../code_generator.dart'; import '../config_provider/config_types.dart'; diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index b1e010c2c3..c94a179a47 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -3,7 +3,7 @@ # BSD-style license that can be found in the LICENSE file. name: ffigen -version: 20.0.0 +version: 20.1.0-dev description: > Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift files. diff --git a/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart b/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart index 7c66c0da4b..ac54a853f6 100644 --- a/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart +++ b/pkgs/ffigen/test/large_integration_tests/large_objc_test.dart @@ -16,7 +16,6 @@ import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/code_generator/utils.dart'; import 'package:logging/logging.dart'; import 'package:path/path.dart' as path; -import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; import '../test_utils.dart'; diff --git a/pkgs/ffigen/test/unit_tests/api_availability_test.dart b/pkgs/ffigen/test/unit_tests/api_availability_test.dart index 84e7d6fea1..79a383228e 100644 --- a/pkgs/ffigen/test/unit_tests/api_availability_test.dart +++ b/pkgs/ffigen/test/unit_tests/api_availability_test.dart @@ -4,7 +4,6 @@ import 'package:ffigen/src/config_provider/config_types.dart'; import 'package:ffigen/src/header_parser/sub_parsers/api_availability.dart'; -import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; void main() { diff --git a/pkgs/ffigen/test/unit_tests/sdk_variables_test.dart b/pkgs/ffigen/test/unit_tests/sdk_variables_test.dart new file mode 100644 index 0000000000..0e1e678fc7 --- /dev/null +++ b/pkgs/ffigen/test/unit_tests/sdk_variables_test.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Objective C support is only available on mac. +@TestOn('mac-os') +library; + +import 'dart:io'; + +import 'package:ffigen/ffigen.dart'; +import 'package:test/test.dart'; + +void main() { + group('SDK variables', () { + test('directories exist', () { + expect(Directory(xcodePath).existsSync(), isTrue); + expect(Directory(iosSdkPath).existsSync(), isTrue); + expect(Directory(macSdkPath).existsSync(), isTrue); + }); + + test('URIs', () { + expect(xcodeUri.path, '$xcodePath/'); + expect(iosSdkUri.path, '$iosSdkPath/'); + expect(macSdkUri.path, '$macSdkPath/'); + }); + }); +} diff --git a/pkgs/objective_c/CHANGELOG.md b/pkgs/objective_c/CHANGELOG.md index aaa25df99b..1728319792 100644 --- a/pkgs/objective_c/CHANGELOG.md +++ b/pkgs/objective_c/CHANGELOG.md @@ -1,3 +1,7 @@ +## 9.1.0 + +- Use FFIgen 20.1.0 + ## 9.0.0 - Use FFIgen 20.0.0 diff --git a/pkgs/objective_c/lib/src/internal.dart b/pkgs/objective_c/lib/src/internal.dart index 58c63a16a9..cff36a77b7 100644 --- a/pkgs/objective_c/lib/src/internal.dart +++ b/pkgs/objective_c/lib/src/internal.dart @@ -323,7 +323,7 @@ final class ObjCObjectRef extends _ObjCReference { bool _isValid(ObjectPtr ptr) => _isValidObject(ptr); } -/// Only for use by FFIgen bindings. +/// Base class for all Objective-C objects. class ObjCObject extends _ObjCRefHolder { ObjCObject(ObjectPtr ptr, {required bool retain, required bool release}) : super(ObjCObjectRef(ptr, retain: retain, release: release)); @@ -360,7 +360,7 @@ bool _isValidClass(ObjectPtr clazz, {bool forceReloadClasses = false}) { return _allClasses.contains(clazz); } -/// Only for use by FFIgen bindings. +/// Base class for all Objective-C protocols. // This exists so that interface_lists_test.dart can tell the difference between // a protocol and an interface. typedef ObjCProtocol = ObjCObject; diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index 2a17bfbf01..a32d06c69a 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -4,7 +4,7 @@ name: objective_c description: 'A library to access Objective C from Flutter that acts as a support library for package:ffigen.' -version: 9.0.0+1 +version: 9.1.0-dev repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aobjective_c @@ -28,7 +28,7 @@ dependencies: dev_dependencies: args: ^2.6.0 dart_flutter_team_lints: ^3.5.2 - ffigen: ^20.0.0 + ffigen: ^20.1.0 flutter_test: sdk: flutter native_test_helpers: