-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add cargo integration #3
Comments
All of this should happen in the GUI. |
I've been working on a project system lately and the issue of cargo integration really had become a sticking point. I'm unsure how to proceed so please comment and leave suggestions. IntroductionProbably not everyone reading this is 100% familiar with VS projects so quick explanation is in order. Project system is a part of every language implementation in Visual Studio. It's the code that handles loading project file to a nice hierarchy of nodes as seen in Solution Explorer and interactions with VS (building, adding files, adding references, etc). Project file is a file that stores all information about the project. For example .csproj files are project files for C# projects. Project files can have an arbitrary format. Currently, most VS languages (C#, C++, VB.NET, F#) use MSBuild build files as a project backend, that has a nice property of projects being compilable without the presence of VS and eases linking to projects in different languages. ProblemsThere are few goals and use cases that we have to cover with project system that problematic due to cargo being a rather inflexible build system.
Proposed solutions
I'm currently leaning towards solution 3, but that would mean postponing cargo support until after rust-lang/cargo#358 is done. |
Solution 3 sounds reasonable. As an additional note, I think it would be useful if the MSBuild project file can be generated from a cargo manifest, maybe even directly using cargo (does cargo support plugins?). This would allow to build all cargo-based projects with Visual Studio, as long as all cargo features are somehow supported in Visual Rust projects. I've seen this in IntelliJ for Scala SBT support: SBT is a build system that also deals with dependencies (like cargo) and there is (1) an SBT plugin that generates IntelliJ project files (also watching for changes in the SBT manifest with the possibility to automatically regenerate and reload the project files) and (2) an IntelliJ plugin that uses SBT for building. The combination of those two works well and something similar might be possible here. Visual Studio is not IntelliJ, though, of course. |
Thanks. I've checked IntelliJ and they do it differently, they separate project file and build system. So it's closer closer to our solution 2. When it comes to Cargo integration, Cargo --> MSBuild can be done by exposing project template (an entry in "New project..." window) for "Create VisualRust project from existing cargo project". I can't think of any cargo feature that can't be replicated with MSBuild (at least when it comes to building). |
Here is my vision. We should think not only about how nice it will be in VS-only usage scenarios but also about interoperation with non-VS world. Inability to generate cargo.toml file is huge drawback, it means that any Rust project created with VS will be useless to those who don't use VS and will require them to write toml file manualy. Using other file format for project files means that it would be necessary to convert it to/from cargo.toml. I think that supporting cargo.toml as a project file is a must. Just imagine - you can download any (well, probably not) Rust project and it can be just opened and compiled in Visual Studio. Since using cargo.toml for project files has some issues as you described there should be possibility to use more VS friendly project file. So there will be two options:
|
All known to me rust project is on github. All they use cargo for building, that's why cargo support is very important feature for VisualRust and that's why, to my mind, it must be one of next features implemented in Visual Rust. I agree with Ghost that there are 2 working use case for rust developing in visual studio:
But I suppouse that make additional build system over cargo.toml in Visual Studio is too much overhead for this task. To my mind, generation rsproj from cargo.toml and inculding cargo.toml into this project is quite suitable approach as from user side so from developing side. IMHO, in ideal way (if it is possible), we assisiate cargo.toml with visual studio. When it file is being opening first time, we are creating rsproj-file and opening it, otherwise updating rsproj and opening. |
Thanks for your thoughts everyone, the plan is to go with solution nr 2. Here are my rationales and plans. How it will work in practice is that we will rely on Integrating with cargo will be the main focus of 0.2 release. That's because I want to get some kind of usable 0.1 version out. Cargo integration touches every facet of Visual Rust:
This of course relies on existence of a Cargo.toml parser that would allow us for painless loading/editing/saving. I'm not sure if one exists. Worst case scenario we will have to roll our own on top of |
This sounds good to me! Especially the part about managing Cargo dependencies just like Nuget does (i.e. in the way VS users know it) ... this will be great, when it works :-) One concern is the output parsing: Currently we run rustc through MSBuild (as you said in "Building"), and parsing its output is already quite difficult. If we switch to run cargo instead (which is the only reasonable thing to do), it will be even more difficult, since cargo forwards the output of rustc, but also for errors in dependencies, etc. This could be further complicated by a plan to animate the output of rustc/cargo: rust-lang/rust#24335. Maybe an option can be added to rustc/cargo so the build output is printed in a more machine-readable format (e.g. JSON)? I think this would also be beneficial for other similar projects (editor plugins, etc), but I don't know how they currently handle this. Also, this cargo PR looks relevant for us. |
IIRC cargo sends rustc errors to stderr and everything else to stdout. |
I started Cargo.toml wrapper to support this task: https://github.com/lostmsu/Rust.Cargo |
@lostmsu I can't compile your project (even after converting from portable project and adding nuget reference to hypertoml). But the thing about parsing
and the user changes package name from |
@vosen how are you planning to use Rust code in your VS extension? |
@vosen So, what's the current status/design of this? |
@vosen cargo needed 👍 |
@lostmsu I couldn't build your project, so I went with |
@vosen Any progress on this recently? |
This one thing is basically the only blocker for a bunch of people I know that want to use this, including myself. |
I would personally disagree with that, atom's rust plugins have pretty bad syntax highlighting but they integrate really well with cargo for linting. Because of this, I can actually use atom even if the highlighting is off now and then, while VisualRust is entirely unusable for me because of the lack of cargo integration. |
Even though I am very eager to see the Cargo integration, I agree with this. I often use a different editor because the syntax highlighting in it works better. (In particular, that other editor does brace matching, which is very important for Rust.) |
@vosen, I mostly agree with retep998 and LaylConway. We can compile with cargo from console. It's not so big deal. But, we can't use Visual Studio debugger without building with cargo inside Visual Studio. IMHO, it's much more valueable feature than syntax highlighting. At least, we can use some another text editor for syntax highlighting, but debugger is still not allowed at all, because almost all programs slightly more complex than "Hello world" use cargo. |
Cargo integration still appears to be missing.... |
FYI: |
Cargo support would be great, but this thread has been silent for some months, so I am not sure if this is happening. On the other hand, it seems impossible to write much beyond "Hello World" without using external crates. Is there any workaround to compile & run a project with dependencies, in VisualRust? |
@huettenhain Project and build support for Cargo has been added in #234, but it has not been released yet. You can try it with a build from AppVeyor. |
@Boddlnagg Thanks for the suggestion, the Cargo support looks good. Unfortunately, the plugin is not working - the linked build of VisualRust fails to build the default template, let alone anything more complex. I can post the error message if requested, but I do not think this is the right thread for that. |
The text was updated successfully, but these errors were encountered: