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

cargo relies on unknown crate type warnings to detect if a target supports crate types, which can be suppressed by -Awarnings and thus break cargo's detection #116626

Closed
cybersoulK opened this issue Oct 11, 2023 · 6 comments
Labels
A-CLI Area: Command-line interface (CLI) to the compiler C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cybersoulK
Copy link

cybersoulK commented Oct 11, 2023

When compiling a Rust project for the wasm32-unknown-unknown target with the -Awarnings flag, the following error is encountered:

error: output of --print=file-names missing when learning about target-specific information from rustc
command was: `.../.rustup/toolchains/nightly-2023-07-12-aarch64-apple-darwin/bin/rustc - --crate-name ___ --print=file-names -Awarnings --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=split-debuginfo --print=crate-name --print=cfg`

Steps To Reproduce:

Create blank project
Set RUSTFLAGS to "-Awarnings"
Run the command: cargo build --target wasm32-unknown-unknown

(Tested on Latest Stable as well)

@cybersoulK cybersoulK added the C-bug Category: This is a bug. label Oct 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 11, 2023
@bjorn3
Copy link
Member

bjorn3 commented Oct 14, 2023

What happens if you manually run the mentioned rustc command? Does it print anything? Does it crash?

@ehuss
Copy link
Contributor

ehuss commented Oct 14, 2023

The problem is that cargo is looking for:

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

to know which crate types are not supported. Suppressing that warning causes a mismatch of the list of crate names and what cargo is expecting.

One unbaked idea is to have a better interface between cargo and rustc of discovering target information (like maybe a JSON api). Right now, it uses a hacked delimiter system (using the ___ crate name), which is not great.

@cybersoulK
Copy link
Author

cybersoulK commented Oct 14, 2023

Something else i have to say, even if this bug is fixed:

i have a reasonably long wasm rusflags in the config.toml. They need to be there for rust Anylazer to interpret the code correctly, and facilitate development.
And because the rustflags in the export are not additive but overwritable, and because putting awarnings in config.toml removes warnings from rust analyzer, i am in an tough spot.

My project is growing very big, and i have occasional warnings to mark unimplemented pieces.
Mutting every warning makes them less noticeable in RA than if having a TODO. i like warnings as another layer additional to TODO

But when i am running many builds for deployment, warnings clutter the output, and i miss what's happening, if there is a crate that fails, because i am not looking and waiting for the entire period.

Also, i use a combination of cargo, cross and zigbuild to cross compile from my mac. I cannot just use cargo rust c for these extensions.

That's why disabling warning must be separate than the other rustflags, as a cargo argument, --disable-warnings. And that can then be added to cross and zigbuilds afterwards too.

@Noratrieb Noratrieb added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. A-CLI Area: Command-line interface (CLI) to the compiler and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 30, 2023
@terrybrash
Copy link

terrybrash commented Nov 25, 2024

Is there a workaround? I'd like to keep warnings disabled when targeting wasm.

@terrybrash
Copy link

Seems like #![allow(warnings)] works well enough and doesn't break wasm compilation.

@Noratrieb Noratrieb marked this as a duplicate of #135233 Jan 8, 2025
@jieyouxu jieyouxu changed the title Compilation Error with -Awarnings flag on wasm target cargo relies on unknown crate type warnings to detect if a target supports crate types, which can be suppressed by -Awarnings and thus break cargo's detection Jan 8, 2025
@jieyouxu jieyouxu self-assigned this Jan 8, 2025
@weihanglo
Copy link
Member

This should be fixed via rust-lang/cargo#15036.

@jieyouxu guess we can close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler C-bug Category: This is a bug. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants