blob: fb0be2a2a29b09be317e7da8042dfe104df90057 [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"
Thiébaud Weksteene4dd14b2021-04-14 11:18:47 +020025 "android/soong/bloaty"
Ivan Lozanoffee3342019-08-27 12:03:00 -070026 "android/soong/cc"
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +020027 cc_config "android/soong/cc/config"
Ivan Lozanoffee3342019-08-27 12:03:00 -070028 "android/soong/rust/config"
29)
30
31var pctx = android.NewPackageContext("android/soong/rust")
32
33func init() {
34 // Only allow rust modules to be defined for certain projects
Ivan Lozanoffee3342019-08-27 12:03:00 -070035
36 android.AddNeverAllowRules(
37 android.NeverAllow().
Ivan Lozanoe169ad72019-09-18 08:42:54 -070038 NotIn(config.RustAllowedPaths...).
39 ModuleType(config.RustModuleTypes...))
Ivan Lozanoffee3342019-08-27 12:03:00 -070040
41 android.RegisterModuleType("rust_defaults", defaultsFactory)
42 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
43 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -040044 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040045 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano6cd99e62020-02-11 08:24:25 -050046
47 })
48 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070050 })
51 pctx.Import("android/soong/rust/config")
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020052 pctx.ImportAs("cc_config", "android/soong/cc/config")
Ivan Lozanoffee3342019-08-27 12:03:00 -070053}
54
55type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040056 GlobalRustFlags []string // Flags that apply globally to rust
57 GlobalLinkFlags []string // Flags that apply globally to linker
58 RustFlags []string // Flags that apply to rust
59 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020060 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Ivan Lozanof1c84332019-09-20 11:00:37 -070061 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040062 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020063 Clippy bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070064}
65
66type BaseProperties struct {
67 AndroidMkRlibs []string
68 AndroidMkDylibs []string
69 AndroidMkProcMacroLibs []string
70 AndroidMkSharedLibs []string
71 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040072
Ivan Lozano6a884432020-12-02 09:15:16 -050073 ImageVariationPrefix string `blueprint:"mutated"`
74 VndkVersion string `blueprint:"mutated"`
75 SubName string `blueprint:"mutated"`
76
77 // Set by imageMutator
Ivan Lozanoe6d30982021-02-05 10:57:43 -050078 CoreVariantNeeded bool `blueprint:"mutated"`
79 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
80 ExtraVariants []string `blueprint:"mutated"`
81
82 // Make this module available when building for vendor ramdisk.
83 // On device without a dedicated recovery partition, the module is only
84 // available after switching root into
85 // /first_stage_ramdisk. To expose the module before switching root, install
86 // the recovery variant instead (TODO(b/165791368) recovery not yet supported)
87 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040088
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050089 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
90 Min_sdk_version *string
91
Ivan Lozano43845682020-07-09 21:03:28 -040092 PreventInstall bool
93 HideFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070094}
95
96type Module struct {
97 android.ModuleBase
98 android.DefaultableModuleBase
Jiyong Park99644e92020-11-17 22:21:02 +090099 android.ApexModuleBase
Ivan Lozanoffee3342019-08-27 12:03:00 -0700100
Ivan Lozano6a884432020-12-02 09:15:16 -0500101 VendorProperties cc.VendorProperties
102
Ivan Lozanoffee3342019-08-27 12:03:00 -0700103 Properties BaseProperties
104
105 hod android.HostOrDeviceSupported
106 multilib android.Multilib
107
Ivan Lozano6a884432020-12-02 09:15:16 -0500108 makeLinkType string
109
Ivan Lozanoffee3342019-08-27 12:03:00 -0700110 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400111 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200112 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500113 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700114 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400115 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700116 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400117
Jiyong Parke54f07e2021-04-07 15:08:04 +0900118 // Unstripped output. This is usually used when this module is linked to another module
119 // as a library. The stripped output which is used for installation can be found via
120 // compiler.strippedOutputFile if it exists.
121 unstrippedOutputFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900122
123 hideApexVariantFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700124}
125
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500126func (mod *Module) Header() bool {
127 //TODO: If Rust libraries provide header variants, this needs to be updated.
128 return false
129}
130
131func (mod *Module) SetPreventInstall() {
132 mod.Properties.PreventInstall = true
133}
134
135// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
136func (mod *Module) InVendor() bool {
137 return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix
138}
139
140func (mod *Module) SetHideFromMake() {
141 mod.Properties.HideFromMake = true
142}
143
144func (mod *Module) SanitizePropDefined() bool {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500145 // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
146 // nil since we need compiler to actually sanitize.
147 return mod.sanitize != nil && mod.compiler != nil
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500148}
149
150func (mod *Module) IsDependencyRoot() bool {
151 if mod.compiler != nil {
152 return mod.compiler.isDependencyRoot()
153 }
154 panic("IsDependencyRoot called on a non-compiler Rust module")
155}
156
157func (mod *Module) IsPrebuilt() bool {
158 if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
159 return true
160 }
161 return false
162}
163
Ivan Lozano43845682020-07-09 21:03:28 -0400164func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
165 switch tag {
166 case "":
Andrei Homescu5db69cc2020-08-06 15:27:45 -0700167 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
Ivan Lozano43845682020-07-09 21:03:28 -0400168 return mod.sourceProvider.Srcs(), nil
169 } else {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900170 if mod.OutputFile().Valid() {
171 return android.Paths{mod.OutputFile().Path()}, nil
Ivan Lozano43845682020-07-09 21:03:28 -0400172 }
173 return android.Paths{}, nil
174 }
175 default:
176 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
177 }
178}
179
Ivan Lozano52767be2019-10-18 14:49:46 -0700180func (mod *Module) SelectedStl() string {
181 return ""
182}
183
Ivan Lozano2b262972019-11-21 12:30:50 -0800184func (mod *Module) NonCcVariants() bool {
185 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400186 if _, ok := mod.compiler.(libraryInterface); ok {
187 return false
Ivan Lozano2b262972019-11-21 12:30:50 -0800188 }
189 }
190 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
191}
192
Ivan Lozano52767be2019-10-18 14:49:46 -0700193func (mod *Module) Static() bool {
194 if mod.compiler != nil {
195 if library, ok := mod.compiler.(libraryInterface); ok {
196 return library.static()
197 }
198 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400199 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700200}
201
202func (mod *Module) Shared() bool {
203 if mod.compiler != nil {
204 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400205 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700206 }
207 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400208 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700209}
210
211func (mod *Module) Toc() android.OptionalPath {
212 if mod.compiler != nil {
213 if _, ok := mod.compiler.(libraryInterface); ok {
214 return android.OptionalPath{}
215 }
216 }
217 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
218}
219
Colin Crossc511bc52020-04-07 16:50:32 +0000220func (mod *Module) UseSdk() bool {
221 return false
222}
223
Ivan Lozano6a884432020-12-02 09:15:16 -0500224// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
225// "product" and "vendor" variant modules return true for this function.
226// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
227// "soc_specific: true" and more vendor installed modules are included here.
228// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
229// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700230func (mod *Module) UseVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500231 return mod.Properties.VndkVersion != ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700232}
233
234func (mod *Module) MustUseVendorVariant() bool {
235 return false
236}
237
238func (mod *Module) IsVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500239 // TODO(b/165791368)
Ivan Lozano52767be2019-10-18 14:49:46 -0700240 return false
241}
242
Ivan Lozanof9e21722020-12-02 09:00:51 -0500243func (mod *Module) IsVndkExt() bool {
244 return false
245}
246
Colin Cross127bb8b2020-12-16 16:46:01 -0800247func (c *Module) IsVndkPrivate() bool {
248 return false
249}
250
251func (c *Module) IsLlndk() bool {
252 return false
253}
254
255func (c *Module) IsLlndkPublic() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500256 return false
257}
258
Ivan Lozano52767be2019-10-18 14:49:46 -0700259func (mod *Module) SdkVersion() string {
260 return ""
261}
262
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900263func (mod *Module) MinSdkVersion() string {
264 return ""
265}
266
Colin Crossc511bc52020-04-07 16:50:32 +0000267func (mod *Module) AlwaysSdk() bool {
268 return false
269}
270
Jiyong Park2286afd2020-06-16 21:58:53 +0900271func (mod *Module) IsSdkVariant() bool {
272 return false
273}
274
Colin Cross1348ce32020-10-01 13:37:16 -0700275func (mod *Module) SplitPerApiLevel() bool {
276 return false
277}
278
Ivan Lozanoffee3342019-08-27 12:03:00 -0700279type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400280 Dylibs []string
281 Rlibs []string
282 Rustlibs []string
283 Stdlibs []string
284 ProcMacros []string
285 SharedLibs []string
286 StaticLibs []string
287 WholeStaticLibs []string
288 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700289
290 CrtBegin, CrtEnd string
291}
292
293type PathDeps struct {
Ivan Lozanoec6e9912021-01-21 15:23:29 -0500294 DyLibs RustLibraries
295 RLibs RustLibraries
296 SharedLibs android.Paths
297 SharedLibDeps android.Paths
298 StaticLibs android.Paths
299 ProcMacros RustLibraries
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500300
301 // depFlags and depLinkFlags are rustc and linker (clang) flags.
302 depFlags []string
303 depLinkFlags []string
304
305 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
306 // Both of these are exported and propagate to dependencies.
307 linkDirs []string
308 linkObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700309
Ivan Lozano45901ed2020-07-24 16:05:01 -0400310 // Used by bindgen modules which call clang
311 depClangFlags []string
312 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400313 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400314 depSystemIncludePaths android.Paths
315
Ivan Lozanof1c84332019-09-20 11:00:37 -0700316 CrtBegin android.OptionalPath
317 CrtEnd android.OptionalPath
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700318
319 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500320 SrcDeps android.Paths
321 srcProviderFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700322}
323
324type RustLibraries []RustLibrary
325
326type RustLibrary struct {
327 Path android.Path
328 CrateName string
329}
330
331type compiler interface {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100332 initialize(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700333 compilerFlags(ctx ModuleContext, flags Flags) Flags
334 compilerProps() []interface{}
335 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
336 compilerDeps(ctx DepsContext, deps Deps) Deps
337 crateName() string
338
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100339 // Output directory in which source-generated code from dependencies is
340 // copied. This is equivalent to Cargo's OUT_DIR variable.
341 CargoOutDir() android.OptionalPath
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800342 inData() bool
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200343 install(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700344 relativeInstallPath() string
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400345
346 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400347
348 Disabled() bool
349 SetDisabled()
Ivan Lozano042504f2020-08-18 14:31:23 -0400350
Ivan Lozanodd055472020-09-28 13:22:45 -0400351 stdLinkage(ctx *depsContext) RustLinkage
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500352 isDependencyRoot() bool
Jiyong Parke54f07e2021-04-07 15:08:04 +0900353
354 strippedOutputFilePath() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400355}
356
Matthew Maurerbb3add12020-06-25 09:34:12 -0700357type exportedFlagsProducer interface {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700358 exportLinkDirs(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400359 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700360}
361
362type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400363 linkDirs []string
364 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700365}
366
Matthew Maurerbb3add12020-06-25 09:34:12 -0700367func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
368 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
369}
370
Ivan Lozano2093af22020-08-25 12:48:19 -0400371func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
372 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
373}
374
Colin Cross0de8a1e2020-09-18 14:15:30 -0700375func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
376 ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700377 LinkDirs: flagExporter.linkDirs,
378 LinkObjects: flagExporter.linkObjects,
379 })
380}
381
Matthew Maurerbb3add12020-06-25 09:34:12 -0700382var _ exportedFlagsProducer = (*flagExporter)(nil)
383
384func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700385 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700386}
387
Colin Cross0de8a1e2020-09-18 14:15:30 -0700388type FlagExporterInfo struct {
389 Flags []string
390 LinkDirs []string // TODO: this should be android.Paths
391 LinkObjects []string // TODO: this should be android.Paths
392}
393
394var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
395
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400396func (mod *Module) isCoverageVariant() bool {
397 return mod.coverage.Properties.IsCoverageVariant
398}
399
400var _ cc.Coverage = (*Module)(nil)
401
402func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
403 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
404}
405
406func (mod *Module) PreventInstall() {
407 mod.Properties.PreventInstall = true
408}
409
410func (mod *Module) HideFromMake() {
411 mod.Properties.HideFromMake = true
412}
413
414func (mod *Module) MarkAsCoverageVariant(coverage bool) {
415 mod.coverage.Properties.IsCoverageVariant = coverage
416}
417
418func (mod *Module) EnableCoverageIfNeeded() {
419 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700420}
421
422func defaultsFactory() android.Module {
423 return DefaultsFactory()
424}
425
426type Defaults struct {
427 android.ModuleBase
428 android.DefaultsModuleBase
429}
430
431func DefaultsFactory(props ...interface{}) android.Module {
432 module := &Defaults{}
433
434 module.AddProperties(props...)
435 module.AddProperties(
436 &BaseProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500437 &cc.VendorProperties{},
Jakub Kotur1d640d02021-01-06 12:40:43 +0100438 &BenchmarkProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400439 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700440 &BaseCompilerProperties{},
441 &BinaryCompilerProperties{},
442 &LibraryCompilerProperties{},
443 &ProcMacroCompilerProperties{},
444 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400445 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700446 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400447 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400448 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200449 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500450 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700451 )
452
453 android.InitDefaultsModule(module)
454 return module
455}
456
457func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700458 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700459}
460
Ivan Lozano183a3212019-10-18 14:18:45 -0700461func (mod *Module) CcLibrary() bool {
462 if mod.compiler != nil {
463 if _, ok := mod.compiler.(*libraryDecorator); ok {
464 return true
465 }
466 }
467 return false
468}
469
470func (mod *Module) CcLibraryInterface() bool {
471 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400472 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
473 // VariantIs{Static,Shared} is set.
474 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700475 return true
476 }
477 }
478 return false
479}
480
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800481func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700482 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700483 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800484 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700485 }
486 }
487 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
488}
489
490func (mod *Module) SetStatic() {
491 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700492 if library, ok := mod.compiler.(libraryInterface); ok {
493 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700494 return
495 }
496 }
497 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
498}
499
500func (mod *Module) SetShared() {
501 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700502 if library, ok := mod.compiler.(libraryInterface); ok {
503 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700504 return
505 }
506 }
507 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
508}
509
Ivan Lozano183a3212019-10-18 14:18:45 -0700510func (mod *Module) BuildStaticVariant() bool {
511 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700512 if library, ok := mod.compiler.(libraryInterface); ok {
513 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700514 }
515 }
516 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
517}
518
519func (mod *Module) BuildSharedVariant() bool {
520 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700521 if library, ok := mod.compiler.(libraryInterface); ok {
522 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700523 }
524 }
525 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
526}
527
Ivan Lozano183a3212019-10-18 14:18:45 -0700528func (mod *Module) Module() android.Module {
529 return mod
530}
531
Ivan Lozano183a3212019-10-18 14:18:45 -0700532func (mod *Module) OutputFile() android.OptionalPath {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900533 if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() {
534 return mod.compiler.strippedOutputFilePath()
535 }
536 return mod.unstrippedOutputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700537}
538
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400539func (mod *Module) CoverageFiles() android.Paths {
540 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800541 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400542 }
543 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
544}
545
Jiyong Park459feca2020-12-15 11:02:21 +0900546func (mod *Module) installable(apexInfo android.ApexInfo) bool {
547 // The apex variant is not installable because it is included in the APEX and won't appear
548 // in the system partition as a standalone file.
549 if !apexInfo.IsForPlatform() {
550 return false
551 }
552
Jiyong Parke54f07e2021-04-07 15:08:04 +0900553 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900554}
555
Ivan Lozano183a3212019-10-18 14:18:45 -0700556var _ cc.LinkableInterface = (*Module)(nil)
557
Ivan Lozanoffee3342019-08-27 12:03:00 -0700558func (mod *Module) Init() android.Module {
559 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500560 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700561
562 if mod.compiler != nil {
563 mod.AddProperties(mod.compiler.compilerProps()...)
564 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400565 if mod.coverage != nil {
566 mod.AddProperties(mod.coverage.props()...)
567 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200568 if mod.clippy != nil {
569 mod.AddProperties(mod.clippy.props()...)
570 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400571 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700572 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400573 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500574 if mod.sanitize != nil {
575 mod.AddProperties(mod.sanitize.props()...)
576 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400577
Ivan Lozanoffee3342019-08-27 12:03:00 -0700578 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900579 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700580
581 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700582 return mod
583}
584
585func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
586 return &Module{
587 hod: hod,
588 multilib: multilib,
589 }
590}
591func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
592 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400593 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200594 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500595 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700596 return module
597}
598
599type ModuleContext interface {
600 android.ModuleContext
601 ModuleContextIntf
602}
603
604type BaseModuleContext interface {
605 android.BaseModuleContext
606 ModuleContextIntf
607}
608
609type DepsContext interface {
610 android.BottomUpMutatorContext
611 ModuleContextIntf
612}
613
614type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200615 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700616 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700617}
618
619type depsContext struct {
620 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700621}
622
623type moduleContext struct {
624 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700625}
626
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200627type baseModuleContext struct {
628 android.BaseModuleContext
629}
630
631func (ctx *moduleContext) RustModule() *Module {
632 return ctx.Module().(*Module)
633}
634
635func (ctx *moduleContext) toolchain() config.Toolchain {
636 return ctx.RustModule().toolchain(ctx)
637}
638
639func (ctx *depsContext) RustModule() *Module {
640 return ctx.Module().(*Module)
641}
642
643func (ctx *depsContext) toolchain() config.Toolchain {
644 return ctx.RustModule().toolchain(ctx)
645}
646
647func (ctx *baseModuleContext) RustModule() *Module {
648 return ctx.Module().(*Module)
649}
650
651func (ctx *baseModuleContext) toolchain() config.Toolchain {
652 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400653}
654
655func (mod *Module) nativeCoverage() bool {
656 return mod.compiler != nil && mod.compiler.nativeCoverage()
657}
658
Ivan Lozanoffee3342019-08-27 12:03:00 -0700659func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
660 if mod.cachedToolchain == nil {
661 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
662 }
663 return mod.cachedToolchain
664}
665
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200666func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
667 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
668}
669
Ivan Lozanoffee3342019-08-27 12:03:00 -0700670func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
671}
672
673func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
674 ctx := &moduleContext{
675 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700676 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700677
Jiyong Park99644e92020-11-17 22:21:02 +0900678 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
679 if !apexInfo.IsForPlatform() {
680 mod.hideApexVariantFromMake = true
681 }
682
Ivan Lozanoffee3342019-08-27 12:03:00 -0700683 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500684 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
685
686 // Differentiate static libraries that are vendor available
687 if mod.UseVndk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500688 mod.Properties.SubName += cc.VendorSuffix
689 } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
690 mod.Properties.SubName += cc.VendorRamdiskSuffix
Ivan Lozano6a884432020-12-02 09:15:16 -0500691 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700692
693 if !toolchain.Supported() {
694 // This toolchain's unsupported, there's nothing to do for this mod.
695 return
696 }
697
698 deps := mod.depsToPaths(ctx)
699 flags := Flags{
700 Toolchain: toolchain,
701 }
702
703 if mod.compiler != nil {
704 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400705 }
706 if mod.coverage != nil {
707 flags, deps = mod.coverage.flags(ctx, flags, deps)
708 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200709 if mod.clippy != nil {
710 flags, deps = mod.clippy.flags(ctx, flags, deps)
711 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500712 if mod.sanitize != nil {
713 flags, deps = mod.sanitize.flags(ctx, flags, deps)
714 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400715
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200716 // SourceProvider needs to call GenerateSource() before compiler calls
717 // compile() so it can provide the source. A SourceProvider has
718 // multiple variants (e.g. source, rlib, dylib). Only the "source"
719 // variant is responsible for effectively generating the source. The
720 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400721 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200722 if mod.compiler.(libraryInterface).source() {
723 mod.sourceProvider.GenerateSource(ctx, deps)
724 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
725 } else {
726 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
727 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700728 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200729 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400730 }
731
732 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100733 mod.compiler.initialize(ctx)
Jiyong Parke54f07e2021-04-07 15:08:04 +0900734 unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps)
Jiyong Parke54f07e2021-04-07 15:08:04 +0900735 mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
Thiébaud Weksteene4dd14b2021-04-14 11:18:47 +0200736 bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), mod.unstrippedOutputFile)
Jiyong Park459feca2020-12-15 11:02:21 +0900737
738 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
739 if mod.installable(apexInfo) {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200740 mod.compiler.install(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400741 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700742 }
743}
744
745func (mod *Module) deps(ctx DepsContext) Deps {
746 deps := Deps{}
747
748 if mod.compiler != nil {
749 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400750 }
751 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700752 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700753 }
754
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400755 if mod.coverage != nil {
756 deps = mod.coverage.deps(ctx, deps)
757 }
758
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500759 if mod.sanitize != nil {
760 deps = mod.sanitize.deps(ctx, deps)
761 }
762
Ivan Lozanoffee3342019-08-27 12:03:00 -0700763 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
764 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700765 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700766 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
767 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
768 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400769 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700770 return deps
771
772}
773
Ivan Lozanoffee3342019-08-27 12:03:00 -0700774type dependencyTag struct {
775 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800776 name string
777 library bool
778 procMacro bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700779}
780
Jiyong Park65b62242020-11-25 12:44:59 +0900781// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
782// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
783func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800784 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +0900785}
786
787var _ android.InstallNeededDependencyTag = dependencyTag{}
788
Ivan Lozanoffee3342019-08-27 12:03:00 -0700789var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400790 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
791 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
792 dylibDepTag = dependencyTag{name: "dylib", library: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800793 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400794 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200795 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700796)
797
Jiyong Park99644e92020-11-17 22:21:02 +0900798func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
799 tag, ok := depTag.(dependencyTag)
800 return ok && tag == dylibDepTag
801}
802
Jiyong Park94e22fd2021-04-08 18:19:15 +0900803func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
804 tag, ok := depTag.(dependencyTag)
805 return ok && tag == rlibDepTag
806}
807
Matthew Maurer0f003b12020-06-29 14:34:06 -0700808type autoDep struct {
809 variation string
810 depTag dependencyTag
811}
812
813var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200814 rlibVariation = "rlib"
815 dylibVariation = "dylib"
816 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
817 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -0700818)
819
820type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -0500821 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -0700822}
823
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400824func (mod *Module) begin(ctx BaseModuleContext) {
825 if mod.coverage != nil {
826 mod.coverage.begin(ctx)
827 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500828 if mod.sanitize != nil {
829 mod.sanitize.begin(ctx)
830 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400831}
832
Ivan Lozanoffee3342019-08-27 12:03:00 -0700833func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
834 var depPaths PathDeps
835
836 directRlibDeps := []*Module{}
837 directDylibDeps := []*Module{}
838 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700839 directSharedLibDeps := [](cc.LinkableInterface){}
840 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400841 directSrcProvidersDeps := []*Module{}
842 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700843
844 ctx.VisitDirectDeps(func(dep android.Module) {
845 depName := ctx.OtherModuleName(dep)
846 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozano89435d12020-07-31 11:01:18 -0400847 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700848 //Handle Rust Modules
Ivan Lozano70e0a072019-09-13 14:23:15 -0700849
Ivan Lozanoffee3342019-08-27 12:03:00 -0700850 switch depTag {
851 case dylibDepTag:
852 dylib, ok := rustDep.compiler.(libraryInterface)
853 if !ok || !dylib.dylib() {
854 ctx.ModuleErrorf("mod %q not an dylib library", depName)
855 return
856 }
857 directDylibDeps = append(directDylibDeps, rustDep)
858 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
859 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -0400860
Ivan Lozanoffee3342019-08-27 12:03:00 -0700861 rlib, ok := rustDep.compiler.(libraryInterface)
862 if !ok || !rlib.rlib() {
Ivan Lozano2b081132020-09-08 12:46:52 -0400863 ctx.ModuleErrorf("mod %q not an rlib library", depName+rustDep.Properties.SubName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700864 return
865 }
866 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozano2b081132020-09-08 12:46:52 -0400867 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName+rustDep.Properties.SubName)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700868 case procMacroDepTag:
869 directProcMacroDeps = append(directProcMacroDeps, rustDep)
870 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400871 case android.SourceDepTag:
872 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
873 // OS/Arch variant is used.
874 var helper string
875 if ctx.Host() {
876 helper = "missing 'host_supported'?"
877 } else {
878 helper = "device module defined?"
879 }
880
881 if dep.Target().Os != ctx.Os() {
882 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
883 return
884 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
885 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
886 return
887 }
888 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700889 }
890
Ivan Lozano2bbcacf2020-08-07 09:00:50 -0400891 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -0700892 if depTag != procMacroDepTag {
893 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
894 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
895 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
896 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700897 }
898
Ivan Lozanoffee3342019-08-27 12:03:00 -0700899 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900900 linkFile := rustDep.unstrippedOutputFile
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400901 if !linkFile.Valid() {
902 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
903 depName, ctx.ModuleName())
904 return
905 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700906 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700907 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
908 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700909 }
910 }
911
Ivan Lozano89435d12020-07-31 11:01:18 -0400912 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -0700913 //Handle C dependencies
914 if _, ok := ccDep.(*Module); !ok {
915 if ccDep.Module().Target().Os != ctx.Os() {
916 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
917 return
918 }
919 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
920 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
921 return
922 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700923 }
Ivan Lozano2093af22020-08-25 12:48:19 -0400924 linkObject := ccDep.OutputFile()
925 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500926
Ivan Lozano2093af22020-08-25 12:48:19 -0400927 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700928 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
929 }
930
931 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700932 switch {
933 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -0400934 if cc.IsWholeStaticLib(depTag) {
935 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
936 // if the library is not prefixed by "lib".
Ivan Lozanofb6f36f2021-02-05 12:27:08 -0500937 if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
938 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400939 } else {
940 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 -0500941 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500942 }
943
944 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
945 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -0400946 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500947 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
948
Colin Cross0de8a1e2020-09-18 14:15:30 -0700949 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
950 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
951 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
952 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
953 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700954 directStaticLibDeps = append(directStaticLibDeps, ccDep)
955 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
Colin Cross6e511a92020-07-27 21:26:48 -0700956 case cc.IsSharedDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700957 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400958 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -0700959 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
960 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
961 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
962 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
963 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700964 directSharedLibDeps = append(directSharedLibDeps, ccDep)
965 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
966 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -0800967 case cc.IsHeaderDepTag(depTag):
968 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
969 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
970 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
971 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -0700972 case depTag == cc.CrtBeginDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400973 depPaths.CrtBegin = linkObject
Colin Cross6e511a92020-07-27 21:26:48 -0700974 case depTag == cc.CrtEndDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400975 depPaths.CrtEnd = linkObject
Ivan Lozanoffee3342019-08-27 12:03:00 -0700976 }
977
978 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -0700979 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
980 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400981 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700982 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700983 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400984
985 if srcDep, ok := dep.(android.SourceFileProducer); ok {
986 switch depTag {
987 case android.SourceDepTag:
988 // These are usually genrules which don't have per-target variants.
989 directSrcDeps = append(directSrcDeps, srcDep)
990 }
991 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700992 })
993
994 var rlibDepFiles RustLibraries
995 for _, dep := range directRlibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900996 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -0700997 }
998 var dylibDepFiles RustLibraries
999 for _, dep := range directDylibDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001000 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001001 }
1002 var procMacroDepFiles RustLibraries
1003 for _, dep := range directProcMacroDeps {
Jiyong Parke54f07e2021-04-07 15:08:04 +09001004 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001005 }
1006
1007 var staticLibDepFiles android.Paths
1008 for _, dep := range directStaticLibDeps {
1009 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1010 }
1011
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001012 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001013 var sharedLibDepFiles android.Paths
1014 for _, dep := range directSharedLibDeps {
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001015 sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path())
1016 if dep.Toc().Valid() {
1017 sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path())
1018 } else {
1019 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
1020 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001021 }
1022
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001023 var srcProviderDepFiles android.Paths
1024 for _, dep := range directSrcProvidersDeps {
1025 srcs, _ := dep.OutputFiles("")
1026 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1027 }
1028 for _, dep := range directSrcDeps {
1029 srcs := dep.Srcs()
1030 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1031 }
1032
Ivan Lozanoffee3342019-08-27 12:03:00 -07001033 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1034 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1035 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001036 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001037 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1038 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001039 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001040
1041 // Dedup exported flags from dependencies
1042 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001043 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001044 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001045 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1046 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1047 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001048
1049 return depPaths
1050}
1051
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001052func (mod *Module) InstallInData() bool {
1053 if mod.compiler == nil {
1054 return false
1055 }
1056 return mod.compiler.inData()
1057}
1058
Ivan Lozanoffee3342019-08-27 12:03:00 -07001059func linkPathFromFilePath(filepath android.Path) string {
1060 return strings.Split(filepath.String(), filepath.Base())[0]
1061}
Ivan Lozanod648c432020-02-06 12:05:10 -05001062
Ivan Lozanoffee3342019-08-27 12:03:00 -07001063func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1064 ctx := &depsContext{
1065 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001066 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001067
1068 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001069 var commonDepVariations []blueprint.Variation
Ivan Lozanodd055472020-09-28 13:22:45 -04001070
Ivan Lozano2b081132020-09-08 12:46:52 -04001071 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001072 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001073 stdLinkage = "rlib-std"
1074 }
1075
1076 rlibDepVariations := commonDepVariations
1077 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1078 rlibDepVariations = append(rlibDepVariations,
1079 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1080 }
1081
Ivan Lozano52767be2019-10-18 14:49:46 -07001082 actx.AddVariationDependencies(
Ivan Lozano2b081132020-09-08 12:46:52 -04001083 append(rlibDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001084 {Mutator: "rust_libraries", Variation: rlibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001085 rlibDepTag, deps.Rlibs...)
1086 actx.AddVariationDependencies(
1087 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001088 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001089 dylibDepTag, deps.Dylibs...)
1090
Ivan Lozano042504f2020-08-18 14:31:23 -04001091 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1092 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2b081132020-09-08 12:46:52 -04001093 if autoDep.depTag == rlibDepTag {
1094 actx.AddVariationDependencies(
1095 append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1096 autoDep.depTag, deps.Rustlibs...)
1097 } else {
1098 actx.AddVariationDependencies(
1099 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}),
1100 autoDep.depTag, deps.Rustlibs...)
1101 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001102 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001103 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001104 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001105 actx.AddVariationDependencies(
1106 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
1107 rlibDepTag, deps.Stdlibs...)
1108 } else {
1109 actx.AddVariationDependencies(
1110 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1111 dylibDepTag, deps.Stdlibs...)
1112 }
1113 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001114 actx.AddVariationDependencies(append(commonDepVariations,
1115 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001116 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -07001117 actx.AddVariationDependencies(append(commonDepVariations,
1118 blueprint.Variation{Mutator: "link", Variation: "static"}),
Ivan Lozano63bb7682021-03-23 15:53:44 -04001119 cc.StaticDepTag(false), deps.StaticLibs...)
1120 actx.AddVariationDependencies(append(commonDepVariations,
1121 blueprint.Variation{Mutator: "link", Variation: "static"}),
1122 cc.StaticDepTag(true), deps.WholeStaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001123
Zach Johnson3df4e632020-11-06 11:56:27 -08001124 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1125
Colin Cross565cafd2020-09-25 18:47:38 -07001126 crtVariations := cc.GetCrtVariations(ctx, mod)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001127 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001128 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001129 }
1130 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001131 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001132 }
1133
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001134 if mod.sourceProvider != nil {
1135 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1136 bindgen.Properties.Custom_bindgen != "" {
1137 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1138 bindgen.Properties.Custom_bindgen)
1139 }
1140 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001141 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001142 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001143}
1144
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001145func BeginMutator(ctx android.BottomUpMutatorContext) {
1146 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1147 mod.beginMutator(ctx)
1148 }
1149}
1150
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001151func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1152 ctx := &baseModuleContext{
1153 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001154 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001155
1156 mod.begin(ctx)
1157}
1158
Ivan Lozanoffee3342019-08-27 12:03:00 -07001159func (mod *Module) Name() string {
1160 name := mod.ModuleBase.Name()
1161 if p, ok := mod.compiler.(interface {
1162 Name(string) string
1163 }); ok {
1164 name = p.Name(name)
1165 }
1166 return name
1167}
1168
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001169func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001170 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001171 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001172 }
1173}
1174
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001175var _ android.HostToolProvider = (*Module)(nil)
1176
1177func (mod *Module) HostToolPath() android.OptionalPath {
1178 if !mod.Host() {
1179 return android.OptionalPath{}
1180 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001181 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1182 return android.OptionalPathForPath(binary.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001183 }
1184 return android.OptionalPath{}
1185}
1186
Jiyong Park99644e92020-11-17 22:21:02 +09001187var _ android.ApexModule = (*Module)(nil)
1188
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001189func (mod *Module) minSdkVersion() string {
1190 return String(mod.Properties.Min_sdk_version)
1191}
1192
Jiyong Park45bf82e2020-12-15 22:29:02 +09001193var _ android.ApexModule = (*Module)(nil)
1194
1195// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001196func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001197 minSdkVersion := mod.minSdkVersion()
1198 if minSdkVersion == "apex_inherit" {
1199 return nil
1200 }
1201 if minSdkVersion == "" {
1202 return fmt.Errorf("min_sdk_version is not specificed")
1203 }
1204
1205 // Not using nativeApiLevelFromUser because the context here is not
1206 // necessarily a native context.
1207 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1208 if err != nil {
1209 return err
1210 }
1211
1212 if ver.GreaterThan(sdkVersion) {
1213 return fmt.Errorf("newer SDK(%v)", ver)
1214 }
Jiyong Park99644e92020-11-17 22:21:02 +09001215 return nil
1216}
1217
Jiyong Park45bf82e2020-12-15 22:29:02 +09001218// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001219func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1220 depTag := ctx.OtherModuleDependencyTag(dep)
1221
1222 if ccm, ok := dep.(*cc.Module); ok {
1223 if ccm.HasStubsVariants() {
1224 if cc.IsSharedDepTag(depTag) {
1225 // dynamic dep to a stubs lib crosses APEX boundary
1226 return false
1227 }
1228 if cc.IsRuntimeDepTag(depTag) {
1229 // runtime dep to a stubs lib also crosses APEX boundary
1230 return false
1231 }
1232
1233 if cc.IsHeaderDepTag(depTag) {
1234 return false
1235 }
1236 }
1237 if mod.Static() && cc.IsSharedDepTag(depTag) {
1238 // shared_lib dependency from a static lib is considered as crossing
1239 // the APEX boundary because the dependency doesn't actually is
1240 // linked; the dependency is used only during the compilation phase.
1241 return false
1242 }
1243 }
1244
1245 if depTag == procMacroDepTag {
1246 return false
1247 }
1248
1249 return true
1250}
1251
1252// Overrides ApexModule.IsInstallabeToApex()
1253func (mod *Module) IsInstallableToApex() bool {
1254 if mod.compiler != nil {
1255 if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) {
1256 return true
1257 }
1258 if _, ok := mod.compiler.(*binaryDecorator); ok {
1259 return true
1260 }
1261 }
1262 return false
1263}
1264
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001265// If a library file has a "lib" prefix, extract the library name without the prefix.
1266func libNameFromFilePath(filepath android.Path) (string, bool) {
1267 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1268 if strings.HasPrefix(libName, "lib") {
1269 libName = libName[3:]
1270 return libName, true
1271 }
1272 return "", false
1273}
1274
Ivan Lozanoffee3342019-08-27 12:03:00 -07001275var Bool = proptools.Bool
1276var BoolDefault = proptools.BoolDefault
1277var String = proptools.String
1278var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001279
1280var _ android.OutputFileProducer = (*Module)(nil)