Skip to content

Allow panic = "abort" for benchmarks when harness = false. #11214

Open

Description

Problem

The panic setting is ignored for benchmarks since (by default) they link libtest which is compiled with panic = "unwind". This would otherwise lead to confusing errors at link time when "abort" is used (#3166, #3175).

However, it is possible to disable the default harness for a benchmark (which means libtest is no longer linked):

[[bench]]
name = "my_bench"
harness = false

(this is common when using external benchmarking frameworks such as criterion)

The ability to disable unwinding when benchmarking is useful since the inclusion of unwinding machinery can affect performance.

Proposed Solution

Allow panic = "abort" when harness = false.

Cargo currently always prints a warning when the bench profile contains panic = "abort". With this proposal that warning would only be printed when building/running a benchmark where the setting is ignored. (Note: currently running a benchmark with a different profile, e.g. cargo bench --profile release that has panic = "abort" will ignore the panic setting but not print any warning)

Notes

No response

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

Metadata

Assignees

No one assigned

    Labels

    A-profilesArea: profilesArea: profilesC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-benchCommand-testS-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.Status: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    • Status

      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions