summaryrefslogtreecommitdiff
path: root/cc/ndk_library.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 /cc/ndk_library.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 'cc/ndk_library.go')
-rw-r--r--cc/ndk_library.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 27a9f66c1..4321bebfd 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -133,13 +133,13 @@ type stubDecorator struct {
unversionedUntil android.ApiLevel
}
-var _ versionedInterface = (*stubDecorator)(nil)
+var _ VersionedInterface = (*stubDecorator)(nil)
func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool {
return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil)
}
-func (stub *stubDecorator) implementationModuleName(name string) string {
+func (stub *stubDecorator) ImplementationModuleName(name string) string {
return strings.TrimSuffix(name, ndkLibrarySuffix)
}
@@ -155,7 +155,7 @@ func ndkLibraryVersions(ctx android.BaseModuleContext, from android.ApiLevel) []
return versionStrs
}
-func (this *stubDecorator) stubsVersions(ctx android.BaseModuleContext) []string {
+func (this *stubDecorator) StubsVersions(ctx android.BaseModuleContext) []string {
if !ctx.Module().Enabled(ctx) {
return nil
}
@@ -163,7 +163,7 @@ func (this *stubDecorator) stubsVersions(ctx android.BaseModuleContext) []string
ctx.Module().Disable()
return nil
}
- firstVersion, err := nativeApiLevelFromUser(ctx,
+ firstVersion, err := NativeApiLevelFromUser(ctx,
String(this.properties.First_version))
if err != nil {
ctx.PropertyErrorf("first_version", err.Error())
@@ -173,10 +173,10 @@ func (this *stubDecorator) stubsVersions(ctx android.BaseModuleContext) []string
}
func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
- this.apiLevel = nativeApiLevelOrPanic(ctx, this.stubsVersion())
+ this.apiLevel = nativeApiLevelOrPanic(ctx, this.StubsVersion())
var err error
- this.firstVersion, err = nativeApiLevelFromUser(ctx,
+ this.firstVersion, err = NativeApiLevelFromUser(ctx,
String(this.properties.First_version))
if err != nil {
ctx.PropertyErrorf("first_version", err.Error())
@@ -184,7 +184,7 @@ func (this *stubDecorator) initializeProperties(ctx BaseModuleContext) bool {
}
str := proptools.StringDefault(this.properties.Unversioned_until, "minimum")
- this.unversionedUntil, err = nativeApiLevelFromUser(ctx, str)
+ this.unversionedUntil, err = NativeApiLevelFromUser(ctx, str)
if err != nil {
ctx.PropertyErrorf("unversioned_until", err.Error())
return false
@@ -250,14 +250,14 @@ func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps Pa
return addStubLibraryCompilerFlags(flags)
}
-type ndkApiOutputs struct {
- stubSrc android.ModuleGenPath
- versionScript android.ModuleGenPath
+type NdkApiOutputs struct {
+ StubSrc android.ModuleGenPath
+ VersionScript android.ModuleGenPath
symbolList android.ModuleGenPath
}
-func parseNativeAbiDefinition(ctx ModuleContext, symbolFile string,
- apiLevel android.ApiLevel, genstubFlags string) ndkApiOutputs {
+func ParseNativeAbiDefinition(ctx android.ModuleContext, symbolFile string,
+ apiLevel android.ApiLevel, genstubFlags string) NdkApiOutputs {
stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
@@ -279,20 +279,20 @@ func parseNativeAbiDefinition(ctx ModuleContext, symbolFile string,
},
})
- return ndkApiOutputs{
- stubSrc: stubSrcPath,
- versionScript: versionScriptPath,
+ return NdkApiOutputs{
+ StubSrc: stubSrcPath,
+ VersionScript: versionScriptPath,
symbolList: symbolListPath,
}
}
-func compileStubLibrary(ctx ModuleContext, flags Flags, src android.Path) Objects {
+func CompileStubLibrary(ctx android.ModuleContext, flags Flags, src android.Path, sharedFlags *SharedFlags) Objects {
// libc/libm stubs libraries end up mismatching with clang's internal definition of these
// functions (which have noreturn attributes and other things). Because we just want to create a
// stub with symbol definitions, and types aren't important in C, ignore the mismatch.
flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, "-fno-builtin")
return compileObjs(ctx, flagsToBuilderFlags(flags), "",
- android.Paths{src}, nil, nil, nil, nil)
+ android.Paths{src}, nil, nil, nil, nil, sharedFlags)
}
func (this *stubDecorator) findImplementationLibrary(ctx ModuleContext) android.Path {
@@ -489,7 +489,7 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O
ctx.PropertyErrorf("symbol_file", "must end with .map.txt")
}
- if !c.buildStubs() {
+ if !c.BuildStubs() {
// NDK libraries have no implementation variant, nothing to do
return Objects{}
}
@@ -500,9 +500,9 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O
}
symbolFile := String(c.properties.Symbol_file)
- nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, c.apiLevel, "")
- objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
- c.versionScriptPath = nativeAbiResult.versionScript
+ nativeAbiResult := ParseNativeAbiDefinition(ctx, symbolFile, c.apiLevel, "")
+ objs := CompileStubLibrary(ctx, flags, nativeAbiResult.StubSrc, ctx.getSharedFlags())
+ c.versionScriptPath = nativeAbiResult.VersionScript
if c.canDumpAbi(ctx) {
c.dumpAbi(ctx, nativeAbiResult.symbolList)
if c.canDiffAbi(ctx.Config()) {
@@ -541,7 +541,7 @@ func (stub *stubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
objs Objects) android.Path {
- if !stub.buildStubs() {
+ if !stub.BuildStubs() {
// NDK libraries have no implementation variant, nothing to do
return nil
}