diff --git a/integrations/rust-project/src/buck.rs b/integrations/rust-project/src/buck.rs index 63c597a7c10d4..bf7b73aa3df21 100644 --- a/integrations/rust-project/src/buck.rs +++ b/integrations/rust-project/src/buck.rs @@ -50,9 +50,10 @@ pub(crate) fn to_json_project( aliases: FxHashMap, relative_paths: bool, check_cycles: bool, + buck2_command: Option, ) -> Result { let mode = select_mode(None); - let buck = Buck::new(mode); + let buck = Buck::new(buck2_command, mode); let project_root = buck.resolve_project_root()?; let ExpandedAndResolved { @@ -436,12 +437,16 @@ fn merge_unit_test_targets( #[derive(Debug, Default)] pub(crate) struct Buck { + command: String, mode: Option, } impl Buck { - pub(crate) fn new(mode: Option) -> Self { - Buck { mode } + pub(crate) fn new(command: Option, mode: Option) -> Self { + Buck { + command: command.unwrap_or_else(|| "buck2".into()), + mode, + } } /// Invoke `buck2` with the given subcommands. @@ -471,7 +476,7 @@ impl Buck { I: IntoIterator, S: AsRef, { - let mut cmd = Command::new("buck2"); + let mut cmd = Command::new(&self.command); // rust-analyzer invokes the check-on-save command with `RUST_BACKTRACE=short` // set. Unfortunately, buck2 doesn't handle that well and becomes extremely diff --git a/integrations/rust-project/src/cli/check.rs b/integrations/rust-project/src/cli/check.rs index 71c3adae01491..e54afba7266c3 100644 --- a/integrations/rust-project/src/cli/check.rs +++ b/integrations/rust-project/src/cli/check.rs @@ -23,11 +23,16 @@ pub(crate) struct Check { } impl Check { - pub(crate) fn new(mode: Option, use_clippy: bool, saved_file: PathBuf) -> Self { + pub(crate) fn new( + buck2_command: Option, + mode: Option, + use_clippy: bool, + saved_file: PathBuf, + ) -> Self { let saved_file = canonicalize(&saved_file).unwrap_or(saved_file); let mode = select_mode(mode.as_deref()); - let buck = buck::Buck::new(mode); + let buck = buck::Buck::new(buck2_command, mode); Self { buck, use_clippy, diff --git a/integrations/rust-project/src/cli/develop.rs b/integrations/rust-project/src/cli/develop.rs index 2d18cb3498f0a..c9322c15981be 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) buck2_command: Option, } pub(crate) struct OutputCfg { @@ -64,6 +65,7 @@ impl Develop { relative_paths, mode, check_cycles, + buck2_command, } = command { let out = if stdout { @@ -81,7 +83,7 @@ impl Develop { }; let mode = select_mode(mode.as_deref()); - let buck = buck::Buck::new(mode); + let buck = buck::Buck::new(buck2_command.clone(), mode); let develop = Develop { sysroot, @@ -89,6 +91,7 @@ impl Develop { buck, check_cycles, invoked_by_ra: false, + buck2_command, }; let out = OutputCfg { out, pretty }; @@ -102,7 +105,12 @@ impl Develop { return (develop, input, out); } - if let crate::Command::DevelopJson { sysroot_mode, args } = command { + if let crate::Command::DevelopJson { + sysroot_mode, + args, + buck2_command, + } = command + { let out = Output::Stdout; let mode = select_mode(None); @@ -119,7 +127,7 @@ impl Develop { } }; - let buck = buck::Buck::new(mode); + let buck = buck::Buck::new(buck2_command.clone(), mode); let develop = Develop { sysroot, @@ -127,6 +135,7 @@ impl Develop { buck, check_cycles: false, invoked_by_ra: true, + buck2_command, }; let out = OutputCfg { out, pretty: false }; @@ -226,6 +235,7 @@ impl Develop { relative_paths, buck, check_cycles, + buck2_command, .. } = self; @@ -265,6 +275,7 @@ impl Develop { aliased_libraries, *relative_paths, *check_cycles, + buck2_command.clone(), )?; Ok(rust_project) diff --git a/integrations/rust-project/src/main.rs b/integrations/rust-project/src/main.rs index 082d47c8dc0c7..b82f215ac53a0 100644 --- a/integrations/rust-project/src/main.rs +++ b/integrations/rust-project/src/main.rs @@ -107,6 +107,10 @@ enum Command { /// Optional argument specifying build mode. #[clap(short = 'm', long)] mode: Option, + + /// Command used to run Buck2. Defaults to `buck2`. + #[clap(long)] + buck2_command: Option, }, /// `DevelopJson` is a more limited, stripped down [`Command::Develop`]. /// @@ -123,6 +127,10 @@ enum Command { sysroot_mode: SysrootMode, args: JsonArguments, + + /// Command used to run Buck2. Defaults to `buck2`. + #[clap(long)] + buck2_command: Option, }, /// Build the saved file's owning target. This is meant to be used by IDEs to provide diagnostics on save. Check { @@ -133,6 +141,9 @@ enum Command { use_clippy: bool, /// The file saved by the user. `rust-project` will infer the owning target(s) of the saved file and build them. saved_file: PathBuf, + /// Command used to run Buck2. Defaults to `buck2`. + #[clap(long)] + buck2_command: Option, }, } @@ -266,11 +277,12 @@ fn main() -> Result<(), anyhow::Error> { mode, use_clippy, saved_file, + buck2_command, } => { let subscriber = tracing_subscriber::registry().with(fmt.with_filter(filter)); tracing::subscriber::set_global_default(subscriber)?; - cli::Check::new(mode, use_clippy, saved_file).run() + cli::Check::new(buck2_command, mode, use_clippy, saved_file).run() } } }