Skip to content

Conversation

@Alexhuszagh
Copy link
Contributor

@Alexhuszagh Alexhuszagh commented Jul 2, 2022

Provides a warning if a docker command fails and rust-std is not available for the target. For example, for x86_64-unknown-dragonfly, the added output would be:

[cross] warning: rust-std is not available for x86_64-unknown-dragonfly
[cross] note: you may need to build components for the target via `-Z build-std=<components>` or in your cross configuration specify `target.x86_64-unknown-dragonfly.build-std`
              the available components are core, std, alloc, and proc_macro

This is done solely if the command fails and if the target is a built-in, so we don't get misleading warnings for custom targets, and there is no overhead if the build succeeds.

Closes #94.
Closes #167.

@Alexhuszagh Alexhuszagh added enhancement better-errors no changelog A valid PR without changelog (no-changelog) labels Jul 2, 2022
@Alexhuszagh Alexhuszagh requested a review from a team as a code owner July 2, 2022 06:00
@Alexhuszagh
Copy link
Contributor Author

An example of the new error diagnostics is as follows. We can't remove the cargo output without basically recreating it, and trying to tee/capture it would run into issues with terminal coloring, etc. However, the resulting messages are quite nice:

rust_std

If we have an unknown target, we get:

$ cross build --target x86_64-unknown-dragonfly1
[cross] note: Falling back to `cargo` on the host.
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target x86_64-unknown-dragonfly1 --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
  --- stderr
  error: Error loading target specification: Could not find specification for target "x86_64-unknown-dragonfly1". Run `rustc --print target-list` for a list of built-in targets

And if the component is installed but does not support the standard library, we get:

$ cross build --target thumbv6m-none-eabi

   Compiling hello v0.1.0 (/project)
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv6m-none-eabi` target may not support the standard library
  = note: `std` is required by `hello` because it does not declare `#![no_std]`

error: cannot find macro `println` in this scope
 --> src/main.rs:2:5
  |
2 |     println!("Hello, world!");
  |     ^^^^^^^

error: `#[panic_handler]` function required, but not found

For more information about this error, try `rustc --explain E0463`.
error: could not compile `hello` due to 3 previous errors

@Emilgardis
Copy link
Member

Emilgardis commented Jul 2, 2022

I'm not sure this is the correct approach, specifically the wording. If I don't require libstd this message would still always be shown on err.

@Alexhuszagh
Copy link
Contributor Author

We could specific to use -Z build-std=<components> (which we could change once we've implemented #896), so we can make it clear that libstd (it might be core, alloc, etc.) isn't required but may be an issue?

@Emilgardis
Copy link
Member

Emilgardis commented Jul 2, 2022

In addition, what about making component_is_installed returning an enum (or Option<bool>), signaling a component is installed, available but not installed, and not available. Then if not available, signal to use build-std.

@Alexhuszagh Alexhuszagh force-pushed the toolchain_warn branch 2 times, most recently from aa6d15d to f65965c Compare July 2, 2022 17:23
@Alexhuszagh
Copy link
Contributor Author

I've updated the error messages to make it clear std itself is not needed, and how build-std may be used.
Screenshot_20220702_122407

Provides a warning if a docker command fails and `rust-std` is not available for the target. For example, for `x86_64-unknown-dragonfly`, the added output would be:

```bash
[cross] warning: rust-std is not available for x86_64-unknown-dragonfly
[cross] note: you may need to build components for the target via `-Z build-std=<components>` or in your cross configuration specify `target.x86_64-unknown-dragonfly.build-std`
              the available components are core, std, alloc, and proc_macro
```

This is done solely if the command fails and if the target is a built-in, so we don't get misleading warnings for custom targets, and there is no overhead if the build succeeds.
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 3, 2022

Build succeeded:

@bors bors bot merged commit 4c091de into cross-rs:main Jul 3, 2022
@Alexhuszagh Alexhuszagh deleted the toolchain_warn branch July 3, 2022 20:20
@Emilgardis Emilgardis modified the milestone: v0.2.3 Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

better-errors enhancement no changelog A valid PR without changelog (no-changelog)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No error on unsupported target Missing rust-std for targets

2 participants