Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when compiling with --allow warnings with certain targets #8010

Closed
dakom opened this issue Mar 17, 2020 · 7 comments · Fixed by #15036
Closed

error when compiling with --allow warnings with certain targets #8010

dakom opened this issue Mar 17, 2020 · 7 comments · Fixed by #15036
Labels
A-rustflags Area: rustflags C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@dakom
Copy link

dakom commented Mar 17, 2020

When I set RUSTFLAGS="--allow warnings" and try to cargo build --target wasm32-unknown-unknown I get the following error:

error: output of --print=file-names has changed in the compiler, cannot parse
command was: `rustc - --crate-name ___ --print=file-names --allow warnings --target wasm32-unknown-unknown --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg`

rustc 1.43.0-nightly (564758c4c 2020-03-08)
cargo 1.43.0-nightly (bda5051 2020-03-02)

originally filed here: rust-lang/rust#70070

@dakom dakom added the C-bug Category: bug label Mar 17, 2020
@ehuss
Copy link
Contributor

ehuss commented Mar 17, 2020

Hm, that's a tricky one. The --allow warnings prevents these lines from being printed:

warning: dropping unsupported crate type `dylib` for target `wasm32-unknown-unknown`
warning: dropping unsupported crate type `proc-macro` for target `wasm32-unknown-unknown`

This is required by Cargo in order to know which crate types are valid (and what their output names are).

I don't have any good ideas on how to accommodate this. Some bad ones:

  • Filter RUSTFLAGS to remove things like "--allow".
  • Filter RUSTFLAGS with an allowed list of flags. (Occasionally certain rustc flags cause problems with this code that queries rustc with the --print flag.)
  • Make a better interface in rustc for querying this information (maybe like a more structured format like JSON).
    • Or a similar option would be for rustc to print some kind of separator between the different groups of output.

@ehuss ehuss added the A-rustflags Area: rustflags label Apr 15, 2020
Anton-4 added a commit to roc-lang/roc that referenced this issue May 20, 2022
see rust-lang/cargo#8010 on why I removed RUSTFLAGS="-Awarnings"
@epage
Copy link
Contributor

epage commented Nov 3, 2023

If we had #8424, I wonder if we could still show that warning.

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label Nov 3, 2023
@ia0
Copy link

ia0 commented Nov 10, 2023

This bug is quite annoying because I'm not sure how to work around it right now. Even when specifying the crate type I get the error:

RUSTFLAGS=--allow=warnings cargo rustc --crate-type=cdylib --target=wasm32-unknown-unknown

The best I found so far is to just ignore all the output:

cargo check --target=wasm32-unknown-unknown 2>/dev/null

@ehuss ehuss changed the title error when compiling with --allow warnings and --target wasm32-unknown-unknown error when compiling with --allow warnings with certain targets Jul 9, 2024
@mo8it
Copy link
Contributor

mo8it commented Jul 9, 2024

Is this really a Cargo issue? It looks like a rustc argument parsing issue to me.

If you point me in the right direction, I would be happy to try to fix it since it currently affects Rustlings: rust-lang/rustlings#2036

@ehuss
Copy link
Contributor

ehuss commented Jul 9, 2024

As mentioned above, this isn't really easy to fix. I think we may need to transition to a JSON interface, and that isn't simple.

What is your use case for -Awarnings? I generally wouldn't recommend using that flag, since it could silence important information.

@mo8it
Copy link
Contributor

mo8it commented Jul 9, 2024

My use case in Rustlings is that I run cargo clippy and capture its output. Then, I run cargo test and don't want its output of cargo check. I only want the output of the tests. Is there a way to achieve this otherwise?

@ia0
Copy link

ia0 commented Jul 9, 2024

My use-case can most probably be done better. The idea is that I have exercises with todo!()s that have to be completed. I want the Cargo.lock files of those exercises to be up-to-date when I change (possibly nested) dependencies somewhere else in the mono-repo. So part of my CI is to cargo check --target=wasm32-unknown-unknown 2> /dev/null to make sure the Cargo.lock is idempotent. The warnings I want to hide are mostly unused_variables, unused_imports, and dead_code, because I don't want the person doing the exercise to care about removing leading underscores on variable names, or adding missing imports, etc. And I also don't want to see irrelevant warnings in my CI which should run without warnings (because sometimes it's also hard to make sure everything runs with --deny=warnings). My work-around of ignoring all output seems good enough so far. It didn't hide anything important as far as I'm aware of. So I'm really just describing my usecase as a data point for possible decisions in this issue.

weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
but at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
but at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
It lets the rustc invocation for learning target info always
emit warnings as warnings.
But at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
It lets the rustc invocation for learning target info always
emit warnings as warnings.
But at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
It lets the rustc invocation for learning target info always
emit warnings as warnings.
But at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
weihanglo added a commit to weihanglo/cargo that referenced this issue Jan 8, 2025
This is a horrible hack,
It lets the rustc invocation for learning target info always
emit warnings as warnings.
But at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
github-merge-queue bot pushed a commit that referenced this issue Jan 9, 2025
### What does this PR try to resolve?

This is a horrible hack,
which lets the rustc invocation for learning target info always emit
warnings as warnings.
But at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:

https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes #8010

### How should we test and review this PR?

Ensure `CFG_DISABLE_CROSS_TESTS` is not set,
and run `cargo t --test testsuite
always_emit_warnings_as_warnings_when_learning_target_info`

This also additionally adds `wasm32-unknown-unknown` target to Cargo's
CI.

### Additional information
ia0 added a commit to ia0/wasefire that referenced this issue Jan 13, 2025
ia0 added a commit to google/wasefire that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustflags Area: rustflags C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants