rust: Emit -x c++ for bindgen modules with cpp_std
rust_bindgen modules which defined cpp_std with a .h file were not
correctly emitting the `-x c++` flag. This CL addresses that, and
ensures that if either cpp_std or c_std is set then the appropriate
behavior occurs no matter the file extension.
Bug: 304269101
Test: Soong tests
Change-Id: I71a8ae30ac0ed502d9d3fbf2f3039b0c56529d39
diff --git a/rust/bindgen.go b/rust/bindgen.go
index a80a587..ffe532f 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -124,18 +124,20 @@
ctx.PropertyErrorf("c_std", "c_std and cpp_std cannot both be defined at the same time.")
}
- if String(b.ClangProperties.Cpp_std) != "" {
+ if b.ClangProperties.Cpp_std != nil {
+ isCpp = true
if String(b.ClangProperties.Cpp_std) == "experimental" {
stdVersion = cc_config.ExperimentalCppStdVersion
- } else if String(b.ClangProperties.Cpp_std) == "default" {
+ } else if String(b.ClangProperties.Cpp_std) == "default" || String(b.ClangProperties.Cpp_std) == "" {
stdVersion = cc_config.CppStdVersion
} else {
stdVersion = String(b.ClangProperties.Cpp_std)
}
} else if b.ClangProperties.C_std != nil {
+ isCpp = false
if String(b.ClangProperties.C_std) == "experimental" {
stdVersion = cc_config.ExperimentalCStdVersion
- } else if String(b.ClangProperties.C_std) == "default" {
+ } else if String(b.ClangProperties.C_std) == "default" || String(b.ClangProperties.C_std) == "" {
stdVersion = cc_config.CStdVersion
} else {
stdVersion = String(b.ClangProperties.C_std)