From 9eaacc824c4e567e2e2c41be3504e8564aad98bf Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Wed, 30 Oct 2024 14:28:17 +0000 Subject: Refactor cc/rust to prep for Rust stubs This CL largely handles this refactoring in preparation for Rust stubs support. Rust modules need to be able to communicate stubs information to cc, and certain bits of cc needs to be exported so rust can reuse them. A new VersionedLinkableInterface is added to capture most of the stubs-related interface definitions. Bug: 203478530 Test: m blueprint_tests Change-Id: I380225402fa85a3c39e7b18deb657054b3a52fbe --- rust/rust.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'rust/rust.go') diff --git a/rust/rust.go b/rust/rust.go index ba6e29383..a4c1afd45 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -406,10 +406,6 @@ func (mod *Module) HasLlndkStubs() bool { return false } -func (mod *Module) StubsVersion() string { - panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName())) -} - func (mod *Module) SdkVersion() string { return "" } @@ -561,6 +557,9 @@ func (mod *Module) ExportedCrateLinkDirs() []string { func (mod *Module) PreventInstall() bool { return mod.Properties.PreventInstall } +func (c *Module) ForceDisableSanitizers() { + c.sanitize.Properties.ForceDisable = true +} func (mod *Module) MarkAsCoverageVariant(coverage bool) { mod.coverage.Properties.IsCoverageVariant = coverage @@ -743,11 +742,28 @@ func (mod *Module) IsNdk(config android.Config) bool { return false } +func (mod *Module) IsStubs() bool { + return false +} + func (mod *Module) HasStubsVariants() bool { return false } -func (mod *Module) IsStubs() bool { +func (mod *Module) ApexSdkVersion() android.ApiLevel { + panic(fmt.Errorf("ApexSdkVersion called on unsupported Rust module: %q", mod.BaseModuleName())) +} + +func (mod *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string { + return mod.Name() +} + +func (mod *Module) Multilib() string { + return mod.Arch().ArchType.Multilib +} + +func (mod *Module) IsCrt() bool { + // Rust does not currently provide any crt modules. return false } @@ -771,6 +787,7 @@ func (ctx moduleContext) apexVariationName() string { } var _ cc.LinkableInterface = (*Module)(nil) +var _ cc.VersionedLinkableInterface = (*Module)(nil) func (mod *Module) Init() android.Module { mod.AddProperties(&mod.Properties) @@ -881,6 +898,25 @@ func (mod *Module) nativeCoverage() bool { return mod.compiler != nil && mod.compiler.nativeCoverage() } +func (mod *Module) SetStl(s string) { + // STL is a CC concept; do nothing for Rust +} + +func (mod *Module) SetSdkVersion(s string) { + panic(fmt.Errorf("SetSdkVersion called on unsupported Rust module: %q", mod.BaseModuleName())) +} + +func (mod *Module) SetMinSdkVersion(s string) { + mod.Properties.Min_sdk_version = StringPtr(s) +} + +func (mod *Module) VersionedInterface() cc.VersionedInterface { + if _, ok := mod.compiler.(cc.VersionedInterface); ok { + return mod.compiler.(cc.VersionedInterface) + } + return nil +} + func (mod *Module) EverInstallable() bool { return mod.compiler != nil && // Check to see whether the module is actually ever installable. @@ -1064,6 +1100,12 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } android.SetProvider(ctx, RustInfoProvider, rustInfo) + ccInfo := &cc.CcInfo{ + IsPrebuilt: mod.IsPrebuilt(), + } + + android.SetProvider(ctx, cc.CcInfoProvider, ccInfo) + mod.setOutputFiles(ctx) buildComplianceMetadataInfo(ctx, mod, deps) -- cgit v1.2.3-59-g8ed1b