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

Multiple simultaneous target triples #10021

Open
trevyn opened this issue Aug 25, 2021 · 9 comments
Open

Multiple simultaneous target triples #10021

trevyn opened this issue Aug 25, 2021 · 9 comments
Labels
C-feature Category: feature request E-hard

Comments

@trevyn
Copy link

trevyn commented Aug 25, 2021

I have a project that compiles to both wasm32-unknown-unknown and the host triple, with heavy use of

#[cfg(target_arch = "wasm32")]

and

#[cfg(not(target_arch = "wasm32"))]

Right now, I can select one or the other target triple with rust-analyzer.cargo.target, but I miss errors and warnings from the other, and half of the code is dimmed out.

It would be cool to be able to show a combined view of errors and warnings from both triples at the same time, and no code would need to be dimmed.

@ruabmbua
Copy link
Contributor

ruabmbua commented Sep 6, 2021

This is probably a duplicate of the following ticket: #8521

@kpreid
Copy link
Contributor

kpreid commented Oct 30, 2021

I have a similar situation and would find this feature very useful. I can temporarily change the target triple, but because rust-analyzer is never aware of both variants of the code, it can never give me a complete list of references to an item that is used in the two target-specific parts, or check both at once, which would be useful when I am trying to change the interface between the generic code and the target-specific code.

(#8521 says it is specifically about two different workspaces, but I have only one workspace. Changing that is an idea I hadn't thought of, and I'm not yet sure whether it would improve the situation more than it complicates it, but regardless, rust-analyzer currently supports neither case.)

@Veykril Veykril added the C-feature Category: feature request label Nov 3, 2021
@trevyn
Copy link
Author

trevyn commented Jan 1, 2022

For reference, I stumbled upon something vaguely resembling a workaround: I have an attribute proc-macro that just applies the appropriate cfg, which r-a is set not to expand. This then requires all relevant crates to be available as dependencies for the current target, but other than that does appear to ultimately result in the desired behavior of all code being processed by r-a.

EDIT: A similar result could probably be achieved by having a special cargo feature that r-a is configured to pass in, which disables the cfgs when checking. Again, this is only a partial workaround; my codebase happens to play well with this setup, others may not.

@nasso
Copy link

nasso commented Jun 4, 2022

What makes this particularly hard to implement?

My naive approach to fix this problem would be to run cargo check multiple times with a different --target triple each time, and combine the results (eliminating duplicates). The list of targets to check could be manually specified through a user-specified array of triples (e.g. default/native/auto + wasm32-unknown-unknown).
Now this is clearly not ideal since a lot of the work is duplicated, but it could serve as a temporary solution before a more elaborate algorithm can be implemented (e.g. one that would ignore any #[cfg(...)] and "fork" the checking process only where necessary).

The current behaviour makes it really difficult to work on crates containing a lot of platform-specific code paths!

@DianaNites
Copy link
Contributor

I just noticed this seems to be valid now

"rust-analyzer.check.targets": ["aarch64-apple-darwin", "x86_64-apple-darwin"]

Rust-analyzer › Check: Targets
Check for specific targets. Defaults to Rust-analyzer › Cargo: Target if empty.

Can be a single target, e.g. "x86_64-unknown-linux-gnu" or a list of targets, e.g. ["aarch64-apple-darwin", "x86_64-apple-darwin"].

Aliased as "checkOnSave.targets".

@nasso
Copy link

nasso commented Feb 25, 2023

but is it possible to say "whatever is the default/native target + wasm32-unknown-unknown" ?

@DianaNites
Copy link
Contributor

Does not appear so, no, but at least you probably arent changing your host target very often?

This doesn't work well in workspaces where some crates only compile on some targets but not others though

@nasso
Copy link

nasso commented Feb 26, 2023

I work in a team; some of us are on different platforms and we would like to share the same editor configuration

though, yeah, in our workspace some crates only compile on some targets but not others, so we would need crate-specific configuration here anyway

@kpreid
Copy link
Contributor

kpreid commented Feb 26, 2023

It occurs to me that it might be useful for cargo/rustc to have a special target string that means "the host's target triple, whatever that is". That would finish this problem for r-a and also be useful in build tools that have reason to deal with mixed cross-compiling and not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request E-hard
Projects
None yet
Development

No branches or pull requests

7 participants