Revert "Split Rust crate builds into compile and link phases."

This reverts commit e7c71c344d.
The intermediates created by the separated rust compile steps are very
large, on the order of 60GB.  This is more than CI can support for now,
revert the split into compile and link phases.  This comes at the expense
of incremental build time, especially when modifying C/C++ sources that
are dependencies of rust modules.

Bug: 293349612
Test: builds
Change-Id: I81169e7d0727330c8de5e7688dcdc87fe7b8d3b5
This commit is contained in:
Colin Cross
2023-10-02 11:39:17 -07:00
parent 0af40657ff
commit 004bd3f526
15 changed files with 111 additions and 232 deletions

View File

@@ -447,12 +447,13 @@ type Deps struct {
}
type PathDeps struct {
DyLibs RustLibraries
RLibs RustLibraries
LibDeps android.Paths
WholeStaticLibs android.Paths
ProcMacros RustLibraries
AfdoProfiles android.Paths
DyLibs RustLibraries
RLibs RustLibraries
SharedLibs android.Paths
SharedLibDeps android.Paths
StaticLibs android.Paths
ProcMacros RustLibraries
AfdoProfiles android.Paths
// depFlags and depLinkFlags are rustc and linker (clang) flags.
depFlags []string
@@ -461,7 +462,7 @@ type PathDeps struct {
// linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
// Both of these are exported and propagate to dependencies.
linkDirs []string
linkObjects android.Paths
linkObjects []string
// Used by bindgen modules which call clang
depClangFlags []string
@@ -524,7 +525,7 @@ type compiler interface {
type exportedFlagsProducer interface {
exportLinkDirs(...string)
exportLinkObjects(...android.Path)
exportLinkObjects(...string)
}
type xref interface {
@@ -533,27 +534,21 @@ type xref interface {
type flagExporter struct {
linkDirs []string
linkObjects android.Paths
libDeps android.Paths
linkObjects []string
}
func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
}
func (flagExporter *flagExporter) exportLinkObjects(flags ...android.Path) {
flagExporter.linkObjects = android.FirstUniquePaths(append(flagExporter.linkObjects, flags...))
}
func (flagExporter *flagExporter) exportLibDeps(paths ...android.Path) {
flagExporter.libDeps = android.FirstUniquePaths(append(flagExporter.libDeps, paths...))
func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
}
func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
LinkDirs: flagExporter.linkDirs,
LinkObjects: flagExporter.linkObjects,
LibDeps: flagExporter.libDeps,
})
}
@@ -566,8 +561,7 @@ func NewFlagExporter() *flagExporter {
type FlagExporterInfo struct {
Flags []string
LinkDirs []string // TODO: this should be android.Paths
LinkObjects android.Paths
LibDeps android.Paths
LinkObjects []string // TODO: this should be android.Paths
}
var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
@@ -1319,7 +1313,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
depPaths.LibDeps = append(depPaths.LibDeps, exportedInfo.LibDeps...)
}
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
@@ -1375,7 +1368,6 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
} else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
depPaths.WholeStaticLibs = append(depPaths.WholeStaticLibs, linkObject.Path())
} else {
ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName())
}
@@ -1383,7 +1375,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// Add this to linkObjects to pass the library directly to the linker as well. This propagates
// to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...)
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
@@ -1417,7 +1409,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
linkPath = linkPathFromFilePath(linkObject.Path())
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...)
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
@@ -1443,9 +1435,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// Make sure these dependencies are propagated
if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
lib.exportLinkDirs(linkPath)
if linkObject.Valid() {
lib.exportLinkObjects(linkObject.Path())
}
lib.exportLinkObjects(linkObject.String())
}
} else {
switch {
@@ -1479,16 +1469,19 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
}
var libDepFiles android.Paths
var staticLibDepFiles android.Paths
for _, dep := range directStaticLibDeps {
libDepFiles = append(libDepFiles, dep.OutputFile().Path())
staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
}
var sharedLibFiles android.Paths
var sharedLibDepFiles android.Paths
for _, dep := range directSharedLibDeps {
sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary)
if dep.TableOfContents.Valid() {
libDepFiles = append(libDepFiles, dep.TableOfContents.Path())
sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path())
} else {
libDepFiles = append(libDepFiles, dep.SharedLibrary)
sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary)
}
}
@@ -1504,13 +1497,15 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
depPaths.LibDeps = append(depPaths.LibDeps, libDepFiles...)
depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibFiles...)
depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, 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.linkObjects = android.FirstUniquePaths(depPaths.linkObjects)
depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)