diff options
Diffstat (limited to 'rust/rust.go')
| -rw-r--r-- | rust/rust.go | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/rust/rust.go b/rust/rust.go index 7a98c6468..89b89e20c 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -42,6 +42,7 @@ func init() { ctx.BottomUp("rust_begin", BeginMutator).Parallel() }) pctx.Import("android/soong/rust/config") + pctx.ImportAs("ccConfig", "android/soong/cc/config") } type Flags struct { @@ -61,9 +62,10 @@ type BaseProperties struct { AndroidMkProcMacroLibs []string AndroidMkSharedLibs []string AndroidMkStaticLibs []string - SubName string `blueprint:"mutated"` - PreventInstall bool - HideFromMake bool + + SubName string `blueprint:"mutated"` + PreventInstall bool + HideFromMake bool } type Module struct { @@ -79,8 +81,27 @@ type Module struct { coverage *coverage clippy *clippy cachedToolchain config.Toolchain + sourceProvider SourceProvider subAndroidMkOnce map[subAndroidMkProvider]bool outputFile android.OptionalPath + + subName string +} + +func (mod *Module) OutputFiles(tag string) (android.Paths, error) { + switch tag { + case "": + if mod.sourceProvider != nil { + return mod.sourceProvider.Srcs(), nil + } else { + if mod.outputFile.Valid() { + return android.Paths{mod.outputFile.Path()}, nil + } + return android.Paths{}, nil + } + default: + return nil, fmt.Errorf("unsupported module reference tag %q", tag) + } } var _ android.ImageInterface = (*Module)(nil) @@ -348,6 +369,7 @@ func DefaultsFactory(props ...interface{}) android.Module { &LibraryCompilerProperties{}, &ProcMacroCompilerProperties{}, &PrebuiltProperties{}, + &SourceProviderProperties{}, &TestProperties{}, &cc.CoverageProperties{}, &ClippyProperties{}, @@ -507,6 +529,9 @@ func (mod *Module) Init() android.Module { if mod.clippy != nil { mod.AddProperties(mod.clippy.props()...) } + if mod.sourceProvider != nil { + mod.AddProperties(mod.sourceProvider.sourceProviderProps()...) + } android.InitAndroidArchModule(mod, mod.hod, mod.multilib) @@ -645,6 +670,10 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { if !mod.Properties.PreventInstall { mod.compiler.install(ctx, mod.outputFile.Path()) } + } else if mod.sourceProvider != nil { + outputFile := mod.sourceProvider.generateSource(ctx) + mod.outputFile = android.OptionalPathForPath(outputFile) + mod.subName = ctx.ModuleSubDir() } } @@ -653,6 +682,8 @@ func (mod *Module) deps(ctx DepsContext) Deps { if mod.compiler != nil { deps = mod.compiler.compilerDeps(ctx, deps) + } else if mod.sourceProvider != nil { + deps = mod.sourceProvider.sourceProviderDeps(ctx, deps) } if mod.coverage != nil { @@ -712,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) @@ -745,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 @@ -762,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 { @@ -837,16 +896,26 @@ 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) depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) - depPaths.SrcDeps = android.FirstUniquePaths(depPaths.SrcDeps) return depPaths } @@ -963,3 +1032,5 @@ var Bool = proptools.Bool var BoolDefault = proptools.BoolDefault var String = proptools.String var StringPtr = proptools.StringPtr + +var _ android.OutputFileProducer = (*Module)(nil) |