Skip to content

[native_toolchain_c] Fix treeshaking on mac #2399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

mosuem
Copy link
Member

@mosuem mosuem commented Jul 11, 2025

By creating a list of symbols to be exported.

Also needs to be tested with ICU4X, but manually setting this seems to do the trick to solve dart-lang/i18n#989


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Copy link

github-actions bot commented Jul 11, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:code_assets 0.19.4 already published at pub.dev
package:data_assets 0.19.1 already published at pub.dev
package:ffi 2.1.5-wip WIP (no publish necessary)
package:ffigen 19.1.0-wip WIP (no publish necessary)
package:hooks 0.19.5 already published at pub.dev
package:hooks_runner 0.21.0 already published at pub.dev
package:jni 0.14.3-wip WIP (no publish necessary)
package:jnigen 0.15.0-wip WIP (no publish necessary)
package:native_doc_dartifier 0.0.1-pre already published at pub.dev
package:native_toolchain_c 0.17.0 ready to publish native_toolchain_c-v0.17.0
package:objective_c 8.1.0-wip WIP (no publish necessary)
package:swift2objc 0.0.1-wip WIP (no publish necessary)
package:swiftgen 0.0.1-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

Copy link

github-actions bot commented Jul 11, 2025

PR Health

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
hooks_runner Breaking 0.21.0 0.21.0 0.22.0
Got "0.21.0" expected >= "0.22.0" (breaking changes)
⚠️
native_toolchain_c Breaking 0.16.8 0.17.0 0.17.0 ✔️

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

Changelog Entry ✔️
Package Changed Files

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

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 symbols
License Headers ✔️
// 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.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart
pkgs/native_doc_dartifier/lib/src/native_doc_dartifier_base.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jul 11, 2025

Coverage Status

coverage: 87.096% (-3.4%) from 90.52%
when pulling 1b27f49 on fixTreeshakeMac
into 3481346 on main.

@dcharkes
Copy link
Collaborator

Probably needs a test of some sort

We have tests for binary sizes: pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart Shouldn't pkgs/native_toolchain_c/test/clinker/treeshake_test.dart and pkgs/native_toolchain_c/test/clinker/treeshake_cross_test.dart already invoke those? Why aren't those tests failing before this PR?

Copy link
Contributor

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

This will need some sort of a test to verify that a symbol that previously wasn't treeshaken on macos is now removed.

@goderbauer
Copy link
Contributor

We have tests for binary sizes: pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart Shouldn't pkgs/native_toolchain_c/test/clinker/treeshake_test.dart and pkgs/native_toolchain_c/test/clinker/treeshake_cross_test.dart already invoke those?

Yes, those are getting invoked.

Why aren't those tests failing before this PR?

It seems like prior to this PR some symbols were already treeshaken. The existing tests are confirming that. But apparently it doesn't treeshake some other symbols marked as global. We'll need a specific new test for those cases.

@mosuem
Copy link
Member Author

mosuem commented Jul 14, 2025

Probably needs a test of some sort - I am open for ideas.

I agree on the calls for a test ;) I'll figure out how to build one.

@mosuem mosuem changed the title Fix treeshaking on mac [native_toolchain_c] Fix treeshaking on mac Jul 14, 2025
@dcharkes
Copy link
Collaborator

Probably needs a test of some sort - I am open for ideas.

I agree on the calls for a test ;) I'll figure out how to build one.

Are the global symbols visible with dlsym? If yes, we could do DynamicLibrary.open().providesSymbol https://api.flutter.dev/flutter/dart-ffi/DynamicLibrary/providesSymbol.html

Otherwise, maybe add a global symbol that holds on to stuff? E.g. like a very very very long const char*? (In the order of megabytes.)

@mosuem mosuem force-pushed the fixTreeshakeMac branch from e880b44 to 589755e Compare July 14, 2025 12:19
@github-actions github-actions bot added package:hooks_runner type-infra A repository infrastructure change or enhancement labels Jul 15, 2025
@mosuem mosuem force-pushed the fixTreeshakeMac branch from 1b27f49 to d1483ae Compare July 15, 2025 16:15
@mosuem mosuem requested a review from goderbauer July 15, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:hooks_runner package:native_toolchain_c type-infra A repository infrastructure change or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants