rustlto

could not compile `rustls-platform-verifier` (lib) in LTO mode


Using lto RUSTFLAGS='-Clto' fails the build with the following error:

error: lto can only be run for executables, cdylibs and static library outputs
error: could not compile `rustls-platform-verifier` (lib) due to 1 previous error

What is special about this dependency that it is failing the build? The rustls-platform-verifier dependency is indirectly added from other deps.


Solution

  • Setting RUSTFLAGS='-Clto' would affect all stages of the compilation, but the LTO decision needs to be centralized in the right place.

    Try enabling LTO in your binary's Cargo.toml file:

    [profile.release]
    lto = true
    

    And running:

    cargo build --release
    

    If that doesn't work or you can't do it (maybe you're not using cargo), please document your build process in your question!