Merge "Build rust libraries against C ModuleLib API surface." am: 0c7ea9582a
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2494340 Change-Id: I98961e2f8bedd3cd25d242658e82db52076b4ef3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
6
cc/cc.go
6
cc/cc.go
@@ -2954,7 +2954,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
depName := ctx.OtherModuleName(dep)
|
depName := ctx.OtherModuleName(dep)
|
||||||
if apiLibrary, ok := targetOrigModuleList[depName]; ok {
|
if apiLibrary, ok := targetOrigModuleList[depName]; ok {
|
||||||
if shouldUseStubForApex(ctx, dep) {
|
if ShouldUseStubForApex(ctx, dep) {
|
||||||
skipModuleList[depName] = true
|
skipModuleList[depName] = true
|
||||||
} else {
|
} else {
|
||||||
skipModuleList[apiLibrary] = true
|
skipModuleList[apiLibrary] = true
|
||||||
@@ -3307,7 +3307,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
return depPaths
|
return depPaths
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool {
|
func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool {
|
||||||
depName := ctx.OtherModuleName(dep)
|
depName := ctx.OtherModuleName(dep)
|
||||||
thisModule, ok := ctx.Module().(android.ApexModule)
|
thisModule, ok := ctx.Module().(android.ApexModule)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -3409,7 +3409,7 @@ func ChooseStubOrImpl(ctx android.ModuleContext, dep android.Module) (SharedLibr
|
|||||||
|
|
||||||
if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
|
if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
|
||||||
// when to use (unspecified) stubs, use the latest one.
|
// when to use (unspecified) stubs, use the latest one.
|
||||||
if shouldUseStubForApex(ctx, dep) {
|
if ShouldUseStubForApex(ctx, dep) {
|
||||||
stubs := sharedLibraryStubsInfo.SharedStubLibraries
|
stubs := sharedLibraryStubsInfo.SharedStubLibraries
|
||||||
toUse := stubs[len(stubs)-1]
|
toUse := stubs[len(stubs)-1]
|
||||||
sharedLibraryInfo = toUse.SharedLibraryInfo
|
sharedLibraryInfo = toUse.SharedLibraryInfo
|
||||||
|
73
rust/rust.go
73
rust/rust.go
@@ -26,6 +26,7 @@ import (
|
|||||||
"android/soong/cc"
|
"android/soong/cc"
|
||||||
cc_config "android/soong/cc/config"
|
cc_config "android/soong/cc/config"
|
||||||
"android/soong/fuzz"
|
"android/soong/fuzz"
|
||||||
|
"android/soong/multitree"
|
||||||
"android/soong/rust/config"
|
"android/soong/rust/config"
|
||||||
"android/soong/snapshot"
|
"android/soong/snapshot"
|
||||||
)
|
)
|
||||||
@@ -1147,10 +1148,56 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
mod.apexSdkVersion = android.FutureApiLevel
|
mod.apexSdkVersion = android.FutureApiLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skipModuleList := map[string]bool{}
|
||||||
|
|
||||||
|
var apiImportInfo multitree.ApiImportInfo
|
||||||
|
hasApiImportInfo := false
|
||||||
|
|
||||||
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
|
if dep.Name() == "api_imports" {
|
||||||
|
apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo)
|
||||||
|
hasApiImportInfo = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if hasApiImportInfo {
|
||||||
|
targetStubModuleList := map[string]string{}
|
||||||
|
targetOrigModuleList := map[string]string{}
|
||||||
|
|
||||||
|
// Search for dependency which both original module and API imported library with APEX stub exists
|
||||||
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
|
depName := ctx.OtherModuleName(dep)
|
||||||
|
if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok {
|
||||||
|
targetStubModuleList[apiLibrary] = depName
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
|
depName := ctx.OtherModuleName(dep)
|
||||||
|
if origLibrary, ok := targetStubModuleList[depName]; ok {
|
||||||
|
targetOrigModuleList[origLibrary] = depName
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Decide which library should be used between original and API imported library
|
||||||
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
|
depName := ctx.OtherModuleName(dep)
|
||||||
|
if apiLibrary, ok := targetOrigModuleList[depName]; ok {
|
||||||
|
if cc.ShouldUseStubForApex(ctx, dep) {
|
||||||
|
skipModuleList[depName] = true
|
||||||
|
} else {
|
||||||
|
skipModuleList[apiLibrary] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
depName := ctx.OtherModuleName(dep)
|
depName := ctx.OtherModuleName(dep)
|
||||||
depTag := ctx.OtherModuleDependencyTag(dep)
|
depTag := ctx.OtherModuleDependencyTag(dep)
|
||||||
|
|
||||||
|
if _, exists := skipModuleList[depName]; exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
|
if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
|
||||||
//Handle Rust Modules
|
//Handle Rust Modules
|
||||||
makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
|
makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
|
||||||
@@ -1406,6 +1453,16 @@ func linkPathFromFilePath(filepath android.Path) string {
|
|||||||
return strings.Split(filepath.String(), filepath.Base())[0]
|
return strings.Split(filepath.String(), filepath.Base())[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// usePublicApi returns true if the rust variant should link against NDK (publicapi)
|
||||||
|
func (r *Module) usePublicApi() bool {
|
||||||
|
return r.Device() && r.UseSdk()
|
||||||
|
}
|
||||||
|
|
||||||
|
// useVendorApi returns true if the rust variant should link against LLNDK (vendorapi)
|
||||||
|
func (r *Module) useVendorApi() bool {
|
||||||
|
return r.Device() && (r.InVendor() || r.InProduct())
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||||
ctx := &depsContext{
|
ctx := &depsContext{
|
||||||
BottomUpMutatorContext: actx,
|
BottomUpMutatorContext: actx,
|
||||||
@@ -1416,8 +1473,10 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||||||
var snapshotInfo *cc.SnapshotInfo
|
var snapshotInfo *cc.SnapshotInfo
|
||||||
|
|
||||||
apiImportInfo := cc.GetApiImports(mod, actx)
|
apiImportInfo := cc.GetApiImports(mod, actx)
|
||||||
for idx, lib := range deps.SharedLibs {
|
if mod.usePublicApi() || mod.useVendorApi() {
|
||||||
deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs)
|
for idx, lib := range deps.SharedLibs {
|
||||||
|
deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Os() == android.Android {
|
if ctx.Os() == android.Android {
|
||||||
@@ -1497,7 +1556,15 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||||||
variations := []blueprint.Variation{
|
variations := []blueprint.Variation{
|
||||||
{Mutator: "link", Variation: "shared"},
|
{Mutator: "link", Variation: "shared"},
|
||||||
}
|
}
|
||||||
cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
|
// For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists)
|
||||||
|
// GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary
|
||||||
|
if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) {
|
||||||
|
cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok {
|
||||||
|
cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, lib := range deps.WholeStaticLibs {
|
for _, lib := range deps.WholeStaticLibs {
|
||||||
|
Reference in New Issue
Block a user