blob: d2de1bcae5d36f4d64d688416747c42e1265e22b [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// Copyright 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package rust
16
17import (
Ivan Lozano183a3212019-10-18 14:18:45 -070018 "fmt"
Ivan Lozanoffee3342019-08-27 12:03:00 -070019 "strings"
20
21 "github.com/google/blueprint"
22 "github.com/google/blueprint/proptools"
23
24 "android/soong/android"
25 "android/soong/cc"
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +020026 cc_config "android/soong/cc/config"
Ivan Lozanoffee3342019-08-27 12:03:00 -070027 "android/soong/rust/config"
28)
29
30var pctx = android.NewPackageContext("android/soong/rust")
31
32func init() {
33 // Only allow rust modules to be defined for certain projects
Ivan Lozanoffee3342019-08-27 12:03:00 -070034
35 android.AddNeverAllowRules(
36 android.NeverAllow().
Ivan Lozanoe169ad72019-09-18 08:42:54 -070037 NotIn(config.RustAllowedPaths...).
38 ModuleType(config.RustModuleTypes...))
Ivan Lozanoffee3342019-08-27 12:03:00 -070039
40 android.RegisterModuleType("rust_defaults", defaultsFactory)
41 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
42 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -040043 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040044 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano6cd99e62020-02-11 08:24:25 -050045
46 })
47 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
48 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070049 })
50 pctx.Import("android/soong/rust/config")
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020051 pctx.ImportAs("cc_config", "android/soong/cc/config")
Ivan Lozanoffee3342019-08-27 12:03:00 -070052}
53
54type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040055 GlobalRustFlags []string // Flags that apply globally to rust
56 GlobalLinkFlags []string // Flags that apply globally to linker
57 RustFlags []string // Flags that apply to rust
58 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020059 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Ivan Lozanof1c84332019-09-20 11:00:37 -070060 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040061 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020062 Clippy bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070063}
64
65type BaseProperties struct {
66 AndroidMkRlibs []string
67 AndroidMkDylibs []string
68 AndroidMkProcMacroLibs []string
69 AndroidMkSharedLibs []string
70 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040071
Ivan Lozano6a884432020-12-02 09:15:16 -050072 ImageVariationPrefix string `blueprint:"mutated"`
73 VndkVersion string `blueprint:"mutated"`
74 SubName string `blueprint:"mutated"`
75
Ivan Lozanoc08897c2021-04-02 12:41:32 -040076 // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
77 // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be
78 // appended before SubName.
79 RustSubName string `blueprint:"mutated"`
80
Ivan Lozano6a884432020-12-02 09:15:16 -050081 // Set by imageMutator
Ivan Lozanoe6d30982021-02-05 10:57:43 -050082 CoreVariantNeeded bool `blueprint:"mutated"`
83 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
84 ExtraVariants []string `blueprint:"mutated"`
85
86 // Make this module available when building for vendor ramdisk.
87 // On device without a dedicated recovery partition, the module is only
88 // available after switching root into
89 // /first_stage_ramdisk. To expose the module before switching root, install
90 // the recovery variant instead (TODO(b/165791368) recovery not yet supported)
91 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040092
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050093 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
94 Min_sdk_version *string
95
Ivan Lozano43845682020-07-09 21:03:28 -040096 PreventInstall bool
97 HideFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070098}
99
100type Module struct {
101 android.ModuleBase
102 android.DefaultableModuleBase
Jiyong Park99644e92020-11-17 22:21:02 +0900103 android.ApexModuleBase
Ivan Lozanoffee3342019-08-27 12:03:00 -0700104
Ivan Lozano6a884432020-12-02 09:15:16 -0500105 VendorProperties cc.VendorProperties
106
Ivan Lozanoffee3342019-08-27 12:03:00 -0700107 Properties BaseProperties
108
109 hod android.HostOrDeviceSupported
110 multilib android.Multilib
111
Ivan Lozano6a884432020-12-02 09:15:16 -0500112 makeLinkType string
113
Ivan Lozanoffee3342019-08-27 12:03:00 -0700114 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400115 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200116 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500117 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700118 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400119 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700120 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400121
Jiyong Parke54f07e2021-04-07 15:08:04 +0900122 // Unstripped output. This is usually used when this module is linked to another module
123 // as a library. The stripped output which is used for installation can be found via
124 // compiler.strippedOutputFile if it exists.
125 unstrippedOutputFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900126
127 hideApexVariantFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700128}
129
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500130func (mod *Module) Header() bool {
131 //TODO: If Rust libraries provide header variants, this needs to be updated.
132 return false
133}
134
135func (mod *Module) SetPreventInstall() {
136 mod.Properties.PreventInstall = true
137}
138
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500139func (mod *Module) SetHideFromMake() {
140 mod.Properties.HideFromMake = true
141}
142
143func (mod *Module) SanitizePropDefined() bool {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500144 // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
145 // nil since we need compiler to actually sanitize.
146 return mod.sanitize != nil && mod.compiler != nil
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500147}
148
149func (mod *Module) IsDependencyRoot() bool {
150 if mod.compiler != nil {
151 return mod.compiler.isDependencyRoot()
152 }
153 panic("IsDependencyRoot called on a non-compiler Rust module")
154}
155
156func (mod *Module) IsPrebuilt() bool {
157 if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
158 return true
159 }
160 return false
161}
162
Ivan Lozano43845682020-07-09 21:03:28 -0400163func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
164 switch tag {
165 case "":
Andrei Homescu5db69cc2020-08-06 15:27:45 -0700166 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
Ivan Lozano43845682020-07-09 21:03:28 -0400167 return mod.sourceProvider.Srcs(), nil
168 } else {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900169 if mod.OutputFile().Valid() {
170 return android.Paths{mod.OutputFile().Path()}, nil
Ivan Lozano43845682020-07-09 21:03:28 -0400171 }
172 return android.Paths{}, nil
173 }
174 default:
175 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
176 }
177}
178
Ivan Lozano52767be2019-10-18 14:49:46 -0700179func (mod *Module) SelectedStl() string {
180 return ""
181}
182
Ivan Lozano2b262972019-11-21 12:30:50 -0800183func (mod *Module) NonCcVariants() bool {
184 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400185 if _, ok := mod.compiler.(libraryInterface); ok {
186 return false
Ivan Lozano2b262972019-11-21 12:30:50 -0800187 }
188 }
189 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
190}
191
Ivan Lozano52767be2019-10-18 14:49:46 -0700192func (mod *Module) Static() bool {
193 if mod.compiler != nil {
194 if library, ok := mod.compiler.(libraryInterface); ok {
195 return library.static()
196 }
197 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400198 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700199}
200
201func (mod *Module) Shared() bool {
202 if mod.compiler != nil {
203 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400204 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700205 }
206 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400207 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700208}
209
210func (mod *Module) Toc() android.OptionalPath {
211 if mod.compiler != nil {
212 if _, ok := mod.compiler.(libraryInterface); ok {
213 return android.OptionalPath{}
214 }
215 }
216 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
217}
218
Colin Crossc511bc52020-04-07 16:50:32 +0000219func (mod *Module) UseSdk() bool {
220 return false
221}
222
Ivan Lozano6a884432020-12-02 09:15:16 -0500223// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
224// "product" and "vendor" variant modules return true for this function.
225// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
226// "soc_specific: true" and more vendor installed modules are included here.
227// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
228// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700229func (mod *Module) UseVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500230 return mod.Properties.VndkVersion != ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700231}
232
233func (mod *Module) MustUseVendorVariant() bool {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400234 return true
235}
236
237func (mod *Module) SubName() string {
238 return mod.Properties.SubName
Ivan Lozano52767be2019-10-18 14:49:46 -0700239}
240
241func (mod *Module) IsVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500242 // TODO(b/165791368)
Ivan Lozano52767be2019-10-18 14:49:46 -0700243 return false
244}
245
Ivan Lozanof9e21722020-12-02 09:00:51 -0500246func (mod *Module) IsVndkExt() bool {
247 return false
248}
249
Colin Cross127bb8b2020-12-16 16:46:01 -0800250func (c *Module) IsVndkPrivate() bool {
251 return false
252}
253
254func (c *Module) IsLlndk() bool {
255 return false
256}
257
258func (c *Module) IsLlndkPublic() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500259 return false
260}
261
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400262func (m *Module) IsLlndkHeaders() bool {
263 return false
264}
265
266func (m *Module) IsLlndkLibrary() bool {
267 return false
268}
269
270func (mod *Module) KernelHeadersDecorator() bool {
271 return false
272}
273
274func (m *Module) HasLlndkStubs() bool {
275 return false
276}
277
Ivan Lozano52767be2019-10-18 14:49:46 -0700278func (mod *Module) SdkVersion() string {
279 return ""
280}
281
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900282func (mod *Module) MinSdkVersion() string {
283 return ""
284}
285
Colin Crossc511bc52020-04-07 16:50:32 +0000286func (mod *Module) AlwaysSdk() bool {
287 return false
288}
289
Jiyong Park2286afd2020-06-16 21:58:53 +0900290func (mod *Module) IsSdkVariant() bool {
291 return false
292}
293
Colin Cross1348ce32020-10-01 13:37:16 -0700294func (mod *Module) SplitPerApiLevel() bool {
295 return false
296}
297
Ivan Lozanoffee3342019-08-27 12:03:00 -0700298type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400299 Dylibs []string
300 Rlibs []string
301 Rustlibs []string
302 Stdlibs []string
303 ProcMacros []string
304 SharedLibs []string
305 StaticLibs []string
306 WholeStaticLibs []string
307 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700308
309 CrtBegin, CrtEnd string
310}
311
312type PathDeps struct {
Ivan Lozanoec6e9912021-01-21 15:23:29 -0500313 DyLibs RustLibraries
314 RLibs RustLibraries
315 SharedLibs android.Paths
316 SharedLibDeps android.Paths
317 StaticLibs android.Paths
318 ProcMacros RustLibraries
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500319
320 // depFlags and depLinkFlags are rustc and linker (clang) flags.
321 depFlags []string
322 depLinkFlags []string
323
324 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
325 // Both of these are exported and propagate to dependencies.
326 linkDirs []string
327 linkObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700328
Ivan Lozano45901ed2020-07-24 16:05:01 -0400329 // Used by bindgen modules which call clang
330 depClangFlags []string
331 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400332 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400333 depSystemIncludePaths android.Paths
334
Ivan Lozanof1c84332019-09-20 11:00:37 -0700335 CrtBegin android.OptionalPath
336 CrtEnd android.OptionalPath
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700337
338 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500339 SrcDeps android.Paths
340 srcProviderFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700341}
342
343type RustLibraries []RustLibrary
344
345type RustLibrary struct {
346 Path android.Path
347 CrateName string
348}
349
350type compiler interface {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100351 initialize(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700352 compilerFlags(ctx ModuleContext, flags Flags) Flags
353 compilerProps() []interface{}
354 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
355 compilerDeps(ctx DepsContext, deps Deps) Deps
356 crateName() string
357
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100358 // Output directory in which source-generated code from dependencies is
359 // copied. This is equivalent to Cargo's OUT_DIR variable.
360 CargoOutDir() android.OptionalPath
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800361 inData() bool
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200362 install(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700363 relativeInstallPath() string
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400364
365 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400366
367 Disabled() bool
368 SetDisabled()
Ivan Lozano042504f2020-08-18 14:31:23 -0400369
Ivan Lozanodd055472020-09-28 13:22:45 -0400370 stdLinkage(ctx *depsContext) RustLinkage
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500371 isDependencyRoot() bool
Jiyong Parke54f07e2021-04-07 15:08:04 +0900372
373 strippedOutputFilePath() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400374}
375
Matthew Maurerbb3add12020-06-25 09:34:12 -0700376type exportedFlagsProducer interface {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700377 exportLinkDirs(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400378 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700379}
380
381type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400382 linkDirs []string
383 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700384}
385
Matthew Maurerbb3add12020-06-25 09:34:12 -0700386func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
387 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
388}
389
Ivan Lozano2093af22020-08-25 12:48:19 -0400390func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
391 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
392}
393
Colin Cross0de8a1e2020-09-18 14:15:30 -0700394func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
395 ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700396 LinkDirs: flagExporter.linkDirs,
397 LinkObjects: flagExporter.linkObjects,
398 })
399}
400
Matthew Maurerbb3add12020-06-25 09:34:12 -0700401var _ exportedFlagsProducer = (*flagExporter)(nil)
402
403func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700404 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700405}
406
Colin Cross0de8a1e2020-09-18 14:15:30 -0700407type FlagExporterInfo struct {
408 Flags []string
409 LinkDirs []string // TODO: this should be android.Paths
410 LinkObjects []string // TODO: this should be android.Paths
411}
412
413var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
414
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400415func (mod *Module) isCoverageVariant() bool {
416 return mod.coverage.Properties.IsCoverageVariant
417}
418
419var _ cc.Coverage = (*Module)(nil)
420
421func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
422 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
423}
424
425func (mod *Module) PreventInstall() {
426 mod.Properties.PreventInstall = true
427}
428
429func (mod *Module) HideFromMake() {
430 mod.Properties.HideFromMake = true
431}
432
433func (mod *Module) MarkAsCoverageVariant(coverage bool) {
434 mod.coverage.Properties.IsCoverageVariant = coverage
435}
436
437func (mod *Module) EnableCoverageIfNeeded() {
438 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700439}
440
441func defaultsFactory() android.Module {
442 return DefaultsFactory()
443}
444
445type Defaults struct {
446 android.ModuleBase
447 android.DefaultsModuleBase
448}
449
450func DefaultsFactory(props ...interface{}) android.Module {
451 module := &Defaults{}
452
453 module.AddProperties(props...)
454 module.AddProperties(
455 &BaseProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500456 &cc.VendorProperties{},
Jakub Kotur1d640d02021-01-06 12:40:43 +0100457 &BenchmarkProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400458 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700459 &BaseCompilerProperties{},
460 &BinaryCompilerProperties{},
461 &LibraryCompilerProperties{},
462 &ProcMacroCompilerProperties{},
463 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400464 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700465 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400466 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400467 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200468 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500469 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700470 )
471
472 android.InitDefaultsModule(module)
473 return module
474}
475
476func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700477 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700478}
479
Ivan Lozano183a3212019-10-18 14:18:45 -0700480func (mod *Module) CcLibrary() bool {
481 if mod.compiler != nil {
482 if _, ok := mod.compiler.(*libraryDecorator); ok {
483 return true
484 }
485 }
486 return false
487}
488
489func (mod *Module) CcLibraryInterface() bool {
490 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400491 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
492 // VariantIs{Static,Shared} is set.
493 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700494 return true
495 }
496 }
497 return false
498}
499
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800500func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700501 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700502 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800503 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700504 }
505 }
506 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
507}
508
509func (mod *Module) SetStatic() {
510 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700511 if library, ok := mod.compiler.(libraryInterface); ok {
512 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700513 return
514 }
515 }
516 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
517}
518
519func (mod *Module) SetShared() {
520 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700521 if library, ok := mod.compiler.(libraryInterface); ok {
522 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700523 return
524 }
525 }
526 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
527}
528
Ivan Lozano183a3212019-10-18 14:18:45 -0700529func (mod *Module) BuildStaticVariant() bool {
530 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700531 if library, ok := mod.compiler.(libraryInterface); ok {
532 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700533 }
534 }
535 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
536}
537
538func (mod *Module) BuildSharedVariant() bool {
539 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700540 if library, ok := mod.compiler.(libraryInterface); ok {
541 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700542 }
543 }
544 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
545}
546
Ivan Lozano183a3212019-10-18 14:18:45 -0700547func (mod *Module) Module() android.Module {
548 return mod
549}
550
Ivan Lozano183a3212019-10-18 14:18:45 -0700551func (mod *Module) OutputFile() android.OptionalPath {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900552 if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() {
553 return mod.compiler.strippedOutputFilePath()
554 }
555 return mod.unstrippedOutputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700556}
557
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400558func (mod *Module) CoverageFiles() android.Paths {
559 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800560 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400561 }
562 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
563}
564
Jiyong Park459feca2020-12-15 11:02:21 +0900565func (mod *Module) installable(apexInfo android.ApexInfo) bool {
566 // The apex variant is not installable because it is included in the APEX and won't appear
567 // in the system partition as a standalone file.
568 if !apexInfo.IsForPlatform() {
569 return false
570 }
571
Jiyong Parke54f07e2021-04-07 15:08:04 +0900572 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900573}
574
Ivan Lozano183a3212019-10-18 14:18:45 -0700575var _ cc.LinkableInterface = (*Module)(nil)
576
Ivan Lozanoffee3342019-08-27 12:03:00 -0700577func (mod *Module) Init() android.Module {
578 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500579 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700580
581 if mod.compiler != nil {
582 mod.AddProperties(mod.compiler.compilerProps()...)
583 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400584 if mod.coverage != nil {
585 mod.AddProperties(mod.coverage.props()...)
586 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200587 if mod.clippy != nil {
588 mod.AddProperties(mod.clippy.props()...)
589 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400590 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700591 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400592 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500593 if mod.sanitize != nil {
594 mod.AddProperties(mod.sanitize.props()...)
595 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400596
Ivan Lozanoffee3342019-08-27 12:03:00 -0700597 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900598 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700599
600 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700601 return mod
602}
603
604func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
605 return &Module{
606 hod: hod,
607 multilib: multilib,
608 }
609}
610func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
611 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400612 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200613 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500614 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700615 return module
616}
617
618type ModuleContext interface {
619 android.ModuleContext
620 ModuleContextIntf
621}
622
623type BaseModuleContext interface {
624 android.BaseModuleContext
625 ModuleContextIntf
626}
627
628type DepsContext interface {
629 android.BottomUpMutatorContext
630 ModuleContextIntf
631}
632
633type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200634 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700635 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700636}
637
638type depsContext struct {
639 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700640}
641
642type moduleContext struct {
643 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700644}
645
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200646type baseModuleContext struct {
647 android.BaseModuleContext
648}
649
650func (ctx *moduleContext) RustModule() *Module {
651 return ctx.Module().(*Module)
652}
653
654func (ctx *moduleContext) toolchain() config.Toolchain {
655 return ctx.RustModule().toolchain(ctx)
656}
657
658func (ctx *depsContext) RustModule() *Module {
659 return ctx.Module().(*Module)
660}
661
662func (ctx *depsContext) toolchain() config.Toolchain {
663 return ctx.RustModule().toolchain(ctx)
664}
665
666func (ctx *baseModuleContext) RustModule() *Module {
667 return ctx.Module().(*Module)
668}
669
670func (ctx *baseModuleContext) toolchain() config.Toolchain {
671 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400672}
673
674func (mod *Module) nativeCoverage() bool {
675 return mod.compiler != nil && mod.compiler.nativeCoverage()
676}
677
Ivan Lozanoffee3342019-08-27 12:03:00 -0700678func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
679 if mod.cachedToolchain == nil {
680 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
681 }
682 return mod.cachedToolchain
683}
684
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200685func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
686 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
687}
688
Ivan Lozanoffee3342019-08-27 12:03:00 -0700689func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
690}
691
692func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
693 ctx := &moduleContext{
694 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700695 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700696
Jiyong Park99644e92020-11-17 22:21:02 +0900697 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
698 if !apexInfo.IsForPlatform() {
699 mod.hideApexVariantFromMake = true
700 }
701
Ivan Lozanoffee3342019-08-27 12:03:00 -0700702 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500703 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
704
705 // Differentiate static libraries that are vendor available
706 if mod.UseVndk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500707 mod.Properties.SubName += cc.VendorSuffix
708 } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
709 mod.Properties.SubName += cc.VendorRamdiskSuffix
Ivan Lozano6a884432020-12-02 09:15:16 -0500710 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700711
712 if !toolchain.Supported() {
713 // This toolchain's unsupported, there's nothing to do for this mod.
714 return
715 }
716
717 deps := mod.depsToPaths(ctx)
718 flags := Flags{
719 Toolchain: toolchain,
720 }
721
722 if mod.compiler != nil {
723 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400724 }
725 if mod.coverage != nil {
726 flags, deps = mod.coverage.flags(ctx, flags, deps)
727 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200728 if mod.clippy != nil {
729 flags, deps = mod.clippy.flags(ctx, flags, deps)
730 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500731 if mod.sanitize != nil {
732 flags, deps = mod.sanitize.flags(ctx, flags, deps)
733 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400734
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200735 // SourceProvider needs to call GenerateSource() before compiler calls
736 // compile() so it can provide the source. A SourceProvider has
737 // multiple variants (e.g. source, rlib, dylib). Only the "source"
738 // variant is responsible for effectively generating the source. The
739 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400740 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200741 if mod.compiler.(libraryInterface).source() {
742 mod.sourceProvider.GenerateSource(ctx, deps)
743 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
744 } else {
745 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
746 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700747 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200748 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400749 }
750
751 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100752 mod.compiler.initialize(ctx)
Jiyong Parke54f07e2021-04-07 15:08:04 +0900753 unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400754
Jiyong Parke54f07e2021-04-07 15:08:04 +0900755 mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
Jiyong Park459feca2020-12-15 11:02:21 +0900756
757 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
758 if mod.installable(apexInfo) {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200759 mod.compiler.install(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400760 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700761 }
762}
763
764func (mod *Module) deps(ctx DepsContext) Deps {
765 deps := Deps{}
766
767 if mod.compiler != nil {
768 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400769 }
770 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700771 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700772 }
773
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400774 if mod.coverage != nil {
775 deps = mod.coverage.deps(ctx, deps)
776 }
777
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500778 if mod.sanitize != nil {
779 deps = mod.sanitize.deps(ctx, deps)
780 }
781
Ivan Lozanoffee3342019-08-27 12:03:00 -0700782 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
783 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700784 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700785 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
786 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
787 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400788 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700789 return deps
790
791}
792
Ivan Lozanoffee3342019-08-27 12:03:00 -0700793type dependencyTag struct {
794 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800795 name string
796 library bool
797 procMacro bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700798}
799
Jiyong Park65b62242020-11-25 12:44:59 +0900800// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
801// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
802func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800803 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +0900804}
805
806var _ android.InstallNeededDependencyTag = dependencyTag{}
807
Ivan Lozanoffee3342019-08-27 12:03:00 -0700808var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400809 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
810 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
811 dylibDepTag = dependencyTag{name: "dylib", library: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800812 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400813 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200814 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700815)
816
Jiyong Park99644e92020-11-17 22:21:02 +0900817func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
818 tag, ok := depTag.(dependencyTag)
819 return ok && tag == dylibDepTag
820}
821
Jiyong Park94e22fd2021-04-08 18:19:15 +0900822func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
823 tag, ok := depTag.(dependencyTag)
824 return ok && tag == rlibDepTag
825}
826
Matthew Maurer0f003b12020-06-29 14:34:06 -0700827type autoDep struct {
828 variation string
829 depTag dependencyTag
830}
831
832var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200833 rlibVariation = "rlib"
834 dylibVariation = "dylib"
835 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
836 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -0700837)
838
839type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -0500840 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -0700841}
842
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400843func (mod *Module) begin(ctx BaseModuleContext) {
844 if mod.coverage != nil {
845 mod.coverage.begin(ctx)
846 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500847 if mod.sanitize != nil {
848 mod.sanitize.begin(ctx)
849 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400850}
851
Ivan Lozanoffee3342019-08-27 12:03:00 -0700852func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
853 var depPaths PathDeps
854
855 directRlibDeps := []*Module{}
856 directDylibDeps := []*Module{}
857 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700858 directSharedLibDeps := [](cc.LinkableInterface){}
859 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400860 directSrcProvidersDeps := []*Module{}
861 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700862
863 ctx.VisitDirectDeps(func(dep android.Module) {
864 depName := ctx.OtherModuleName(dep)
865 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400866
Ivan Lozano89435d12020-07-31 11:01:18 -0400867 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700868 //Handle Rust Modules
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400869 makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -0700870
Ivan Lozanoffee3342019-08-27 12:03:00 -0700871 switch depTag {
872 case dylibDepTag:
873 dylib, ok := rustDep.compiler.(libraryInterface)
874 if !ok || !dylib.dylib() {
875 ctx.ModuleErrorf("mod %q not an dylib library", depName)
876 return
877 }
878 directDylibDeps = append(directDylibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400879 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700880 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -0400881
Ivan Lozanoffee3342019-08-27 12:03:00 -0700882 rlib, ok := rustDep.compiler.(libraryInterface)
883 if !ok || !rlib.rlib() {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400884 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700885 return
886 }
887 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400888 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700889 case procMacroDepTag:
890 directProcMacroDeps = append(directProcMacroDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400891 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400892 case android.SourceDepTag:
893 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
894 // OS/Arch variant is used.
895 var helper string
896 if ctx.Host() {
897 helper = "missing 'host_supported'?"
898 } else {
899 helper = "device module defined?"
900 }
901
902 if dep.Target().Os != ctx.Os() {
903 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
904 return
905 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
906 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
907 return
908 }
909 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700910 }
911
Ivan Lozano2bbcacf2020-08-07 09:00:50 -0400912 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700913 if depTag != procMacroDepTag {
914 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
915 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
916 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
917 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700918 }
919
Ivan Lozanoffee3342019-08-27 12:03:00 -0700920 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900921 linkFile := rustDep.unstrippedOutputFile
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400922 if !linkFile.Valid() {
923 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
924 depName, ctx.ModuleName())
925 return
926 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700927 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700928 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
929 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700930 }
931 }
932
Ivan Lozano89435d12020-07-31 11:01:18 -0400933 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -0700934 //Handle C dependencies
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400935 makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
Ivan Lozano52767be2019-10-18 14:49:46 -0700936 if _, ok := ccDep.(*Module); !ok {
937 if ccDep.Module().Target().Os != ctx.Os() {
938 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
939 return
940 }
941 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
942 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
943 return
944 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700945 }
Ivan Lozano2093af22020-08-25 12:48:19 -0400946 linkObject := ccDep.OutputFile()
947 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500948
Ivan Lozano2093af22020-08-25 12:48:19 -0400949 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700950 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
951 }
952
953 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700954 switch {
955 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -0400956 if cc.IsWholeStaticLib(depTag) {
957 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
958 // if the library is not prefixed by "lib".
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500959 if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
960 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400961 } else {
962 ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName())
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500963 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500964 }
965
966 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
967 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -0400968 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500969 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
970
Colin Cross0de8a1e2020-09-18 14:15:30 -0700971 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
972 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
973 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
974 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
975 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700976 directStaticLibDeps = append(directStaticLibDeps, ccDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400977 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -0700978 case cc.IsSharedDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700979 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400980 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -0700981 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
982 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
983 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
984 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
985 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700986 directSharedLibDeps = append(directSharedLibDeps, ccDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400987 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700988 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -0800989 case cc.IsHeaderDepTag(depTag):
990 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
991 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
992 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
993 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -0700994 case depTag == cc.CrtBeginDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400995 depPaths.CrtBegin = linkObject
Colin Cross6e511a92020-07-27 21:26:48 -0700996 case depTag == cc.CrtEndDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400997 depPaths.CrtEnd = linkObject
Ivan Lozanoffee3342019-08-27 12:03:00 -0700998 }
999
1000 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001001 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1002 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001003 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001004 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001005 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001006
1007 if srcDep, ok := dep.(android.SourceFileProducer); ok {
1008 switch depTag {
1009 case android.SourceDepTag:
1010 // These are usually genrules which don't have per-target variants.
1011 directSrcDeps = append(directSrcDeps, srcDep)
1012 }
1013 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001014 })
1015
1016 var rlibDepFiles RustLibraries
1017 for _, dep := range directRlibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001018 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001019 }
1020 var dylibDepFiles RustLibraries
1021 for _, dep := range directDylibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001022 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001023 }
1024 var procMacroDepFiles RustLibraries
1025 for _, dep := range directProcMacroDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001026 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001027 }
1028
1029 var staticLibDepFiles android.Paths
1030 for _, dep := range directStaticLibDeps {
1031 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1032 }
1033
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001034 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001035 var sharedLibDepFiles android.Paths
1036 for _, dep := range directSharedLibDeps {
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001037 sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path())
1038 if dep.Toc().Valid() {
1039 sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path())
1040 } else {
1041 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
1042 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001043 }
1044
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001045 var srcProviderDepFiles android.Paths
1046 for _, dep := range directSrcProvidersDeps {
1047 srcs, _ := dep.OutputFiles("")
1048 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1049 }
1050 for _, dep := range directSrcDeps {
1051 srcs := dep.Srcs()
1052 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1053 }
1054
Ivan Lozanoffee3342019-08-27 12:03:00 -07001055 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1056 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1057 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001058 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001059 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1060 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001061 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001062
1063 // Dedup exported flags from dependencies
1064 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001065 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001066 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001067 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1068 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1069 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001070
1071 return depPaths
1072}
1073
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001074func (mod *Module) InstallInData() bool {
1075 if mod.compiler == nil {
1076 return false
1077 }
1078 return mod.compiler.inData()
1079}
1080
Ivan Lozanoffee3342019-08-27 12:03:00 -07001081func linkPathFromFilePath(filepath android.Path) string {
1082 return strings.Split(filepath.String(), filepath.Base())[0]
1083}
Ivan Lozanod648c432020-02-06 12:05:10 -05001084
Ivan Lozanoffee3342019-08-27 12:03:00 -07001085func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1086 ctx := &depsContext{
1087 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001088 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001089
1090 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001091 var commonDepVariations []blueprint.Variation
Ivan Lozanodd055472020-09-28 13:22:45 -04001092
Ivan Lozano2b081132020-09-08 12:46:52 -04001093 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001094 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001095 stdLinkage = "rlib-std"
1096 }
1097
1098 rlibDepVariations := commonDepVariations
1099 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1100 rlibDepVariations = append(rlibDepVariations,
1101 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1102 }
1103
Ivan Lozano52767be2019-10-18 14:49:46 -07001104 actx.AddVariationDependencies(
Ivan Lozano2b081132020-09-08 12:46:52 -04001105 append(rlibDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001106 {Mutator: "rust_libraries", Variation: rlibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001107 rlibDepTag, deps.Rlibs...)
1108 actx.AddVariationDependencies(
1109 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001110 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001111 dylibDepTag, deps.Dylibs...)
1112
Ivan Lozano042504f2020-08-18 14:31:23 -04001113 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1114 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2b081132020-09-08 12:46:52 -04001115 if autoDep.depTag == rlibDepTag {
1116 actx.AddVariationDependencies(
1117 append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1118 autoDep.depTag, deps.Rustlibs...)
1119 } else {
1120 actx.AddVariationDependencies(
1121 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1122 autoDep.depTag, deps.Rustlibs...)
1123 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001124 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001125 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001126 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001127 actx.AddVariationDependencies(
1128 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
1129 rlibDepTag, deps.Stdlibs...)
1130 } else {
1131 actx.AddVariationDependencies(
1132 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1133 dylibDepTag, deps.Stdlibs...)
1134 }
1135 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001136 actx.AddVariationDependencies(append(commonDepVariations,
1137 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001138 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -07001139 actx.AddVariationDependencies(append(commonDepVariations,
1140 blueprint.Variation{Mutator: "link", Variation: "static"}),
Ivan Lozano63bb7682021-03-23 15:53:44 -04001141 cc.StaticDepTag(false), deps.StaticLibs...)
1142 actx.AddVariationDependencies(append(commonDepVariations,
1143 blueprint.Variation{Mutator: "link", Variation: "static"}),
1144 cc.StaticDepTag(true), deps.WholeStaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001145
Zach Johnson3df4e632020-11-06 11:56:27 -08001146 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1147
Colin Cross565cafd2020-09-25 18:47:38 -07001148 crtVariations := cc.GetCrtVariations(ctx, mod)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001149 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001150 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001151 }
1152 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001153 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001154 }
1155
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001156 if mod.sourceProvider != nil {
1157 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1158 bindgen.Properties.Custom_bindgen != "" {
1159 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1160 bindgen.Properties.Custom_bindgen)
1161 }
1162 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001163 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001164 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001165}
1166
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001167func BeginMutator(ctx android.BottomUpMutatorContext) {
1168 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1169 mod.beginMutator(ctx)
1170 }
1171}
1172
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001173func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1174 ctx := &baseModuleContext{
1175 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001176 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001177
1178 mod.begin(ctx)
1179}
1180
Ivan Lozanoffee3342019-08-27 12:03:00 -07001181func (mod *Module) Name() string {
1182 name := mod.ModuleBase.Name()
1183 if p, ok := mod.compiler.(interface {
1184 Name(string) string
1185 }); ok {
1186 name = p.Name(name)
1187 }
1188 return name
1189}
1190
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001191func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001192 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001193 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001194 }
1195}
1196
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001197var _ android.HostToolProvider = (*Module)(nil)
1198
1199func (mod *Module) HostToolPath() android.OptionalPath {
1200 if !mod.Host() {
1201 return android.OptionalPath{}
1202 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001203 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1204 return android.OptionalPathForPath(binary.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001205 }
1206 return android.OptionalPath{}
1207}
1208
Jiyong Park99644e92020-11-17 22:21:02 +09001209var _ android.ApexModule = (*Module)(nil)
1210
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001211func (mod *Module) minSdkVersion() string {
1212 return String(mod.Properties.Min_sdk_version)
1213}
1214
Jiyong Park45bf82e2020-12-15 22:29:02 +09001215var _ android.ApexModule = (*Module)(nil)
1216
1217// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001218func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001219 minSdkVersion := mod.minSdkVersion()
1220 if minSdkVersion == "apex_inherit" {
1221 return nil
1222 }
1223 if minSdkVersion == "" {
1224 return fmt.Errorf("min_sdk_version is not specificed")
1225 }
1226
1227 // Not using nativeApiLevelFromUser because the context here is not
1228 // necessarily a native context.
1229 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1230 if err != nil {
1231 return err
1232 }
1233
1234 if ver.GreaterThan(sdkVersion) {
1235 return fmt.Errorf("newer SDK(%v)", ver)
1236 }
Jiyong Park99644e92020-11-17 22:21:02 +09001237 return nil
1238}
1239
Jiyong Park45bf82e2020-12-15 22:29:02 +09001240// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001241func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1242 depTag := ctx.OtherModuleDependencyTag(dep)
1243
1244 if ccm, ok := dep.(*cc.Module); ok {
1245 if ccm.HasStubsVariants() {
1246 if cc.IsSharedDepTag(depTag) {
1247 // dynamic dep to a stubs lib crosses APEX boundary
1248 return false
1249 }
1250 if cc.IsRuntimeDepTag(depTag) {
1251 // runtime dep to a stubs lib also crosses APEX boundary
1252 return false
1253 }
1254
1255 if cc.IsHeaderDepTag(depTag) {
1256 return false
1257 }
1258 }
1259 if mod.Static() && cc.IsSharedDepTag(depTag) {
1260 // shared_lib dependency from a static lib is considered as crossing
1261 // the APEX boundary because the dependency doesn't actually is
1262 // linked; the dependency is used only during the compilation phase.
1263 return false
1264 }
1265 }
1266
1267 if depTag == procMacroDepTag {
1268 return false
1269 }
1270
1271 return true
1272}
1273
1274// Overrides ApexModule.IsInstallabeToApex()
1275func (mod *Module) IsInstallableToApex() bool {
1276 if mod.compiler != nil {
1277 if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) {
1278 return true
1279 }
1280 if _, ok := mod.compiler.(*binaryDecorator); ok {
1281 return true
1282 }
1283 }
1284 return false
1285}
1286
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001287// If a library file has a "lib" prefix, extract the library name without the prefix.
1288func libNameFromFilePath(filepath android.Path) (string, bool) {
1289 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1290 if strings.HasPrefix(libName, "lib") {
1291 libName = libName[3:]
1292 return libName, true
1293 }
1294 return "", false
1295}
1296
Ivan Lozanoffee3342019-08-27 12:03:00 -07001297var Bool = proptools.Bool
1298var BoolDefault = proptools.BoolDefault
1299var String = proptools.String
1300var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001301
1302var _ android.OutputFileProducer = (*Module)(nil)