Skip to content

Commit 633e56d

Browse files
authored
Fix rust_bindgen compile flag filtering (#3363)
All flags were treated as accepting a parameter, causing any argument following a parameterless flag (e.g. `-no-standard-includes`) to be passed through. This causes bindgen failures if the next argument isn't supported by clang. `-nostd*` flags has also been expanded using https://clang.llvm.org/docs/ClangCommandLineReference.html to make it clearer that these flags are parameterless. Since these flags resulted in a prefix match, not a full match, they wouldn't set `open_arg = True` and therefore wouldn't cause issues, but this behavior is unnecessarily subtle now that there are two lists. Fixes #3359
1 parent 2f81c8d commit 633e56d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

extensions/bindgen/private/bindgen.bzl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def _rust_bindgen_impl(ctx):
271271
# Ideally we could depend on a more specific toolchain, requesting one which is specifically clang via some constraint.
272272
# Unfortunately, we can't currently rely on this, so instead we filter only to flags we know clang supports.
273273
# We can add extra flags here as needed.
274-
flags_known_to_clang = (
274+
# Flags in this tuple accept a parameter in the same argument (`-Ipath`, `--target=T`) or separately (`-I path`).
275+
param_flags_known_to_clang = (
275276
"-I",
276277
"-iquote",
277278
"-isystem",
@@ -283,8 +284,16 @@ def _rust_bindgen_impl(ctx):
283284
"--no-system-header-prefix",
284285
"-Xclang",
285286
"-D",
287+
)
288+
289+
# Flags in this tuple do not accept a parameter.
290+
paramless_flags_known_to_clang = (
286291
"-no-canonical-prefixes",
287-
"-nostd",
292+
"-nostdinc",
293+
"--no-standard-includes",
294+
"-nostdinc++",
295+
"-nostdlib++",
296+
"-nostdlibinc",
288297
)
289298
open_arg = False
290299
for arg in compile_flags:
@@ -298,12 +307,12 @@ def _rust_bindgen_impl(ctx):
298307
args.add(arg)
299308
continue
300309

301-
if not arg.startswith(flags_known_to_clang):
310+
if not arg.startswith(param_flags_known_to_clang) and not arg in paramless_flags_known_to_clang:
302311
continue
303312

304313
args.add(arg)
305314

306-
if arg in flags_known_to_clang:
315+
if arg in param_flags_known_to_clang:
307316
open_arg = True
308317
continue
309318

0 commit comments

Comments
 (0)