Skip to content

Commit

Permalink
rust-project: Don't include all buildfiles by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
darichey authored and facebook-github-bot committed Jan 21, 2025
1 parent 15a71c5 commit 0c732d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
16 changes: 11 additions & 5 deletions integrations/rust-project/src/buck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub(crate) fn to_json_project(
aliases: FxHashMap<Target, AliasedTargetInfo>,
relative_paths: bool,
check_cycles: bool,
include_all_buildfiles: bool,
) -> Result<JsonProject, anyhow::Error> {
let mode = select_mode(None);
let buck = Buck::new(mode);
Expand Down Expand Up @@ -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()),
Expand Down
6 changes: 6 additions & 0 deletions integrations/rust-project/src/cli/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -64,6 +65,7 @@ impl Develop {
relative_paths,
mode,
check_cycles,
include_all_buildfiles,
..
} = command
{
Expand All @@ -90,6 +92,7 @@ impl Develop {
buck,
check_cycles,
invoked_by_ra: false,
include_all_buildfiles,
};
let out = OutputCfg { out, pretty };

Expand Down Expand Up @@ -131,6 +134,7 @@ impl Develop {
buck,
check_cycles: false,
invoked_by_ra: true,
include_all_buildfiles: false,
};
let out = OutputCfg { out, pretty: false };

Expand Down Expand Up @@ -230,6 +234,7 @@ impl Develop {
relative_paths,
buck,
check_cycles,
include_all_buildfiles,
..
} = self;

Expand Down Expand Up @@ -269,6 +274,7 @@ impl Develop {
aliased_libraries,
*relative_paths,
*check_cycles,
*include_all_buildfiles,
)?;

Ok(rust_project)
Expand Down
4 changes: 4 additions & 0 deletions integrations/rust-project/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ enum Command {
/// Optional argument specifying build mode.
#[clap(short = 'm', long)]
mode: Option<String>,

/// 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`].
///
Expand Down

0 comments on commit 0c732d6

Please sign in to comment.