summaryrefslogtreecommitdiff
path: root/rust/rust.go
diff options
context:
space:
mode:
Diffstat (limited to 'rust/rust.go')
-rw-r--r--rust/rust.go172
1 files changed, 123 insertions, 49 deletions
diff --git a/rust/rust.go b/rust/rust.go
index 28f8e1a62..113b0b262 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -63,7 +63,8 @@ type BaseProperties struct {
AndroidMkSharedLibs []string
AndroidMkStaticLibs []string
- SubName string `blueprint:"mutated"`
+ SubName string `blueprint:"mutated"`
+
PreventInstall bool
HideFromMake bool
}
@@ -83,9 +84,9 @@ type Module struct {
cachedToolchain config.Toolchain
sourceProvider SourceProvider
subAndroidMkOnce map[subAndroidMkProvider]bool
- outputFile android.OptionalPath
- subName string
+ outputFile android.OptionalPath
+ generatedFile android.OptionalPath
}
func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
@@ -141,12 +142,8 @@ func (mod *Module) SelectedStl() string {
func (mod *Module) NonCcVariants() bool {
if mod.compiler != nil {
- if library, ok := mod.compiler.(libraryInterface); ok {
- if library.buildRlib() || library.buildDylib() {
- return true
- } else {
- return false
- }
+ if _, ok := mod.compiler.(libraryInterface); ok {
+ return false
}
}
panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
@@ -162,16 +159,16 @@ func (mod *Module) Static() bool {
return library.static()
}
}
- panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
+ return false
}
func (mod *Module) Shared() bool {
if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok {
- return library.static()
+ return library.shared()
}
}
- panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
+ return false
}
func (mod *Module) Toc() android.OptionalPath {
@@ -256,6 +253,11 @@ type PathDeps struct {
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
@@ -284,6 +286,9 @@ type compiler interface {
relativeInstallPath() string
nativeCoverage() bool
+
+ Disabled() bool
+ SetDisabled()
}
type exportedFlagsProducer interface {
@@ -394,7 +399,9 @@ func (mod *Module) CcLibrary() bool {
func (mod *Module) CcLibraryInterface() bool {
if mod.compiler != nil {
- if _, ok := mod.compiler.(libraryInterface); ok {
+ // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
+ // VariantIs{Static,Shared} is set.
+ if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
return true
}
}
@@ -664,16 +671,21 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags, deps = mod.clippy.flags(ctx, flags, deps)
}
- if mod.compiler != nil {
+ // SourceProvider needs to call generateSource() before compiler calls compile() so it can provide the source.
+ // TODO(b/162588681) This shouldn't have to run for every variant.
+ if mod.sourceProvider != nil {
+ generatedFile := mod.sourceProvider.generateSource(ctx, deps)
+ mod.generatedFile = android.OptionalPathForPath(generatedFile)
+ mod.sourceProvider.setSubName(ctx.ModuleSubDir())
+ }
+
+ if mod.compiler != nil && !mod.compiler.Disabled() {
outputFile := mod.compiler.compile(ctx, flags, deps)
+
mod.outputFile = android.OptionalPathForPath(outputFile)
- if !mod.Properties.PreventInstall {
+ if mod.outputFile.Valid() && !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()
}
}
@@ -682,7 +694,8 @@ func (mod *Module) deps(ctx DepsContext) Deps {
if mod.compiler != nil {
deps = mod.compiler.compilerDeps(ctx, deps)
- } else if mod.sourceProvider != nil {
+ }
+ if mod.sourceProvider != nil {
deps = mod.sourceProvider.sourceProviderDeps(ctx, deps)
}
@@ -709,10 +722,11 @@ type dependencyTag struct {
}
var (
- rlibDepTag = dependencyTag{name: "rlibTag", library: true}
- dylibDepTag = dependencyTag{name: "dylib", library: true}
- procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
- testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
+ customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
+ rlibDepTag = dependencyTag{name: "rlibTag", library: true}
+ dylibDepTag = dependencyTag{name: "dylib", library: true}
+ procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
+ testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
)
type autoDep struct {
@@ -743,18 +757,15 @@ 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)
depTag := ctx.OtherModuleDependencyTag(dep)
- if rustDep, ok := dep.(*Module); ok {
+ if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
//Handle Rust Modules
- linkFile := rustDep.outputFile
- if !linkFile.Valid() {
- ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
- }
-
switch depTag {
case dylibDepTag:
dylib, ok := rustDep.compiler.(libraryInterface)
@@ -776,24 +787,46 @@ 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
- if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok {
+ //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
+ if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok && depTag != procMacroDepTag {
depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedLinkDirs()...)
depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
}
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
+ linkFile := rustDep.outputFile
+ if !linkFile.Valid() {
+ ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
+ depName, ctx.ModuleName())
+ return
+ }
linkDir := linkPathFromFilePath(linkFile.Path())
if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
lib.exportLinkDirs(linkDir)
}
}
- }
-
- if ccDep, ok := dep.(cc.LinkableInterface); ok {
+ } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
//Handle C dependencies
if _, ok := ccDep.(*Module); !ok {
if ccDep.Module().Target().Os != ctx.Os() {
@@ -805,7 +838,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return
}
}
-
linkFile := ccDep.OutputFile()
linkPath := linkPathFromFilePath(linkFile.Path())
libName := libNameFromFilePath(linkFile.Path())
@@ -816,24 +848,34 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
exportDep := false
- switch depTag {
- case cc.StaticDepTag:
+ switch {
+ case cc.IsStaticDepTag(depTag):
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)
- case cc.SharedDepTag:
+ case cc.IsSharedDepTag(depTag):
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
- case cc.CrtBeginDepTag:
+ case depTag == cc.CrtBeginDepTag:
depPaths.CrtBegin = linkFile
- case cc.CrtEndDepTag:
+ case depTag == cc.CrtEndDepTag:
depPaths.CrtEnd = linkFile
}
@@ -843,6 +885,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
lib.exportDepFlags(depFlag)
}
}
+
+ 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)
+ }
+ }
})
var rlibDepFiles RustLibraries
@@ -868,15 +918,29 @@ 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.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
+ depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
+ depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
return depPaths
}
@@ -917,30 +981,27 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: "rlib"},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: "rlib"}}...),
rlibDepTag, deps.Rlibs...)
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: "dylib"},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: "dylib"}}...),
dylibDepTag, deps.Dylibs...)
if deps.Rustlibs != nil {
autoDep := mod.compiler.(autoDeppable).autoDep()
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
- {Mutator: "rust_libraries", Variation: autoDep.variation},
- {Mutator: "link", Variation: ""}}...),
+ {Mutator: "rust_libraries", Variation: autoDep.variation}}...),
autoDep.depTag, deps.Rustlibs...)
}
actx.AddVariationDependencies(append(commonDepVariations,
blueprint.Variation{Mutator: "link", Variation: "shared"}),
- cc.SharedDepTag, deps.SharedLibs...)
+ cc.SharedDepTag(), deps.SharedLibs...)
actx.AddVariationDependencies(append(commonDepVariations,
blueprint.Variation{Mutator: "link", Variation: "static"}),
- cc.StaticDepTag, deps.StaticLibs...)
+ cc.StaticDepTag(), deps.StaticLibs...)
if deps.CrtBegin != "" {
actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin)
@@ -949,6 +1010,13 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd)
}
+ if mod.sourceProvider != nil {
+ if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
+ bindgen.Properties.Custom_bindgen != "" {
+ actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
+ bindgen.Properties.Custom_bindgen)
+ }
+ }
// proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
}
@@ -977,6 +1045,12 @@ func (mod *Module) Name() string {
return name
}
+func (mod *Module) setClippy(clippy bool) {
+ if mod.clippy != nil {
+ mod.clippy.Properties.Clippy = proptools.BoolPtr(clippy)
+ }
+}
+
var _ android.HostToolProvider = (*Module)(nil)
func (mod *Module) HostToolPath() android.OptionalPath {