@@ -94,6 +94,19 @@ def create_single_label(label, num_spaces):
9494
9595""" .lstrip ()
9696
97+ cc_arg_os_tpl = """
98+ cc_args(
99+ name = "llvm-{action}",
100+ actions = [
101+ "@rules_cc//cc/toolchains/actions:{action}",
102+ ],
103+ args = select({{
104+ {args}
105+ }}),
106+ )
107+
108+ """ .lstrip ()
109+
97110# ==================
98111# || MODULE.bazel ||
99112# ==================
@@ -143,7 +156,7 @@ def generate_module():
143156def create_latest (row , dir ):
144157 name = row ["name" ]
145158
146- if "configurations" not in row :
159+ if "configurations" not in row or "all" not in row [ "configurations" ] :
147160 return config_setting_tpl .format (
148161 name = f"{ name } -latest" ,
149162 value = f"{ name } " ,
@@ -171,6 +184,9 @@ def create_latest_with_configurations(row, dir):
171184 if "configurations" not in row :
172185 return ""
173186
187+ if "all" not in row ["configurations" ]:
188+ return ""
189+
174190 name = row ["name" ]
175191 default_config = row ["default-configuration" ]
176192
@@ -198,7 +214,7 @@ def create_version(row):
198214 settings = ""
199215 for version_item in row ["versions" ]:
200216 version = version_item ["version" ]
201- if "configurations" in row :
217+ if "configurations" in row and "all" in row [ "configurations" ] :
202218 configs = []
203219 for config_item in row ["configurations" ]["all" ]:
204220 config = config_item ["name" ]
@@ -219,7 +235,7 @@ def create_version(row):
219235def create_version_with_configurations (row , dir ):
220236 name = row ["name" ]
221237
222- if "configurations" not in row :
238+ if "configurations" not in row or "all" not in row [ "configurations" ] :
223239 settings = ""
224240 for version_item in row ["versions" ]:
225241 version = version_item ["version" ]
@@ -256,6 +272,9 @@ def create_version_configs(row):
256272 if "configurations" not in row :
257273 return ""
258274
275+ if "all" not in row ["configurations" ]:
276+ return ""
277+
259278 name = row ["name" ]
260279 settings = ""
261280 for config_item in row ["configurations" ]["all" ]:
@@ -415,6 +434,9 @@ def create_platform_aliases(name, version_item, actions):
415434def create_configuration_args (row ):
416435 if "configurations" not in row :
417436 return ""
437+
438+ if "all" not in row ["configurations" ]:
439+ return ""
418440
419441 action_to_args = {}
420442
@@ -442,6 +464,39 @@ def create_configuration_args(row):
442464
443465 return cc_args
444466
467+ def create_os_configuration_args (row ):
468+ if "configurations" not in row :
469+ return ""
470+
471+ if "os" not in row ["configurations" ]:
472+ return ""
473+
474+ action_to_args = {}
475+
476+ name = row ["name" ]
477+ for config_item in row ["configurations" ]["os" ]:
478+ config = config_item ["name" ]
479+ for action_item in config_item ["actions" ]:
480+ action = action_item ["name" ]
481+ args = ""
482+ args += f" \" @platforms//os:{ config } \" : [\n "
483+ for arg in action_item ["args" ]:
484+ args += f" \" { arg } \" ,\n "
485+ args += " ],\n "
486+
487+ if action not in action_to_args :
488+ action_to_args [action ] = ""
489+ action_to_args [action ] += args
490+
491+ cc_args = ""
492+ for action , args in action_to_args .items ():
493+ cc_args += cc_arg_os_tpl .format (
494+ action = action ,
495+ args = args .strip ()
496+ )
497+
498+ return cc_args
499+
445500def generate_build_files (dir , actions ):
446501 with open (f'repo_gen/{ dir } /BUILD.tpl' , 'r' ) as file :
447502 build_tpl = file .read ()
@@ -454,6 +509,7 @@ def generate_build_files(dir, actions):
454509 with open (f"{ dir } /{ name } /BUILD" , 'w' ) as file :
455510 build = build_tpl .format (name = name )
456511 build += create_configuration_args (config )
512+ build += create_os_configuration_args (config )
457513 build += create_version_aliases (config , dir , actions )
458514 build += create_top_level_config_settings_group (config )
459515 build += create_version_configs (config )
0 commit comments