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 {
|
||||
return binary.baseCompiler.staticStd(ctx) || Bool(binary.Properties.Prefer_rlib)
|
||||
func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||
if Bool(binary.Properties.Prefer_rlib) {
|
||||
return RlibLinkage
|
||||
}
|
||||
return binary.baseCompiler.stdLinkage(ctx)
|
||||
}
|
||||
|
|
|
@ -24,6 +24,14 @@ import (
|
|||
"android/soong/rust/config"
|
||||
)
|
||||
|
||||
type RustLinkage int
|
||||
|
||||
const (
|
||||
DefaultLinkage RustLinkage = iota
|
||||
RlibLinkage
|
||||
DylibLinkage
|
||||
)
|
||||
|
||||
func (compiler *baseCompiler) edition() string {
|
||||
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
|
||||
}
|
||||
|
@ -146,12 +154,12 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
|
|||
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.
|
||||
if ctx.Device() {
|
||||
return false
|
||||
return DylibLinkage
|
||||
} else {
|
||||
return true
|
||||
return RlibLinkage
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,9 +158,12 @@ func (library *libraryDecorator) static() bool {
|
|||
return library.MutatedProperties.VariantIsStatic
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) staticStd(ctx *depsContext) bool {
|
||||
// libraries should only request the staticStd when building a static FFI or when variant is staticStd
|
||||
return library.static() || library.MutatedProperties.VariantIsStaticStd
|
||||
func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||
// libraries should only request the RlibLinkage when building a static FFI or when variant is StaticStd
|
||||
if library.static() || library.MutatedProperties.VariantIsStaticStd {
|
||||
return RlibLinkage
|
||||
}
|
||||
return DefaultLinkage
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) source() bool {
|
||||
|
|
|
@ -294,7 +294,7 @@ type compiler interface {
|
|||
Disabled() bool
|
||||
SetDisabled()
|
||||
|
||||
staticStd(ctx *depsContext) bool
|
||||
stdLinkage(ctx *depsContext) RustLinkage
|
||||
}
|
||||
|
||||
type exportedFlagsProducer interface {
|
||||
|
@ -997,8 +997,9 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||
commonDepVariations = append(commonDepVariations,
|
||||
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
|
||||
}
|
||||
|
||||
stdLinkage := "dylib-std"
|
||||
if mod.compiler.staticStd(ctx) {
|
||||
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||
stdLinkage = "rlib-std"
|
||||
}
|
||||
|
||||
|
@ -1030,7 +1031,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
|||
}
|
||||
}
|
||||
if deps.Stdlibs != nil {
|
||||
if mod.compiler.staticStd(ctx) {
|
||||
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||
actx.AddVariationDependencies(
|
||||
append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
|
||||
rlibDepTag, deps.Stdlibs...)
|
||||
|
|
|
@ -134,6 +134,6 @@ func RustTestHostFactory() android.Module {
|
|||
return module.Init()
|
||||
}
|
||||
|
||||
func (test *testDecorator) staticStd(ctx *depsContext) bool {
|
||||
return true
|
||||
func (test *testDecorator) stdLinkage(ctx *depsContext) RustLinkage {
|
||||
return RlibLinkage
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue