Build a static library for header-only libraries am: a48ab5b207
am: ec0932ba0f
Change-Id: Idc38bde71d5a0be32f26cf31883306d1f63809c8
This commit is contained in:
@@ -64,7 +64,9 @@ type LibraryProperties struct {
|
|||||||
// export headers generated from .proto sources
|
// export headers generated from .proto sources
|
||||||
Export_proto_headers bool
|
Export_proto_headers bool
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type LibraryMutatedProperties struct {
|
||||||
VariantName string `blueprint:"mutated"`
|
VariantName string `blueprint:"mutated"`
|
||||||
|
|
||||||
// Build a static variant
|
// Build a static variant
|
||||||
@@ -176,6 +178,7 @@ var _ exportedFlagsProducer = (*flagExporter)(nil)
|
|||||||
// functionality: static vs. shared linkage, reusing object files for shared libraries
|
// functionality: static vs. shared linkage, reusing object files for shared libraries
|
||||||
type libraryDecorator struct {
|
type libraryDecorator struct {
|
||||||
Properties LibraryProperties
|
Properties LibraryProperties
|
||||||
|
MutatedProperties LibraryMutatedProperties
|
||||||
|
|
||||||
// For reusing static library objects for shared library
|
// For reusing static library objects for shared library
|
||||||
reuseObjects Objects
|
reuseObjects Objects
|
||||||
@@ -213,6 +216,7 @@ func (library *libraryDecorator) linkerProps() []interface{} {
|
|||||||
props = append(props, library.baseLinker.linkerProps()...)
|
props = append(props, library.baseLinker.linkerProps()...)
|
||||||
return append(props,
|
return append(props,
|
||||||
&library.Properties,
|
&library.Properties,
|
||||||
|
&library.MutatedProperties,
|
||||||
&library.flagExporter.Properties,
|
&library.flagExporter.Properties,
|
||||||
&library.stripper.StripProperties,
|
&library.stripper.StripProperties,
|
||||||
&library.relocationPacker.Properties)
|
&library.relocationPacker.Properties)
|
||||||
@@ -230,11 +234,11 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
|
|||||||
|
|
||||||
if library.static() {
|
if library.static() {
|
||||||
flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
|
flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...)
|
||||||
} else {
|
} else if library.shared() {
|
||||||
flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
|
flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !library.static() {
|
if library.shared() {
|
||||||
libName := library.getLibName(ctx)
|
libName := library.getLibName(ctx)
|
||||||
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
// GCC for Android assumes that -shared means -Bsymbolic, use -Wl,-shared instead
|
||||||
sharedFlag := "-Wl,-shared"
|
sharedFlag := "-Wl,-shared"
|
||||||
@@ -303,7 +307,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
|
|||||||
srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
|
srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs)
|
||||||
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary,
|
||||||
srcs, library.baseCompiler.deps))
|
srcs, library.baseCompiler.deps))
|
||||||
} else {
|
} else if library.shared() {
|
||||||
srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
|
srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs)
|
||||||
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary,
|
||||||
srcs, library.baseCompiler.deps))
|
srcs, library.baseCompiler.deps))
|
||||||
@@ -324,7 +328,8 @@ type libraryInterface interface {
|
|||||||
buildShared() bool
|
buildShared() bool
|
||||||
|
|
||||||
// Sets whether a specific variant is static or shared
|
// Sets whether a specific variant is static or shared
|
||||||
setStatic(bool)
|
setStatic()
|
||||||
|
setShared()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
||||||
@@ -339,7 +344,7 @@ func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return name + library.Properties.VariantName
|
return name + library.MutatedProperties.VariantName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
||||||
@@ -362,7 +367,7 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
library.Properties.Static.Whole_static_libs...)
|
library.Properties.Static.Whole_static_libs...)
|
||||||
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
|
deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
|
||||||
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
|
deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
|
||||||
} else {
|
} else if library.shared() {
|
||||||
if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
|
if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
|
||||||
if !ctx.sdk() && !ctx.vndk() {
|
if !ctx.sdk() && !ctx.vndk() {
|
||||||
deps.CrtBegin = "crtbegin_so"
|
deps.CrtBegin = "crtbegin_so"
|
||||||
@@ -395,13 +400,13 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
|
|||||||
library.objects = library.objects.Append(objs)
|
library.objects = library.objects.Append(objs)
|
||||||
|
|
||||||
outputFile := android.PathForModuleOut(ctx,
|
outputFile := android.PathForModuleOut(ctx,
|
||||||
ctx.ModuleName()+library.Properties.VariantName+staticLibraryExtension)
|
ctx.ModuleName()+library.MutatedProperties.VariantName+staticLibraryExtension)
|
||||||
builderFlags := flagsToBuilderFlags(flags)
|
builderFlags := flagsToBuilderFlags(flags)
|
||||||
|
|
||||||
TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles)
|
TransformObjToStaticLib(ctx, library.objects.objFiles, builderFlags, outputFile, objs.tidyFiles)
|
||||||
|
|
||||||
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags,
|
library.coverageOutputFile = TransformCoverageFilesToLib(ctx, library.objects, builderFlags,
|
||||||
ctx.ModuleName()+library.Properties.VariantName)
|
ctx.ModuleName()+library.MutatedProperties.VariantName)
|
||||||
|
|
||||||
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
library.wholeStaticMissingDeps = ctx.GetMissingDependencies()
|
||||||
|
|
||||||
@@ -522,7 +527,7 @@ func (library *libraryDecorator) link(ctx ModuleContext,
|
|||||||
objs = objs.Append(deps.Objs)
|
objs = objs.Append(deps.Objs)
|
||||||
|
|
||||||
var out android.Path
|
var out android.Path
|
||||||
if library.static() {
|
if library.static() || library.header() {
|
||||||
out = library.linkStatic(ctx, flags, deps, objs)
|
out = library.linkStatic(ctx, flags, deps, objs)
|
||||||
} else {
|
} else {
|
||||||
out = library.linkShared(ctx, flags, deps, objs)
|
out = library.linkShared(ctx, flags, deps, objs)
|
||||||
@@ -555,12 +560,12 @@ func (library *libraryDecorator) link(ctx ModuleContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) buildStatic() bool {
|
func (library *libraryDecorator) buildStatic() bool {
|
||||||
return library.Properties.BuildStatic &&
|
return library.MutatedProperties.BuildStatic &&
|
||||||
(library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled)
|
(library.Properties.Static.Enabled == nil || *library.Properties.Static.Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) buildShared() bool {
|
func (library *libraryDecorator) buildShared() bool {
|
||||||
return library.Properties.BuildShared &&
|
return library.MutatedProperties.BuildShared &&
|
||||||
(library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled)
|
(library.Properties.Shared.Enabled == nil || *library.Properties.Shared.Enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,31 +592,45 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) static() bool {
|
func (library *libraryDecorator) static() bool {
|
||||||
return library.Properties.VariantIsStatic
|
return library.MutatedProperties.VariantIsStatic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) setStatic(static bool) {
|
func (library *libraryDecorator) shared() bool {
|
||||||
library.Properties.VariantIsStatic = static
|
return library.MutatedProperties.VariantIsShared
|
||||||
|
}
|
||||||
|
|
||||||
|
func (library *libraryDecorator) header() bool {
|
||||||
|
return !library.static() && !library.shared()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (library *libraryDecorator) setStatic() {
|
||||||
|
library.MutatedProperties.VariantIsStatic = true
|
||||||
|
library.MutatedProperties.VariantIsShared = false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (library *libraryDecorator) setShared() {
|
||||||
|
library.MutatedProperties.VariantIsStatic = false
|
||||||
|
library.MutatedProperties.VariantIsShared = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) BuildOnlyStatic() {
|
func (library *libraryDecorator) BuildOnlyStatic() {
|
||||||
library.Properties.BuildShared = false
|
library.MutatedProperties.BuildShared = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) BuildOnlyShared() {
|
func (library *libraryDecorator) BuildOnlyShared() {
|
||||||
library.Properties.BuildStatic = false
|
library.MutatedProperties.BuildStatic = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) HeaderOnly() {
|
func (library *libraryDecorator) HeaderOnly() {
|
||||||
library.Properties.BuildShared = false
|
library.MutatedProperties.BuildShared = false
|
||||||
library.Properties.BuildStatic = false
|
library.MutatedProperties.BuildStatic = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
||||||
module := newModule(hod, android.MultilibBoth)
|
module := newModule(hod, android.MultilibBoth)
|
||||||
|
|
||||||
library := &libraryDecorator{
|
library := &libraryDecorator{
|
||||||
Properties: LibraryProperties{
|
MutatedProperties: LibraryMutatedProperties{
|
||||||
BuildShared: true,
|
BuildShared: true,
|
||||||
BuildStatic: true,
|
BuildStatic: true,
|
||||||
},
|
},
|
||||||
@@ -637,8 +656,8 @@ func linkageMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
static := modules[0].(*Module)
|
static := modules[0].(*Module)
|
||||||
shared := modules[1].(*Module)
|
shared := modules[1].(*Module)
|
||||||
|
|
||||||
static.linker.(libraryInterface).setStatic(true)
|
static.linker.(libraryInterface).setStatic()
|
||||||
shared.linker.(libraryInterface).setStatic(false)
|
shared.linker.(libraryInterface).setShared()
|
||||||
|
|
||||||
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
if staticCompiler, ok := static.compiler.(*libraryDecorator); ok {
|
||||||
sharedCompiler := shared.compiler.(*libraryDecorator)
|
sharedCompiler := shared.compiler.(*libraryDecorator)
|
||||||
@@ -652,10 +671,10 @@ func linkageMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
} else if library.buildStatic() {
|
} else if library.buildStatic() {
|
||||||
modules = mctx.CreateLocalVariations("static")
|
modules = mctx.CreateLocalVariations("static")
|
||||||
modules[0].(*Module).linker.(libraryInterface).setStatic(true)
|
modules[0].(*Module).linker.(libraryInterface).setStatic()
|
||||||
} else if library.buildShared() {
|
} else if library.buildShared() {
|
||||||
modules = mctx.CreateLocalVariations("shared")
|
modules = mctx.CreateLocalVariations("shared")
|
||||||
modules[0].(*Module).linker.(libraryInterface).setStatic(false)
|
modules[0].(*Module).linker.(libraryInterface).setShared()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -335,7 +335,7 @@ func newStubLibrary() (*Module, []interface{}) {
|
|||||||
module.linker = stub
|
module.linker = stub
|
||||||
module.installer = stub
|
module.installer = stub
|
||||||
|
|
||||||
return module, []interface{}{&stub.properties}
|
return module, []interface{}{&stub.properties, &library.MutatedProperties}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ndkLibraryFactory() (blueprint.Module, []interface{}) {
|
func ndkLibraryFactory() (blueprint.Module, []interface{}) {
|
||||||
|
@@ -194,7 +194,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
|
|||||||
|
|
||||||
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
|
||||||
libExt := flags.Toolchain.ShlibSuffix()
|
libExt := flags.Toolchain.ShlibSuffix()
|
||||||
if ndk.Properties.BuildStatic {
|
if ndk.static() {
|
||||||
libExt = staticLibraryExtension
|
libExt = staticLibraryExtension
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user