rust: Refactor staticStd to stdLinkage
Instead of returning a boolean, return an enum value to improve readability and provide greater flexibility for future modifications. Bug: 168729404 Test: Soong tests pass Change-Id: Iddcdae8c34be09e476404382e43d1ea5935bae65
This commit is contained in:
parent
11200870b0
commit
dd0554722a
|
@ -145,6 +145,9 @@ func (binary *binaryDecorator) autoDep(ctx BaseModuleContext) autoDep {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (binary *binaryDecorator) staticStd(ctx *depsContext) bool {
|
func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||||
return binary.baseCompiler.staticStd(ctx) || Bool(binary.Properties.Prefer_rlib)
|
if Bool(binary.Properties.Prefer_rlib) {
|
||||||
|
return RlibLinkage
|
||||||
|
}
|
||||||
|
return binary.baseCompiler.stdLinkage(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,14 @@ import (
|
||||||
"android/soong/rust/config"
|
"android/soong/rust/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RustLinkage int
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultLinkage RustLinkage = iota
|
||||||
|
RlibLinkage
|
||||||
|
DylibLinkage
|
||||||
|
)
|
||||||
|
|
||||||
func (compiler *baseCompiler) edition() string {
|
func (compiler *baseCompiler) edition() string {
|
||||||
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
|
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
|
||||||
}
|
}
|
||||||
|
@ -146,12 +154,12 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
|
||||||
panic("baseCompiler does not implement coverageOutputZipPath()")
|
panic("baseCompiler does not implement coverageOutputZipPath()")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (compiler *baseCompiler) staticStd(ctx *depsContext) bool {
|
func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
|
||||||
// For devices, we always link stdlibs in as dylibs by default.
|
// For devices, we always link stdlibs in as dylibs by default.
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
return false
|
return DylibLinkage
|
||||||
} else {
|
} else {
|
||||||
return true
|
return RlibLinkage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,9 +158,12 @@ func (library *libraryDecorator) static() bool {
|
||||||
return library.MutatedProperties.VariantIsStatic
|
return library.MutatedProperties.VariantIsStatic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) staticStd(ctx *depsContext) bool {
|
func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||||
// libraries should only request the staticStd when building a static FFI or when variant is staticStd
|
// libraries should only request the RlibLinkage when building a static FFI or when variant is StaticStd
|
||||||
return library.static() || library.MutatedProperties.VariantIsStaticStd
|
if library.static() || library.MutatedProperties.VariantIsStaticStd {
|
||||||
|
return RlibLinkage
|
||||||
|
}
|
||||||
|
return DefaultLinkage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) source() bool {
|
func (library *libraryDecorator) source() bool {
|
||||||
|
|
|
@ -294,7 +294,7 @@ type compiler interface {
|
||||||
Disabled() bool
|
Disabled() bool
|
||||||
SetDisabled()
|
SetDisabled()
|
||||||
|
|
||||||
staticStd(ctx *depsContext) bool
|
stdLinkage(ctx *depsContext) RustLinkage
|
||||||
}
|
}
|
||||||
|
|
||||||
type exportedFlagsProducer interface {
|
type exportedFlagsProducer interface {
|
||||||
|
@ -997,8 +997,9 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||||
commonDepVariations = append(commonDepVariations,
|
commonDepVariations = append(commonDepVariations,
|
||||||
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
|
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
|
||||||
}
|
}
|
||||||
|
|
||||||
stdLinkage := "dylib-std"
|
stdLinkage := "dylib-std"
|
||||||
if mod.compiler.staticStd(ctx) {
|
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||||
stdLinkage = "rlib-std"
|
stdLinkage = "rlib-std"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1030,7 +1031,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if deps.Stdlibs != nil {
|
if deps.Stdlibs != nil {
|
||||||
if mod.compiler.staticStd(ctx) {
|
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||||
actx.AddVariationDependencies(
|
actx.AddVariationDependencies(
|
||||||
append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
|
append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
|
||||||
rlibDepTag, deps.Stdlibs...)
|
rlibDepTag, deps.Stdlibs...)
|
||||||
|
|
|
@ -134,6 +134,6 @@ func RustTestHostFactory() android.Module {
|
||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (test *testDecorator) staticStd(ctx *depsContext) bool {
|
func (test *testDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||||
return true
|
return RlibLinkage
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue