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

Commit 89435d1a authored by Ivan Lozano's avatar Ivan Lozano
Browse files

[rust] Clean up unused link variations.

rust_library modules no longer produce "link" variants alongside
"rust_libraries" variants as the former have been moved to rust_ffi
modules. rust_library modules however still create empty link variants
and code paths still assume that modules can support both rust linkage
and cc linkage. This adds unnecessary complexity that no longer serves a
purpose.

This cleans this up by removing the unused "link" variant for
rust_library modules and simplifies code paths that can now assume
modules are either a rust library or a cc library, but not both.

This also fixes a bug where Shared() was returning the wrong value.

Bug: 159064919
Test: cd external/rust/; mma
Test: cd external/crosvm/; mma

Change-Id: I3b5498c80b315c56b621dcb1388022fecc1bfc1b
parent afb7c1b7
Loading
Loading
Loading
Loading
+13 −19
Original line number Diff line number Diff line
@@ -454,11 +454,6 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
	if m, ok := mctx.Module().(*Module); ok && m.compiler != nil {
		switch library := m.compiler.(type) {
		case libraryInterface:

			// We only build the rust library variants here. This assumes that
			// LinkageMutator runs first and there's an empty variant
			// if rust variants are required.
			if !library.static() && !library.shared() {
			if library.buildRlib() && library.buildDylib() {
				modules := mctx.CreateLocalVariations("rlib", "dylib")
				rlib := modules[0].(*Module)
@@ -476,4 +471,3 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
		}
	}
}
}
+21 −28
Original line number Diff line number Diff line
@@ -141,14 +141,10 @@ func (mod *Module) SelectedStl() string {

func (mod *Module) NonCcVariants() bool {
	if mod.compiler != nil {
		if library, ok := mod.compiler.(libraryInterface); ok {
			if library.buildRlib() || library.buildDylib() {
				return true
			} else {
		if _, ok := mod.compiler.(libraryInterface); ok {
			return false
		}
	}
	}
	panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
}

@@ -162,16 +158,16 @@ func (mod *Module) Static() bool {
			return library.static()
		}
	}
	panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
	return false
}

func (mod *Module) Shared() bool {
	if mod.compiler != nil {
		if library, ok := mod.compiler.(libraryInterface); ok {
			return library.static()
			return library.shared()
		}
	}
	panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
	return false
}

func (mod *Module) Toc() android.OptionalPath {
@@ -399,7 +395,9 @@ func (mod *Module) CcLibrary() bool {

func (mod *Module) CcLibraryInterface() bool {
	if mod.compiler != nil {
		if _, ok := mod.compiler.(libraryInterface); ok {
		// use build{Static,Shared}() instead of {static,shared}() here because this might be called before
		// VariantIs{Static,Shared} is set.
		if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
			return true
		}
	}
@@ -754,7 +752,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
	ctx.VisitDirectDeps(func(dep android.Module) {
		depName := ctx.OtherModuleName(dep)
		depTag := ctx.OtherModuleDependencyTag(dep)
		if rustDep, ok := dep.(*Module); ok {
		if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
			//Handle Rust Modules

			linkFile := rustDep.outputFile
@@ -816,17 +814,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
				}
			}

		}

		if srcDep, ok := dep.(android.SourceFileProducer); ok {
			switch depTag {
			case android.SourceDepTag:
				// These are usually genrules which don't have per-target variants.
				directSrcDeps = append(directSrcDeps, srcDep)
			}
		}

		if ccDep, ok := dep.(cc.LinkableInterface); ok {
		} else if ccDep, ok := dep.(cc.LinkableInterface); ok {
			//Handle C dependencies
			if _, ok := ccDep.(*Module); !ok {
				if ccDep.Module().Target().Os != ctx.Os() {
@@ -886,6 +874,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
				lib.exportDepFlags(depFlag)
			}
		}

		if srcDep, ok := dep.(android.SourceFileProducer); ok {
			switch depTag {
			case android.SourceDepTag:
				// These are usually genrules which don't have per-target variants.
				directSrcDeps = append(directSrcDeps, srcDep)
			}
		}
	})

	var rlibDepFiles RustLibraries
@@ -974,21 +970,18 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
	}
	actx.AddVariationDependencies(
		append(commonDepVariations, []blueprint.Variation{
			{Mutator: "rust_libraries", Variation: "rlib"},
			{Mutator: "link", Variation: ""}}...),
			{Mutator: "rust_libraries", Variation: "rlib"}}...),
		rlibDepTag, deps.Rlibs...)
	actx.AddVariationDependencies(
		append(commonDepVariations, []blueprint.Variation{
			{Mutator: "rust_libraries", Variation: "dylib"},
			{Mutator: "link", Variation: ""}}...),
			{Mutator: "rust_libraries", Variation: "dylib"}}...),
		dylibDepTag, deps.Dylibs...)

	if deps.Rustlibs != nil {
		autoDep := mod.compiler.(autoDeppable).autoDep()
		actx.AddVariationDependencies(
			append(commonDepVariations, []blueprint.Variation{
				{Mutator: "rust_libraries", Variation: autoDep.variation},
				{Mutator: "link", Variation: ""}}...),
				{Mutator: "rust_libraries", Variation: autoDep.variation}}...),
			autoDep.depTag, deps.Rustlibs...)
	}