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

Commit 416149e0 authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Gerrit Code Review
Browse files

Merge changes I94fd8bbc,I497dcdff,I1873a180

* changes:
  rust: strip libraries and binaries
  rust: add ccToolchain to Module
  rust: enable use-android-relr-tags
parents 9c35c9ae fabaff6b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ bootstrap_go_package {
        "proc_macro.go",
        "project_json.go",
        "rust.go",
        "strip.go",
        "source_provider.go",
        "test.go",
        "testing.go",
+7 −4
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ func (binary *binaryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.Andr

	ret.Class = "EXECUTABLES"
	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
		fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", binary.unstrippedOutputFile.String())
		if binary.coverageOutputZipFile.Valid() {
			fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+binary.coverageOutputZipFile.String())
		}
@@ -139,9 +138,6 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
	}

	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
		if !library.rlib() {
			fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", library.unstrippedOutputFile.String())
		}
		if library.coverageOutputZipFile.Valid() {
			fmt.Fprintln(w, "LOCAL_PREBUILT_COVERAGE_ARCHIVE := "+library.coverageOutputZipFile.String())
		}
@@ -180,12 +176,19 @@ func (bindgen *bindgenDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
}

func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
	var unstrippedOutputFile android.OptionalPath
	// Soong installation is only supported for host modules. Have Make
	// installation trigger Soong installation.
	if ctx.Target().Os.Class == android.Host {
		ret.OutputFile = android.OptionalPathForPath(compiler.path)
	} else if compiler.strippedOutputFile.Valid() {
		unstrippedOutputFile = ret.OutputFile
		ret.OutputFile = compiler.strippedOutputFile
	}
	ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) {
		if compiler.strippedOutputFile.Valid() {
			fmt.Fprintln(w, "LOCAL_SOONG_UNSTRIPPED_BINARY :=", unstrippedOutputFile)
		}
		path, file := filepath.Split(compiler.path.ToMakePath().String())
		stem, suffix, _ := android.SplitFileExt(file)
		fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix)
+10 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ type BinaryCompilerProperties struct {

type binaryDecorator struct {
	*baseCompiler
	stripper Stripper

	Properties BinaryCompilerProperties
}
@@ -86,7 +87,8 @@ func (binary *binaryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {

func (binary *binaryDecorator) compilerProps() []interface{} {
	return append(binary.baseCompiler.compilerProps(),
		&binary.Properties)
		&binary.Properties,
		&binary.stripper.StripProperties)
}

func (binary *binaryDecorator) nativeCoverage() bool {
@@ -95,16 +97,20 @@ func (binary *binaryDecorator) nativeCoverage() bool {

func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
	fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()

	srcPath, _ := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)

	outputFile := android.PathForModuleOut(ctx, fileName)
	binary.unstrippedOutputFile = outputFile

	flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
	flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)

	outputs := TransformSrcToBinary(ctx, srcPath, deps, flags, outputFile, deps.linkDirs)

	if binary.stripper.NeedsStrip(ctx) {
		strippedOutputFile := android.PathForModuleOut(ctx, "stripped", fileName)
		binary.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
		binary.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
	}

	binary.coverageFile = outputs.coverageFile

	var coverageFiles android.Paths
+30 −0
Original line number Diff line number Diff line
@@ -96,3 +96,33 @@ func TestLinkObjects(t *testing.T) {
		t.Errorf("missing shared dependency 'libfoo.so' in linkFlags: %#v", linkFlags)
	}
}

// Test that stripped versions are correctly generated and used.
func TestStrippedBinary(t *testing.T) {
	ctx := testRust(t, `
		rust_binary {
			name: "foo",
			srcs: ["foo.rs"],
		}
		rust_binary {
			name: "bar",
			srcs: ["foo.rs"],
			strip: {
				none: true
			}
		}
	`)

	foo := ctx.ModuleForTests("foo", "android_arm64_armv8-a")
	foo.Output("stripped/foo")
	// Check that the `cp` rules is using the stripped version as input.
	cp := foo.Rule("android.Cp")
	if !strings.HasSuffix(cp.Input.String(), "stripped/foo") {
		t.Errorf("installed binary not based on stripped version: %v", cp.Input)
	}

	fizzBar := ctx.ModuleForTests("bar", "android_arm64_armv8-a").MaybeOutput("stripped/bar")
	if fizzBar.Rule != nil {
		t.Errorf("stripped version of bar has been generated")
	}
}
+2 −3
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import (
	"github.com/google/blueprint/proptools"

	"android/soong/android"
	ccConfig "android/soong/cc/config"
)

var (
@@ -92,8 +91,8 @@ type bindgenDecorator struct {
	Properties BindgenProperties
}

func (b *bindgenDecorator) GenerateSource(ctx android.ModuleContext, deps PathDeps) android.Path {
	ccToolchain := ccConfig.FindToolchain(ctx.Os(), ctx.Arch())
func (b *bindgenDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) android.Path {
	ccToolchain := ctx.RustModule().ccToolchain(ctx)

	var cflags []string
	var implicits android.Paths
Loading