@@ -265,7 +265,13 @@ class BazelTools(BuildTools):
265265 Utilities for interacting with Bazel.
266266 """
267267
268- def __init__ (self , option_prefix : str = "" , command_timeout : float = 10.0 , build_timeout : float = 180.0 ) -> None :
268+ def __init__ (
269+ self ,
270+ option_prefix : str = "" ,
271+ config : str = "" ,
272+ command_timeout : float = 10.0 ,
273+ build_timeout : float = 180.0 ,
274+ ) -> None :
269275 """
270276 Create Bazel tools instance.
271277
@@ -275,12 +281,16 @@ def __init__(self, option_prefix: str = "", command_timeout: float = 10.0, build
275281 Prefix for options expected by 'select_target_path'.
276282 - '' will expect '--target-path' and '--target-name'.
277283 - 'cpp' will expect '--cpp-target-path' and '--cpp-target-name'.
284+ config : str
285+ Explicitly define config used by Bazel commands.
286+ E.g., "per-x86_64-linux" adds "--config=per-x86_64-linux".
278287 command_timeout : float
279288 Common command timeout in seconds.
280289 build_timeout : float
281290 "bazel build" timeout in seconds.
282291 """
283292 super ().__init__ (option_prefix , command_timeout , build_timeout )
293+ self .config = config
284294
285295 def query (self , query : str = "//..." ) -> list [str ]:
286296 """
@@ -326,11 +336,13 @@ def find_target_path(self, target_name: str, *, expect_exists: bool = True) -> P
326336 ws_path = Path (ws_str )
327337
328338 # Find executable path relative to workspace root path.
339+ config = f'--config={ self .config } ' if self .config else ""
329340 command = [
330341 "bazel" ,
331342 "cquery" ,
332343 "--output=starlark" ,
333344 "--starlark:expr=target.files_to_run.executable.path" ,
345+ config ,
334346 target_name ,
335347 ]
336348 logger .debug (f"Running Bazel cquery command: `{ ' ' .join (command )} `" )
@@ -348,7 +360,7 @@ def find_target_path(self, target_name: str, *, expect_exists: bool = True) -> P
348360 logger .debug (f"Found target path: { target_path } " )
349361 return target_path
350362
351- def build (self , target_name : str , * options ) -> Path :
363+ def build (self , target_name : str ) -> Path :
352364 """
353365 Run build for selected target.
354366
@@ -358,7 +370,8 @@ def build(self, target_name: str, *options) -> Path:
358370 Name of the target to build.
359371 """
360372 # Run build.
361- command = ["bazel" , "build" , target_name , * options ]
373+ config = f'--config={ self .config } ' if self .config else ""
374+ command = ["bazel" , "build" , config , target_name ]
362375 logger .debug (f"Running Bazel build command: `{ ' ' .join (command )} `" )
363376 with Popen (command , text = True ) as p :
364377 _ , _ = p .communicate (timeout = self .build_timeout )
0 commit comments