xref: /aosp_15_r20/build/soong/cc/linkable.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1package cc
2
3import (
4	"android/soong/android"
5	"android/soong/fuzz"
6
7	"github.com/google/blueprint"
8	"github.com/google/blueprint/depset"
9)
10
11// 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
18	// 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
25	// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
26	SetSanitizer(t SanitizerType, b bool)
27
28	// 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
40	// 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
54	// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
55	SanitizableDepTagChecker() SantizableDependencyTagChecker
56}
57
58// SantizableDependencyTagChecker functions check whether or not a dependency
59// tag can be sanitized. These functions should return true if the tag can be
60// sanitized, otherwise they should return false. These functions should also
61// handle all possible dependency tags in the dependency tree. For example,
62// Rust modules can depend on both Rust and CC libraries, so the Rust module
63// implementation should handle tags from both.
64type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
65
66// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
67type LinkableInterface interface {
68	android.Module
69
70	Module() android.Module
71	CcLibrary() bool
72	CcLibraryInterface() bool
73
74	// RustLibraryInterface returns true if this is a Rust library module
75	RustLibraryInterface() bool
76
77	// CrateName returns the crateName for a Rust library, panics if not a Rust library.
78	CrateName() string
79
80	// DepFlags returns a slice of Rustc string flags, panics if not a Rust library
81	ExportedCrateLinkDirs() []string
82
83	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
84	BaseModuleName() string
85
86	OutputFile() android.OptionalPath
87	UnstrippedOutputFile() android.Path
88	CoverageFiles() android.Paths
89
90	// CoverageOutputFile returns the output archive of gcno coverage information files.
91	CoverageOutputFile() android.OptionalPath
92
93	NonCcVariants() bool
94
95	SelectedStl() string
96
97	BuildStaticVariant() bool
98	BuildRlibVariant() bool
99	BuildSharedVariant() bool
100	SetStatic()
101	SetShared()
102	IsPrebuilt() bool
103	Toc() android.OptionalPath
104
105	// IsRustFFI returns true if this is a Rust FFI library.
106	IsRustFFI() bool
107
108	// IsFuzzModule returns true if this a *_fuzz module.
109	IsFuzzModule() bool
110
111	// FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
112	// Expects that IsFuzzModule returns true.
113	FuzzPackagedModule() fuzz.FuzzPackagedModule
114
115	// FuzzSharedLibraries returns the shared library dependencies for this module.
116	// Expects that IsFuzzModule returns true.
117	FuzzSharedLibraries() android.RuleBuilderInstalls
118
119	Device() bool
120	Host() bool
121
122	InRamdisk() bool
123	OnlyInRamdisk() bool
124
125	InVendorRamdisk() bool
126	OnlyInVendorRamdisk() bool
127
128	InRecovery() bool
129	OnlyInRecovery() bool
130
131	InVendor() bool
132
133	UseSdk() bool
134
135	// IsNdk returns true if the library is in the configs known NDK list.
136	IsNdk(config android.Config) bool
137
138	// HasStubsVariants true if this module is a stub or has a sibling variant
139	// that is a stub.
140	HasStubsVariants() bool
141
142	// IsStubs returns true if the this is a stubs library.
143	IsStubs() bool
144
145	// IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
146	IsLlndk() bool
147
148	// HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
149	HasLlndkStubs() bool
150
151	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
152	NeedsLlndkVariants() bool
153
154	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
155	NeedsVendorPublicLibraryVariants() bool
156
157	//StubsVersion returns the stubs version for this module.
158	StubsVersion() string
159
160	// UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
161	// "product" and "vendor" variant modules return true for this function.
162	// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
163	// "soc_specific: true" and more vendor installed modules are included here.
164	// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
165	// "product_specific: true" modules are included here.
166	UseVndk() bool
167
168	// Bootstrap tests if this module is allowed to use non-APEX version of libraries.
169	Bootstrap() bool
170
171	IsVendorPublicLibrary() bool
172	IsVndkPrebuiltLibrary() bool
173	HasVendorVariant() bool
174	HasProductVariant() bool
175	HasNonSystemVariants() bool
176	ProductSpecific() bool
177	InProduct() bool
178	SdkAndPlatformVariantVisibleToMake() bool
179	InVendorOrProduct() bool
180
181	// SubName returns the modules SubName, used for image and NDK/SDK variations.
182	SubName() string
183
184	SdkVersion() string
185	MinSdkVersion() string
186	AlwaysSdk() bool
187	IsSdkVariant() bool
188
189	SplitPerApiLevel() bool
190
191	// SetPreventInstall sets the PreventInstall property to 'true' for this module.
192	SetPreventInstall()
193	// SetHideFromMake sets the HideFromMake property to 'true' for this module.
194	SetHideFromMake()
195
196	// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
197	// This is specific to cc and should always return false for all other packages.
198	KernelHeadersDecorator() bool
199
200	// HiddenFromMake returns true if this module is hidden from Make.
201	HiddenFromMake() bool
202
203	// RelativeInstallPath returns the relative install path for this module.
204	RelativeInstallPath() string
205
206	// Binary returns true if this is a binary module.
207	Binary() bool
208
209	// Object returns true if this is an object module.
210	Object() bool
211
212	// Rlib returns true if this is an rlib module.
213	Rlib() bool
214
215	// Dylib returns true if this is an dylib module.
216	Dylib() bool
217
218	// RlibStd returns true if this is an rlib which links against an rlib libstd.
219	RlibStd() bool
220
221	// Static returns true if this is a static library module.
222	Static() bool
223
224	// Shared returns true if this is a shared library module.
225	Shared() bool
226
227	// Header returns true if this is a library headers module.
228	Header() bool
229
230	// StaticExecutable returns true if this is a binary module with "static_executable: true".
231	StaticExecutable() bool
232
233	// EverInstallable returns true if the module is ever installable
234	EverInstallable() bool
235
236	// PreventInstall returns true if this module is prevented from installation.
237	PreventInstall() bool
238
239	// InstallInData returns true if this module is installed in data.
240	InstallInData() bool
241
242	// Installable returns a bool pointer to the module installable property.
243	Installable() *bool
244
245	// Symlinks returns a list of symlinks that should be created for this module.
246	Symlinks() []string
247
248	// VndkVersion returns the VNDK version string for this module.
249	VndkVersion() string
250
251	// Partition returns the partition string for this module.
252	Partition() string
253
254	// FuzzModule returns the fuzz.FuzzModule associated with the module.
255	FuzzModuleStruct() fuzz.FuzzModule
256}
257
258var (
259	// Dependency tag for crtbegin, an object file responsible for initialization.
260	CrtBeginDepTag = dependencyTag{name: "crtbegin"}
261	// Dependency tag for crtend, an object file responsible for program termination.
262	CrtEndDepTag = dependencyTag{name: "crtend"}
263	// Dependency tag for coverage library.
264	CoverageDepTag = dependencyTag{name: "coverage"}
265)
266
267// GetImageVariantType returns the ImageVariantType string value for the given module
268// (these are defined in cc/image.go).
269func GetImageVariantType(c LinkableInterface) ImageVariantType {
270	if c.Host() {
271		return hostImageVariant
272	} else if c.InVendor() {
273		return vendorImageVariant
274	} else if c.InProduct() {
275		return productImageVariant
276	} else if c.InRamdisk() {
277		return ramdiskImageVariant
278	} else if c.InVendorRamdisk() {
279		return vendorRamdiskImageVariant
280	} else if c.InRecovery() {
281		return recoveryImageVariant
282	} else {
283		return coreImageVariant
284	}
285}
286
287// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
288// Returns an empty string if not a library dependency tag.
289func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
290	if libDepTag, ok := depTag.(libraryDependencyTag); ok {
291		return libDepTag.makeSuffix
292	}
293	return ""
294}
295
296// SharedDepTag returns the dependency tag for any C++ shared libraries.
297func SharedDepTag() blueprint.DependencyTag {
298	return libraryDependencyTag{Kind: sharedLibraryDependency}
299}
300
301// StaticDepTag returns the dependency tag for any C++ static libraries.
302func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
303	return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
304}
305
306// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
307func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
308	if tag, ok := depTag.(libraryDependencyTag); ok {
309		return tag.wholeStatic
310	}
311	return false
312}
313
314// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
315func HeaderDepTag() blueprint.DependencyTag {
316	return libraryDependencyTag{Kind: headerLibraryDependency}
317}
318
319// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
320type SharedLibraryInfo struct {
321	SharedLibrary android.Path
322	Target        android.Target
323
324	TableOfContents    android.OptionalPath
325	IsStubs            bool
326	ImplementationDeps depset.DepSet[string]
327
328	// should be obtained from static analogue
329	TransitiveStaticLibrariesForOrdering depset.DepSet[android.Path]
330}
331
332var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]()
333
334// SharedStubLibrary is a struct containing information about a stub shared library.
335// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
336// library in another APEX, it must depend on the stub version of that library.
337type SharedStubLibrary struct {
338	// The version of the stub (corresponding to the stable version of the shared library being
339	// stubbed).
340	Version           string
341	SharedLibraryInfo SharedLibraryInfo
342	FlagExporterInfo  FlagExporterInfo
343}
344
345// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
346// which are dependencies of a 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 SharedLibraryStubsInfo struct {
350	SharedStubLibraries []SharedStubLibrary
351
352	IsLLNDK bool
353}
354
355var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]()
356
357// StaticLibraryInfo is a provider to propagate information about a static C++ library.
358type StaticLibraryInfo struct {
359	StaticLibrary android.Path
360	Objects       Objects
361	ReuseObjects  Objects
362
363	// A static library may contain prebuilt static libraries included with whole_static_libs
364	// that won't appear in Objects.  They are transitively available in
365	// WholeStaticLibsFromPrebuilts.
366	WholeStaticLibsFromPrebuilts android.Paths
367
368	// This isn't the actual transitive DepSet, shared library dependencies have been
369	// converted into static library analogues.  It is only used to order the static
370	// library dependencies that were specified for the current module.
371	TransitiveStaticLibrariesForOrdering depset.DepSet[android.Path]
372}
373
374var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]()
375
376// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
377type HeaderLibraryInfo struct {
378}
379
380// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
381var HeaderLibraryInfoProvider = blueprint.NewProvider[HeaderLibraryInfo]()
382
383// FlagExporterInfo is a provider to propagate transitive library information
384// pertaining to exported include paths and flags.
385type FlagExporterInfo struct {
386	IncludeDirs       android.Paths // Include directories to be included with -I
387	SystemIncludeDirs android.Paths // System include directories to be included with -isystem
388	Flags             []string      // Exported raw flags.
389	Deps              android.Paths
390	RustRlibDeps      []RustRlibDep
391	GeneratedHeaders  android.Paths
392}
393
394var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()
395
396var ImplementationDepInfoProvider = blueprint.NewProvider[*ImplementationDepInfo]()
397
398type ImplementationDepInfo struct {
399	ImplementationDeps depset.DepSet[android.Path]
400}
401