From ec6e9910e68ac792dcc66f0b3c568c6c51467415 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Thu, 21 Jan 2021 15:23:29 -0500 Subject: [PATCH] rust: Depend on CC a shared library's TOC, not .so CC libraries generate TOC files which contain the list of exported symbols. By depending on the TOC file instead of the .so, changes to shared library dependencies will not result in rebuilding Rust dependencies as long as the exported symbols remain unchanged. This should improve incremental build times during development. This also includes a minor fix where exported linkObjects should be deduplicated to avoid the same object being included many times. Bug: 173619911 Test: m libkeystore2; modify a bionic file; m libkeystore2 doesn't rebuild the rust target. Change-Id: I6383217c125bf8dd7125a5e013a78754cac4edf2 --- rust/builder.go | 2 +- rust/rust.go | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/rust/builder.go b/rust/builder.go index e5f0ab5e1..baeab69e9 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -188,7 +188,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl implicits = append(implicits, rustLibsToPaths(deps.DyLibs)...) implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...) implicits = append(implicits, deps.StaticLibs...) - implicits = append(implicits, deps.SharedLibs...) + implicits = append(implicits, deps.SharedLibDeps...) implicits = append(implicits, deps.srcProviderFiles...) if deps.CrtBegin.Valid() { diff --git a/rust/rust.go b/rust/rust.go index 1fa97af96..83add87b7 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -267,14 +267,15 @@ type Deps struct { } type PathDeps struct { - DyLibs RustLibraries - RLibs RustLibraries - SharedLibs android.Paths - StaticLibs android.Paths - ProcMacros RustLibraries - linkDirs []string - depFlags []string - linkObjects []string + DyLibs RustLibraries + RLibs RustLibraries + SharedLibs android.Paths + SharedLibDeps android.Paths + StaticLibs android.Paths + ProcMacros RustLibraries + linkDirs []string + depFlags []string + linkObjects []string //ReexportedDeps android.Paths // Used by bindgen modules which call clang @@ -952,9 +953,15 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) } + var sharedLibFiles android.Paths var sharedLibDepFiles android.Paths for _, dep := range directSharedLibDeps { - sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) + sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path()) + if dep.Toc().Valid() { + sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path()) + } else { + sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) + } } var srcProviderDepFiles android.Paths @@ -970,12 +977,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) + 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.FirstUniqueStrings(depPaths.linkObjects) depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)