blob: f0da2ced0cbddda7c7abb9d2045577730105c12d [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
76 // Set by imageMutator
Ivan Lozanoe6d30982021-02-05 10:57:43 -050077 CoreVariantNeeded bool `blueprint:"mutated"`
78 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
79 ExtraVariants []string `blueprint:"mutated"`
80
81 // Make this module available when building for vendor ramdisk.
82 // On device without a dedicated recovery partition, the module is only
83 // available after switching root into
84 // /first_stage_ramdisk. To expose the module before switching root, install
85 // the recovery variant instead (TODO(b/165791368) recovery not yet supported)
86 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040087
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050088 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
89 Min_sdk_version *string
90
Ivan Lozano43845682020-07-09 21:03:28 -040091 PreventInstall bool
92 HideFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070093}
94
95type Module struct {
96 android.ModuleBase
97 android.DefaultableModuleBase
Jiyong Park99644e92020-11-17 22:21:02 +090098 android.ApexModuleBase
Ivan Lozanoffee3342019-08-27 12:03:00 -070099
Ivan Lozano6a884432020-12-02 09:15:16 -0500100 VendorProperties cc.VendorProperties
101
Ivan Lozanoffee3342019-08-27 12:03:00 -0700102 Properties BaseProperties
103
104 hod android.HostOrDeviceSupported
105 multilib android.Multilib
106
Ivan Lozano6a884432020-12-02 09:15:16 -0500107 makeLinkType string
108
Ivan Lozanoffee3342019-08-27 12:03:00 -0700109 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400110 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200111 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500112 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700113 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400114 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700115 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400116
Jiyong Parke54f07e2021-04-07 15:08:04 +0900117 // Unstripped output. This is usually used when this module is linked to another module
118 // as a library. The stripped output which is used for installation can be found via
119 // compiler.strippedOutputFile if it exists.
120 unstrippedOutputFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900121
122 hideApexVariantFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700123}
124
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500125func (mod *Module) Header() bool {
126 //TODO: If Rust libraries provide header variants, this needs to be updated.
127 return false
128}
129
130func (mod *Module) SetPreventInstall() {
131 mod.Properties.PreventInstall = true
132}
133
134// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
135func (mod *Module) InVendor() bool {
136 return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix
137}
138
139func (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 {
234 return false
235}
236
237func (mod *Module) IsVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500238 // TODO(b/165791368)
Ivan Lozano52767be2019-10-18 14:49:46 -0700239 return false
240}
241
Ivan Lozanof9e21722020-12-02 09:00:51 -0500242func (mod *Module) IsVndkExt() bool {
243 return false
244}
245
Colin Cross127bb8b2020-12-16 16:46:01 -0800246func (c *Module) IsVndkPrivate() bool {
247 return false
248}
249
250func (c *Module) IsLlndk() bool {
251 return false
252}
253
254func (c *Module) IsLlndkPublic() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500255 return false
256}
257
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400258func (m *Module) IsLlndkHeaders() bool {
259 return false
260}
261
262func (m *Module) IsLlndkLibrary() bool {
263 return false
264}
265
266func (mod *Module) KernelHeadersDecorator() bool {
267 return false
268}
269
270func (m *Module) HasLlndkStubs() bool {
271 return false
272}
273
Ivan Lozano52767be2019-10-18 14:49:46 -0700274func (mod *Module) SdkVersion() string {
275 return ""
276}
277
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900278func (mod *Module) MinSdkVersion() string {
279 return ""
280}
281
Colin Crossc511bc52020-04-07 16:50:32 +0000282func (mod *Module) AlwaysSdk() bool {
283 return false
284}
285
Jiyong Park2286afd2020-06-16 21:58:53 +0900286func (mod *Module) IsSdkVariant() bool {
287 return false
288}
289
Colin Cross1348ce32020-10-01 13:37:16 -0700290func (mod *Module) SplitPerApiLevel() bool {
291 return false
292}
293
Ivan Lozanoffee3342019-08-27 12:03:00 -0700294type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400295 Dylibs []string
296 Rlibs []string
297 Rustlibs []string
298 Stdlibs []string
299 ProcMacros []string
300 SharedLibs []string
301 StaticLibs []string
302 WholeStaticLibs []string
303 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700304
305 CrtBegin, CrtEnd string
306}
307
308type PathDeps struct {
Ivan Lozanoec6e9912021-01-21 15:23:29 -0500309 DyLibs RustLibraries
310 RLibs RustLibraries
311 SharedLibs android.Paths
312 SharedLibDeps android.Paths
313 StaticLibs android.Paths
314 ProcMacros RustLibraries
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500315
316 // depFlags and depLinkFlags are rustc and linker (clang) flags.
317 depFlags []string
318 depLinkFlags []string
319
320 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
321 // Both of these are exported and propagate to dependencies.
322 linkDirs []string
323 linkObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700324
Ivan Lozano45901ed2020-07-24 16:05:01 -0400325 // Used by bindgen modules which call clang
326 depClangFlags []string
327 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400328 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400329 depSystemIncludePaths android.Paths
330
Ivan Lozanof1c84332019-09-20 11:00:37 -0700331 CrtBegin android.OptionalPath
332 CrtEnd android.OptionalPath
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700333
334 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500335 SrcDeps android.Paths
336 srcProviderFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700337}
338
339type RustLibraries []RustLibrary
340
341type RustLibrary struct {
342 Path android.Path
343 CrateName string
344}
345
346type compiler interface {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100347 initialize(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700348 compilerFlags(ctx ModuleContext, flags Flags) Flags
349 compilerProps() []interface{}
350 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
351 compilerDeps(ctx DepsContext, deps Deps) Deps
352 crateName() string
353
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100354 // Output directory in which source-generated code from dependencies is
355 // copied. This is equivalent to Cargo's OUT_DIR variable.
356 CargoOutDir() android.OptionalPath
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800357 inData() bool
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200358 install(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700359 relativeInstallPath() string
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400360
361 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400362
363 Disabled() bool
364 SetDisabled()
Ivan Lozano042504f2020-08-18 14:31:23 -0400365
Ivan Lozanodd055472020-09-28 13:22:45 -0400366 stdLinkage(ctx *depsContext) RustLinkage
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500367 isDependencyRoot() bool
Jiyong Parke54f07e2021-04-07 15:08:04 +0900368
369 strippedOutputFilePath() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400370}
371
Matthew Maurerbb3add12020-06-25 09:34:12 -0700372type exportedFlagsProducer interface {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700373 exportLinkDirs(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400374 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700375}
376
377type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400378 linkDirs []string
379 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700380}
381
Matthew Maurerbb3add12020-06-25 09:34:12 -0700382func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
383 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
384}
385
Ivan Lozano2093af22020-08-25 12:48:19 -0400386func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
387 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
388}
389
Colin Cross0de8a1e2020-09-18 14:15:30 -0700390func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
391 ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700392 LinkDirs: flagExporter.linkDirs,
393 LinkObjects: flagExporter.linkObjects,
394 })
395}
396
Matthew Maurerbb3add12020-06-25 09:34:12 -0700397var _ exportedFlagsProducer = (*flagExporter)(nil)
398
399func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700400 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700401}
402
Colin Cross0de8a1e2020-09-18 14:15:30 -0700403type FlagExporterInfo struct {
404 Flags []string
405 LinkDirs []string // TODO: this should be android.Paths
406 LinkObjects []string // TODO: this should be android.Paths
407}
408
409var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
410
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400411func (mod *Module) isCoverageVariant() bool {
412 return mod.coverage.Properties.IsCoverageVariant
413}
414
415var _ cc.Coverage = (*Module)(nil)
416
417func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
418 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
419}
420
421func (mod *Module) PreventInstall() {
422 mod.Properties.PreventInstall = true
423}
424
425func (mod *Module) HideFromMake() {
426 mod.Properties.HideFromMake = true
427}
428
429func (mod *Module) MarkAsCoverageVariant(coverage bool) {
430 mod.coverage.Properties.IsCoverageVariant = coverage
431}
432
433func (mod *Module) EnableCoverageIfNeeded() {
434 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700435}
436
437func defaultsFactory() android.Module {
438 return DefaultsFactory()
439}
440
441type Defaults struct {
442 android.ModuleBase
443 android.DefaultsModuleBase
444}
445
446func DefaultsFactory(props ...interface{}) android.Module {
447 module := &Defaults{}
448
449 module.AddProperties(props...)
450 module.AddProperties(
451 &BaseProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500452 &cc.VendorProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400453 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700454 &BaseCompilerProperties{},
455 &BinaryCompilerProperties{},
456 &LibraryCompilerProperties{},
457 &ProcMacroCompilerProperties{},
458 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400459 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700460 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400461 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400462 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200463 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500464 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700465 )
466
467 android.InitDefaultsModule(module)
468 return module
469}
470
471func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700472 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700473}
474
Ivan Lozano183a3212019-10-18 14:18:45 -0700475func (mod *Module) CcLibrary() bool {
476 if mod.compiler != nil {
477 if _, ok := mod.compiler.(*libraryDecorator); ok {
478 return true
479 }
480 }
481 return false
482}
483
484func (mod *Module) CcLibraryInterface() bool {
485 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400486 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
487 // VariantIs{Static,Shared} is set.
488 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700489 return true
490 }
491 }
492 return false
493}
494
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800495func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700496 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700497 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800498 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700499 }
500 }
501 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
502}
503
504func (mod *Module) SetStatic() {
505 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700506 if library, ok := mod.compiler.(libraryInterface); ok {
507 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700508 return
509 }
510 }
511 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
512}
513
514func (mod *Module) SetShared() {
515 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700516 if library, ok := mod.compiler.(libraryInterface); ok {
517 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700518 return
519 }
520 }
521 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
522}
523
Ivan Lozano183a3212019-10-18 14:18:45 -0700524func (mod *Module) BuildStaticVariant() bool {
525 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700526 if library, ok := mod.compiler.(libraryInterface); ok {
527 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700528 }
529 }
530 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
531}
532
533func (mod *Module) BuildSharedVariant() bool {
534 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700535 if library, ok := mod.compiler.(libraryInterface); ok {
536 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700537 }
538 }
539 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
540}
541
Ivan Lozano183a3212019-10-18 14:18:45 -0700542func (mod *Module) Module() android.Module {
543 return mod
544}
545
Ivan Lozano183a3212019-10-18 14:18:45 -0700546func (mod *Module) OutputFile() android.OptionalPath {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900547 if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() {
548 return mod.compiler.strippedOutputFilePath()
549 }
550 return mod.unstrippedOutputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700551}
552
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400553func (mod *Module) CoverageFiles() android.Paths {
554 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800555 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400556 }
557 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
558}
559
Jiyong Park459feca2020-12-15 11:02:21 +0900560func (mod *Module) installable(apexInfo android.ApexInfo) bool {
561 // The apex variant is not installable because it is included in the APEX and won't appear
562 // in the system partition as a standalone file.
563 if !apexInfo.IsForPlatform() {
564 return false
565 }
566
Jiyong Parke54f07e2021-04-07 15:08:04 +0900567 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900568}
569
Ivan Lozano183a3212019-10-18 14:18:45 -0700570var _ cc.LinkableInterface = (*Module)(nil)
571
Ivan Lozanoffee3342019-08-27 12:03:00 -0700572func (mod *Module) Init() android.Module {
573 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500574 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700575
576 if mod.compiler != nil {
577 mod.AddProperties(mod.compiler.compilerProps()...)
578 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400579 if mod.coverage != nil {
580 mod.AddProperties(mod.coverage.props()...)
581 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200582 if mod.clippy != nil {
583 mod.AddProperties(mod.clippy.props()...)
584 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400585 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700586 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400587 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500588 if mod.sanitize != nil {
589 mod.AddProperties(mod.sanitize.props()...)
590 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400591
Ivan Lozanoffee3342019-08-27 12:03:00 -0700592 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900593 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700594
595 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700596 return mod
597}
598
599func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
600 return &Module{
601 hod: hod,
602 multilib: multilib,
603 }
604}
605func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
606 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400607 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200608 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500609 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700610 return module
611}
612
613type ModuleContext interface {
614 android.ModuleContext
615 ModuleContextIntf
616}
617
618type BaseModuleContext interface {
619 android.BaseModuleContext
620 ModuleContextIntf
621}
622
623type DepsContext interface {
624 android.BottomUpMutatorContext
625 ModuleContextIntf
626}
627
628type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200629 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700630 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700631}
632
633type depsContext struct {
634 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700635}
636
637type moduleContext struct {
638 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700639}
640
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200641type baseModuleContext struct {
642 android.BaseModuleContext
643}
644
645func (ctx *moduleContext) RustModule() *Module {
646 return ctx.Module().(*Module)
647}
648
649func (ctx *moduleContext) toolchain() config.Toolchain {
650 return ctx.RustModule().toolchain(ctx)
651}
652
653func (ctx *depsContext) RustModule() *Module {
654 return ctx.Module().(*Module)
655}
656
657func (ctx *depsContext) toolchain() config.Toolchain {
658 return ctx.RustModule().toolchain(ctx)
659}
660
661func (ctx *baseModuleContext) RustModule() *Module {
662 return ctx.Module().(*Module)
663}
664
665func (ctx *baseModuleContext) toolchain() config.Toolchain {
666 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400667}
668
669func (mod *Module) nativeCoverage() bool {
670 return mod.compiler != nil && mod.compiler.nativeCoverage()
671}
672
Ivan Lozanoffee3342019-08-27 12:03:00 -0700673func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
674 if mod.cachedToolchain == nil {
675 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
676 }
677 return mod.cachedToolchain
678}
679
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200680func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
681 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
682}
683
Ivan Lozanoffee3342019-08-27 12:03:00 -0700684func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
685}
686
687func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
688 ctx := &moduleContext{
689 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700690 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700691
Jiyong Park99644e92020-11-17 22:21:02 +0900692 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
693 if !apexInfo.IsForPlatform() {
694 mod.hideApexVariantFromMake = true
695 }
696
Ivan Lozanoffee3342019-08-27 12:03:00 -0700697 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500698 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
699
700 // Differentiate static libraries that are vendor available
701 if mod.UseVndk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500702 mod.Properties.SubName += cc.VendorSuffix
703 } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
704 mod.Properties.SubName += cc.VendorRamdiskSuffix
Ivan Lozano6a884432020-12-02 09:15:16 -0500705 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700706
707 if !toolchain.Supported() {
708 // This toolchain's unsupported, there's nothing to do for this mod.
709 return
710 }
711
712 deps := mod.depsToPaths(ctx)
713 flags := Flags{
714 Toolchain: toolchain,
715 }
716
717 if mod.compiler != nil {
718 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400719 }
720 if mod.coverage != nil {
721 flags, deps = mod.coverage.flags(ctx, flags, deps)
722 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200723 if mod.clippy != nil {
724 flags, deps = mod.clippy.flags(ctx, flags, deps)
725 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500726 if mod.sanitize != nil {
727 flags, deps = mod.sanitize.flags(ctx, flags, deps)
728 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400729
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200730 // SourceProvider needs to call GenerateSource() before compiler calls
731 // compile() so it can provide the source. A SourceProvider has
732 // multiple variants (e.g. source, rlib, dylib). Only the "source"
733 // variant is responsible for effectively generating the source. The
734 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400735 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200736 if mod.compiler.(libraryInterface).source() {
737 mod.sourceProvider.GenerateSource(ctx, deps)
738 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
739 } else {
740 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
741 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700742 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200743 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400744 }
745
746 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100747 mod.compiler.initialize(ctx)
Jiyong Parke54f07e2021-04-07 15:08:04 +0900748 unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400749
Jiyong Parke54f07e2021-04-07 15:08:04 +0900750 mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
Jiyong Park459feca2020-12-15 11:02:21 +0900751
752 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
753 if mod.installable(apexInfo) {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200754 mod.compiler.install(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400755 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700756 }
757}
758
759func (mod *Module) deps(ctx DepsContext) Deps {
760 deps := Deps{}
761
762 if mod.compiler != nil {
763 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400764 }
765 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700766 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700767 }
768
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400769 if mod.coverage != nil {
770 deps = mod.coverage.deps(ctx, deps)
771 }
772
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500773 if mod.sanitize != nil {
774 deps = mod.sanitize.deps(ctx, deps)
775 }
776
Ivan Lozanoffee3342019-08-27 12:03:00 -0700777 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
778 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700779 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700780 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
781 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
782 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400783 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700784 return deps
785
786}
787
Ivan Lozanoffee3342019-08-27 12:03:00 -0700788type dependencyTag struct {
789 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800790 name string
791 library bool
792 procMacro bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700793}
794
Jiyong Park65b62242020-11-25 12:44:59 +0900795// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
796// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
797func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800798 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +0900799}
800
801var _ android.InstallNeededDependencyTag = dependencyTag{}
802
Ivan Lozanoffee3342019-08-27 12:03:00 -0700803var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400804 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
805 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
806 dylibDepTag = dependencyTag{name: "dylib", library: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800807 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400808 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200809 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700810)
811
Jiyong Park99644e92020-11-17 22:21:02 +0900812func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
813 tag, ok := depTag.(dependencyTag)
814 return ok && tag == dylibDepTag
815}
816
Jiyong Park94e22fd2021-04-08 18:19:15 +0900817func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
818 tag, ok := depTag.(dependencyTag)
819 return ok && tag == rlibDepTag
820}
821
Matthew Maurer0f003b12020-06-29 14:34:06 -0700822type autoDep struct {
823 variation string
824 depTag dependencyTag
825}
826
827var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200828 rlibVariation = "rlib"
829 dylibVariation = "dylib"
830 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
831 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -0700832)
833
834type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -0500835 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -0700836}
837
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400838func (mod *Module) begin(ctx BaseModuleContext) {
839 if mod.coverage != nil {
840 mod.coverage.begin(ctx)
841 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500842 if mod.sanitize != nil {
843 mod.sanitize.begin(ctx)
844 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400845}
846
Ivan Lozanoffee3342019-08-27 12:03:00 -0700847func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
848 var depPaths PathDeps
849
850 directRlibDeps := []*Module{}
851 directDylibDeps := []*Module{}
852 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700853 directSharedLibDeps := [](cc.LinkableInterface){}
854 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400855 directSrcProvidersDeps := []*Module{}
856 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700857
858 ctx.VisitDirectDeps(func(dep android.Module) {
859 depName := ctx.OtherModuleName(dep)
860 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozano89435d12020-07-31 11:01:18 -0400861 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700862 //Handle Rust Modules
Ivan Lozano70e0a072019-09-13 14:23:15 -0700863
Ivan Lozanoffee3342019-08-27 12:03:00 -0700864 switch depTag {
865 case dylibDepTag:
866 dylib, ok := rustDep.compiler.(libraryInterface)
867 if !ok || !dylib.dylib() {
868 ctx.ModuleErrorf("mod %q not an dylib library", depName)
869 return
870 }
871 directDylibDeps = append(directDylibDeps, rustDep)
872 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
873 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -0400874
Ivan Lozanoffee3342019-08-27 12:03:00 -0700875 rlib, ok := rustDep.compiler.(libraryInterface)
876 if !ok || !rlib.rlib() {
Ivan Lozano2b081132020-09-08 12:46:52 -0400877 ctx.ModuleErrorf("mod %q not an rlib library", depName+rustDep.Properties.SubName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700878 return
879 }
880 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozano2b081132020-09-08 12:46:52 -0400881 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName+rustDep.Properties.SubName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700882 case procMacroDepTag:
883 directProcMacroDeps = append(directProcMacroDeps, rustDep)
884 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400885 case android.SourceDepTag:
886 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
887 // OS/Arch variant is used.
888 var helper string
889 if ctx.Host() {
890 helper = "missing 'host_supported'?"
891 } else {
892 helper = "device module defined?"
893 }
894
895 if dep.Target().Os != ctx.Os() {
896 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
897 return
898 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
899 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
900 return
901 }
902 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700903 }
904
Ivan Lozano2bbcacf2020-08-07 09:00:50 -0400905 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700906 if depTag != procMacroDepTag {
907 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
908 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
909 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
910 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700911 }
912
Ivan Lozanoffee3342019-08-27 12:03:00 -0700913 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900914 linkFile := rustDep.unstrippedOutputFile
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400915 if !linkFile.Valid() {
916 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
917 depName, ctx.ModuleName())
918 return
919 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700920 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700921 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
922 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700923 }
924 }
925
Ivan Lozano89435d12020-07-31 11:01:18 -0400926 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -0700927 //Handle C dependencies
928 if _, ok := ccDep.(*Module); !ok {
929 if ccDep.Module().Target().Os != ctx.Os() {
930 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
931 return
932 }
933 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
934 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
935 return
936 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700937 }
Ivan Lozano2093af22020-08-25 12:48:19 -0400938 linkObject := ccDep.OutputFile()
939 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500940
Ivan Lozano2093af22020-08-25 12:48:19 -0400941 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700942 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
943 }
944
945 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700946 switch {
947 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -0400948 if cc.IsWholeStaticLib(depTag) {
949 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
950 // if the library is not prefixed by "lib".
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500951 if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
952 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400953 } else {
954 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 -0500955 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500956 }
957
958 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
959 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -0400960 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500961 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
962
Colin Cross0de8a1e2020-09-18 14:15:30 -0700963 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
964 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
965 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
966 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
967 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700968 directStaticLibDeps = append(directStaticLibDeps, ccDep)
969 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
Colin Cross6e511a92020-07-27 21:26:48 -0700970 case cc.IsSharedDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700971 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400972 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -0700973 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
974 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
975 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
976 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
977 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700978 directSharedLibDeps = append(directSharedLibDeps, ccDep)
979 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
980 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -0800981 case cc.IsHeaderDepTag(depTag):
982 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
983 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
984 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
985 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -0700986 case depTag == cc.CrtBeginDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400987 depPaths.CrtBegin = linkObject
Colin Cross6e511a92020-07-27 21:26:48 -0700988 case depTag == cc.CrtEndDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400989 depPaths.CrtEnd = linkObject
Ivan Lozanoffee3342019-08-27 12:03:00 -0700990 }
991
992 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -0700993 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
994 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400995 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700996 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700997 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400998
999 if srcDep, ok := dep.(android.SourceFileProducer); ok {
1000 switch depTag {
1001 case android.SourceDepTag:
1002 // These are usually genrules which don't have per-target variants.
1003 directSrcDeps = append(directSrcDeps, srcDep)
1004 }
1005 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001006 })
1007
1008 var rlibDepFiles RustLibraries
1009 for _, dep := range directRlibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001010 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001011 }
1012 var dylibDepFiles RustLibraries
1013 for _, dep := range directDylibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001014 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001015 }
1016 var procMacroDepFiles RustLibraries
1017 for _, dep := range directProcMacroDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001018 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001019 }
1020
1021 var staticLibDepFiles android.Paths
1022 for _, dep := range directStaticLibDeps {
1023 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1024 }
1025
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001026 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001027 var sharedLibDepFiles android.Paths
1028 for _, dep := range directSharedLibDeps {
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001029 sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path())
1030 if dep.Toc().Valid() {
1031 sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path())
1032 } else {
1033 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
1034 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001035 }
1036
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001037 var srcProviderDepFiles android.Paths
1038 for _, dep := range directSrcProvidersDeps {
1039 srcs, _ := dep.OutputFiles("")
1040 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1041 }
1042 for _, dep := range directSrcDeps {
1043 srcs := dep.Srcs()
1044 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1045 }
1046
Ivan Lozanoffee3342019-08-27 12:03:00 -07001047 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1048 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1049 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001050 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001051 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1052 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001053 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001054
1055 // Dedup exported flags from dependencies
1056 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001057 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001058 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001059 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1060 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1061 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001062
1063 return depPaths
1064}
1065
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001066func (mod *Module) InstallInData() bool {
1067 if mod.compiler == nil {
1068 return false
1069 }
1070 return mod.compiler.inData()
1071}
1072
Ivan Lozanoffee3342019-08-27 12:03:00 -07001073func linkPathFromFilePath(filepath android.Path) string {
1074 return strings.Split(filepath.String(), filepath.Base())[0]
1075}
Ivan Lozanod648c432020-02-06 12:05:10 -05001076
Ivan Lozanoffee3342019-08-27 12:03:00 -07001077func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1078 ctx := &depsContext{
1079 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001080 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001081
1082 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001083 var commonDepVariations []blueprint.Variation
Ivan Lozanodd055472020-09-28 13:22:45 -04001084
Ivan Lozano2b081132020-09-08 12:46:52 -04001085 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001086 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001087 stdLinkage = "rlib-std"
1088 }
1089
1090 rlibDepVariations := commonDepVariations
1091 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1092 rlibDepVariations = append(rlibDepVariations,
1093 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1094 }
1095
Ivan Lozano52767be2019-10-18 14:49:46 -07001096 actx.AddVariationDependencies(
Ivan Lozano2b081132020-09-08 12:46:52 -04001097 append(rlibDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001098 {Mutator: "rust_libraries", Variation: rlibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001099 rlibDepTag, deps.Rlibs...)
1100 actx.AddVariationDependencies(
1101 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001102 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001103 dylibDepTag, deps.Dylibs...)
1104
Ivan Lozano042504f2020-08-18 14:31:23 -04001105 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1106 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2b081132020-09-08 12:46:52 -04001107 if autoDep.depTag == rlibDepTag {
1108 actx.AddVariationDependencies(
1109 append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1110 autoDep.depTag, deps.Rustlibs...)
1111 } else {
1112 actx.AddVariationDependencies(
1113 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1114 autoDep.depTag, deps.Rustlibs...)
1115 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001116 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001117 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001118 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001119 actx.AddVariationDependencies(
1120 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
1121 rlibDepTag, deps.Stdlibs...)
1122 } else {
1123 actx.AddVariationDependencies(
1124 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1125 dylibDepTag, deps.Stdlibs...)
1126 }
1127 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001128 actx.AddVariationDependencies(append(commonDepVariations,
1129 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001130 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -07001131 actx.AddVariationDependencies(append(commonDepVariations,
1132 blueprint.Variation{Mutator: "link", Variation: "static"}),
Ivan Lozano63bb7682021-03-23 15:53:44 -04001133 cc.StaticDepTag(false), deps.StaticLibs...)
1134 actx.AddVariationDependencies(append(commonDepVariations,
1135 blueprint.Variation{Mutator: "link", Variation: "static"}),
1136 cc.StaticDepTag(true), deps.WholeStaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001137
Zach Johnson3df4e632020-11-06 11:56:27 -08001138 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1139
Colin Cross565cafd2020-09-25 18:47:38 -07001140 crtVariations := cc.GetCrtVariations(ctx, mod)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001141 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001142 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001143 }
1144 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001145 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001146 }
1147
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001148 if mod.sourceProvider != nil {
1149 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1150 bindgen.Properties.Custom_bindgen != "" {
1151 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1152 bindgen.Properties.Custom_bindgen)
1153 }
1154 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001155 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001156 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001157}
1158
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001159func BeginMutator(ctx android.BottomUpMutatorContext) {
1160 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1161 mod.beginMutator(ctx)
1162 }
1163}
1164
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001165func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1166 ctx := &baseModuleContext{
1167 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001168 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001169
1170 mod.begin(ctx)
1171}
1172
Ivan Lozanoffee3342019-08-27 12:03:00 -07001173func (mod *Module) Name() string {
1174 name := mod.ModuleBase.Name()
1175 if p, ok := mod.compiler.(interface {
1176 Name(string) string
1177 }); ok {
1178 name = p.Name(name)
1179 }
1180 return name
1181}
1182
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001183func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001184 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001185 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001186 }
1187}
1188
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001189var _ android.HostToolProvider = (*Module)(nil)
1190
1191func (mod *Module) HostToolPath() android.OptionalPath {
1192 if !mod.Host() {
1193 return android.OptionalPath{}
1194 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001195 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1196 return android.OptionalPathForPath(binary.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001197 }
1198 return android.OptionalPath{}
1199}
1200
Jiyong Park99644e92020-11-17 22:21:02 +09001201var _ android.ApexModule = (*Module)(nil)
1202
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001203func (mod *Module) minSdkVersion() string {
1204 return String(mod.Properties.Min_sdk_version)
1205}
1206
Jiyong Park45bf82e2020-12-15 22:29:02 +09001207var _ android.ApexModule = (*Module)(nil)
1208
1209// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001210func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001211 minSdkVersion := mod.minSdkVersion()
1212 if minSdkVersion == "apex_inherit" {
1213 return nil
1214 }
1215 if minSdkVersion == "" {
1216 return fmt.Errorf("min_sdk_version is not specificed")
1217 }
1218
1219 // Not using nativeApiLevelFromUser because the context here is not
1220 // necessarily a native context.
1221 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1222 if err != nil {
1223 return err
1224 }
1225
1226 if ver.GreaterThan(sdkVersion) {
1227 return fmt.Errorf("newer SDK(%v)", ver)
1228 }
Jiyong Park99644e92020-11-17 22:21:02 +09001229 return nil
1230}
1231
Jiyong Park45bf82e2020-12-15 22:29:02 +09001232// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001233func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1234 depTag := ctx.OtherModuleDependencyTag(dep)
1235
1236 if ccm, ok := dep.(*cc.Module); ok {
1237 if ccm.HasStubsVariants() {
1238 if cc.IsSharedDepTag(depTag) {
1239 // dynamic dep to a stubs lib crosses APEX boundary
1240 return false
1241 }
1242 if cc.IsRuntimeDepTag(depTag) {
1243 // runtime dep to a stubs lib also crosses APEX boundary
1244 return false
1245 }
1246
1247 if cc.IsHeaderDepTag(depTag) {
1248 return false
1249 }
1250 }
1251 if mod.Static() && cc.IsSharedDepTag(depTag) {
1252 // shared_lib dependency from a static lib is considered as crossing
1253 // the APEX boundary because the dependency doesn't actually is
1254 // linked; the dependency is used only during the compilation phase.
1255 return false
1256 }
1257 }
1258
1259 if depTag == procMacroDepTag {
1260 return false
1261 }
1262
1263 return true
1264}
1265
1266// Overrides ApexModule.IsInstallabeToApex()
1267func (mod *Module) IsInstallableToApex() bool {
1268 if mod.compiler != nil {
1269 if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) {
1270 return true
1271 }
1272 if _, ok := mod.compiler.(*binaryDecorator); ok {
1273 return true
1274 }
1275 }
1276 return false
1277}
1278
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001279// If a library file has a "lib" prefix, extract the library name without the prefix.
1280func libNameFromFilePath(filepath android.Path) (string, bool) {
1281 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1282 if strings.HasPrefix(libName, "lib") {
1283 libName = libName[3:]
1284 return libName, true
1285 }
1286 return "", false
1287}
1288
Ivan Lozanoffee3342019-08-27 12:03:00 -07001289var Bool = proptools.Bool
1290var BoolDefault = proptools.BoolDefault
1291var String = proptools.String
1292var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001293
1294var _ android.OutputFileProducer = (*Module)(nil)