blob: abe25a4a8c20d7ec13dfd918d0fbfdfd9e25c3ce [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{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400457 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700458 &BaseCompilerProperties{},
459 &BinaryCompilerProperties{},
460 &LibraryCompilerProperties{},
461 &ProcMacroCompilerProperties{},
462 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400463 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700464 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400465 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400466 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200467 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500468 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700469 )
470
471 android.InitDefaultsModule(module)
472 return module
473}
474
475func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700476 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700477}
478
Ivan Lozano183a3212019-10-18 14:18:45 -0700479func (mod *Module) CcLibrary() bool {
480 if mod.compiler != nil {
481 if _, ok := mod.compiler.(*libraryDecorator); ok {
482 return true
483 }
484 }
485 return false
486}
487
488func (mod *Module) CcLibraryInterface() bool {
489 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400490 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
491 // VariantIs{Static,Shared} is set.
492 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700493 return true
494 }
495 }
496 return false
497}
498
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800499func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700500 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700501 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800502 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700503 }
504 }
505 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
506}
507
508func (mod *Module) SetStatic() {
509 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700510 if library, ok := mod.compiler.(libraryInterface); ok {
511 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700512 return
513 }
514 }
515 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
516}
517
518func (mod *Module) SetShared() {
519 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700520 if library, ok := mod.compiler.(libraryInterface); ok {
521 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700522 return
523 }
524 }
525 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
526}
527
Ivan Lozano183a3212019-10-18 14:18:45 -0700528func (mod *Module) BuildStaticVariant() bool {
529 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700530 if library, ok := mod.compiler.(libraryInterface); ok {
531 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700532 }
533 }
534 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
535}
536
537func (mod *Module) BuildSharedVariant() bool {
538 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700539 if library, ok := mod.compiler.(libraryInterface); ok {
540 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700541 }
542 }
543 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
544}
545
Ivan Lozano183a3212019-10-18 14:18:45 -0700546func (mod *Module) Module() android.Module {
547 return mod
548}
549
Ivan Lozano183a3212019-10-18 14:18:45 -0700550func (mod *Module) OutputFile() android.OptionalPath {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900551 if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() {
552 return mod.compiler.strippedOutputFilePath()
553 }
554 return mod.unstrippedOutputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700555}
556
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400557func (mod *Module) CoverageFiles() android.Paths {
558 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800559 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400560 }
561 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
562}
563
Jiyong Park459feca2020-12-15 11:02:21 +0900564func (mod *Module) installable(apexInfo android.ApexInfo) bool {
565 // The apex variant is not installable because it is included in the APEX and won't appear
566 // in the system partition as a standalone file.
567 if !apexInfo.IsForPlatform() {
568 return false
569 }
570
Jiyong Parke54f07e2021-04-07 15:08:04 +0900571 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900572}
573
Ivan Lozano183a3212019-10-18 14:18:45 -0700574var _ cc.LinkableInterface = (*Module)(nil)
575
Ivan Lozanoffee3342019-08-27 12:03:00 -0700576func (mod *Module) Init() android.Module {
577 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500578 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700579
580 if mod.compiler != nil {
581 mod.AddProperties(mod.compiler.compilerProps()...)
582 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400583 if mod.coverage != nil {
584 mod.AddProperties(mod.coverage.props()...)
585 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200586 if mod.clippy != nil {
587 mod.AddProperties(mod.clippy.props()...)
588 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400589 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700590 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400591 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500592 if mod.sanitize != nil {
593 mod.AddProperties(mod.sanitize.props()...)
594 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400595
Ivan Lozanoffee3342019-08-27 12:03:00 -0700596 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900597 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700598
599 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700600 return mod
601}
602
603func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
604 return &Module{
605 hod: hod,
606 multilib: multilib,
607 }
608}
609func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
610 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400611 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200612 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500613 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700614 return module
615}
616
617type ModuleContext interface {
618 android.ModuleContext
619 ModuleContextIntf
620}
621
622type BaseModuleContext interface {
623 android.BaseModuleContext
624 ModuleContextIntf
625}
626
627type DepsContext interface {
628 android.BottomUpMutatorContext
629 ModuleContextIntf
630}
631
632type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200633 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700634 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700635}
636
637type depsContext struct {
638 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700639}
640
641type moduleContext struct {
642 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700643}
644
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200645type baseModuleContext struct {
646 android.BaseModuleContext
647}
648
649func (ctx *moduleContext) RustModule() *Module {
650 return ctx.Module().(*Module)
651}
652
653func (ctx *moduleContext) toolchain() config.Toolchain {
654 return ctx.RustModule().toolchain(ctx)
655}
656
657func (ctx *depsContext) RustModule() *Module {
658 return ctx.Module().(*Module)
659}
660
661func (ctx *depsContext) toolchain() config.Toolchain {
662 return ctx.RustModule().toolchain(ctx)
663}
664
665func (ctx *baseModuleContext) RustModule() *Module {
666 return ctx.Module().(*Module)
667}
668
669func (ctx *baseModuleContext) toolchain() config.Toolchain {
670 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400671}
672
673func (mod *Module) nativeCoverage() bool {
674 return mod.compiler != nil && mod.compiler.nativeCoverage()
675}
676
Ivan Lozanoffee3342019-08-27 12:03:00 -0700677func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
678 if mod.cachedToolchain == nil {
679 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
680 }
681 return mod.cachedToolchain
682}
683
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200684func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
685 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
686}
687
Ivan Lozanoffee3342019-08-27 12:03:00 -0700688func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
689}
690
691func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
692 ctx := &moduleContext{
693 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700694 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700695
Jiyong Park99644e92020-11-17 22:21:02 +0900696 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
697 if !apexInfo.IsForPlatform() {
698 mod.hideApexVariantFromMake = true
699 }
700
Ivan Lozanoffee3342019-08-27 12:03:00 -0700701 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500702 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
703
704 // Differentiate static libraries that are vendor available
705 if mod.UseVndk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500706 mod.Properties.SubName += cc.VendorSuffix
707 } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
708 mod.Properties.SubName += cc.VendorRamdiskSuffix
Ivan Lozano6a884432020-12-02 09:15:16 -0500709 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700710
711 if !toolchain.Supported() {
712 // This toolchain's unsupported, there's nothing to do for this mod.
713 return
714 }
715
716 deps := mod.depsToPaths(ctx)
717 flags := Flags{
718 Toolchain: toolchain,
719 }
720
721 if mod.compiler != nil {
722 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400723 }
724 if mod.coverage != nil {
725 flags, deps = mod.coverage.flags(ctx, flags, deps)
726 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200727 if mod.clippy != nil {
728 flags, deps = mod.clippy.flags(ctx, flags, deps)
729 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500730 if mod.sanitize != nil {
731 flags, deps = mod.sanitize.flags(ctx, flags, deps)
732 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400733
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200734 // SourceProvider needs to call GenerateSource() before compiler calls
735 // compile() so it can provide the source. A SourceProvider has
736 // multiple variants (e.g. source, rlib, dylib). Only the "source"
737 // variant is responsible for effectively generating the source. The
738 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400739 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200740 if mod.compiler.(libraryInterface).source() {
741 mod.sourceProvider.GenerateSource(ctx, deps)
742 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
743 } else {
744 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
745 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700746 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200747 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400748 }
749
750 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100751 mod.compiler.initialize(ctx)
Jiyong Parke54f07e2021-04-07 15:08:04 +0900752 unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400753
Jiyong Parke54f07e2021-04-07 15:08:04 +0900754 mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
Jiyong Park459feca2020-12-15 11:02:21 +0900755
756 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
757 if mod.installable(apexInfo) {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200758 mod.compiler.install(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400759 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700760 }
761}
762
763func (mod *Module) deps(ctx DepsContext) Deps {
764 deps := Deps{}
765
766 if mod.compiler != nil {
767 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400768 }
769 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700770 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700771 }
772
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400773 if mod.coverage != nil {
774 deps = mod.coverage.deps(ctx, deps)
775 }
776
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500777 if mod.sanitize != nil {
778 deps = mod.sanitize.deps(ctx, deps)
779 }
780
Ivan Lozanoffee3342019-08-27 12:03:00 -0700781 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
782 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700783 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700784 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
785 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
786 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400787 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700788 return deps
789
790}
791
Ivan Lozanoffee3342019-08-27 12:03:00 -0700792type dependencyTag struct {
793 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800794 name string
795 library bool
796 procMacro bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700797}
798
Jiyong Park65b62242020-11-25 12:44:59 +0900799// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
800// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
801func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800802 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +0900803}
804
805var _ android.InstallNeededDependencyTag = dependencyTag{}
806
Ivan Lozanoffee3342019-08-27 12:03:00 -0700807var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400808 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
809 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
810 dylibDepTag = dependencyTag{name: "dylib", library: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800811 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400812 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200813 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700814)
815
Jiyong Park99644e92020-11-17 22:21:02 +0900816func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
817 tag, ok := depTag.(dependencyTag)
818 return ok && tag == dylibDepTag
819}
820
Jiyong Park94e22fd2021-04-08 18:19:15 +0900821func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
822 tag, ok := depTag.(dependencyTag)
823 return ok && tag == rlibDepTag
824}
825
Matthew Maurer0f003b12020-06-29 14:34:06 -0700826type autoDep struct {
827 variation string
828 depTag dependencyTag
829}
830
831var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200832 rlibVariation = "rlib"
833 dylibVariation = "dylib"
834 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
835 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -0700836)
837
838type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -0500839 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -0700840}
841
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400842func (mod *Module) begin(ctx BaseModuleContext) {
843 if mod.coverage != nil {
844 mod.coverage.begin(ctx)
845 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500846 if mod.sanitize != nil {
847 mod.sanitize.begin(ctx)
848 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400849}
850
Ivan Lozanoffee3342019-08-27 12:03:00 -0700851func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
852 var depPaths PathDeps
853
854 directRlibDeps := []*Module{}
855 directDylibDeps := []*Module{}
856 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700857 directSharedLibDeps := [](cc.LinkableInterface){}
858 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400859 directSrcProvidersDeps := []*Module{}
860 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700861
862 ctx.VisitDirectDeps(func(dep android.Module) {
863 depName := ctx.OtherModuleName(dep)
864 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400865
Ivan Lozano89435d12020-07-31 11:01:18 -0400866 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700867 //Handle Rust Modules
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400868 makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -0700869
Ivan Lozanoffee3342019-08-27 12:03:00 -0700870 switch depTag {
871 case dylibDepTag:
872 dylib, ok := rustDep.compiler.(libraryInterface)
873 if !ok || !dylib.dylib() {
874 ctx.ModuleErrorf("mod %q not an dylib library", depName)
875 return
876 }
877 directDylibDeps = append(directDylibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400878 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700879 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -0400880
Ivan Lozanoffee3342019-08-27 12:03:00 -0700881 rlib, ok := rustDep.compiler.(libraryInterface)
882 if !ok || !rlib.rlib() {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400883 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700884 return
885 }
886 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400887 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700888 case procMacroDepTag:
889 directProcMacroDeps = append(directProcMacroDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400890 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400891 case android.SourceDepTag:
892 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
893 // OS/Arch variant is used.
894 var helper string
895 if ctx.Host() {
896 helper = "missing 'host_supported'?"
897 } else {
898 helper = "device module defined?"
899 }
900
901 if dep.Target().Os != ctx.Os() {
902 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
903 return
904 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
905 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
906 return
907 }
908 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700909 }
910
Ivan Lozano2bbcacf2020-08-07 09:00:50 -0400911 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700912 if depTag != procMacroDepTag {
913 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
914 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
915 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
916 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700917 }
918
Ivan Lozanoffee3342019-08-27 12:03:00 -0700919 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900920 linkFile := rustDep.unstrippedOutputFile
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400921 if !linkFile.Valid() {
922 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
923 depName, ctx.ModuleName())
924 return
925 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700926 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700927 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
928 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700929 }
930 }
931
Ivan Lozano89435d12020-07-31 11:01:18 -0400932 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -0700933 //Handle C dependencies
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400934 makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
Ivan Lozano52767be2019-10-18 14:49:46 -0700935 if _, ok := ccDep.(*Module); !ok {
936 if ccDep.Module().Target().Os != ctx.Os() {
937 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
938 return
939 }
940 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
941 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
942 return
943 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700944 }
Ivan Lozano2093af22020-08-25 12:48:19 -0400945 linkObject := ccDep.OutputFile()
946 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500947
Ivan Lozano2093af22020-08-25 12:48:19 -0400948 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700949 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
950 }
951
952 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700953 switch {
954 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -0400955 if cc.IsWholeStaticLib(depTag) {
956 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
957 // if the library is not prefixed by "lib".
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500958 if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
959 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400960 } else {
961 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 -0500962 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500963 }
964
965 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
966 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -0400967 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500968 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
969
Colin Cross0de8a1e2020-09-18 14:15:30 -0700970 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
971 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
972 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
973 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
974 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700975 directStaticLibDeps = append(directStaticLibDeps, ccDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400976 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -0700977 case cc.IsSharedDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700978 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400979 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -0700980 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
981 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
982 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
983 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
984 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700985 directSharedLibDeps = append(directSharedLibDeps, ccDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400986 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700987 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -0800988 case cc.IsHeaderDepTag(depTag):
989 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
990 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
991 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
992 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -0700993 case depTag == cc.CrtBeginDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400994 depPaths.CrtBegin = linkObject
Colin Cross6e511a92020-07-27 21:26:48 -0700995 case depTag == cc.CrtEndDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400996 depPaths.CrtEnd = linkObject
Ivan Lozanoffee3342019-08-27 12:03:00 -0700997 }
998
999 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001000 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1001 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001002 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001003 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001004 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001005
1006 if srcDep, ok := dep.(android.SourceFileProducer); ok {
1007 switch depTag {
1008 case android.SourceDepTag:
1009 // These are usually genrules which don't have per-target variants.
1010 directSrcDeps = append(directSrcDeps, srcDep)
1011 }
1012 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001013 })
1014
1015 var rlibDepFiles RustLibraries
1016 for _, dep := range directRlibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001017 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001018 }
1019 var dylibDepFiles RustLibraries
1020 for _, dep := range directDylibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001021 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001022 }
1023 var procMacroDepFiles RustLibraries
1024 for _, dep := range directProcMacroDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001025 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001026 }
1027
1028 var staticLibDepFiles android.Paths
1029 for _, dep := range directStaticLibDeps {
1030 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1031 }
1032
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001033 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001034 var sharedLibDepFiles android.Paths
1035 for _, dep := range directSharedLibDeps {
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001036 sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path())
1037 if dep.Toc().Valid() {
1038 sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path())
1039 } else {
1040 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
1041 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001042 }
1043
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001044 var srcProviderDepFiles android.Paths
1045 for _, dep := range directSrcProvidersDeps {
1046 srcs, _ := dep.OutputFiles("")
1047 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1048 }
1049 for _, dep := range directSrcDeps {
1050 srcs := dep.Srcs()
1051 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1052 }
1053
Ivan Lozanoffee3342019-08-27 12:03:00 -07001054 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1055 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1056 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001057 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001058 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1059 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001060 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001061
1062 // Dedup exported flags from dependencies
1063 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001064 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001065 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001066 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1067 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1068 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001069
1070 return depPaths
1071}
1072
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001073func (mod *Module) InstallInData() bool {
1074 if mod.compiler == nil {
1075 return false
1076 }
1077 return mod.compiler.inData()
1078}
1079
Ivan Lozanoffee3342019-08-27 12:03:00 -07001080func linkPathFromFilePath(filepath android.Path) string {
1081 return strings.Split(filepath.String(), filepath.Base())[0]
1082}
Ivan Lozanod648c432020-02-06 12:05:10 -05001083
Ivan Lozanoffee3342019-08-27 12:03:00 -07001084func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1085 ctx := &depsContext{
1086 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001087 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001088
1089 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001090 var commonDepVariations []blueprint.Variation
Ivan Lozanodd055472020-09-28 13:22:45 -04001091
Ivan Lozano2b081132020-09-08 12:46:52 -04001092 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001093 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001094 stdLinkage = "rlib-std"
1095 }
1096
1097 rlibDepVariations := commonDepVariations
1098 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1099 rlibDepVariations = append(rlibDepVariations,
1100 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1101 }
1102
Ivan Lozano52767be2019-10-18 14:49:46 -07001103 actx.AddVariationDependencies(
Ivan Lozano2b081132020-09-08 12:46:52 -04001104 append(rlibDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001105 {Mutator: "rust_libraries", Variation: rlibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001106 rlibDepTag, deps.Rlibs...)
1107 actx.AddVariationDependencies(
1108 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001109 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001110 dylibDepTag, deps.Dylibs...)
1111
Ivan Lozano042504f2020-08-18 14:31:23 -04001112 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1113 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2b081132020-09-08 12:46:52 -04001114 if autoDep.depTag == rlibDepTag {
1115 actx.AddVariationDependencies(
1116 append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1117 autoDep.depTag, deps.Rustlibs...)
1118 } else {
1119 actx.AddVariationDependencies(
1120 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1121 autoDep.depTag, deps.Rustlibs...)
1122 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001123 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001124 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001125 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001126 actx.AddVariationDependencies(
1127 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
1128 rlibDepTag, deps.Stdlibs...)
1129 } else {
1130 actx.AddVariationDependencies(
1131 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1132 dylibDepTag, deps.Stdlibs...)
1133 }
1134 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001135 actx.AddVariationDependencies(append(commonDepVariations,
1136 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001137 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -07001138 actx.AddVariationDependencies(append(commonDepVariations,
1139 blueprint.Variation{Mutator: "link", Variation: "static"}),
Ivan Lozano63bb7682021-03-23 15:53:44 -04001140 cc.StaticDepTag(false), deps.StaticLibs...)
1141 actx.AddVariationDependencies(append(commonDepVariations,
1142 blueprint.Variation{Mutator: "link", Variation: "static"}),
1143 cc.StaticDepTag(true), deps.WholeStaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001144
Zach Johnson3df4e632020-11-06 11:56:27 -08001145 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1146
Colin Cross565cafd2020-09-25 18:47:38 -07001147 crtVariations := cc.GetCrtVariations(ctx, mod)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001148 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001149 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001150 }
1151 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001152 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001153 }
1154
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001155 if mod.sourceProvider != nil {
1156 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1157 bindgen.Properties.Custom_bindgen != "" {
1158 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1159 bindgen.Properties.Custom_bindgen)
1160 }
1161 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001162 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001163 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001164}
1165
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001166func BeginMutator(ctx android.BottomUpMutatorContext) {
1167 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1168 mod.beginMutator(ctx)
1169 }
1170}
1171
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001172func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1173 ctx := &baseModuleContext{
1174 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001175 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001176
1177 mod.begin(ctx)
1178}
1179
Ivan Lozanoffee3342019-08-27 12:03:00 -07001180func (mod *Module) Name() string {
1181 name := mod.ModuleBase.Name()
1182 if p, ok := mod.compiler.(interface {
1183 Name(string) string
1184 }); ok {
1185 name = p.Name(name)
1186 }
1187 return name
1188}
1189
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001190func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001191 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001192 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001193 }
1194}
1195
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001196var _ android.HostToolProvider = (*Module)(nil)
1197
1198func (mod *Module) HostToolPath() android.OptionalPath {
1199 if !mod.Host() {
1200 return android.OptionalPath{}
1201 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001202 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1203 return android.OptionalPathForPath(binary.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001204 }
1205 return android.OptionalPath{}
1206}
1207
Jiyong Park99644e92020-11-17 22:21:02 +09001208var _ android.ApexModule = (*Module)(nil)
1209
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001210func (mod *Module) minSdkVersion() string {
1211 return String(mod.Properties.Min_sdk_version)
1212}
1213
Jiyong Park45bf82e2020-12-15 22:29:02 +09001214var _ android.ApexModule = (*Module)(nil)
1215
1216// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001217func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001218 minSdkVersion := mod.minSdkVersion()
1219 if minSdkVersion == "apex_inherit" {
1220 return nil
1221 }
1222 if minSdkVersion == "" {
1223 return fmt.Errorf("min_sdk_version is not specificed")
1224 }
1225
1226 // Not using nativeApiLevelFromUser because the context here is not
1227 // necessarily a native context.
1228 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1229 if err != nil {
1230 return err
1231 }
1232
1233 if ver.GreaterThan(sdkVersion) {
1234 return fmt.Errorf("newer SDK(%v)", ver)
1235 }
Jiyong Park99644e92020-11-17 22:21:02 +09001236 return nil
1237}
1238
Jiyong Park45bf82e2020-12-15 22:29:02 +09001239// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001240func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1241 depTag := ctx.OtherModuleDependencyTag(dep)
1242
1243 if ccm, ok := dep.(*cc.Module); ok {
1244 if ccm.HasStubsVariants() {
1245 if cc.IsSharedDepTag(depTag) {
1246 // dynamic dep to a stubs lib crosses APEX boundary
1247 return false
1248 }
1249 if cc.IsRuntimeDepTag(depTag) {
1250 // runtime dep to a stubs lib also crosses APEX boundary
1251 return false
1252 }
1253
1254 if cc.IsHeaderDepTag(depTag) {
1255 return false
1256 }
1257 }
1258 if mod.Static() && cc.IsSharedDepTag(depTag) {
1259 // shared_lib dependency from a static lib is considered as crossing
1260 // the APEX boundary because the dependency doesn't actually is
1261 // linked; the dependency is used only during the compilation phase.
1262 return false
1263 }
1264 }
1265
1266 if depTag == procMacroDepTag {
1267 return false
1268 }
1269
1270 return true
1271}
1272
1273// Overrides ApexModule.IsInstallabeToApex()
1274func (mod *Module) IsInstallableToApex() bool {
1275 if mod.compiler != nil {
1276 if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) {
1277 return true
1278 }
1279 if _, ok := mod.compiler.(*binaryDecorator); ok {
1280 return true
1281 }
1282 }
1283 return false
1284}
1285
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001286// If a library file has a "lib" prefix, extract the library name without the prefix.
1287func libNameFromFilePath(filepath android.Path) (string, bool) {
1288 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1289 if strings.HasPrefix(libName, "lib") {
1290 libName = libName[3:]
1291 return libName, true
1292 }
1293 return "", false
1294}
1295
Ivan Lozanoffee3342019-08-27 12:03:00 -07001296var Bool = proptools.Bool
1297var BoolDefault = proptools.BoolDefault
1298var String = proptools.String
1299var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001300
1301var _ android.OutputFileProducer = (*Module)(nil)