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 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..0ce8d405ba 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 + +hooks: + user_defines: + objective_c: + include_test_utils: true 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, ); 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);