From da74ce71a9099c42929a4e153ae43071ef258927 Mon Sep 17 00:00:00 2001 From: Gurleen Kansray Date: Thu, 23 Apr 2026 04:39:40 +0530 Subject: [PATCH 1/5] [objective_c] Use user_defines to gate test utilities in build hook (Fixes #2999) --- pkgs/objective_c/CHANGELOG.md | 1 + pkgs/objective_c/hook/build.dart | 15 ++++----------- pkgs/objective_c/pubspec.yaml | 6 +++++- pkgs/objective_c/test/util.dart | 7 ++++++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkgs/objective_c/CHANGELOG.md b/pkgs/objective_c/CHANGELOG.md index 2c488f51e6..10c557a39b 100644 --- a/pkgs/objective_c/CHANGELOG.md +++ b/pkgs/objective_c/CHANGELOG.md @@ -7,6 +7,7 @@ Objective-C. - Fix a [bug](https://github.com/dart-lang/native/issues/3290) where missing debug symbols caused app store valiadtion warnings. +- Removed some test-only utilities from the release dylib (fixes [#2999](https://github.com/dart-lang/native/issues/2999)). ## 9.3.0 - `autoReleasePool` now returns the value produced by its callback. diff --git a/pkgs/objective_c/hook/build.dart b/pkgs/objective_c/hook/build.dart index 0d9d420f4a..acc908c1c4 100644 --- a/pkgs/objective_c/hook/build.dart +++ b/pkgs/objective_c/hook/build.dart @@ -13,10 +13,6 @@ const objCFlags = ['-x', 'objective-c', '-fobjc-arc']; const assetName = 'objective_c.dylib'; -// TODO(https://github.com/dart-lang/native/issues/2272): Remove this from the -// main build. -const testFiles = ['test/util.c']; - final logger = Logger('') ..level = Level.INFO ..onRecord.listen((record) { @@ -59,13 +55,10 @@ void main(List args) async { } } - // Only include the test utils on mac OS. They use memory functions that - // aren't supported on iOS, like mach_vm_region. We don't need them on iOS - // anyway since we only run memory tests on mac. - if (os == OS.macOS) { - cFiles.addAll( - testFiles.map((f) => input.packageRoot.resolve(f).toFilePath()), - ); + final includeTestUtils = + input.userDefines['include_test_utils'] as bool? ?? false; + if (includeTestUtils) { + cFiles.add(input.packageRoot.resolve('test/util.c').toFilePath()); } final sysroot = sdkPath(codeConfig); diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index b2c36821c3..abe9570857 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -1,7 +1,6 @@ # Copyright (c) 2024, 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. - name: objective_c description: 'A library to access Objective C from Flutter that acts as a support library for package:ffigen.' version: 9.4.0-wip @@ -45,3 +44,8 @@ dependency_overrides: path: ../hooks native_toolchain_c: path: ../native_toolchain_c + +hook: + user_defines: + objective_c: + include_test_utils: true diff --git a/pkgs/objective_c/test/util.dart b/pkgs/objective_c/test/util.dart index d0300e8eb3..c946a2a5bc 100644 --- a/pkgs/objective_c/test/util.dart +++ b/pkgs/objective_c/test/util.dart @@ -32,12 +32,17 @@ void doGC() { calloc.free(gcNow); } -@Native)>(isLeaf: true, symbol: 'isReadableMemory') +@Native)>( + isLeaf: true, + symbol: 'isReadableMemory', + assetId: 'package:objective_c/objective_c.dylib', +) external int _isReadableMemory(Pointer ptr); @Native)>( isLeaf: true, symbol: 'getObjectRetainCount', + assetId: 'package:objective_c/objective_c.dylib', ) external int _getObjectRetainCount(Pointer object); From 152809f96b90c5e561c03b6a9ce4397e033ea7b4 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 28 Apr 2026 11:45:29 +1000 Subject: [PATCH 2/5] fix typo --- pkgs/objective_c/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/objective_c/pubspec.yaml b/pkgs/objective_c/pubspec.yaml index abe9570857..0ce8d405ba 100644 --- a/pkgs/objective_c/pubspec.yaml +++ b/pkgs/objective_c/pubspec.yaml @@ -45,7 +45,7 @@ dependency_overrides: native_toolchain_c: path: ../native_toolchain_c -hook: +hooks: user_defines: objective_c: include_test_utils: true From aee6fedea82e816cb5c4590b8e862f0f51ef46db Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 28 Apr 2026 12:06:44 +1000 Subject: [PATCH 3/5] fix ffigen --- pkgs/ffigen/pubspec.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/ffigen/pubspec.yaml b/pkgs/ffigen/pubspec.yaml index 05133f14ca..ab4e61b602 100644 --- a/pkgs/ffigen/pubspec.yaml +++ b/pkgs/ffigen/pubspec.yaml @@ -52,3 +52,8 @@ dependency_overrides: path: ../native_toolchain_c objective_c: path: ../objective_c + +hooks: + user_defines: + objective_c: + include_test_utils: true From a8df3fb8669275a4d3a0003f9defbe972da4ac4d Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 28 Apr 2026 12:43:34 +1000 Subject: [PATCH 4/5] Fix hook_build_path_test --- .../lib/src/objective_c_bindings_generated.dart | 3 +-- pkgs/objective_c/test/hook_build_path_test.dart | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart index 0cdfbefc69..68924488b9 100644 --- a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart +++ b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart @@ -2106,8 +2106,7 @@ enum NSAttributedStringMarkdownParsingFailurePolicy { /// macOS: introduced 12.0.0 extension type NSAttributedStringMarkdownParsingOptions._( objc.ObjCObject object$ -) - implements objc.ObjCObject, NSObject, NSCopying { +) implements objc.ObjCObject, NSObject, NSCopying { /// Constructs a [NSAttributedStringMarkdownParsingOptions] that points to the same underlying object as [other]. NSAttributedStringMarkdownParsingOptions.as(objc.ObjCObject other) : object$ = other { diff --git a/pkgs/objective_c/test/hook_build_path_test.dart b/pkgs/objective_c/test/hook_build_path_test.dart index ee08fe490f..885b661f9c 100644 --- a/pkgs/objective_c/test/hook_build_path_test.dart +++ b/pkgs/objective_c/test/hook_build_path_test.dart @@ -100,9 +100,12 @@ exit 0 } final logLines = File(compilerLog).readAsLinesSync(); - final decodedUtil = '$symlinkPath/test/util.c'; - expect(logLines, contains(decodedUtil)); + final decodedSrc = '$symlinkPath/src/objective_c.c'; + expect(logLines, contains(decodedSrc)); expect(logLines.any((line) => line.contains('%2547')), isFalse); + + final decodedUtil = '$symlinkPath/test/util.c'; + expect(logLines, isNot(contains(decodedUtil))); }, skip: !Platform.isMacOS ? 'Requires macOS' : null, ); From dc76ba6a9b95fbf37b7bb00aaf0d6f0a19eae8c5 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 28 Apr 2026 13:10:25 +1000 Subject: [PATCH 5/5] revert unrelated bindings diffs --- pkgs/objective_c/lib/src/objective_c_bindings_generated.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart index 68924488b9..0cdfbefc69 100644 --- a/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart +++ b/pkgs/objective_c/lib/src/objective_c_bindings_generated.dart @@ -2106,7 +2106,8 @@ enum NSAttributedStringMarkdownParsingFailurePolicy { /// macOS: introduced 12.0.0 extension type NSAttributedStringMarkdownParsingOptions._( objc.ObjCObject object$ -) implements objc.ObjCObject, NSObject, NSCopying { +) + implements objc.ObjCObject, NSObject, NSCopying { /// Constructs a [NSAttributedStringMarkdownParsingOptions] that points to the same underlying object as [other]. NSAttributedStringMarkdownParsingOptions.as(objc.ObjCObject other) : object$ = other {