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

Commit 0f003b18 authored by Matthew Maurer's avatar Matthew Maurer
Browse files

rust: Add rustlibs auto dependency selection

Adds the rustlibs dependency type which will automatically select
between rlib and dylib based on the type of the library.

Bug: 143217452
Test: cd external/rust; mma
Change-Id: I97faadae98bf957090a32939cfb2d3a10f74a057
parent 2ae0513a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -131,3 +131,11 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
func (binary *binaryDecorator) coverageOutputZipPath() android.OptionalPath {
	return binary.coverageOutputZipFile
}

func (binary *binaryDecorator) autoDep() autoDep {
	if binary.preferDynamic() {
		return dylibAutoDep
	} else {
		return rlibAutoDep
	}
}
+4 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ type BaseCompilerProperties struct {
	// list of rust dylib crate dependencies
	Dylibs []string `android:"arch_variant"`

	// list of rust automatic crate dependencies
	Rustlibs []string `android:"arch_variant"`

	// list of rust proc_macro crate dependencies
	Proc_macros []string `android:"arch_variant"`

@@ -178,6 +181,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
	deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...)
	deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...)
	deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...)
	deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
	deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
	deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
+10 −0
Original line number Diff line number Diff line
@@ -186,6 +186,16 @@ func (library *libraryDecorator) setStatic() {
	library.MutatedProperties.VariantIsDylib = false
}

func (library *libraryDecorator) autoDep() autoDep {
	if library.rlib() || library.static() {
		return rlibAutoDep
	} else if library.dylib() || library.shared() {
		return dylibAutoDep
	} else {
		return rlibAutoDep
	}
}

var _ compiler = (*libraryDecorator)(nil)
var _ libraryInterface = (*libraryDecorator)(nil)

+47 −0
Original line number Diff line number Diff line
@@ -143,3 +143,50 @@ func TestSharedLibrary(t *testing.T) {
			libfoo.Module().(*Module).Properties.AndroidMkDylibs)
	}
}

// Test that variants pull in the right type of rustlib autodep
func TestAutoDeps(t *testing.T) {

	ctx := testRust(t, `
                rust_library_host {
                        name: "libbar",
                        srcs: ["bar.rs"],
                        crate_name: "bar",
                }
		rust_library_host {
			name: "libfoo",
			srcs: ["foo.rs"],
			crate_name: "foo",
                        rustlibs: ["libbar"],
		}
                rust_ffi_host {
                        name: "libfoo.ffi",
                        srcs: ["foo.rs"],
                        crate_name: "foo",
                        rustlibs: ["libbar"],
                }`)

	libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib")
	libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib")
	libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static")
	libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared")

	for _, static := range []android.TestingModule{libfooRlib, libfooStatic} {
		if !android.InList("libbar", static.Module().(*Module).Properties.AndroidMkRlibs) {
			t.Errorf("libbar not present as static dependency in static lib")
		}
		if android.InList("libbar", static.Module().(*Module).Properties.AndroidMkDylibs) {
			t.Errorf("libbar present as dynamic dependency in static lib")
		}
	}

	for _, dyn := range []android.TestingModule{libfooDylib, libfooShared} {
		if !android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkDylibs) {
			t.Errorf("libbar not present as dynamic dependency in dynamic lib")
		}
		if android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkRlibs) {
			t.Errorf("libbar present as static dependency in dynamic lib")
		}

	}
}
+4 −0
Original line number Diff line number Diff line
@@ -76,3 +76,7 @@ func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string {

	return stem + String(procMacro.baseCompiler.Properties.Suffix)
}

func (procMacro *procMacroDecorator) autoDep() autoDep {
	return rlibAutoDep
}
Loading