Skip to content

Commit 2dba4f5

Browse files
authored
[ffigen] Prepare to publish v18 (#2083)
1 parent b5727b5 commit 2dba4f5

File tree

8 files changed

+394
-307
lines changed

8 files changed

+394
-307
lines changed

pkgs/ffigen/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 18.0.0-wip
1+
## 18.0.0
22

33
- Add variable substitutions that can be used in the `headers.entry-points` to
44
locate Apple APIs: `$XCODE`, `$IOS_SDK`, and `$MACOS_SDK`.

pkgs/ffigen/lib/src/code_generator/objc_built_in_functions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ObjCBuiltInFunctions {
4747
static const protocolBuilder = ObjCImport('ObjCProtocolBuilder');
4848
static const unimplementedOptionalMethodException =
4949
ObjCImport('UnimplementedOptionalMethodException');
50-
static const checkOsVersion = ObjCImport('checkOsVersion');
50+
static const checkOsVersion = ObjCImport('checkOsVersionInternal');
5151

5252
// Keep in sync with pkgs/objective_c/ffigen_objc.yaml.
5353

pkgs/ffigen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
name: ffigen
6-
version: 18.0.0-wip
6+
version: 18.0.0
77
description: >
88
Generator for FFI bindings, using LibClang to parse C, Objective-C, and Swift
99
files.

pkgs/objective_c/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 7.0.0-wip
1+
## 7.0.0
22

33
- Use ffigen 18.0.0
44
- `ObjCProtocolBuilder` supports implementing protocol methods directly using a
@@ -15,6 +15,7 @@
1515
- __Breaking change__: Some API names have changed due to ffigen's new duplicate
1616
identifier renaming logic. `$` is now used as a delimiter, to match jnigen's
1717
renaming logic.
18+
- Added a `checkOsVersion` function.
1819

1920
## 6.0.0
2021

pkgs/objective_c/lib/src/objective_c_bindings_generated.dart

Lines changed: 354 additions & 298 deletions
Large diffs are not rendered by default.

pkgs/objective_c/lib/src/os_version.dart

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@ import 'package:pub_semver/pub_semver.dart';
77

88
import 'c_bindings_generated.dart' as c;
99

10+
/// Returns the current MacOS/iOS version.
1011
Version get osVersion => _osVersion;
1112

1213
Version _osVersion = () {
1314
final ver = c.getOsVesion();
1415
return Version(ver.major, ver.minor, ver.patch);
1516
}();
1617

18+
/// Returns whether the current MacOS/iOS version is greater than or equal to
19+
/// the given version.
20+
///
21+
/// Designed to replace Objective-C's `@available` check.
22+
///
23+
/// The each platform's version is optional, and the function returns false if
24+
/// no version is provided for the current platform.
25+
bool checkOSVersion({Version? iOS, Version? macOS}) {
26+
if (Platform.isIOS) return _checkOSVersionImpl(iOS);
27+
if (Platform.isMacOS) return _checkOSVersionImpl(macOS);
28+
throw UnsupportedError('Only supported on iOS and macOS');
29+
}
30+
31+
bool _checkOSVersionImpl(Version? version) {
32+
if (version == null) return false;
33+
return osVersion >= version;
34+
}
35+
1736
final class OsVersionError implements Exception {
1837
final String apiName;
1938
final String message;
@@ -26,16 +45,16 @@ final class OsVersionError implements Exception {
2645
typedef PlatformAvailability = (bool unavailable, (int, int, int)? introduced);
2746

2847
/// Only for use by ffigen bindings.
29-
void checkOsVersion(
48+
void checkOsVersionInternal(
3049
String apiName, {
3150
PlatformAvailability? iOS,
3251
PlatformAvailability? macOS,
3352
}) {
34-
if (Platform.isIOS) _checkOsVersionImpl(apiName, 'iOS', iOS);
35-
if (Platform.isMacOS) _checkOsVersionImpl(apiName, 'macOS', macOS);
53+
if (Platform.isIOS) _checkOsVersionInternalImpl(apiName, 'iOS', iOS);
54+
if (Platform.isMacOS) _checkOsVersionInternalImpl(apiName, 'macOS', macOS);
3655
}
3756

38-
void _checkOsVersionImpl(
57+
void _checkOsVersionInternalImpl(
3958
String apiName, String osName, PlatformAvailability? availability) {
4059
if (availability == null) return;
4160
final (bool unavailable, (int, int, int)? introduced) = availability;

pkgs/objective_c/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
name: objective_c
66
description: 'A library to access Objective C from Flutter that acts as a support library for package:ffigen.'
7-
version: 7.0.0-wip
7+
version: 7.0.0
88
repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c
99
issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aobjective_c
1010

pkgs/objective_c/test/os_version_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,16 @@ void main() {
2323
final oldVersion = Version(11, 0, 0);
2424
expect(osVersion, greaterThan(oldVersion));
2525
});
26+
27+
test('check', () {
28+
// This test is only run on macOS.
29+
expect(checkOSVersion(iOS: Version(1, 0, 0)), isFalse);
30+
expect(checkOSVersion(iOS: Version(1, 0, 0), macOS: Version(11, 0, 0)),
31+
isTrue);
32+
expect(checkOSVersion(iOS: Version(1, 0, 0), macOS: Version(1000, 0, 0)),
33+
isFalse);
34+
expect(checkOSVersion(macOS: Version(11, 0, 0)), isTrue);
35+
expect(checkOSVersion(macOS: Version(1000, 0, 0)), isFalse);
36+
});
2637
});
2738
}

0 commit comments

Comments
 (0)