-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
macOS: Crate symbols get discarded when crate appears unused #133491
Copy link
Copy link
Closed
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.O-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)O-macosOperating system: macOSOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.O-appleOperating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS)O-macosOperating system: macOSOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code:
Within the base crate, the
#[divan::bench]macro is used for benchmarking crate internals. Its generated code translates to something similar to:This crate has a benchmark executable with only:
I expected to see this happen: run the
addbenchmark and output the results. This runs correctly on Linux and Windows, but not macOS.Instead, this happened:
divan::main()cannot find the benchmark because the pre-mainconstructor function never ran.In order to make the benchmarks visible to the executable, the base crate needs to have one of its items appear to be used, such as
black_box-ing any item from the crate.Note that this also happens with code like:
This issue occurs even when doing
extern crate my_crateoruse my_crate as _, which is a known workaround for similar issues.Meta
rustc --version --verbose: