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

Commit d466b4a1 authored by Ivan Lozano's avatar Ivan Lozano Committed by Gerrit Code Review
Browse files

Merge changes from topic "rust_vendor_support"

* changes:
  Add more Rust vendor image support.
  rust: Use new common image mutator interface.
parents e8dfbdfb c08897c1
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -1203,6 +1203,10 @@ func (c *Module) IsVndkExt() bool {
	return false
}

func (c *Module) SubName() string {
	return c.Properties.SubName
}

func (c *Module) MustUseVendorVariant() bool {
	return c.isVndkSp() || c.Properties.MustUseVendorVariant
}
@@ -2306,12 +2310,7 @@ func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to Lin
			if ccFrom.vndkdep != nil {
				ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
			}
		} else if linkableMod, ok := to.(LinkableInterface); ok {
			// Static libraries from other languages can be linked
			if !linkableMod.Static() {
				ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
			}
		} else {
		} else if _, ok := to.(LinkableInterface); !ok {
			ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
		}
		return
@@ -2824,7 +2823,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
					c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
			}

			makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
			makeLibName := MakeLibName(ctx, c, ccDep, depName) + libDepTag.makeSuffix
			switch {
			case libDepTag.header():
				c.Properties.AndroidMkHeaderLibs = append(
@@ -2863,7 +2862,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
			switch depTag {
			case runtimeDepTag:
				c.Properties.AndroidMkRuntimeLibs = append(
					c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
					c.Properties.AndroidMkRuntimeLibs, MakeLibName(ctx, c, ccDep, depName)+libDepTag.makeSuffix)
				// Record baseLibName for snapshots.
				c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
			case objDepTag:
@@ -2941,7 +2940,8 @@ func baseLibName(depName string) string {
	return libName
}

func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableInterface, depName string) string {

	vendorPublicLibraries := vendorPublicLibraries(ctx.Config())

	libName := baseLibName(depName)
@@ -2951,6 +2951,7 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface,
	nonSystemVariantsExist := ccDep.HasNonSystemVariants() || isLLndk

	if ccDepModule != nil {
		// TODO(ivanlozano) Support snapshots for Rust-produced C library variants.
		// Use base module name for snapshots when exporting to Makefile.
		if snapshotPrebuilt, ok := ccDepModule.linker.(snapshotInterface); ok {
			baseName := ccDepModule.BaseModuleName()
@@ -2964,10 +2965,10 @@ func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface,
		// The vendor module is a no-vendor-variant VNDK library.  Depend on the
		// core module instead.
		return libName
	} else if ccDep.UseVndk() && nonSystemVariantsExist && ccDepModule != nil {
	} else if ccDep.UseVndk() && nonSystemVariantsExist {
		// The vendor and product modules in Make will have been renamed to not conflict with the
		// core module, so update the dependency name here accordingly.
		return libName + ccDepModule.Properties.SubName
		return libName + ccDep.SubName()
	} else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
		return libName + vendorPublicLibrarySuffix
	} else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
+12 −0
Original line number Diff line number Diff line
@@ -124,6 +124,9 @@ type LinkableInterface interface {
	HasNonSystemVariants() bool
	InProduct() bool

	// SubName returns the modules SubName, used for image and NDK/SDK variations.
	SubName() string

	SdkVersion() string
	MinSdkVersion() string
	AlwaysSdk() bool
@@ -170,6 +173,15 @@ func GetImageVariantType(c LinkableInterface) ImageVariantType {
	}
}

// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
// Returns an empty string if not a library dependency tag.
func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
	if libDepTag, ok := depTag.(libraryDependencyTag); ok {
		return libDepTag.makeSuffix
	}
	return ""
}

// SharedDepTag returns the dependency tag for any C++ shared libraries.
func SharedDepTag() blueprint.DependencyTag {
	return libraryDependencyTag{Kind: sharedLibraryDependency}
+5 −0
Original line number Diff line number Diff line
@@ -60,6 +60,10 @@ func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
				entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.Properties.AndroidMkSharedLibs...)
				entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
				entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
				if mod.UseVndk() {
					entries.SetBool("LOCAL_USE_VNDK", true)
				}

			},
		},
	}
@@ -75,6 +79,7 @@ func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
		mod.SubAndroidMk(&ret, mod.sanitize)
	}

	ret.SubName += mod.Properties.RustSubName
	ret.SubName += mod.Properties.SubName

	return []android.AndroidMkEntries{ret}
+4 −1
Original line number Diff line number Diff line
@@ -303,7 +303,6 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
			if ctx.Target().Os == android.BuildOs {
				stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
			}

			deps.Stdlibs = append(deps.Stdlibs, stdlib)
		}
	}
@@ -344,6 +343,10 @@ func (compiler *baseCompiler) installDir(ctx ModuleContext) android.InstallPath
	if !ctx.Host() && ctx.Config().HasMultilibConflict(ctx.Arch().ArchType) {
		dir = filepath.Join(dir, ctx.Arch().ArchType.String())
	}

	if compiler.location == InstallInData && ctx.RustModule().UseVndk() {
		dir = filepath.Join(dir, "vendor")
	}
	return android.PathForModuleInstall(ctx, dir, compiler.subDir,
		compiler.relativeInstallPath(), compiler.relative)
}
+97 −51
Original line number Diff line number Diff line
@@ -23,6 +23,68 @@ import (

var _ android.ImageInterface = (*Module)(nil)

var _ cc.ImageMutatableModule = (*Module)(nil)

func (mod *Module) VendorAvailable() bool {
	return Bool(mod.VendorProperties.Vendor_available)
}

func (mod *Module) OdmAvailable() bool {
	return Bool(mod.VendorProperties.Odm_available)
}

func (mod *Module) ProductAvailable() bool {
	return false
}

func (mod *Module) RamdiskAvailable() bool {
	return false
}

func (mod *Module) VendorRamdiskAvailable() bool {
	return Bool(mod.Properties.Vendor_ramdisk_available)
}

func (mod *Module) AndroidModuleBase() *android.ModuleBase {
	return &mod.ModuleBase
}

func (mod *Module) RecoveryAvailable() bool {
	return false
}

func (mod *Module) ExtraVariants() []string {
	return mod.Properties.ExtraVariants
}

func (mod *Module) AppendExtraVariant(extraVariant string) {
	mod.Properties.ExtraVariants = append(mod.Properties.ExtraVariants, extraVariant)
}

func (mod *Module) SetRamdiskVariantNeeded(b bool) {
	if b {
		panic("Setting ramdisk variant needed for Rust module is unsupported: " + mod.BaseModuleName())
	}
}

func (mod *Module) SetVendorRamdiskVariantNeeded(b bool) {
	mod.Properties.VendorRamdiskVariantNeeded = b
}

func (mod *Module) SetRecoveryVariantNeeded(b bool) {
	if b {
		panic("Setting recovery variant needed for Rust module is unsupported: " + mod.BaseModuleName())
	}
}

func (mod *Module) SetCoreVariantNeeded(b bool) {
	mod.Properties.CoreVariantNeeded = b
}

func (mod *Module) SnapshotVersion(mctx android.BaseModuleContext) string {
	panic("Rust modules do not support snapshotting: " + mod.BaseModuleName())
}

func (mod *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
	return mod.Properties.VendorRamdiskVariantNeeded
}
@@ -43,6 +105,29 @@ func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
	return mod.Properties.ExtraVariants
}

func (mod *Module) IsSnapshotPrebuilt() bool {
	// Rust does not support prebuilts in its snapshots
	return false
}

func (ctx *moduleContext) SocSpecific() bool {
	// Additionally check if this module is inVendor() that means it is a "vendor" variant of a
	// module. As well as SoC specific modules, vendor variants must be installed to /vendor
	// unless they have "odm_available: true".
	return ctx.ModuleContext.SocSpecific() || (ctx.RustModule().InVendor() && !ctx.RustModule().VendorVariantToOdm())
}

func (ctx *moduleContext) DeviceSpecific() bool {
	// Some vendor variants want to be installed to /odm by setting "odm_available: true".
	return ctx.ModuleContext.DeviceSpecific() || (ctx.RustModule().InVendor() && ctx.RustModule().VendorVariantToOdm())
}

// Returns true when this module creates a vendor variant and wants to install the vendor variant
// to the odm partition.
func (c *Module) VendorVariantToOdm() bool {
	return Bool(c.VendorProperties.Odm_available)
}

func (ctx *moduleContext) ProductSpecific() bool {
	return false
}
@@ -84,10 +169,15 @@ func (mod *Module) HasNonSystemVariants() bool {
	return mod.HasVendorVariant() || mod.HasProductVariant()
}

func (c *Module) InProduct() bool {
func (mod *Module) InProduct() bool {
	return false
}

// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
func (mod *Module) InVendor() bool {
	return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix
}

func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
	m := module.(*Module)
	if variant == android.VendorRamdiskVariation {
@@ -107,9 +197,6 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
}

func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
	vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
	platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()

	// Rust does not support installing to the product image yet.
	if Bool(mod.VendorProperties.Product_available) {
		mctx.PropertyErrorf("product_available",
@@ -121,60 +208,19 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
		mctx.PropertyErrorf("double_loadable",
			"Rust modules do not yet support double loading")
	}

	coreVariantNeeded := true
	vendorRamdiskVariantNeeded := false

	var vendorVariants []string

	if mod.HasVendorVariant() {
		prop := "vendor_available"
		if Bool(mod.VendorProperties.Odm_available) {
			prop = "odm_available"
		}

		if vendorSpecific {
			mctx.PropertyErrorf(prop,
				"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
		}

		if lib, ok := mod.compiler.(libraryInterface); ok {
			// Explicitly disallow rust_ffi variants which produce shared libraries from setting vendor_available.
			// Vendor variants do not produce an error for dylibs, rlibs with dylib-std linkage are disabled in the respective library
			// mutators until support is added.
			//
			// We can't check shared() here because image mutator is called before the library mutator, so we need to
			// check buildShared()
			if lib.buildShared() {
				mctx.PropertyErrorf(prop, "cannot be set for rust_ffi or rust_ffi_shared modules.")
			} else {
				vendorVariants = append(vendorVariants, platformVndkVersion)
			}
		}
	}

	if Bool(mod.Properties.Vendor_ramdisk_available) {
		if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && lib.buildShared()) {
			mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
		} else {
			vendorRamdiskVariantNeeded = true
		}
	}

	if vendorSpecific {
		if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && (lib.buildShared() || lib.buildDylib() || lib.buildRlib())) {
			mctx.ModuleErrorf("Rust vendor specific modules are currently only supported for rust_ffi_static modules.")
		} else {
			coreVariantNeeded = false
			vendorVariants = append(vendorVariants, platformVndkVersion)
		}
	}
	cc.MutateImage(mctx, mod)

	mod.Properties.CoreVariantNeeded = coreVariantNeeded
	mod.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
	if !mod.Properties.CoreVariantNeeded || mod.HasNonSystemVariants() {

	for _, variant := range android.FirstUniqueStrings(vendorVariants) {
		mod.Properties.ExtraVariants = append(mod.Properties.ExtraVariants, cc.VendorVariationPrefix+variant)
		if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
			// Rust does not support prebuilt libraries on non-System images.
			mctx.ModuleErrorf("Rust prebuilt modules not supported for non-system images.")
		}
	}

}
Loading