blob: d0fda645955b0db749ab878bdb43a18443ced108 [file] [log] [blame]
Ivan Lozano183a3212019-10-18 14:18:45 -07001package cc
2
3import (
Ivan Lozano183a3212019-10-18 14:18:45 -07004 "android/soong/android"
Ivan Lozano0f9963e2023-02-06 13:31:02 -05005 "android/soong/fuzz"
Colin Cross6e511a92020-07-27 21:26:48 -07006
7 "github.com/google/blueprint"
Colin Crossa14fb6a2024-10-23 16:57:06 -07008 "github.com/google/blueprint/depset"
Ivan Lozano183a3212019-10-18 14:18:45 -07009)
10
Ivan Lozano3968d8f2020-12-14 11:27:52 -050011// PlatformSanitizeable is an interface for sanitizing platform modules.
12type PlatformSanitizeable interface {
13 LinkableInterface
14
15 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
16 SanitizePropDefined() bool
17
Ivan Lozano3968d8f2020-12-14 11:27:52 -050018 // IsSanitizerEnabled returns whether a sanitizer is enabled.
19 IsSanitizerEnabled(t SanitizerType) bool
20
21 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
22 // than left undefined.
23 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
24
Ivan Lozano3968d8f2020-12-14 11:27:52 -050025 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
26 SetSanitizer(t SanitizerType, b bool)
27
Ivan Lozano3968d8f2020-12-14 11:27:52 -050028 // StaticallyLinked returns true if the module is statically linked.
29 StaticallyLinked() bool
30
31 // SetInSanitizerDir sets the module installation to the sanitizer directory.
32 SetInSanitizerDir()
33
34 // SanitizeNever returns true if this module should never be sanitized.
35 SanitizeNever() bool
36
37 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
38 SanitizerSupported(t SanitizerType) bool
39
Ivan Lozanod7586b62021-04-01 09:49:36 -040040 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
41 // either because it requires it or because a dependent module which requires it to be linked in this module.
42 MinimalRuntimeDep() bool
43
44 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
45 // either because it requires it or because a dependent module which requires it to be linked in this module.
46 UbsanRuntimeDep() bool
47
48 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
49 UbsanRuntimeNeeded() bool
50
51 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
52 MinimalRuntimeNeeded() bool
53
Ivan Lozano3968d8f2020-12-14 11:27:52 -050054 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
55 SanitizableDepTagChecker() SantizableDependencyTagChecker
Ivan Lozano9eaacc82024-10-30 14:28:17 +000056
57 // ForceDisableSanitizers sets the ForceDisable sanitize property
58 ForceDisableSanitizers()
Ivan Lozano3968d8f2020-12-14 11:27:52 -050059}
60
61// SantizableDependencyTagChecker functions check whether or not a dependency
62// tag can be sanitized. These functions should return true if the tag can be
63// sanitized, otherwise they should return false. These functions should also
64// handle all possible dependency tags in the dependency tree. For example,
65// Rust modules can depend on both Rust and CC libraries, so the Rust module
66// implementation should handle tags from both.
67type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
68
Ivan Lozano9eaacc82024-10-30 14:28:17 +000069type VersionedLinkableInterface interface {
70 LinkableInterface
71 android.ApexModule
72
73 // VersionedInterface returns the VersionedInterface for this module
74 // (e.g. c.library), or nil if this is module is not a VersionedInterface.
75 VersionedInterface() VersionedInterface
76
77 // HasStubsVariants true if this module is a stub or has a sibling variant
78 // that is a stub.
79 HasStubsVariants() bool
80
81 // SetStl sets the stl property for CC modules. Does not panic if for other module types.
82 SetStl(string)
83 SetSdkVersion(string)
84 SetMinSdkVersion(version string)
85 ApexSdkVersion() android.ApiLevel
86 ImplementationModuleNameForMake(ctx android.BaseModuleContext) string
87}
88
Chris Parsons3c27ca32020-11-20 12:42:07 -050089// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070090type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050091 android.Module
92
Ivan Lozano183a3212019-10-18 14:18:45 -070093 Module() android.Module
94 CcLibrary() bool
95 CcLibraryInterface() bool
96
Ivan Lozano61c02cc2023-06-09 14:06:44 -040097 // RustLibraryInterface returns true if this is a Rust library module
98 RustLibraryInterface() bool
99
Ivan Lozano0a468a42024-05-13 21:03:34 -0400100 // CrateName returns the crateName for a Rust library, panics if not a Rust library.
101 CrateName() string
102
103 // DepFlags returns a slice of Rustc string flags, panics if not a Rust library
104 ExportedCrateLinkDirs() []string
105
Ivan Lozanod7586b62021-04-01 09:49:36 -0400106 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
107 BaseModuleName() string
108
Ivan Lozano183a3212019-10-18 14:18:45 -0700109 OutputFile() android.OptionalPath
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400110 UnstrippedOutputFile() android.Path
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400111 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700112
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400113 // CoverageOutputFile returns the output archive of gcno coverage information files.
114 CoverageOutputFile() android.OptionalPath
115
Ivan Lozano2b262972019-11-21 12:30:50 -0800116 NonCcVariants() bool
117
Ivan Lozano52767be2019-10-18 14:49:46 -0700118 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700119
120 BuildStaticVariant() bool
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400121 BuildRlibVariant() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700122 BuildSharedVariant() bool
123 SetStatic()
124 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500125 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700126 Toc() android.OptionalPath
127
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500128 // IsFuzzModule returns true if this a *_fuzz module.
129 IsFuzzModule() bool
130
131 // FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
132 // Expects that IsFuzzModule returns true.
133 FuzzPackagedModule() fuzz.FuzzPackagedModule
134
135 // FuzzSharedLibraries returns the shared library dependencies for this module.
136 // Expects that IsFuzzModule returns true.
Hamzeh Zawawy38917492023-04-05 22:08:46 +0000137 FuzzSharedLibraries() android.RuleBuilderInstalls
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500138
Yi-Yo Chiang36d8e4e2021-07-02 21:21:13 +0800139 Device() bool
Jooyung Han624d35c2020-04-10 12:57:24 +0900140 Host() bool
141
Yifan Hong1b3348d2020-01-21 15:53:22 -0800142 InRamdisk() bool
143 OnlyInRamdisk() bool
144
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700145 InVendorRamdisk() bool
146 OnlyInVendorRamdisk() bool
147
Ivan Lozano52767be2019-10-18 14:49:46 -0700148 InRecovery() bool
149 OnlyInRecovery() bool
150
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500151 InVendor() bool
152
Colin Crossc511bc52020-04-07 16:50:32 +0000153 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400154
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400155 // IsNdk returns true if the library is in the configs known NDK list.
156 IsNdk(config android.Config) bool
157
158 // IsStubs returns true if the this is a stubs library.
159 IsStubs() bool
160
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400161 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
162 IsLlndk() bool
163
Colin Cross1f3f1302021-04-26 18:37:44 -0700164 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
165 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400166
Colin Cross5271fea2021-04-27 13:06:04 -0700167 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
168 NeedsVendorPublicLibraryVariants() bool
169
Ivan Lozanod7586b62021-04-01 09:49:36 -0400170 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
171 // "product" and "vendor" variant modules return true for this function.
172 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
173 // "soc_specific: true" and more vendor installed modules are included here.
174 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
175 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700176 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400177
Jiyong Park7d55b612021-06-11 17:22:09 +0900178 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
179 Bootstrap() bool
180
Ivan Lozanof1868af2022-04-12 13:08:36 -0400181 IsVendorPublicLibrary() bool
182 IsVndkPrebuiltLibrary() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700183 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900184 HasProductVariant() bool
185 HasNonSystemVariants() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400186 ProductSpecific() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500187 InProduct() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400188 SdkAndPlatformVariantVisibleToMake() bool
Kiyoung Kimaa394802024-01-08 12:55:45 +0900189 InVendorOrProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700190
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400191 // SubName returns the modules SubName, used for image and NDK/SDK variations.
192 SubName() string
193
Ivan Lozano52767be2019-10-18 14:49:46 -0700194 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900195 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000196 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900197 IsSdkVariant() bool
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000198 Multilib() string
Ivan Lozano52767be2019-10-18 14:49:46 -0700199
Colin Cross1348ce32020-10-01 13:37:16 -0700200 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500201
202 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
203 SetPreventInstall()
204 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
205 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400206
207 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
208 // This is specific to cc and should always return false for all other packages.
209 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400210
211 // HiddenFromMake returns true if this module is hidden from Make.
212 HiddenFromMake() bool
213
214 // RelativeInstallPath returns the relative install path for this module.
215 RelativeInstallPath() string
216
217 // Binary returns true if this is a binary module.
218 Binary() bool
219
220 // Object returns true if this is an object module.
221 Object() bool
222
223 // Rlib returns true if this is an rlib module.
224 Rlib() bool
225
226 // Dylib returns true if this is an dylib module.
227 Dylib() bool
228
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400229 // RlibStd returns true if this is an rlib which links against an rlib libstd.
230 RlibStd() bool
231
Ivan Lozanod7586b62021-04-01 09:49:36 -0400232 // Static returns true if this is a static library module.
233 Static() bool
234
235 // Shared returns true if this is a shared library module.
236 Shared() bool
237
238 // Header returns true if this is a library headers module.
239 Header() bool
240
Justin Yun5e035862021-06-29 20:50:37 +0900241 // StaticExecutable returns true if this is a binary module with "static_executable: true".
242 StaticExecutable() bool
243
Ivan Lozanod7586b62021-04-01 09:49:36 -0400244 // EverInstallable returns true if the module is ever installable
245 EverInstallable() bool
246
247 // PreventInstall returns true if this module is prevented from installation.
248 PreventInstall() bool
249
250 // InstallInData returns true if this module is installed in data.
251 InstallInData() bool
252
253 // Installable returns a bool pointer to the module installable property.
254 Installable() *bool
255
256 // Symlinks returns a list of symlinks that should be created for this module.
257 Symlinks() []string
258
259 // VndkVersion returns the VNDK version string for this module.
260 VndkVersion() string
Jihoon Kangf78a8902022-09-01 22:47:07 +0000261
262 // Partition returns the partition string for this module.
263 Partition() string
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500264
265 // FuzzModule returns the fuzz.FuzzModule associated with the module.
266 FuzzModuleStruct() fuzz.FuzzModule
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000267 IsCrt() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700268}
269
Colin Cross6e511a92020-07-27 21:26:48 -0700270var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500271 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700272 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500273 // Dependency tag for crtend, an object file responsible for program termination.
274 CrtEndDepTag = dependencyTag{name: "crtend"}
275 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700276 CoverageDepTag = dependencyTag{name: "coverage"}
277)
Ivan Lozano183a3212019-10-18 14:18:45 -0700278
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500279// GetImageVariantType returns the ImageVariantType string value for the given module
280// (these are defined in cc/image.go).
281func GetImageVariantType(c LinkableInterface) ImageVariantType {
282 if c.Host() {
283 return hostImageVariant
284 } else if c.InVendor() {
285 return vendorImageVariant
286 } else if c.InProduct() {
287 return productImageVariant
288 } else if c.InRamdisk() {
289 return ramdiskImageVariant
290 } else if c.InVendorRamdisk() {
291 return vendorRamdiskImageVariant
292 } else if c.InRecovery() {
293 return recoveryImageVariant
294 } else {
295 return coreImageVariant
296 }
297}
298
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400299// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
300// Returns an empty string if not a library dependency tag.
301func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
302 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
303 return libDepTag.makeSuffix
304 }
305 return ""
306}
307
Chris Parsons3c27ca32020-11-20 12:42:07 -0500308// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross8acea3e2024-12-12 14:53:30 -0800309func SharedDepTag() blueprint.DependencyTag {
310 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700311}
312
Chris Parsons3c27ca32020-11-20 12:42:07 -0500313// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400314func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
315 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
316}
317
318// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
319func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
320 if tag, ok := depTag.(libraryDependencyTag); ok {
321 return tag.wholeStatic
322 }
323 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700324}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700325
Chris Parsons3c27ca32020-11-20 12:42:07 -0500326// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800327func HeaderDepTag() blueprint.DependencyTag {
328 return libraryDependencyTag{Kind: headerLibraryDependency}
329}
330
Chris Parsons3c27ca32020-11-20 12:42:07 -0500331// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700332type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400333 SharedLibrary android.Path
334 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700335
Colin Crossb614cd42024-10-11 12:52:21 -0700336 TableOfContents android.OptionalPath
337 IsStubs bool
338 ImplementationDeps depset.DepSet[string]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700339
Liz Kammeref6dfea2021-06-08 15:37:09 -0400340 // should be obtained from static analogue
Colin Crossa14fb6a2024-10-23 16:57:06 -0700341 TransitiveStaticLibrariesForOrdering depset.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700342}
343
Colin Crossbc7d76c2023-12-12 16:39:03 -0800344var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]()
Colin Cross0de8a1e2020-09-18 14:15:30 -0700345
Chris Parsons3c27ca32020-11-20 12:42:07 -0500346// SharedStubLibrary is a struct containing information about a stub shared library.
347// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
348// library in another APEX, it must depend on the stub version of that library.
349type SharedStubLibrary struct {
350 // The version of the stub (corresponding to the stable version of the shared library being
351 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700352 Version string
353 SharedLibraryInfo SharedLibraryInfo
354 FlagExporterInfo FlagExporterInfo
355}
356
Chris Parsons3c27ca32020-11-20 12:42:07 -0500357// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
358// which are dependencies of a library.
359// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
360// library in another APEX, it must depend on the stub version of that library.
361type SharedLibraryStubsInfo struct {
362 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700363
Chris Parsons3c27ca32020-11-20 12:42:07 -0500364 IsLLNDK bool
365}
366
Colin Crossbc7d76c2023-12-12 16:39:03 -0800367var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]()
Chris Parsons3c27ca32020-11-20 12:42:07 -0500368
369// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700370type StaticLibraryInfo struct {
371 StaticLibrary android.Path
372 Objects Objects
373 ReuseObjects Objects
374
Colin Crossa2bcf2c2022-02-11 13:11:55 -0800375 // A static library may contain prebuilt static libraries included with whole_static_libs
376 // that won't appear in Objects. They are transitively available in
377 // WholeStaticLibsFromPrebuilts.
378 WholeStaticLibsFromPrebuilts android.Paths
379
Colin Cross0de8a1e2020-09-18 14:15:30 -0700380 // This isn't the actual transitive DepSet, shared library dependencies have been
381 // converted into static library analogues. It is only used to order the static
382 // library dependencies that were specified for the current module.
Colin Crossa14fb6a2024-10-23 16:57:06 -0700383 TransitiveStaticLibrariesForOrdering depset.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700384}
385
Colin Crossbc7d76c2023-12-12 16:39:03 -0800386var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]()
Colin Cross0de8a1e2020-09-18 14:15:30 -0700387
Colin Cross649d8172020-12-10 12:30:21 -0800388// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
389type HeaderLibraryInfo struct {
390}
391
392// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
Colin Crossbc7d76c2023-12-12 16:39:03 -0800393var HeaderLibraryInfoProvider = blueprint.NewProvider[HeaderLibraryInfo]()
Colin Cross649d8172020-12-10 12:30:21 -0800394
Chris Parsons3c27ca32020-11-20 12:42:07 -0500395// FlagExporterInfo is a provider to propagate transitive library information
396// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700397type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500398 IncludeDirs android.Paths // Include directories to be included with -I
399 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
400 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700401 Deps android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400402 RustRlibDeps []RustRlibDep
Colin Cross0de8a1e2020-09-18 14:15:30 -0700403 GeneratedHeaders android.Paths
404}
405
Colin Crossbc7d76c2023-12-12 16:39:03 -0800406var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()
Colin Crossb614cd42024-10-11 12:52:21 -0700407
408var ImplementationDepInfoProvider = blueprint.NewProvider[*ImplementationDepInfo]()
409
410type ImplementationDepInfo struct {
411 ImplementationDeps depset.DepSet[android.Path]
412}