diff --git a/integrations/rust-project/src/buck.rs b/integrations/rust-project/src/buck.rs index 9edcc6120cb2..b3b10614249c 100644 --- a/integrations/rust-project/src/buck.rs +++ b/integrations/rust-project/src/buck.rs @@ -51,9 +51,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 { @@ -445,12 +446,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. @@ -480,7 +485,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 d581ade25a88..bcb7de067ec5 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 cd929bc9d00c..f038d59a4577 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 { @@ -82,7 +84,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, @@ -90,6 +92,7 @@ impl Develop { buck, check_cycles, invoked_by_ra: false, + buck2_command, }; let out = OutputCfg { out, pretty }; @@ -104,7 +107,10 @@ impl Develop { } if let crate::Command::DevelopJson { - sysroot_mode, args, .. + sysroot_mode, + args, + buck2_command, + .. } = command { let out = Output::Stdout; @@ -123,7 +129,7 @@ impl Develop { } }; - let buck = buck::Buck::new(mode); + let buck = buck::Buck::new(buck2_command.clone(), mode); let develop = Develop { sysroot, @@ -131,6 +137,7 @@ impl Develop { buck, check_cycles: false, invoked_by_ra: true, + buck2_command, }; let out = OutputCfg { out, pretty: false }; @@ -233,6 +240,7 @@ impl Develop { relative_paths, buck, check_cycles, + buck2_command, .. } = self; @@ -272,6 +280,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 c42a5ebb0ebf..5ab5424e751c 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, + + /// Command used to run Buck2. Defaults to `buck2`. + #[clap(long)] + buck2_command: Option, }, /// `DevelopJson` is a more limited, stripped down [`Command::Develop`]. /// @@ -131,6 +135,10 @@ enum Command { client: Option, 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 { @@ -147,6 +155,9 @@ enum Command { /// 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, }, } @@ -282,12 +293,13 @@ 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.clone()) + cli::Check::new(buck2_command, mode, use_clippy, saved_file.clone()) .run() .inspect_err(|e| crate::scuba::log_check_error(&e, &saved_file, use_clippy)) } @@ -371,6 +383,7 @@ fn json_args_pass() { args, sysroot_mode: SysrootMode::Rustc, client: None, + buck2_command: None, }), version: false, }; @@ -388,6 +401,7 @@ fn json_args_pass() { args, sysroot_mode: SysrootMode::Rustc, client: None, + buck2_command: None, }), version: false, }; @@ -405,6 +419,7 @@ fn json_args_pass() { args, sysroot_mode: SysrootMode::Rustc, client: None, + buck2_command: None, }), version: false, };