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

Commit 21fa0a58 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

rust: Add common interface for binaries

Structs embedding binaryDecorator (rust_test, rust_benchmark, rust_fuzz)
are binaries as well, but won't pass checks against *binaryDecorator,
such as the check in StaticExecutable().

Add a binaryInterface that can be checked instead to simplify these
checks and ensure we catch all binaries.

Bug: 170672854
Test: rust_test, rust_benchmark return true StaticallyLinked
Change-Id: I2373d3663373a6977260785602a02d39a41320fe
parent fdadcd79
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -31,6 +31,11 @@ type BinaryCompilerProperties struct {
	Static_executable *bool `android:"arch_variant"`
}

type binaryInterface interface {
	binary() bool
	staticallyLinked() bool
}

type binaryDecorator struct {
	*baseCompiler
	stripper Stripper
@@ -155,3 +160,11 @@ func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
	}
	return binary.baseCompiler.stdLinkage(ctx)
}

func (binary *binaryDecorator) binary() bool {
	return true
}

func (binary *binaryDecorator) staticallyLinked() bool {
	return Bool(binary.Properties.Static_executable)
}
+3 −5
Original line number Diff line number Diff line
@@ -261,10 +261,8 @@ func (mod *Module) Rlib() bool {
}

func (mod *Module) Binary() bool {
	if mod.compiler != nil {
		if _, ok := mod.compiler.(*binaryDecorator); ok {
			return true
		}
	if binary, ok := mod.compiler.(binaryInterface); ok {
		return binary.binary()
	}
	return false
}
@@ -273,7 +271,7 @@ func (mod *Module) StaticExecutable() bool {
	if !mod.Binary() {
		return false
	}
	return Bool(mod.compiler.(*binaryDecorator).Properties.Static_executable)
	return mod.StaticallyLinked()
}

func (mod *Module) Object() bool {
+2 −2
Original line number Diff line number Diff line
@@ -311,8 +311,8 @@ func (mod *Module) SetSanitizeDep(b bool) {
func (mod *Module) StaticallyLinked() bool {
	if lib, ok := mod.compiler.(libraryInterface); ok {
		return lib.rlib() || lib.static()
	} else if binary, ok := mod.compiler.(*binaryDecorator); ok {
		return Bool(binary.Properties.Static_executable)
	} else if binary, ok := mod.compiler.(binaryInterface); ok {
		return binary.staticallyLinked()
	}
	return false
}