@@ -12,7 +12,7 @@ use camino::{Utf8Path, Utf8PathBuf};
1212use clap:: Parser ;
1313use env_logger:: { fmt:: Formatter , Target , WriteStyle } ;
1414use gen_rust_project_lib:: {
15- generate_rust_project , get_bazel_info , DiscoverProject , RustAnalyzerArg , BUILD_FILE_NAMES ,
15+ bazel_info , generate_rust_project , DiscoverProject , RustAnalyzerArg , BUILD_FILE_NAMES ,
1616 WORKSPACE_ROOT_FILE_NAMES ,
1717} ;
1818use log:: { LevelFilter , Record } ;
@@ -37,7 +37,8 @@ fn project_discovery() -> anyhow::Result<DiscoverProject<'static>> {
3737 execution_root,
3838 output_base,
3939 bazel,
40- bazelrc,
40+ bazel_startup_options,
41+ bazel_args,
4142 rust_analyzer_argument,
4243 } = Config :: parse ( ) ?;
4344
@@ -53,20 +54,20 @@ fn project_discovery() -> anyhow::Result<DiscoverProject<'static>> {
5354 log:: info!( "resolved rust-analyzer argument: {ra_arg:?}" ) ;
5455
5556 let ( buildfile, targets) = ra_arg. into_target_details ( & workspace) ?;
56- let targets = & [ targets] ;
5757
5858 log:: debug!( "got buildfile: {buildfile}" ) ;
59- log:: debug!( "got targets: {targets:? }" ) ;
59+ log:: debug!( "got targets: {targets}" ) ;
6060
6161 // Use the generated files to print the rust-project.json.
6262 let project = generate_rust_project (
6363 & bazel,
6464 & output_base,
6565 & workspace,
6666 & execution_root,
67- bazelrc. as_deref ( ) ,
67+ & bazel_startup_options,
68+ & bazel_args,
6869 & rules_rust_name,
69- targets,
70+ & [ targets] ,
7071 ) ?;
7172
7273 Ok ( DiscoverProject :: Finished { buildfile, project } )
@@ -114,19 +115,26 @@ fn main() -> anyhow::Result<()> {
114115#[ derive( Debug ) ]
115116pub struct Config {
116117 /// The path to the Bazel workspace directory. If not specified, uses the result of `bazel info workspace`.
117- pub workspace : Utf8PathBuf ,
118+ workspace : Utf8PathBuf ,
118119
119120 /// The path to the Bazel execution root. If not specified, uses the result of `bazel info execution_root`.
120- pub execution_root : Utf8PathBuf ,
121+ execution_root : Utf8PathBuf ,
121122
122123 /// The path to the Bazel output user root. If not specified, uses the result of `bazel info output_base`.
123- pub output_base : Utf8PathBuf ,
124+ output_base : Utf8PathBuf ,
124125
125126 /// The path to a Bazel binary.
126- pub bazel : Utf8PathBuf ,
127+ bazel : Utf8PathBuf ,
128+
129+ /// Startup options to pass to `bazel` invocations.
130+ /// See the [Command-Line Reference](<https://bazel.build/reference/command-line-reference>)
131+ /// for more details.
132+ bazel_startup_options : Vec < String > ,
127133
128- /// The path to a `bazelrc` configuration file.
129- bazelrc : Option < Utf8PathBuf > ,
134+ /// Arguments to pass to `bazel` invocations.
135+ /// See the [Command-Line Reference](<https://bazel.build/reference/command-line-reference>)
136+ /// for more details.
137+ bazel_args : Vec < String > ,
130138
131139 /// The argument that `rust-analyzer` can pass to the binary.
132140 rust_analyzer_argument : Option < RustAnalyzerArg > ,
@@ -138,12 +146,19 @@ impl Config {
138146 let ConfigParser {
139147 workspace,
140148 bazel,
141- bazelrc,
149+ bazel_startup_options,
150+ bazel_args,
142151 rust_analyzer_argument,
143152 } = ConfigParser :: parse ( ) ;
144153
145154 // We need some info from `bazel info`. Fetch it now.
146- let mut info_map = get_bazel_info ( & bazel, workspace. as_deref ( ) , None , bazelrc. as_deref ( ) ) ?;
155+ let mut info_map = bazel_info (
156+ & bazel,
157+ workspace. as_deref ( ) ,
158+ None ,
159+ & bazel_startup_options,
160+ & bazel_args,
161+ ) ?;
147162
148163 let config = Config {
149164 workspace : info_map
@@ -159,7 +174,8 @@ impl Config {
159174 . expect ( "'output_base' must exist in bazel info" )
160175 . into ( ) ,
161176 bazel,
162- bazelrc,
177+ bazel_startup_options,
178+ bazel_args,
163179 rust_analyzer_argument,
164180 } ;
165181
@@ -177,9 +193,17 @@ struct ConfigParser {
177193 #[ clap( long, default_value = "bazel" ) ]
178194 bazel : Utf8PathBuf ,
179195
180- /// The path to a `bazelrc` configuration file.
181- #[ clap( long) ]
182- bazelrc : Option < Utf8PathBuf > ,
196+ /// Startup options to pass to `bazel` invocations.
197+ /// See the [Command-Line Reference](<https://bazel.build/reference/command-line-reference>)
198+ /// for more details.
199+ #[ clap( long = "bazel_startup_option" ) ]
200+ bazel_startup_options : Vec < String > ,
201+
202+ /// Arguments to pass to `bazel` invocations.
203+ /// See the [Command-Line Reference](<https://bazel.build/reference/command-line-reference>)
204+ /// for more details.
205+ #[ clap( long = "bazel_arg" ) ]
206+ bazel_args : Vec < String > ,
183207
184208 /// The argument that `rust-analyzer` can pass to the binary.
185209 rust_analyzer_argument : Option < RustAnalyzerArg > ,
0 commit comments