Ensure hermetic device rust_bindgen.

rust_bindgen was not hermetic previously as it would pull in host
headers for device targets. This fixes that by using the same flags we
use when compiling with Clang. This also makes sure our rust_bindgen
headers are built as similar as possible to their respective
cc_libraries.

This also pulls in the bionic dependencies as well, which provide the
headers required for device targets.

Bug: 162007475
Test: device rust_bindgen deps file does not reference host headers.

Change-Id: I4efdf333e011a6c6d73a0345e5485823f166d17a
diff --git a/rust/rust.go b/rust/rust.go
index 28f8e1a..8ebd39d 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -256,6 +256,11 @@
 	depFlags   []string
 	//ReexportedDeps android.Paths
 
+	// Used by bindgen modules which call clang
+	depClangFlags         []string
+	depIncludePaths       android.Paths
+	depSystemIncludePaths android.Paths
+
 	coverageFiles android.Paths
 
 	CrtBegin android.OptionalPath
@@ -671,7 +676,7 @@
 			mod.compiler.install(ctx, mod.outputFile.Path())
 		}
 	} else if mod.sourceProvider != nil {
-		outputFile := mod.sourceProvider.generateSource(ctx)
+		outputFile := mod.sourceProvider.generateSource(ctx, deps)
 		mod.outputFile = android.OptionalPathForPath(outputFile)
 		mod.subName = ctx.ModuleSubDir()
 	}
@@ -821,6 +826,11 @@
 				depFlag = "-lstatic=" + libName
 				depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
 				depPaths.depFlags = append(depPaths.depFlags, depFlag)
+				depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
+				if mod, ok := ccDep.(*cc.Module); ok {
+					depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
+					depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
+				}
 				depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
 				directStaticLibDeps = append(directStaticLibDeps, ccDep)
 				mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
@@ -828,6 +838,11 @@
 				depFlag = "-ldylib=" + libName
 				depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
 				depPaths.depFlags = append(depPaths.depFlags, depFlag)
+				depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
+				if mod, ok := ccDep.(*cc.Module); ok {
+					depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
+					depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
+				}
 				directSharedLibDeps = append(directSharedLibDeps, ccDep)
 				mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
 				exportDep = true
@@ -877,6 +892,9 @@
 	// Dedup exported flags from dependencies
 	depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
 	depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
+	depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
+	depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
+	depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
 
 	return depPaths
 }