Skip to content

support cargo build #25

@bf

Description

@bf

As discussed in lite-xl/lite-xl-lsp-servers#47 (comment) it'd be nice to have first-class support for rust projects.

For rust projects, the cargo.toml file defines all dependencies and build targets. With cargo build you can create debug binaries.

Other IDEs such as lapce have their own subfolder .lapce/run.toml with custom config format for building and running a rust binary. The following config is example how lapce handles the situation. I don't think a custom config file like .lapce/run.toml is really needed, if we already can do build.sh. I'm pasting the file just as an inspiration:

# The run config is used for both run mode and debug mode

[[configs]]
# the name of this task
name = "myprogram"

# the type of the debugger. If not set, it can't be debugged but can still be run
# type = "lldb"

# the program to run
program = "./target/debug/myprogram"

tracing_output="Debug"

# the program arguments, e.g. args = ["arg1", "arg2"], optional
args = ["update-hello-world-sample-parameter"]

# current working directory, optional
# cwd = "/home/user/test-data"

# environment variables, optional
[configs.env]
RUST_BACKTRACE = "1"

# task to run before the run/debug session is started, optional
[configs.prelaunch]
program = "cargo"
args = [
   "build",
]

Also lapce IDE will run cargo check on every saving of a .rs file, and it will show the errors in the whole project.

For syntax errors, cargo build will show the following message:

cargo build
   Compiling my-tool v0.1.0 (/home/user/src/my-tool)
error: expected item, found `3`
 --> src/main.rs:6:50
  |
6 | use clap_verbosity_flag::{InfoLevel, Verbosity}; 3
  |                                                  ^ expected item
  |
  = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>

error: could not compile `my-tool` (bin "my-tool") due to 1 previous error

For "normal" builds, cargo build will show heaps of warnings:

[...]
warning: type `parsers::ExtractorError` is more private than the item `<TimestampExtractor as Extractor>::extract`
   --> src/parsers.rs:257:3
    |
257 |   fn extract(&self, input: &Self::InputType) -> ExtractorResult<Self::OutputType> {
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method `<TimestampExtractor as Extractor>::extract` is reachable at visibility `pub(crate)`
    |
note: but type `parsers::ExtractorError` is only usable at visibility `pub(self)`
   --> src/parsers.rs:226:1
    |
226 | enum ExtractorError {
    | ^^^^^^^^^^^^^^^^^^^

warning: `my-tool` (bin "my-tool") generated 19 warnings (run `cargo fix --bin "my-tool"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.83s
warning: the following packages contain code that will be rejected by a future version of Rust: html5ever v0.24.1
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
``

I am not a rust expert but let me know if there is anything I can contribute.

It'd be great if basic cargo build functionality would be possible. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions