summaryrefslogtreecommitdiff
path: root/rust/bindgen.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2020-07-24 16:05:01 -0400
committer Ivan Lozano <ivanlozano@google.com> 2020-07-28 14:53:57 -0400
commit45901edb9a6ba7b42136a3ead126f94f76363eb7 (patch)
treeb5270f6d6fd3889442b77c32f9d8153cd7d388b2 /rust/bindgen.go
parente1e844b83cb37c72bf233034c3985a69f71e2e9d (diff)
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
Diffstat (limited to 'rust/bindgen.go')
-rw-r--r--rust/bindgen.go57
1 files changed, 30 insertions, 27 deletions
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 099bc6e26..43053b02b 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -15,11 +15,11 @@
package rust
import (
- "github.com/google/blueprint"
"strings"
+ "github.com/google/blueprint"
+
"android/soong/android"
- "android/soong/cc"
ccConfig "android/soong/cc/config"
)
@@ -84,40 +84,39 @@ type bindgenDecorator struct {
Properties BindgenProperties
}
-func (b *bindgenDecorator) libraryExports(ctx android.ModuleContext) (android.Paths, []string) {
- var libraryPaths android.Paths
- var libraryFlags []string
+func (b *bindgenDecorator) generateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
+ ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
- for _, static_lib := range b.Properties.Static_libs {
- if dep, ok := ctx.GetDirectDepWithTag(static_lib, cc.StaticDepTag).(*cc.Module); ok {
- libraryPaths = append(libraryPaths, dep.ExportedIncludeDirs()...)
- libraryFlags = append(libraryFlags, dep.ExportedFlags()...)
- }
- }
- for _, shared_lib := range b.Properties.Shared_libs {
- if dep, ok := ctx.GetDirectDepWithTag(shared_lib, cc.SharedDepTag).(*cc.Module); ok {
- libraryPaths = append(libraryPaths, dep.ExportedIncludeDirs()...)
- libraryFlags = append(libraryFlags, dep.ExportedFlags()...)
- }
- }
+ var cflags []string
+ var implicits android.Paths
- return libraryPaths, libraryFlags
-}
+ implicits = append(implicits, deps.depIncludePaths...)
+ implicits = append(implicits, deps.depSystemIncludePaths...)
-func (b *bindgenDecorator) generateSource(ctx android.ModuleContext) android.Path {
- ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
- includes, exportedFlags := b.libraryExports(ctx)
+ // Default clang flags
+ cflags = append(cflags, "${ccConfig.CommonClangGlobalCflags}")
+ if ctx.Device() {
+ cflags = append(cflags, "${ccConfig.DeviceClangGlobalCflags}")
+ }
- var cflags []string
- cflags = append(cflags, b.Properties.Cflags...)
+ // Toolchain clang flags
cflags = append(cflags, "-target "+ccToolchain.ClangTriple())
cflags = append(cflags, strings.ReplaceAll(ccToolchain.ToolchainClangCflags(), "${config.", "${ccConfig."))
- cflags = append(cflags, exportedFlags...)
- for _, include := range includes {
+
+ // Dependency clang flags and include paths
+ cflags = append(cflags, deps.depClangFlags...)
+ for _, include := range deps.depIncludePaths {
cflags = append(cflags, "-I"+include.String())
}
+ for _, include := range deps.depSystemIncludePaths {
+ cflags = append(cflags, "-isystem "+include.String())
+ }
+
+ // Module defined clang flags and include paths
+ cflags = append(cflags, b.Properties.Cflags...)
for _, include := range b.Properties.Local_include_dirs {
cflags = append(cflags, "-I"+android.PathForModuleSrc(ctx, include).String())
+ implicits = append(implicits, android.PathForModuleSrc(ctx, include))
}
bindgenFlags := defaultBindgenFlags
@@ -135,7 +134,7 @@ func (b *bindgenDecorator) generateSource(ctx android.ModuleContext) android.Pat
Description: "bindgen " + wrapperFile.Path().Rel(),
Output: outputFile,
Input: wrapperFile.Path(),
- Implicits: includes,
+ Implicits: implicits,
Args: map[string]string{
"flags": strings.Join(bindgenFlags, " "),
"cflags": strings.Join(cflags, " "),
@@ -172,6 +171,10 @@ func NewRustBindgen(hod android.HostOrDeviceSupported) (*Module, *bindgenDecorat
func (b *bindgenDecorator) sourceProviderDeps(ctx DepsContext, deps Deps) Deps {
deps = b.baseSourceProvider.sourceProviderDeps(ctx, deps)
+ if ctx.toolchain().Bionic() {
+ deps = bionicDeps(deps)
+ }
+
deps.SharedLibs = append(deps.SharedLibs, b.Properties.Shared_libs...)
deps.StaticLibs = append(deps.StaticLibs, b.Properties.Static_libs...)
return deps