From 07cbaf4d893ef00505d6d38d93a286dec11fb08e Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Wed, 22 Jul 2020 16:09:13 -0400 Subject: Enforce correct variant usage for rust_bindgen. Modules defined in the srcs property are automatically added as dependencies with AddDependency(), which will use any variant available. This can cause incorrect architecture bindings to be silently pulled in, such as when a host module uses a rust_bindgen module that doesn't create a host variant. This moves populating depPaths.SrcDeps over to depsToPaths and adds a check for SourceProviders to make sure the correct OS and architecture is being used. Bug: 161826371 Test: Soong no longer silently pulls in bindings for the wrong target. Test: New Soong test to catch this case passes. Change-Id: I2b3651cf6fc7dabf4081434df1c455e637f5b3a4 --- rust/rust.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'rust/rust.go') diff --git a/rust/rust.go b/rust/rust.go index 28f8e1a62..89b89e20c 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -743,6 +743,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { directProcMacroDeps := []*Module{} directSharedLibDeps := [](cc.LinkableInterface){} directStaticLibDeps := [](cc.LinkableInterface){} + directSrcProvidersDeps := []*Module{} + directSrcDeps := [](android.SourceFileProducer){} ctx.VisitDirectDeps(func(dep android.Module) { depName := ctx.OtherModuleName(dep) @@ -776,6 +778,24 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { case procMacroDepTag: directProcMacroDeps = append(directProcMacroDeps, rustDep) mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) + case android.SourceDepTag: + // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct + // OS/Arch variant is used. + var helper string + if ctx.Host() { + helper = "missing 'host_supported'?" + } else { + helper = "device module defined?" + } + + if dep.Target().Os != ctx.Os() { + ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) + return + } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { + ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) + return + } + directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) } //Append the dependencies exportedDirs @@ -793,6 +813,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } + if srcDep, ok := dep.(android.SourceFileProducer); ok { + switch depTag { + case android.SourceDepTag: + // These are usually genrules which don't have per-target variants. + directSrcDeps = append(directSrcDeps, srcDep) + } + } + if ccDep, ok := dep.(cc.LinkableInterface); ok { //Handle C dependencies if _, ok := ccDep.(*Module); !ok { @@ -868,11 +896,22 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) } + var srcProviderDepFiles android.Paths + for _, dep := range directSrcProvidersDeps { + srcs, _ := dep.OutputFiles("") + srcProviderDepFiles = append(srcProviderDepFiles, srcs...) + } + for _, dep := range directSrcDeps { + srcs := dep.Srcs() + srcProviderDepFiles = append(srcProviderDepFiles, srcs...) + } + depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) + depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) // Dedup exported flags from dependencies depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) -- cgit v1.2.3-59-g8ed1b