blob: 5579aaea593eb2399f9ea106e63839ded65f6a1b [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"
Ivan Lozano183a3212019-10-18 14:18:45 -07008)
9
Ivan Lozano3968d8f2020-12-14 11:27:52 -050010// PlatformSanitizeable is an interface for sanitizing platform modules.
11type PlatformSanitizeable interface {
12 LinkableInterface
13
14 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
15 SanitizePropDefined() bool
16
Ivan Lozano3968d8f2020-12-14 11:27:52 -050017 // IsSanitizerEnabled returns whether a sanitizer is enabled.
18 IsSanitizerEnabled(t SanitizerType) bool
19
20 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
21 // than left undefined.
22 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
23
Ivan Lozano3968d8f2020-12-14 11:27:52 -050024 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
25 SetSanitizer(t SanitizerType, b bool)
26
Ivan Lozano3968d8f2020-12-14 11:27:52 -050027 // StaticallyLinked returns true if the module is statically linked.
28 StaticallyLinked() bool
29
30 // SetInSanitizerDir sets the module installation to the sanitizer directory.
31 SetInSanitizerDir()
32
33 // SanitizeNever returns true if this module should never be sanitized.
34 SanitizeNever() bool
35
36 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
37 SanitizerSupported(t SanitizerType) bool
38
Ivan Lozanod7586b62021-04-01 09:49:36 -040039 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
40 // either because it requires it or because a dependent module which requires it to be linked in this module.
41 MinimalRuntimeDep() bool
42
43 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
44 // either because it requires it or because a dependent module which requires it to be linked in this module.
45 UbsanRuntimeDep() bool
46
47 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
48 UbsanRuntimeNeeded() bool
49
50 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
51 MinimalRuntimeNeeded() bool
52
Ivan Lozano3968d8f2020-12-14 11:27:52 -050053 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
54 SanitizableDepTagChecker() SantizableDependencyTagChecker
55}
56
57// SantizableDependencyTagChecker functions check whether or not a dependency
58// tag can be sanitized. These functions should return true if the tag can be
59// sanitized, otherwise they should return false. These functions should also
60// handle all possible dependency tags in the dependency tree. For example,
61// Rust modules can depend on both Rust and CC libraries, so the Rust module
62// implementation should handle tags from both.
63type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
64
Chris Parsons3c27ca32020-11-20 12:42:07 -050065// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070066type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050067 android.Module
68
Ivan Lozano183a3212019-10-18 14:18:45 -070069 Module() android.Module
70 CcLibrary() bool
71 CcLibraryInterface() bool
72
Ivan Lozano61c02cc2023-06-09 14:06:44 -040073 // RustLibraryInterface returns true if this is a Rust library module
74 RustLibraryInterface() bool
75
Ivan Lozano0a468a42024-05-13 21:03:34 -040076 // CrateName returns the crateName for a Rust library, panics if not a Rust library.
77 CrateName() string
78
79 // DepFlags returns a slice of Rustc string flags, panics if not a Rust library
80 ExportedCrateLinkDirs() []string
81
Ivan Lozanod7586b62021-04-01 09:49:36 -040082 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
83 BaseModuleName() string
84
Ivan Lozano183a3212019-10-18 14:18:45 -070085 OutputFile() android.OptionalPath
Ivan Lozano39b0bf02021-10-14 12:22:09 -040086 UnstrippedOutputFile() android.Path
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040087 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -070088
Ivan Lozano7f67c2a2022-06-27 16:00:26 -040089 // CoverageOutputFile returns the output archive of gcno coverage information files.
90 CoverageOutputFile() android.OptionalPath
91
Ivan Lozano2b262972019-11-21 12:30:50 -080092 NonCcVariants() bool
93
Ivan Lozano52767be2019-10-18 14:49:46 -070094 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -070095
96 BuildStaticVariant() bool
97 BuildSharedVariant() bool
98 SetStatic()
99 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500100 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700101 Toc() android.OptionalPath
102
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500103 // IsFuzzModule returns true if this a *_fuzz module.
104 IsFuzzModule() bool
105
106 // FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
107 // Expects that IsFuzzModule returns true.
108 FuzzPackagedModule() fuzz.FuzzPackagedModule
109
110 // FuzzSharedLibraries returns the shared library dependencies for this module.
111 // Expects that IsFuzzModule returns true.
Hamzeh Zawawy38917492023-04-05 22:08:46 +0000112 FuzzSharedLibraries() android.RuleBuilderInstalls
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500113
Yi-Yo Chiang36d8e4e2021-07-02 21:21:13 +0800114 Device() bool
Jooyung Han624d35c2020-04-10 12:57:24 +0900115 Host() bool
116
Yifan Hong1b3348d2020-01-21 15:53:22 -0800117 InRamdisk() bool
118 OnlyInRamdisk() bool
119
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700120 InVendorRamdisk() bool
121 OnlyInVendorRamdisk() bool
122
Ivan Lozano52767be2019-10-18 14:49:46 -0700123 InRecovery() bool
124 OnlyInRecovery() bool
125
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500126 InVendor() bool
127
Colin Crossc511bc52020-04-07 16:50:32 +0000128 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400129
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400130 // IsNdk returns true if the library is in the configs known NDK list.
131 IsNdk(config android.Config) bool
132
133 // IsStubs returns true if the this is a stubs library.
134 IsStubs() bool
135
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400136 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
137 IsLlndk() bool
138
139 // IsLlndkPublic returns true only for LLNDK (public) libs.
140 IsLlndkPublic() bool
141
Ivan Lozanod7586b62021-04-01 09:49:36 -0400142 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
143 HasLlndkStubs() bool
144
Colin Cross1f3f1302021-04-26 18:37:44 -0700145 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
146 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400147
Colin Cross5271fea2021-04-27 13:06:04 -0700148 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
149 NeedsVendorPublicLibraryVariants() bool
150
Ivan Lozanod7586b62021-04-01 09:49:36 -0400151 //StubsVersion returns the stubs version for this module.
152 StubsVersion() string
153
154 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
155 // "product" and "vendor" variant modules return true for this function.
156 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
157 // "soc_specific: true" and more vendor installed modules are included here.
158 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
159 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700160 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400161
Jiyong Park7d55b612021-06-11 17:22:09 +0900162 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
163 Bootstrap() bool
164
Ivan Lozanod7586b62021-04-01 09:49:36 -0400165 // IsVndkSp returns true if this is a VNDK-SP module.
166 IsVndkSp() bool
167
Ivan Lozano52767be2019-10-18 14:49:46 -0700168 MustUseVendorVariant() bool
169 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500170 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800171 IsVndkPrivate() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400172 IsVendorPublicLibrary() bool
173 IsVndkPrebuiltLibrary() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700174 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900175 HasProductVariant() bool
176 HasNonSystemVariants() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400177 ProductSpecific() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500178 InProduct() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400179 SdkAndPlatformVariantVisibleToMake() bool
Kiyoung Kimaa394802024-01-08 12:55:45 +0900180 InVendorOrProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700181
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400182 // SubName returns the modules SubName, used for image and NDK/SDK variations.
183 SubName() string
184
Ivan Lozano52767be2019-10-18 14:49:46 -0700185 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900186 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000187 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900188 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700189
Colin Cross1348ce32020-10-01 13:37:16 -0700190 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500191
192 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
193 SetPreventInstall()
194 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
195 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400196
197 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
198 // This is specific to cc and should always return false for all other packages.
199 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400200
201 // HiddenFromMake returns true if this module is hidden from Make.
202 HiddenFromMake() bool
203
204 // RelativeInstallPath returns the relative install path for this module.
205 RelativeInstallPath() string
206
207 // Binary returns true if this is a binary module.
208 Binary() bool
209
210 // Object returns true if this is an object module.
211 Object() bool
212
213 // Rlib returns true if this is an rlib module.
214 Rlib() bool
215
216 // Dylib returns true if this is an dylib module.
217 Dylib() bool
218
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400219 // RlibStd returns true if this is an rlib which links against an rlib libstd.
220 RlibStd() bool
221
Ivan Lozanod7586b62021-04-01 09:49:36 -0400222 // Static returns true if this is a static library module.
223 Static() bool
224
225 // Shared returns true if this is a shared library module.
226 Shared() bool
227
228 // Header returns true if this is a library headers module.
229 Header() bool
230
Justin Yun5e035862021-06-29 20:50:37 +0900231 // StaticExecutable returns true if this is a binary module with "static_executable: true".
232 StaticExecutable() bool
233
Ivan Lozanod7586b62021-04-01 09:49:36 -0400234 // EverInstallable returns true if the module is ever installable
235 EverInstallable() bool
236
237 // PreventInstall returns true if this module is prevented from installation.
238 PreventInstall() bool
239
240 // InstallInData returns true if this module is installed in data.
241 InstallInData() bool
242
243 // Installable returns a bool pointer to the module installable property.
244 Installable() *bool
245
246 // Symlinks returns a list of symlinks that should be created for this module.
247 Symlinks() []string
248
249 // VndkVersion returns the VNDK version string for this module.
250 VndkVersion() string
Jihoon Kangf78a8902022-09-01 22:47:07 +0000251
252 // Partition returns the partition string for this module.
253 Partition() string
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500254
255 // FuzzModule returns the fuzz.FuzzModule associated with the module.
256 FuzzModuleStruct() fuzz.FuzzModule
Ivan Lozano183a3212019-10-18 14:18:45 -0700257}
258
Colin Cross6e511a92020-07-27 21:26:48 -0700259var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500260 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700261 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500262 // Dependency tag for crtend, an object file responsible for program termination.
263 CrtEndDepTag = dependencyTag{name: "crtend"}
264 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700265 CoverageDepTag = dependencyTag{name: "coverage"}
266)
Ivan Lozano183a3212019-10-18 14:18:45 -0700267
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500268// GetImageVariantType returns the ImageVariantType string value for the given module
269// (these are defined in cc/image.go).
270func GetImageVariantType(c LinkableInterface) ImageVariantType {
271 if c.Host() {
272 return hostImageVariant
273 } else if c.InVendor() {
274 return vendorImageVariant
275 } else if c.InProduct() {
276 return productImageVariant
277 } else if c.InRamdisk() {
278 return ramdiskImageVariant
279 } else if c.InVendorRamdisk() {
280 return vendorRamdiskImageVariant
281 } else if c.InRecovery() {
282 return recoveryImageVariant
283 } else {
284 return coreImageVariant
285 }
286}
287
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400288// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
289// Returns an empty string if not a library dependency tag.
290func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
291 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
292 return libDepTag.makeSuffix
293 }
294 return ""
295}
296
Chris Parsons3c27ca32020-11-20 12:42:07 -0500297// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700298func SharedDepTag() blueprint.DependencyTag {
299 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700300}
301
Chris Parsons3c27ca32020-11-20 12:42:07 -0500302// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400303func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
304 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
305}
306
307// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
308func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
309 if tag, ok := depTag.(libraryDependencyTag); ok {
310 return tag.wholeStatic
311 }
312 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700313}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700314
Chris Parsons3c27ca32020-11-20 12:42:07 -0500315// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800316func HeaderDepTag() blueprint.DependencyTag {
317 return libraryDependencyTag{Kind: headerLibraryDependency}
318}
319
Chris Parsons3c27ca32020-11-20 12:42:07 -0500320// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700321type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400322 SharedLibrary android.Path
323 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700324
Liz Kammeref6dfea2021-06-08 15:37:09 -0400325 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700326
Liz Kammeref6dfea2021-06-08 15:37:09 -0400327 // should be obtained from static analogue
Colin Crossc85750b2022-04-21 12:50:51 -0700328 TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700329}
330
Colin Crossbc7d76c2023-12-12 16:39:03 -0800331var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]()
Colin Cross0de8a1e2020-09-18 14:15:30 -0700332
Chris Parsons3c27ca32020-11-20 12:42:07 -0500333// SharedStubLibrary is a struct containing information about a stub shared library.
334// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
335// library in another APEX, it must depend on the stub version of that library.
336type SharedStubLibrary struct {
337 // The version of the stub (corresponding to the stable version of the shared library being
338 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700339 Version string
340 SharedLibraryInfo SharedLibraryInfo
341 FlagExporterInfo FlagExporterInfo
342}
343
Chris Parsons3c27ca32020-11-20 12:42:07 -0500344// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
345// which are dependencies of a library.
346// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
347// library in another APEX, it must depend on the stub version of that library.
348type SharedLibraryStubsInfo struct {
349 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700350
Chris Parsons3c27ca32020-11-20 12:42:07 -0500351 IsLLNDK bool
352}
353
Colin Crossbc7d76c2023-12-12 16:39:03 -0800354var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]()
Chris Parsons3c27ca32020-11-20 12:42:07 -0500355
356// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700357type StaticLibraryInfo struct {
358 StaticLibrary android.Path
359 Objects Objects
360 ReuseObjects Objects
361
Colin Crossa2bcf2c2022-02-11 13:11:55 -0800362 // A static library may contain prebuilt static libraries included with whole_static_libs
363 // that won't appear in Objects. They are transitively available in
364 // WholeStaticLibsFromPrebuilts.
365 WholeStaticLibsFromPrebuilts android.Paths
366
Colin Cross0de8a1e2020-09-18 14:15:30 -0700367 // This isn't the actual transitive DepSet, shared library dependencies have been
368 // converted into static library analogues. It is only used to order the static
369 // library dependencies that were specified for the current module.
Colin Crossc85750b2022-04-21 12:50:51 -0700370 TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700371}
372
Colin Crossbc7d76c2023-12-12 16:39:03 -0800373var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]()
Colin Cross0de8a1e2020-09-18 14:15:30 -0700374
Colin Cross649d8172020-12-10 12:30:21 -0800375// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
376type HeaderLibraryInfo struct {
377}
378
379// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
Colin Crossbc7d76c2023-12-12 16:39:03 -0800380var HeaderLibraryInfoProvider = blueprint.NewProvider[HeaderLibraryInfo]()
Colin Cross649d8172020-12-10 12:30:21 -0800381
Chris Parsons3c27ca32020-11-20 12:42:07 -0500382// FlagExporterInfo is a provider to propagate transitive library information
383// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700384type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500385 IncludeDirs android.Paths // Include directories to be included with -I
386 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
387 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700388 Deps android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400389 RustRlibDeps []RustRlibDep
Colin Cross0de8a1e2020-09-18 14:15:30 -0700390 GeneratedHeaders android.Paths
391}
392
Colin Crossbc7d76c2023-12-12 16:39:03 -0800393var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()