summaryrefslogtreecommitdiff
path: root/apex/apex.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2024-10-30 14:28:17 +0000
committer Ivan Lozano <ivanlozano@google.com> 2025-01-10 21:30:53 +0000
commit9eaacc824c4e567e2e2c41be3504e8564aad98bf (patch)
tree97dee64bccf10d20d21d21f219076604be025cd2 /apex/apex.go
parent14072ed49ed2e9c5df025ae162d1fd27c349a71e (diff)
Refactor cc/rust to prep for Rust stubs
This CL largely handles this refactoring in preparation for Rust stubs support. Rust modules need to be able to communicate stubs information to cc, and certain bits of cc needs to be exported so rust can reuse them. A new VersionedLinkableInterface is added to capture most of the stubs-related interface definitions. Bug: 203478530 Test: m blueprint_tests Change-Id: I380225402fa85a3c39e7b18deb657054b3a52fbe
Diffstat (limited to 'apex/apex.go')
-rw-r--r--apex/apex.go58
1 files changed, 14 insertions, 44 deletions
diff --git a/apex/apex.go b/apex/apex.go
index d39a17fe7..428d57e08 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1386,12 +1386,12 @@ func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext
// apexFileFor<Type> functions below create an apexFile struct for a given Soong module. The
// returned apexFile saves information about the Soong module that will be used for creating the
// build rules.
-func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, handleSpecialLibs bool) apexFile {
+func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod cc.VersionedLinkableInterface, handleSpecialLibs bool) apexFile {
// Decide the APEX-local directory by the multilib of the library In the future, we may
// query this to the module.
// TODO(jiyong): use the new PackagingSpec
var dirInApex string
- switch ccMod.Arch().ArchType.Multilib {
+ switch ccMod.Multilib() {
case "lib32":
dirInApex = "lib"
case "lib64":
@@ -1418,7 +1418,7 @@ func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, h
dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath())
fileToCopy := android.OutputFileForModule(ctx, ccMod, "")
- androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName
+ androidMkModuleName := ccMod.BaseModuleName() + ccMod.SubName()
return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, ccMod)
}
@@ -1448,25 +1448,6 @@ func apexFileForRustExecutable(ctx android.BaseModuleContext, rustm *rust.Module
return af
}
-func apexFileForRustLibrary(ctx android.BaseModuleContext, rustm *rust.Module) apexFile {
- // Decide the APEX-local directory by the multilib of the library
- // In the future, we may query this to the module.
- var dirInApex string
- switch rustm.Arch().ArchType.Multilib {
- case "lib32":
- dirInApex = "lib"
- case "lib64":
- dirInApex = "lib64"
- }
- if rustm.Target().NativeBridge == android.NativeBridgeEnabled {
- dirInApex = filepath.Join(dirInApex, rustm.Target().NativeBridgeRelativePath)
- }
- dirInApex = filepath.Join(dirInApex, rustm.RelativeInstallPath())
- fileToCopy := android.OutputFileForModule(ctx, rustm, "")
- androidMkModuleName := rustm.BaseModuleName() + rustm.Properties.SubName
- return newApexFile(ctx, fileToCopy, androidMkModuleName, dirInApex, nativeSharedLib, rustm)
-}
-
func apexFileForShBinary(ctx android.BaseModuleContext, sh *sh.ShBinary) apexFile {
dirInApex := filepath.Join("bin", sh.SubDir())
if sh.Target().NativeBridge == android.NativeBridgeEnabled {
@@ -1900,8 +1881,8 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
if isJniLib {
propertyName = "jni_libs"
}
- switch ch := child.(type) {
- case *cc.Module:
+
+ if ch, ok := child.(cc.VersionedLinkableInterface); ok {
if ch.IsStubs() {
ctx.PropertyErrorf(propertyName, "%q is a stub. Remove it from the list.", depName)
}
@@ -1915,14 +1896,11 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
vctx.provideNativeLibs = append(vctx.provideNativeLibs, fi.stem())
}
return true // track transitive dependencies
- case *rust.Module:
- fi := apexFileForRustLibrary(ctx, ch)
- fi.isJniLib = isJniLib
- vctx.filesInfo = append(vctx.filesInfo, fi)
- return true // track transitive dependencies
- default:
- ctx.PropertyErrorf(propertyName, "%q is not a cc_library or cc_library_shared module", depName)
+ } else {
+ ctx.PropertyErrorf(propertyName,
+ "%q is not a VersionLinkableInterface (e.g. cc_library or rust_ffi module)", depName)
}
+
case executableTag:
switch ch := child.(type) {
case *cc.Module:
@@ -2074,7 +2052,7 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
// We cannot use a switch statement on `depTag` here as the checked
// tags used below are private (e.g. `cc.sharedDepTag`).
if cc.IsSharedDepTag(depTag) || cc.IsRuntimeDepTag(depTag) {
- if ch, ok := child.(*cc.Module); ok {
+ if ch, ok := child.(cc.VersionedLinkableInterface); ok {
af := apexFileForNativeLibrary(ctx, ch, vctx.handleSpecialLibs)
af.transitiveDep = true
@@ -2089,9 +2067,10 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
//
// Skip the dependency in unbundled builds where the device image is not
// being built.
- if ch.IsStubsImplementationRequired() && !am.NotInPlatform() && !ctx.Config().UnbundledBuild() {
+ if ch.VersionedInterface().IsStubsImplementationRequired() &&
+ !am.NotInPlatform() && !ctx.Config().UnbundledBuild() {
// we need a module name for Make
- name := ch.ImplementationModuleNameForMake(ctx) + ch.Properties.SubName
+ name := ch.ImplementationModuleNameForMake(ctx) + ch.SubName()
if !android.InList(name, a.makeModulesToInstall) {
a.makeModulesToInstall = append(a.makeModulesToInstall, name)
}
@@ -2116,15 +2095,6 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
vctx.filesInfo = append(vctx.filesInfo, af)
return true // track transitive dependencies
- } else if rm, ok := child.(*rust.Module); ok {
- if !android.IsDepInSameApex(ctx, parent, am) {
- return false
- }
-
- af := apexFileForRustLibrary(ctx, rm)
- af.transitiveDep = true
- vctx.filesInfo = append(vctx.filesInfo, af)
- return true // track transitive dependencies
}
} else if cc.IsHeaderDepTag(depTag) {
// nothing
@@ -2143,7 +2113,7 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext,
return false
}
- af := apexFileForRustLibrary(ctx, rustm)
+ af := apexFileForNativeLibrary(ctx, child.(cc.VersionedLinkableInterface), vctx.handleSpecialLibs)
af.transitiveDep = true
vctx.filesInfo = append(vctx.filesInfo, af)
return true // track transitive dependencies