Skip to content

LTO flags are silently ignored if one the crate-type of the root package is not compatible with LTO #14612

Closed as not planned
@stormshield-kg

Description

@stormshield-kg

Problem

Using the Cargo.toml below, LTO is not used for the staticlib target when building multiple library targets with cargo build --release.

To enable LTO, the lib target must be removed, or we must use cargo rustc --crate-type=staticlib for building separately.

Steps

  1. Cargo.toml:
[package]
name = "a"

[profile.release]
lto = true

[lib]
crate-type = ["lib", "staticlib"]
  1. Command

cargo build --release

Possible Solution(s)

Show a warning that LTO is disabled for the LTO-compatible targets, and suggest using cargo rustc --crate-type=X.

Version

cargo 1.81.0 (2dbb1af80 2024-08-20)
release: 1.81.0
commit-hash: 2dbb1af80a2914475ba76827a312e29cedfa6b2f
commit-date: 2024-08-20
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 20.4.0 (focal) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-ltoArea: link-time optimizationC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions