From 0a2a1154577a8df48e37388ca081c42cae8be141 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Fri, 16 Oct 2020 10:49:08 -0400 Subject: rust: Add cflag checks against -xc++ and -std. If -x c++ is passed through a modules cflags, it will be overridden by a -x c and -std flag added by the build system if the extension is not .hpp/.hh and cpp_std is not set. This leads to confusing behavior. Instead, add a helpful error message to guide developers towards the correct way to specify when a header is a C++ header and which std version should be used. Bug: 171011490 Test: m nothing Change-Id: I7e7cba504798d47ce1c753ba8699d7475a95095b --- rust/bindgen.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'rust/bindgen.go') diff --git a/rust/bindgen.go b/rust/bindgen.go index ac33ff7ef..46d4acbc4 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -150,6 +150,18 @@ func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) andr esc := proptools.NinjaAndShellEscapeList + // Filter out invalid cflags + for _, flag := range b.ClangProperties.Cflags { + if flag == "-x c++" || flag == "-xc++" { + ctx.PropertyErrorf("cflags", + "-x c++ should not be specified in cflags; setting cpp_std specifies this is a C++ header, or change the file extension to '.hpp' or '.hh'") + } + if strings.HasPrefix(flag, "-std=") { + ctx.PropertyErrorf("cflags", + "-std should not be specified in cflags; instead use c_std or cpp_std") + } + } + // Module defined clang flags and include paths cflags = append(cflags, esc(b.ClangProperties.Cflags)...) for _, include := range b.ClangProperties.Local_include_dirs { -- cgit v1.2.3-59-g8ed1b