Skip to content

Better Toolchain Error and Help Messages #14572

Open
@comods

Description

@comods

Problem

Feature to help debug cargo run failing on first-use or changed computer setup (automatic OS update):
New users should not be expected to know rustc, linkers, llvm, cc, nor ld to use cargo run.
New users should not be expected to know which packages have which .o files for which archs.

Current message

$ cargo run
(

error: linking with `cc` failed: exit status: 1
  |

...45 lines of gibberish...

  = note: ld: error: cannot open Scrt1.o: No such file or directory
          ld: error: cannot open crti.o: No such file or directory
          ld: error: unable to find library -lutil
          ld: error: unable to find library -lrt
          ld: error: unable to find library -lpthread
          ld: error: unable to find library -lm
          ld: error: unable to find library -ldl
          ld: error: unable to find library -lc
          ld: error: cannot open crtn.o: No such file or directory
          collect2: error: ld returned 1 exit status

)
...repeated 12 more times.

Proposed Solution

Desired message

$ cargo run

error[E99999]: toolchain `nightly-i686-unknown-linux-gnu` failed linking using `cc`: exit status: 1
  |
  = note: unable to find glibc-devel (crti.o, crtn.o, and Scrt1.o)
  = help: to install glibc-devel for i686, try `rpm-ostree install glibc-devel.i686`
  = help: for native toolchain, try `rustup default nightly`
  = note: visit <https://doc.rust-lang.org/nightly/rustc/platform-support/{platform-page-with-failed-requirements}.html> for more details

For more information about this error, try `rustc --explain E99999`.
error: could not compile `name` (build script) due to 1 previous error
  1. A first pass improvement on this is a low hanging fruit, but a robust solution will take a lot of work and tests per target-triple os pair.

  2. The platform link https://doc.rust-lang.org/nightly/rustc/platform-support/{platform-with-failed-requirements-page}.html
    should display if the toolchain has detected failed requirements or complex undetectable requirements https://doc.rust-lang.org/nightly/rustc/platform-support/apple-darwin.html

  3. Take into account if current project is stable or unstable, but default to unstable if unknown (for compatibility).

  4. Take into account best/default available package manager with sane prioritizing: nix else rpm-ostree else dnf/apt-get else ...etc.

  5. Detect which packages are needed and what labels to use that aren't fixed to a version. (glibc-devel.i686 instead of glibc-devel-2.39-22.fc40.i686, this allows the package manager to handle version requirements.) Show "help: " message(s) recommending needed package(s).

  6. Do not show cc and ld errors if the issue is just a tool-chain dependency isn't installed.

  7. I also installed lld.i686 at some point and I am not sure if rpm-ostree install glibc-devel.i686 lld.i686 is more accurate.

Notes

Versions

$ cargo --version

cargo 1.83.0-nightly (a9a418d1a 2024-09-15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cross-compilingArea: using --target flag for other platformsA-diagnosticsArea: Error and warning messages generated by Cargo itself.C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions