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

Commit c08897c1 authored by Ivan Lozano's avatar Ivan Lozano
Browse files

Add more Rust vendor image support.

This adds Rust vendor image support for all module types except
Rust prebuilts.

Bug: 184042776
Test: New Soong tests.
Test: Example cc_library vendor module can depend on rust_ffi_shared.
Test: Example rust_library vendor-only module compiles.

Change-Id: Iaa30ad51fdaedcbf14687da5472581f6af62ff59
parent 699e2183
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)
}
+30 −20
Original line number Diff line number Diff line
@@ -110,6 +110,24 @@ func (mod *Module) IsSnapshotPrebuilt() bool {
	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
}
@@ -155,6 +173,11 @@ 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 {
@@ -185,32 +208,19 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
		mctx.PropertyErrorf("double_loadable",
			"Rust modules do not yet support double loading")
	}

	if mod.HasVendorVariant() {
		if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildShared() {
			// 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()

			mctx.PropertyErrorf("vendor_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
		}
	}

	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.")
		}
	}

	vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
	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.")
	cc.MutateImage(mctx, mod)

	if !mod.Properties.CoreVariantNeeded || mod.HasNonSystemVariants() {

		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.")
		}
	}

	cc.MutateImage(mctx, mod)
}
Loading