From da37bd781c0371e02ffc4877c3ac1b5f2020c207 Mon Sep 17 00:00:00 2001
From: Matt Jolly <kangie@gentoo.org>
Date: Tue, 17 Feb 2026 15:45:01 +1000
Subject: [PATCH] Handle case where `parsed_rustc_args.cfg` is empty

This may occur when (for example) using the unbundle toolchain

Signed-off-by: Matt Jolly <kangie@gentoo.org>
--- a/third_party/rust/cxx/chromium_integration/run_cxxbridge.py
+++ b/third_party/rust/cxx/chromium_integration/run_cxxbridge.py
@@ -44,18 +44,20 @@ def calculate_cxxbridge_args(unrecognized_script_args, rustc_print_cfg_path):
   parser.add_argument("--cfg", action="append"),
   parsed_rustc_args, _other_args = parser.parse_known_args(
       args=unrecognized_script_args[:rustflags_separator])
-  for cfg_arg in parsed_rustc_args.cfg:
-    if "=" not in cfg_arg:  # `buildflag_header.gni` only supports bool flags.
-      # TODO(https://crbug.com/436606652): Stop using `_BUILDFLAG_NOT_SET_`
-      # prefix and instead use `--check-cfg` in `run_cxxbridge.py` to
-      # detect buildflag names.
-      FALSE_PREFIX = "_BUILDFLAG_NOT_SET_"
-      if cfg_arg.startswith(FALSE_PREFIX):
-        flagname = cfg_arg[len(FALSE_PREFIX):]
-        cxxbridge_args.append(f"--cfg={flagname}=false")
-      else:
-        flagname = cfg_arg
-        cxxbridge_args.append(f"--cfg={flagname}=true")
+  # Unbundled toolchain may not have any `--cfg` flags
+  if parsed_rustc_args.cfg:
+    for cfg_arg in parsed_rustc_args.cfg:
+      if "=" not in cfg_arg:  # `buildflag_header.gni` only supports bool flags.
+        # TODO(https://crbug.com/436606652): Stop using `_BUILDFLAG_NOT_SET_`
+        # prefix and instead use `--check-cfg` in `run_cxxbridge.py` to
+        # detect buildflag names.
+        FALSE_PREFIX = "_BUILDFLAG_NOT_SET_"
+        if cfg_arg.startswith(FALSE_PREFIX):
+          flagname = cfg_arg[len(FALSE_PREFIX):]
+          cxxbridge_args.append(f"--cfg={flagname}=false")
+        else:
+          flagname = cfg_arg
+          cxxbridge_args.append(f"--cfg={flagname}=true")
 
   with open(rustc_print_cfg_path, 'r') as file:
     for line in file:
-- 
2.52.0

