diff options
author | 2023-09-21 23:30:26 -0400 | |
---|---|---|
committer | 2023-09-27 20:53:54 -0400 | |
commit | d106efe76d0301de27868d3c714b5ba4a42a3fb1 (patch) | |
tree | 141ef6e5e5e8113497ade1f9d8d9f9a8c624f361 /rust/rust.go | |
parent | c5b9abba309e4bb65e6ae69c60b44d0f4b59e278 (diff) |
rust: Import protos from dependent rust_protobuf
rust_protobuf were unable to import protos from other rust_protobuf
modules. This CL adds support for that. rust_protobuf modules which are
listed in rustlibs will have their modules imported into the generated
protobuf stub. Additionally, rust_protobuf modules which define
"exported_include_dirs" will export those include paths to dependent
rust_protobuf modules.
Bug: 301266700
Test: m rust
Change-Id: I132edffa4d77e0ac80a7ac934f873374c8e94c1b
Diffstat (limited to 'rust/rust.go')
-rw-r--r-- | rust/rust.go | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/rust/rust.go b/rust/rust.go index 250e39857..49a7ff353 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -267,6 +267,15 @@ func (mod *Module) Dylib() bool { return false } +func (mod *Module) Source() bool { + if mod.compiler != nil { + if library, ok := mod.compiler.(libraryInterface); ok && mod.sourceProvider != nil { + return library.source() + } + } + return false +} + func (mod *Module) RlibStd() bool { if mod.compiler != nil { if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() { @@ -1156,6 +1165,13 @@ func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.L return cc.MakeLibName(ctx, c, dep, depName) } +func collectIncludedProtos(mod *Module, dep *Module) { + if protoMod, ok := mod.sourceProvider.(*protobufDecorator); ok { + if _, ok := dep.sourceProvider.(*protobufDecorator); ok { + protoMod.additionalCrates = append(protoMod.additionalCrates, dep.CrateName()) + } + } +} func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { var depPaths PathDeps @@ -1268,6 +1284,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { case procMacroDepTag: directProcMacroDeps = append(directProcMacroDeps, rustDep) mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) + + case sourceDepTag: + if _, ok := mod.sourceProvider.(*protobufDecorator); ok { + collectIncludedProtos(mod, rustDep) + } } transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs) @@ -1308,7 +1329,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { lib.exportLinkDirs(linkDir) } } - + if depTag == sourceDepTag { + if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() { + if _, ok := rustDep.sourceProvider.(*protobufDecorator); ok { + exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) + depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) + } + } + } } else if ccDep, ok := dep.(cc.LinkableInterface); ok { //Handle C dependencies makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName) @@ -1572,30 +1600,43 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { } // rustlibs - if deps.Rustlibs != nil && !mod.compiler.Disabled() { - autoDep := mod.compiler.(autoDeppable).autoDep(ctx) - for _, lib := range deps.Rustlibs { - if autoDep.depTag == rlibDepTag { - // Handle the rlib deptag case - addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) - } else { - // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. - // Check for the existence of the dylib deptag variant. Select it if available, - // otherwise select the rlib variant. - autoDepVariations := append(commonDepVariations, - blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) + if deps.Rustlibs != nil { + if !mod.compiler.Disabled() { + for _, lib := range deps.Rustlibs { + autoDep := mod.compiler.(autoDeppable).autoDep(ctx) + if autoDep.depTag == rlibDepTag { + // Handle the rlib deptag case + addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) + } else { + // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. + // Check for the existence of the dylib deptag variant. Select it if available, + // otherwise select the rlib variant. + autoDepVariations := append(commonDepVariations, + blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) + + replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs) + if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) { + addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag) + } else { + // If there's no dylib dependency available, try to add the rlib dependency instead. + addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) + } + } + } + } else if _, ok := mod.sourceProvider.(*protobufDecorator); ok { + for _, lib := range deps.Rustlibs { replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs) + srcProviderVariations := append(commonDepVariations, + blueprint.Variation{Mutator: "rust_libraries", Variation: "source"}) - if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) { - addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag) - } else { - // If there's no dylib dependency available, try to add the rlib dependency instead. - addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) + if actx.OtherModuleDependencyVariantExists(srcProviderVariations, replacementLib) { + actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib) } } } } + // stdlibs if deps.Stdlibs != nil { if mod.compiler.stdLinkage(ctx) == RlibLinkage { |