Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.93k stars 420 forks source link

Add Cargo.toml files #1100

Open mahkoh opened 1 month ago

mahkoh commented 1 month ago

Without Cargo.toml files, some significant dev exp features are inaccessible. This includes any kind of support for JetBrains IDEs.

This is not a request for crates to be built with cargo.

It might be possible to generate Cargo.toml files automatically. I believe that some files are already being generated for rust-analyzer support. If not, then it might be necessary to maintain such files manually.

bjorn3 commented 1 month ago

AFAIK IntelliJ doesn't have support for a custom sysroot at all. Rust-for-linux uses a custom sysroot. It also doesn't have a way to point directly to arbitrary compiled proc-macros, unlike rust-analyzer. IntelliJ works best with projects that use cargo with a standard project layout. Even the rust compiler itself, which uses cargo, isn't supported by IntelliJ due to the unusual project layout.

Generating Cargo.toml files would be non-trivial as multiple drivers (which need a separate Cargo.toml file) may be present in a single directory. Rust-analyzer supports this just fine with rust-project.json, but cargo doesn't support this.

Cargo.toml files being present may also cause people to attempt to build using cargo (whether intentionally or due to their IDE automatically running cargo build) which does not work. Not the least because rust-for-linux depends on a bunch of env vars and --cfg arguments which can't be set using Cargo.toml. Without those set a lot of code in the kernel crate is configured out, which would likely also break IDE functionality in IntelliJ.

ojeda commented 1 month ago

If not, then it might be necessary to maintain such files manually.

No, we can't really commit and maintain Cargo.toml files manually everywhere just for a single IDE.

Generating files on the fly is possible, but even if that happened to work (which as @bjorn3 says, it wouldn't, at least not easily), there is already rust-project.json for that (which is better suited for that purpose too).

JetBrains should support non-Cargo Rust projects, and ideally just add support for rust-project.json, since I would expect that is what most non-Cargo Rust projects already use, and it is harder to justify targets/features for individual IDEs.

ojeda commented 1 month ago

@mahkoh Perhaps we could reuse this issue for something like "Support for JetBrains IDEs"? i.e. to track support in general, in whatever form it comes eventually.

mahkoh commented 1 month ago

Sure, that is the primary issue I have.

The issues you mentioned so far sound reasonable and I'm currently out of the office so I cannot investigate them myself.

ojeda commented 1 month ago

Sounds good, thanks!