Skip to content

Commit

Permalink
feat: allow selecting which packages to check for buildscripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Apr 11, 2022
1 parent 24cf957 commit 85ceb64
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/project_model/src/build_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ impl WorkspaceBuildScripts {
cmd.env("RA_RUSTC_WRAPPER", "1");
}
cmd.current_dir(workspace.workspace_root());
cmd.args(&["check", "--quiet", "--workspace", "--message-format=json"]);
cmd.args(&["check", "--quiet", "--message-format=json"]);

if config.build_script_packages.is_empty() {
cmd.arg("--workspace");
} else {
for pkg in &config.build_script_packages {
cmd.arg("-p");
cmd.arg(pkg);
}
}

// --all-targets includes tests, benches and examples in addition to the
// default lib and bins. This is an independent concept from the --targets
Expand Down
2 changes: 2 additions & 0 deletions crates/project_model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub struct CargoConfig {
pub unset_test_crates: UnsetTestCrates,

pub wrap_rustc_in_build_scripts: bool,

pub build_script_packages: Vec<String>,
}

impl CargoConfig {
Expand Down
4 changes: 4 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ config_data! {
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
/// avoid compiling unnecessary things.
cargo_useRustcWrapperForBuildScripts: bool = "true",
/// List of packages to checked when running build scripts. It is
/// empty by default, which checks all packages in the workspace.
cargo_buildScriptPackagesToCheck: Vec<String> = "[]",
/// Do not activate the `default` feature.
cargo_noDefaultFeatures: bool = "false",
/// Compilation target (target triple).
Expand Down Expand Up @@ -803,6 +806,7 @@ impl Config {
rustc_source,
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
wrap_rustc_in_build_scripts: self.data.cargo_useRustcWrapperForBuildScripts,
build_script_packages: self.data.cargo_buildScriptPackagesToCheck.clone(),
}
}

Expand Down
8 changes: 8 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.cargo.buildScriptPackagesToCheck": {
"markdownDescription": "List of packages to checked when running build scripts.",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"rust-analyzer.cargo.noDefaultFeatures": {
"markdownDescription": "Do not activate the `default` feature.",
"default": false,
Expand Down

0 comments on commit 85ceb64

Please sign in to comment.