Skip to content

[objective_c] Use user_defines to gate test utilities in build hook (Fixes #2999)#3325

Merged
liamappelbe merged 5 commits into
dart-lang:mainfrom
Gurleen-kansray:fix/objective_c_user_defines
Apr 28, 2026
Merged

[objective_c] Use user_defines to gate test utilities in build hook (Fixes #2999)#3325
liamappelbe merged 5 commits into
dart-lang:mainfrom
Gurleen-kansray:fix/objective_c_user_defines

Conversation

@Gurleen-kansray
Copy link
Copy Markdown
Contributor

Description

Replaces the objective_c_helper package approach from #3129 with a simpler solution using user_defines in the build hook, as suggested by @liamappelbe.

The core idea: user_defines declared in pubspec.yaml are only visible to the build hook when that package is the root/development package, not when it is a transitive dependency. This means test/util.c is only compiled into the dylib when actively developing objective_c, keeping the production binary clean.

Changes

  • Removed the testFiles constant and the macOS-only gate from hook/build.dart, replacing them with a user_defines-based gate (include_test_utils)
  • Added hook.user_defines (include_test_utils: false) to pubspec.yaml
  • Updated CHANGELOG.md

Note: Will keep an eye on #3307, once it lands, gc_inject.m should be gated with the same include_test_utils define.

Related Issues

Fixes #2999
Supersedes #3129

PR Checklist

  • I've reviewed the contributor guide and applied the relevant portions to this PR.
  • All existing tests are passing. No new tests were needed — this is a build infrastructure change with no behavioral difference for end users.
  • The PR is actually solving the issue — test/util.c is no longer unconditionally compiled into the production dylib.
  • I have updated CHANGELOG.md for the objective_c package.
  • No pubspec version bump needed — this is an internal build infrastructure change with no public API changes.

Comment thread pkgs/objective_c/pubspec.yaml Outdated

hook:
user_defines:
include_test_utils: "false"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be true.

Comment thread pkgs/objective_c/CHANGELOG.md Outdated
Objective-C.
- Fix a [bug](https://github.com/dart-lang/native/issues/3290) where missing
debug symbols caused app store valiadtion warnings.
- Moved test utilities to use `user_defines` in the build hook instead of a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a user's perspective, they only care that some unnecessary stuff has been removed from the dylib. So how about "Removed some test-only utilities from the release dylib (fixes ..."

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
objective_c Breaking 9.3.0 9.4.0-wip 9.4.0-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

@Gurleen-kansray Gurleen-kansray force-pushed the fix/objective_c_user_defines branch from 56498ad to fefe07d Compare April 23, 2026 01:23
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Addressed. Updated the default value and the changelog description. Thanks for the quick review @liamappelbe!

Comment thread pkgs/objective_c/CHANGELOG.md Outdated
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).
Copy link
Copy Markdown
Contributor

@liamappelbe liamappelbe Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This sort of # shorthand doesn't work if the file isn't being viewed on github (eg on pub.dev). Use the same format as the other changelog entries.

@Gurleen-kansray Gurleen-kansray force-pushed the fix/objective_c_user_defines branch from fefe07d to baa27bb Compare April 23, 2026 01:36
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Fixed the changelog link format to use the full URL. Ready for another look, thanks!

@liamappelbe
Copy link
Copy Markdown
Contributor

liamappelbe commented Apr 23, 2026

does this work when you run it locally? On CI I'm seeing errors that look like util.c is never included

Eg: https://github.com/dart-lang/native/actions/runs/24811893252/job/72618483240?pr=3325. nsset_test.dart is a simple one to look at.

@Gurleen-kansray Gurleen-kansray force-pushed the fix/objective_c_user_defines branch from baa27bb to 54a963f Compare April 23, 2026 02:16
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Sorry about that @liamappelbe! The pubspec.yaml structure was wrong, I had the define at the top level instead of nested under the package name, and was comparing as a string instead of a bool. I've now fixed both:

  • pubspec.yaml: nested include_test_utils: true under objective_c: (the package name), matching the pattern in the download_asset example
  • build.dart: changed the comparison to as bool? ?? false

I can't run the hook locally since I'm on Windows, but the fix should resolve the CI failures. Sorry for the noise!

@liamappelbe
Copy link
Copy Markdown
Contributor

Looks pretty good. But you've got some formatting errors: https://github.com/dart-lang/native/actions/runs/24813053011/job/72801287014?pr=3325

@Gurleen-kansray Gurleen-kansray force-pushed the fix/objective_c_user_defines branch from 54a963f to 3ce45cf Compare April 24, 2026 02:03
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Fixed the formatting errors across the modified files. Ready for another look, thanks @liamappelbe :)

@liamappelbe
Copy link
Copy Markdown
Contributor

Ok, looking closer at the errors, I think the issue is that util.dart is using the wrong @Native annotation. You should read about how @Native annotations relate to build hooks, but I think the quick fix is just to specify the asset id in the annotation, and make sure it matches the one in the build hook.

@Gurleen-kansray Gurleen-kansray force-pushed the fix/objective_c_user_defines branch from 3ce45cf to da74ce7 Compare April 24, 2026 08:42
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Thanks @liamappelbe! Added assetId: 'package:objective_c/objective_c.dylib' to both @Native annotations in util.dart, matching the asset name defined in the build hook. Let me know if that's the right value.

@liamappelbe
Copy link
Copy Markdown
Contributor

Ok, the errors have changed a bit. Now they're complaining that the dylib doesn't contain the symbol. That's going to be hard for you to debug without a mac. I'll clone your PR and take a look.

@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Thanks @liamappelbe, really appreciate you taking the time to clone and debug this directly. I'll wait for your findings!

@liamappelbe liamappelbe merged commit 2de78d8 into dart-lang:main Apr 28, 2026
37 checks passed
@Gurleen-kansray
Copy link
Copy Markdown
Contributor Author

Thank you so much @liamappelbe for the fixes, the review, and for taking the time to debug this directly on your Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[objective_c] Move test native code to a helper package

2 participants