rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.3k stars 12.45k forks source link

Overriding LTO option in global config.toml release profile causes bootstrap failure #126141

Open RossSmyth opened 2 months ago

RossSmyth commented 2 months ago

This is on MSVC Windows 10, I'm unsure if that matters.

  1. Have a global config.toml that overrides the release profile with lto = " fat" or lto = " thin"

So for example ~/.cargo/config.toml with

[profile.release]
lto = "thin"
... other settings that don't matter as much
  1. Run x.py build
  2. Wait for build failure
    
    C:\Users\rsmyth\Documents\rust> python .\x.py build
    Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 2.11s
    Building stage0 library artifacts (x86_64-pc-windows-msvc)
    Compiling compiler_builtins v0.1.109
    Compiling core v0.0.0 (C:\Users\rsmyth\Documents\rust\library\core)
    Compiling std v0.0.0 (C:\Users\rsmyth\Documents\rust\library\std)
    Compiling rustc-std-workspace-core v1.99.0 (C:\Users\rsmyth\Documents\rust\library\rustc-std-workspace-core)
    Compiling alloc v0.0.0 (C:\Users\rsmyth\Documents\rust\library\alloc)
    Compiling cfg-if v1.0.0
    Compiling rustc-demangle v0.1.24
    Compiling unwind v0.0.0 (C:\Users\rsmyth\Documents\rust\library\unwind)
    Compiling rustc-std-workspace-alloc v1.99.0 (C:\Users\rsmyth\Documents\rust\library\rustc-std-workspace-alloc)
    Compiling panic_unwind v0.0.0 (C:\Users\rsmyth\Documents\rust\library\panic_unwind)
    Compiling panic_abort v0.0.0 (C:\Users\rsmyth\Documents\rust\library\panic_abort)
    Compiling std_detect v0.1.5 (C:\Users\rsmyth\Documents\rust\library\stdarch\crates\std_detect)
    Compiling hashbrown v0.14.5
    Compiling rustc-std-workspace-std v1.99.0 (C:\Users\rsmyth\Documents\rust\library\rustc-std-workspace-std)
    Compiling proc_macro v0.0.0 (C:\Users\rsmyth\Documents\rust\library\proc_macro)
    error: linker plugin based LTO is not supported together with `-C prefer-dynamic` when targeting Windows-like targets

error: could not compile rustc-std-workspace-std (lib) due to 1 previous error warning: build failed, waiting for other jobs to finish... error: could not compile proc_macro (lib) due to 1 previous error Build completed unsuccessfully in 0:00:41



Luckily I know what this is caused by. But for other people, this may be confusing if they have a custom release profile.
veera-sivarajan commented 2 months ago

@rustbot label -needs-triage +T-bootstrap +O-windows-msvc +A-lto +A-contributor-roadblock

onur-ozkan commented 2 months ago

We don't configure cargo to change the build configurations for the compiler. To set lto, you should do it in config.toml file in the project root

https://github.com/rust-lang/rust/blob/16e8803579e5914a17a4924f47faaefc040a982d/config.example.toml#L730-L734

Additional ref: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html?highlight=config.toml#create-a-configtoml

Noratrieb commented 2 months ago

people might still happen to have this config set for some other reason, which would make it very confusing

RossSmyth commented 2 months ago

We don't configure cargo to change the build configurations for the compiler. To set lto, you should do it in config.toml file in the project root

This is ideal, but the issue isn't about "I want LTO for the compiler." It's about new contributors or just people who want to build the compiler. They attempt to, then get a inscrutable error. And the root cause is a custom global release profile.

When I first saw this I forgot I even had a global config.toml so it took me a couple minutes to figure it out. I basically use it as a "cargo install" profile.