Use Soong modules for the NDK's extra STL libraries
am: b1703659a8
Change-Id: I3be785bc8df249abc023f173917e04b611e8fcf4
This commit is contained in:
4
cc/cc.go
4
cc/cc.go
@@ -1052,10 +1052,6 @@ func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag depe
|
|||||||
// These are always allowed
|
// These are always allowed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
|
|
||||||
// These are allowed, but they don't set sdk_version
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
||||||
// These are allowed, but they don't set sdk_version
|
// These are allowed, but they don't set sdk_version
|
||||||
return
|
return
|
||||||
|
@@ -601,25 +601,6 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
sharedLibs := deps.SharedLibs
|
sharedLibs := deps.SharedLibs
|
||||||
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
|
||||||
|
|
||||||
// TODO(danalbert): Clean this up when soong supports prebuilts.
|
|
||||||
if strings.HasPrefix(ctx.selectedStl(), "ndk_libc++") {
|
|
||||||
libDir := getNdkStlLibDir(ctx, "libc++")
|
|
||||||
|
|
||||||
if strings.HasSuffix(ctx.selectedStl(), "_shared") {
|
|
||||||
deps.StaticLibs = append(deps.StaticLibs,
|
|
||||||
libDir.Join(ctx, "libandroid_support.a"))
|
|
||||||
} else {
|
|
||||||
deps.StaticLibs = append(deps.StaticLibs,
|
|
||||||
libDir.Join(ctx, "libc++abi.a"),
|
|
||||||
libDir.Join(ctx, "libandroid_support.a"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.Arch().ArchType == android.Arm {
|
|
||||||
deps.StaticLibs = append(deps.StaticLibs,
|
|
||||||
libDir.Join(ctx, "libunwind.a"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
|
||||||
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
|
||||||
linkerDeps = append(linkerDeps, objs.tidyFiles...)
|
linkerDeps = append(linkerDeps, objs.tidyFiles...)
|
||||||
|
@@ -23,7 +23,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory)
|
|
||||||
android.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory)
|
android.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory)
|
||||||
android.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory)
|
android.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory)
|
||||||
android.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory)
|
android.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory)
|
||||||
@@ -80,66 +79,32 @@ func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags,
|
|||||||
deps PathDeps, objs Objects) android.Path {
|
deps PathDeps, objs Objects) android.Path {
|
||||||
// A null build step, but it sets up the output path.
|
// A null build step, but it sets up the output path.
|
||||||
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") {
|
||||||
ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name")
|
ctx.ModuleErrorf("NDK prebuilt objects must have an ndk_crt prefixed name")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion())
|
||||||
}
|
}
|
||||||
|
|
||||||
type ndkPrebuiltLibraryLinker struct {
|
type ndkPrebuiltStlLinker struct {
|
||||||
*libraryDecorator
|
*libraryDecorator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} {
|
func (ndk *ndkPrebuiltStlLinker) linkerProps() []interface{} {
|
||||||
return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
|
return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
// NDK libraries can't have any dependencies
|
// NDK libraries can't have any dependencies
|
||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func ndkPrebuiltLibraryFactory() android.Module {
|
|
||||||
module, library := NewLibrary(android.DeviceSupported)
|
|
||||||
library.BuildOnlyShared()
|
|
||||||
linker := &ndkPrebuiltLibraryLinker{
|
|
||||||
libraryDecorator: library,
|
|
||||||
}
|
|
||||||
module.compiler = nil
|
|
||||||
module.linker = linker
|
|
||||||
module.installer = nil
|
|
||||||
module.stl = nil
|
|
||||||
module.Properties.HideFromMake = true
|
|
||||||
return module.Init()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags,
|
|
||||||
deps PathDeps, objs Objects) android.Path {
|
|
||||||
// A null build step, but it sets up the output path.
|
|
||||||
ndk.exportIncludes(ctx, "-isystem")
|
|
||||||
|
|
||||||
return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(),
|
|
||||||
ctx.sdkVersion())
|
|
||||||
}
|
|
||||||
|
|
||||||
// The NDK STLs are slightly different from the prebuilt system libraries:
|
|
||||||
// * Are not specific to each platform version.
|
|
||||||
// * The libraries are not in a predictable location for each STL.
|
|
||||||
|
|
||||||
type ndkPrebuiltStlLinker struct {
|
|
||||||
ndkPrebuiltLibraryLinker
|
|
||||||
}
|
|
||||||
|
|
||||||
func ndkPrebuiltSharedStlFactory() android.Module {
|
func ndkPrebuiltSharedStlFactory() android.Module {
|
||||||
module, library := NewLibrary(android.DeviceSupported)
|
module, library := NewLibrary(android.DeviceSupported)
|
||||||
library.BuildOnlyShared()
|
library.BuildOnlyShared()
|
||||||
linker := &ndkPrebuiltStlLinker{
|
|
||||||
ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
|
|
||||||
libraryDecorator: library,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
module.compiler = nil
|
module.compiler = nil
|
||||||
module.linker = linker
|
module.linker = &ndkPrebuiltStlLinker{
|
||||||
|
libraryDecorator: library,
|
||||||
|
}
|
||||||
module.installer = nil
|
module.installer = nil
|
||||||
minVersionString := "minimum"
|
minVersionString := "minimum"
|
||||||
noStlString := "none"
|
noStlString := "none"
|
||||||
@@ -151,29 +116,25 @@ func ndkPrebuiltSharedStlFactory() android.Module {
|
|||||||
func ndkPrebuiltStaticStlFactory() android.Module {
|
func ndkPrebuiltStaticStlFactory() android.Module {
|
||||||
module, library := NewLibrary(android.DeviceSupported)
|
module, library := NewLibrary(android.DeviceSupported)
|
||||||
library.BuildOnlyStatic()
|
library.BuildOnlyStatic()
|
||||||
linker := &ndkPrebuiltStlLinker{
|
|
||||||
ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{
|
|
||||||
libraryDecorator: library,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
module.compiler = nil
|
module.compiler = nil
|
||||||
module.linker = linker
|
module.linker = &ndkPrebuiltStlLinker{
|
||||||
|
libraryDecorator: library,
|
||||||
|
}
|
||||||
module.installer = nil
|
module.installer = nil
|
||||||
module.Properties.HideFromMake = true
|
module.Properties.HideFromMake = true
|
||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNdkStlLibDir(ctx android.ModuleContext, stl string) android.SourcePath {
|
func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath {
|
||||||
libDir := "cxx-stl/llvm-libc++/libs"
|
libDir := "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs"
|
||||||
ndkSrcRoot := "prebuilts/ndk/current/sources"
|
return android.PathForSource(ctx, libDir).Join(ctx, ctx.Arch().Abi[0])
|
||||||
return android.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
||||||
deps PathDeps, objs Objects) android.Path {
|
deps PathDeps, objs Objects) android.Path {
|
||||||
// A null build step, but it sets up the output path.
|
// A null build step, but it sets up the output path.
|
||||||
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
|
||||||
ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name")
|
ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name")
|
||||||
}
|
}
|
||||||
|
|
||||||
ndk.exportIncludes(ctx, "-isystem")
|
ndk.exportIncludes(ctx, "-isystem")
|
||||||
@@ -184,8 +145,6 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
|||||||
libExt = staticLibraryExtension
|
libExt = staticLibraryExtension
|
||||||
}
|
}
|
||||||
|
|
||||||
stlName := strings.TrimSuffix(libName, "_shared")
|
libDir := getNdkStlLibDir(ctx)
|
||||||
stlName = strings.TrimSuffix(stlName, "_static")
|
|
||||||
libDir := getNdkStlLibDir(ctx, stlName)
|
|
||||||
return libDir.Join(ctx, libName+libExt)
|
return libDir.Join(ctx, libName+libExt)
|
||||||
}
|
}
|
||||||
|
14
cc/stl.go
14
cc/stl.go
@@ -129,10 +129,16 @@ func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
|||||||
// The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have
|
// The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have
|
||||||
// its own includes. The includes are handled in CCBase.Flags().
|
// its own includes. The includes are handled in CCBase.Flags().
|
||||||
deps.SharedLibs = append([]string{"libstdc++"}, deps.SharedLibs...)
|
deps.SharedLibs = append([]string{"libstdc++"}, deps.SharedLibs...)
|
||||||
case "ndk_libc++_shared":
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
||||||
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl)
|
if stl.Properties.SelectedStl == "ndk_libc++_shared" {
|
||||||
case "ndk_libc++_static":
|
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
|
} else {
|
||||||
|
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl, "ndk_libc++abi")
|
||||||
|
}
|
||||||
|
deps.StaticLibs = append(deps.StaticLibs, "ndk_libandroid_support")
|
||||||
|
if ctx.Arch().ArchType == android.Arm {
|
||||||
|
deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind")
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user