Skip to content

Commit

Permalink
better runnables support
Browse files Browse the repository at this point in the history
  • Loading branch information
bobozaur committed Dec 16, 2024
1 parent 5de25c8 commit 98aa3b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion tools/rust_analyzer/aquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,15 @@ fn consolidate_crate_specs(crate_specs: Vec<CrateSpec>) -> anyhow::Result<BTreeS
if spec.crate_type == CrateType::Rlib {
existing.display_name = spec.display_name;
existing.crate_type = CrateType::Rlib;
existing.build = spec.build;
existing.is_test = spec.is_test;
}

// We want to use the test target's build label to provide
// unit tests codelens actions for library crates in IDEs.
if spec.is_test {
existing.build = spec.build;
}

// For proc-macro crates that exist within the workspace, there will be a
// generated crate-spec in both the fastbuild and opt-exec configuration.
// Prefer proc macro paths with an opt-exec component in the path.
Expand Down
2 changes: 1 addition & 1 deletion tools/rust_analyzer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ fn generate_rust_project(
let sysroot_src = &toolchain_info["sysroot_src"];
let sysroot = &toolchain_info["sysroot"];

rust_project::generate_rust_project(workspace, sysroot, sysroot_src, &crate_specs)
rust_project::generate_rust_project(bazel, workspace, sysroot, sysroot_src, &crate_specs)
}
18 changes: 15 additions & 3 deletions tools/rust_analyzer/rust_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub struct Build {
pub target_kind: TargetKind,
}

#[derive(Clone, Copy, Debug, Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum TargetKind {
Bin,
Expand Down Expand Up @@ -213,6 +213,7 @@ pub enum RunnableKind {
}

pub fn generate_rust_project(
bazel: &Utf8Path,
workspace: &Utf8Path,
sysroot: &str,
sysroot_src: &str,
Expand All @@ -224,13 +225,13 @@ pub fn generate_rust_project(
crates: Vec::new(),
runnables: vec![
Runnable {
program: "bazel".to_owned(),
program: bazel.to_string(),
args: vec!["build".to_owned(), "{label}".to_owned()],
cwd: workspace.to_owned(),
kind: RunnableKind::Check,
},
Runnable {
program: "bazel".to_owned(),
program: bazel.to_string(),
args: vec![
"test".to_owned(),
"{label}".to_owned(),
Expand Down Expand Up @@ -284,6 +285,17 @@ pub fn generate_rust_project(
| CrateType::ProcMacro => TargetKind::Lib,
};

if let Some(build) = &c.build {
if target_kind == TargetKind::Bin {
project.runnables.push(Runnable {
program: bazel.to_string(),
args: vec!["run".to_string(), build.label.to_owned()],
cwd: workspace.to_owned(),
kind: RunnableKind::Run,
});
}
}

project.crates.push(Crate {
display_name: Some(c.display_name.clone()),
root_module: c.root_module.clone(),
Expand Down

0 comments on commit 98aa3b9

Please sign in to comment.