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

Commit 2b081131 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

rust: Add libstd linkage mutator for rlibs.

The current state of linkage is that device targets always link
libstd dynamically except for rust_ffi_static which requires a static
libstd linkage. However this prevents producing rust_ffi_static
modules which depend on other Rust libraries as those dependencies
will link libstd dynamically and cause a collision. We also want our
rust_test modules to statically link in libstd as well.

This adds a linkage mutator for rlibs that creates a variant for each
libstd linkage. Dependent modules can then select the variant that
matches their linkage of libstd.

Also fixes an issue where installation paths were being generated for
rlibs and static libs even though they weren't being installed. This broke
when adding the linkage mutator as Make would complain about multiple
targets producing the same output.

Bug: 168729404
Test: rust_ffi_static module with other rustlib dependency can be built.
Change-Id: I955b484bf5809e8fc5517750c7f8df82d3ca8895
parent cc79a6f5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -178,6 +178,10 @@ func (proto *protobufDecorator) AndroidMk(ctx AndroidMkContext, ret *android.And
}

func (compiler *baseCompiler) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
	if compiler.path == (android.InstallPath{}) {
		return
	}

	var unstrippedOutputFile android.OptionalPath
	// Soong installation is only supported for host modules. Have Make
	// installation trigger Soong installation.
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ func TestBinaryLinkage(t *testing.T) {
	fizzBuzzHost := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
	fizzBuzzDevice := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module)

	if !android.InList("libfoo", fizzBuzzHost.Properties.AndroidMkRlibs) {
	if !android.InList("libfoo.rlib-std", fizzBuzzHost.Properties.AndroidMkRlibs) {
		t.Errorf("rustlibs dependency libfoo should be an rlib dep for host modules")
	}

+8 −11
Original line number Diff line number Diff line
@@ -146,8 +146,13 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath {
	panic("baseCompiler does not implement coverageOutputZipPath()")
}

func (compiler *baseCompiler) static() bool {
func (compiler *baseCompiler) staticStd(ctx *depsContext) bool {
	// For devices, we always link stdlibs in as dylibs by default.
	if ctx.Device() {
		return false
	} else {
		return true
	}
}

var _ compiler = (*baseCompiler)(nil)
@@ -221,15 +226,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
				stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
			}

			// For devices, we always link stdlibs in as dylibs except for ffi static libraries.
			// (rustc does not support linking libstd as a dylib for ffi static libraries)
			if ctx.Host() {
				deps.Rustlibs = append(deps.Rustlibs, stdlib)
			} else if ctx.RustModule().compiler.static() {
				deps.Rlibs = append(deps.Rlibs, stdlib)
			} else {
				deps.Dylibs = append(deps.Dylibs, stdlib)
			}
			deps.Stdlibs = append(deps.Stdlibs, stdlib)
		}
	}
	return deps
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ func TestStdDeviceLinkage(t *testing.T) {
			crate_name: "foo",
		}`)
	fizz := ctx.ModuleForTests("fizz", "android_arm64_armv8-a").Module().(*Module)
	fooRlib := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib").Module().(*Module)
	fooRlib := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Module().(*Module)
	fooDylib := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module)

	if !android.InList("libstd", fizz.Properties.AndroidMkDylibs) {
+2 −2
Original line number Diff line number Diff line
@@ -154,12 +154,12 @@ func TestCoverageZip(t *testing.T) {
	}

	// Make sure the expected inputs are provided to the zip rule.
	if !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") ||
	if !android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_rlib_dylib-std_cov/librlib.gcno") ||
		!android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_static_cov/libbaz.gcno") ||
		!android.SuffixInList(fizzZipInputs, "android_arm64_armv8-a_cov/fizz.gcno") {
		t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", fizzZipInputs)
	}
	if !android.SuffixInList(libfooZipInputs, "android_arm64_armv8-a_rlib_cov/librlib.gcno") ||
	if !android.SuffixInList(libfooZipInputs, "android_arm64_armv8-a_rlib_dylib-std_cov/librlib.gcno") ||
		!android.SuffixInList(libfooZipInputs, "android_arm64_armv8-a_dylib_cov/libfoo.dylib.gcno") {
		t.Fatalf("missing expected coverage files for rust 'fizz' binary: %#v", libfooZipInputs)
	}
Loading