Fix compilation errors on release builds.

https://logs.chromium.org/logs/gn/buildbucket/cr-buildbucket/8673622750355527873/+/u/release/linux-amd64/build/stdout
Change-Id: If6200a6b9683f29aac858574629f0bd56a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/25320
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: Matt Stark <msta@google.com>
diff --git a/build/run_cargo.py b/build/run_cargo.py
index 9a2d499..ea5e6b6 100755
--- a/build/run_cargo.py
+++ b/build/run_cargo.py
@@ -211,6 +211,13 @@
     # causing it to discard the shims as unused and leading to LNK2001 link errors.
     cxxflags = cxxflags.replace('/GL', '')
 
+  # Disable -Wunused-template for cargo C++ dependencies compiled with Clang.
+  # Some third-party dependencies (like the `cxx` crate) contain templates that
+  # are only used inside asserts. In release builds (with -DNDEBUG), these asserts
+  # are compiled away, triggering -Wunused-template causing failures with -Werror.
+  if 'clang' in cxx:
+    cxxflags += ' -Wno-unused-template'
+
   os.environ['CXX'] = cxx
   os.environ['CXXFLAGS'] = cxxflags
   # Since Ninja runs commands from the build output directory, CWD is the