From 0c732d649994d18656f8441d2d6f737ad2eae8c0 Mon Sep 17 00:00:00 2001 From: David Richey Date: Tue, 21 Jan 2025 14:06:19 -0800 Subject: [PATCH] rust-project: Don't include all buildfiles by default Summary: Add `--include-all-buildfiles` flag that controls whether `build` is included in every crate. With a default of `false`, this works around an issue where rust-analyzer tries to load all files from the parent of `build.build_file` which results in loading all of `third-party/rust`. Reviewed By: Wilfred Differential Revision: D68453686 fbshipit-source-id: 4478720b2b5bec2d9ce619e000427d58c48c8940 --- integrations/rust-project/src/buck.rs | 16 +++++++++++----- integrations/rust-project/src/cli/develop.rs | 6 ++++++ integrations/rust-project/src/main.rs | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/integrations/rust-project/src/buck.rs b/integrations/rust-project/src/buck.rs index 77e246c0a2ca..344f59f33251 100644 --- a/integrations/rust-project/src/buck.rs +++ b/integrations/rust-project/src/buck.rs @@ -51,6 +51,7 @@ pub(crate) fn to_json_project( aliases: FxHashMap, relative_paths: bool, check_cycles: bool, + include_all_buildfiles: bool, ) -> Result { let mode = select_mode(None); let buck = Buck::new(mode); @@ -159,11 +160,16 @@ pub(crate) fn to_json_project( include_dirs.insert(parent.to_owned()); } - let build = Some(Build { - label: target.clone(), - build_file: build_file.to_owned(), - target_kind: info.kind.clone().into(), - }); + let build = if include_all_buildfiles || info.in_workspace { + let build = Build { + label: target.clone(), + build_file: build_file.to_owned(), + target_kind: info.kind.clone().into(), + }; + Some(build) + } else { + None + }; let crate_info = Crate { display_name: Some(info.display_name()), diff --git a/integrations/rust-project/src/cli/develop.rs b/integrations/rust-project/src/cli/develop.rs index 251fcff1e463..590f23fa7fe4 100644 --- a/integrations/rust-project/src/cli/develop.rs +++ b/integrations/rust-project/src/cli/develop.rs @@ -38,6 +38,7 @@ pub(crate) struct Develop { pub(crate) buck: buck::Buck, pub(crate) check_cycles: bool, pub(crate) invoked_by_ra: bool, + pub(crate) include_all_buildfiles: bool, } pub(crate) struct OutputCfg { @@ -64,6 +65,7 @@ impl Develop { relative_paths, mode, check_cycles, + include_all_buildfiles, .. } = command { @@ -90,6 +92,7 @@ impl Develop { buck, check_cycles, invoked_by_ra: false, + include_all_buildfiles, }; let out = OutputCfg { out, pretty }; @@ -131,6 +134,7 @@ impl Develop { buck, check_cycles: false, invoked_by_ra: true, + include_all_buildfiles: false, }; let out = OutputCfg { out, pretty: false }; @@ -230,6 +234,7 @@ impl Develop { relative_paths, buck, check_cycles, + include_all_buildfiles, .. } = self; @@ -269,6 +274,7 @@ impl Develop { aliased_libraries, *relative_paths, *check_cycles, + *include_all_buildfiles, )?; Ok(rust_project) diff --git a/integrations/rust-project/src/main.rs b/integrations/rust-project/src/main.rs index 5350a19eb22b..d0e2de03a56d 100644 --- a/integrations/rust-project/src/main.rs +++ b/integrations/rust-project/src/main.rs @@ -111,6 +111,10 @@ enum Command { /// Optional argument specifying build mode. #[clap(short = 'm', long)] mode: Option, + + /// Include a `build` section for every crate, including dependencies. Otherwise, `build` is only included for crates in the workspace. + #[clap(long)] + include_all_buildfiles: bool, }, /// `DevelopJson` is a more limited, stripped down [`Command::Develop`]. ///