Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45dda43d authored by Ivan Lozano's avatar Ivan Lozano Committed by Gerrit Code Review
Browse files

Merge "rust: Refactor staticStd to stdLinkage"

parents 3a7e672a dd055472
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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)
}
+11 −3
Original line number Diff line number Diff line
@@ -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
	}
}

+6 −3
Original line number Diff line number Diff line
@@ -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 {
+4 −3
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ type compiler interface {
	Disabled() bool
	SetDisabled()

	staticStd(ctx *depsContext) bool
	stdLinkage(ctx *depsContext) RustLinkage
}

type exportedFlagsProducer interface {
@@ -1002,8 +1002,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"
	}

@@ -1035,7 +1036,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...)
+2 −2
Original line number Diff line number Diff line
@@ -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
}