blob: 8dffb43b75a572d70509501dc6e5c3a2653bb44e [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"
26 "android/soong/rust/config"
27)
28
29var pctx = android.NewPackageContext("android/soong/rust")
30
31func init() {
32 // Only allow rust modules to be defined for certain projects
Ivan Lozanoffee3342019-08-27 12:03:00 -070033
34 android.AddNeverAllowRules(
35 android.NeverAllow().
Ivan Lozanoe169ad72019-09-18 08:42:54 -070036 NotIn(config.RustAllowedPaths...).
37 ModuleType(config.RustModuleTypes...))
Ivan Lozanoffee3342019-08-27 12:03:00 -070038
39 android.RegisterModuleType("rust_defaults", defaultsFactory)
40 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
41 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040042 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070043 })
44 pctx.Import("android/soong/rust/config")
Ivan Lozano4fef93c2020-07-08 08:39:44 -040045 pctx.ImportAs("ccConfig", "android/soong/cc/config")
Ivan Lozanoffee3342019-08-27 12:03:00 -070046}
47
48type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040049 GlobalRustFlags []string // Flags that apply globally to rust
50 GlobalLinkFlags []string // Flags that apply globally to linker
51 RustFlags []string // Flags that apply to rust
52 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020053 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Ivan Lozanof1c84332019-09-20 11:00:37 -070054 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040055 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020056 Clippy bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070057}
58
59type BaseProperties struct {
60 AndroidMkRlibs []string
61 AndroidMkDylibs []string
62 AndroidMkProcMacroLibs []string
63 AndroidMkSharedLibs []string
64 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040065
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040066 SubName string `blueprint:"mutated"`
67
Ivan Lozano43845682020-07-09 21:03:28 -040068 PreventInstall bool
69 HideFromMake bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070070}
71
72type Module struct {
73 android.ModuleBase
74 android.DefaultableModuleBase
75
76 Properties BaseProperties
77
78 hod android.HostOrDeviceSupported
79 multilib android.Multilib
80
81 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040082 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020083 clippy *clippy
Ivan Lozanoffee3342019-08-27 12:03:00 -070084 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -040085 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -070086 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -040087
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040088 outputFile android.OptionalPath
89 generatedFile android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -070090}
91
Ivan Lozano43845682020-07-09 21:03:28 -040092func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
93 switch tag {
94 case "":
Andrei Homescu5db69cc2020-08-06 15:27:45 -070095 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
Ivan Lozano43845682020-07-09 21:03:28 -040096 return mod.sourceProvider.Srcs(), nil
97 } else {
98 if mod.outputFile.Valid() {
99 return android.Paths{mod.outputFile.Path()}, nil
100 }
101 return android.Paths{}, nil
102 }
103 default:
104 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
105 }
106}
107
Colin Cross7228ecd2019-11-18 16:00:16 -0800108var _ android.ImageInterface = (*Module)(nil)
109
110func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {}
111
112func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
113 return true
114}
115
Yifan Hong1b3348d2020-01-21 15:53:22 -0800116func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool {
117 return mod.InRamdisk()
118}
119
Colin Cross7228ecd2019-11-18 16:00:16 -0800120func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool {
121 return mod.InRecovery()
122}
123
124func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
125 return nil
126}
127
128func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
129}
130
Ivan Lozano52767be2019-10-18 14:49:46 -0700131func (mod *Module) BuildStubs() bool {
132 return false
133}
134
135func (mod *Module) HasStubsVariants() bool {
136 return false
137}
138
139func (mod *Module) SelectedStl() string {
140 return ""
141}
142
Ivan Lozano2b262972019-11-21 12:30:50 -0800143func (mod *Module) NonCcVariants() bool {
144 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400145 if _, ok := mod.compiler.(libraryInterface); ok {
146 return false
Ivan Lozano2b262972019-11-21 12:30:50 -0800147 }
148 }
149 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
150}
151
Ivan Lozano52767be2019-10-18 14:49:46 -0700152func (mod *Module) ApiLevel() string {
153 panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName()))
154}
155
156func (mod *Module) Static() bool {
157 if mod.compiler != nil {
158 if library, ok := mod.compiler.(libraryInterface); ok {
159 return library.static()
160 }
161 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400162 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700163}
164
165func (mod *Module) Shared() bool {
166 if mod.compiler != nil {
167 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400168 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700169 }
170 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400171 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700172}
173
174func (mod *Module) Toc() android.OptionalPath {
175 if mod.compiler != nil {
176 if _, ok := mod.compiler.(libraryInterface); ok {
177 return android.OptionalPath{}
178 }
179 }
180 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
181}
182
Yifan Hong1b3348d2020-01-21 15:53:22 -0800183func (mod *Module) OnlyInRamdisk() bool {
184 return false
185}
186
Ivan Lozano52767be2019-10-18 14:49:46 -0700187func (mod *Module) OnlyInRecovery() bool {
188 return false
189}
190
Colin Crossc511bc52020-04-07 16:50:32 +0000191func (mod *Module) UseSdk() bool {
192 return false
193}
194
Ivan Lozano52767be2019-10-18 14:49:46 -0700195func (mod *Module) UseVndk() bool {
196 return false
197}
198
199func (mod *Module) MustUseVendorVariant() bool {
200 return false
201}
202
203func (mod *Module) IsVndk() bool {
204 return false
205}
206
207func (mod *Module) HasVendorVariant() bool {
208 return false
209}
210
211func (mod *Module) SdkVersion() string {
212 return ""
213}
214
Colin Crossc511bc52020-04-07 16:50:32 +0000215func (mod *Module) AlwaysSdk() bool {
216 return false
217}
218
Jiyong Park2286afd2020-06-16 21:58:53 +0900219func (mod *Module) IsSdkVariant() bool {
220 return false
221}
222
Ivan Lozano52767be2019-10-18 14:49:46 -0700223func (mod *Module) ToolchainLibrary() bool {
224 return false
225}
226
227func (mod *Module) NdkPrebuiltStl() bool {
228 return false
229}
230
231func (mod *Module) StubDecorator() bool {
232 return false
233}
234
Ivan Lozanoffee3342019-08-27 12:03:00 -0700235type Deps struct {
236 Dylibs []string
237 Rlibs []string
Matthew Maurer0f003b12020-06-29 14:34:06 -0700238 Rustlibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700239 ProcMacros []string
240 SharedLibs []string
241 StaticLibs []string
242
243 CrtBegin, CrtEnd string
244}
245
246type PathDeps struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400247 DyLibs RustLibraries
248 RLibs RustLibraries
249 SharedLibs android.Paths
250 StaticLibs android.Paths
251 ProcMacros RustLibraries
252 linkDirs []string
253 depFlags []string
254 linkObjects []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700255 //ReexportedDeps android.Paths
Ivan Lozanof1c84332019-09-20 11:00:37 -0700256
Ivan Lozano45901ed2020-07-24 16:05:01 -0400257 // Used by bindgen modules which call clang
258 depClangFlags []string
259 depIncludePaths android.Paths
260 depSystemIncludePaths android.Paths
261
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400262 coverageFiles android.Paths
263
Ivan Lozanof1c84332019-09-20 11:00:37 -0700264 CrtBegin android.OptionalPath
265 CrtEnd android.OptionalPath
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700266
267 // Paths to generated source files
268 SrcDeps android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700269}
270
271type RustLibraries []RustLibrary
272
273type RustLibrary struct {
274 Path android.Path
275 CrateName string
276}
277
278type compiler interface {
279 compilerFlags(ctx ModuleContext, flags Flags) Flags
280 compilerProps() []interface{}
281 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
282 compilerDeps(ctx DepsContext, deps Deps) Deps
283 crateName() string
284
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800285 inData() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700286 install(ctx ModuleContext, path android.Path)
287 relativeInstallPath() string
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400288
289 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400290
291 Disabled() bool
292 SetDisabled()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400293}
294
Matthew Maurerbb3add12020-06-25 09:34:12 -0700295type exportedFlagsProducer interface {
296 exportedLinkDirs() []string
297 exportedDepFlags() []string
Ivan Lozano2093af22020-08-25 12:48:19 -0400298 exportedLinkObjects() []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700299 exportLinkDirs(...string)
300 exportDepFlags(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400301 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700302}
303
304type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400305 depFlags []string
306 linkDirs []string
307 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700308}
309
310func (flagExporter *flagExporter) exportedLinkDirs() []string {
311 return flagExporter.linkDirs
312}
313
314func (flagExporter *flagExporter) exportedDepFlags() []string {
315 return flagExporter.depFlags
316}
317
Ivan Lozano2093af22020-08-25 12:48:19 -0400318func (flagExporter *flagExporter) exportedLinkObjects() []string {
319 return flagExporter.linkObjects
320}
321
Matthew Maurerbb3add12020-06-25 09:34:12 -0700322func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
323 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
324}
325
326func (flagExporter *flagExporter) exportDepFlags(flags ...string) {
327 flagExporter.depFlags = android.FirstUniqueStrings(append(flagExporter.depFlags, flags...))
328}
329
Ivan Lozano2093af22020-08-25 12:48:19 -0400330func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
331 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
332}
333
Matthew Maurerbb3add12020-06-25 09:34:12 -0700334var _ exportedFlagsProducer = (*flagExporter)(nil)
335
336func NewFlagExporter() *flagExporter {
337 return &flagExporter{
Ivan Lozano2093af22020-08-25 12:48:19 -0400338 depFlags: []string{},
339 linkDirs: []string{},
340 linkObjects: []string{},
Matthew Maurerbb3add12020-06-25 09:34:12 -0700341 }
342}
343
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400344func (mod *Module) isCoverageVariant() bool {
345 return mod.coverage.Properties.IsCoverageVariant
346}
347
348var _ cc.Coverage = (*Module)(nil)
349
350func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
351 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
352}
353
354func (mod *Module) PreventInstall() {
355 mod.Properties.PreventInstall = true
356}
357
358func (mod *Module) HideFromMake() {
359 mod.Properties.HideFromMake = true
360}
361
362func (mod *Module) MarkAsCoverageVariant(coverage bool) {
363 mod.coverage.Properties.IsCoverageVariant = coverage
364}
365
366func (mod *Module) EnableCoverageIfNeeded() {
367 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700368}
369
370func defaultsFactory() android.Module {
371 return DefaultsFactory()
372}
373
374type Defaults struct {
375 android.ModuleBase
376 android.DefaultsModuleBase
377}
378
379func DefaultsFactory(props ...interface{}) android.Module {
380 module := &Defaults{}
381
382 module.AddProperties(props...)
383 module.AddProperties(
384 &BaseProperties{},
385 &BaseCompilerProperties{},
386 &BinaryCompilerProperties{},
387 &LibraryCompilerProperties{},
388 &ProcMacroCompilerProperties{},
389 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400390 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700391 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400392 &cc.CoverageProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200393 &ClippyProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700394 )
395
396 android.InitDefaultsModule(module)
397 return module
398}
399
400func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700401 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700402}
403
Ivan Lozano183a3212019-10-18 14:18:45 -0700404func (mod *Module) CcLibrary() bool {
405 if mod.compiler != nil {
406 if _, ok := mod.compiler.(*libraryDecorator); ok {
407 return true
408 }
409 }
410 return false
411}
412
413func (mod *Module) CcLibraryInterface() bool {
414 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400415 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
416 // VariantIs{Static,Shared} is set.
417 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700418 return true
419 }
420 }
421 return false
422}
423
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800424func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700425 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700426 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800427 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700428 }
429 }
430 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
431}
432
433func (mod *Module) SetStatic() {
434 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700435 if library, ok := mod.compiler.(libraryInterface); ok {
436 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700437 return
438 }
439 }
440 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
441}
442
443func (mod *Module) SetShared() {
444 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700445 if library, ok := mod.compiler.(libraryInterface); ok {
446 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700447 return
448 }
449 }
450 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
451}
452
453func (mod *Module) SetBuildStubs() {
454 panic("SetBuildStubs not yet implemented for rust modules")
455}
456
457func (mod *Module) SetStubsVersions(string) {
458 panic("SetStubsVersions not yet implemented for rust modules")
459}
460
Jooyung Han03b51852020-02-26 22:45:42 +0900461func (mod *Module) StubsVersion() string {
462 panic("SetStubsVersions not yet implemented for rust modules")
463}
464
Ivan Lozano183a3212019-10-18 14:18:45 -0700465func (mod *Module) BuildStaticVariant() bool {
466 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700467 if library, ok := mod.compiler.(libraryInterface); ok {
468 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700469 }
470 }
471 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
472}
473
474func (mod *Module) BuildSharedVariant() bool {
475 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700476 if library, ok := mod.compiler.(libraryInterface); ok {
477 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700478 }
479 }
480 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
481}
482
483// Rust module deps don't have a link order (?)
484func (mod *Module) SetDepsInLinkOrder([]android.Path) {}
485
486func (mod *Module) GetDepsInLinkOrder() []android.Path {
487 return []android.Path{}
488}
489
490func (mod *Module) GetStaticVariant() cc.LinkableInterface {
491 return nil
492}
493
494func (mod *Module) Module() android.Module {
495 return mod
496}
497
498func (mod *Module) StubsVersions() []string {
499 // For now, Rust has no stubs versions.
500 if mod.compiler != nil {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700501 if _, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700502 return []string{}
503 }
504 }
505 panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName()))
506}
507
508func (mod *Module) OutputFile() android.OptionalPath {
509 return mod.outputFile
510}
511
512func (mod *Module) InRecovery() bool {
513 // For now, Rust has no notion of the recovery image
514 return false
515}
516func (mod *Module) HasStaticVariant() bool {
517 if mod.GetStaticVariant() != nil {
518 return true
519 }
520 return false
521}
522
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400523func (mod *Module) CoverageFiles() android.Paths {
524 if mod.compiler != nil {
Matthew Maurerc761eec2020-06-25 00:47:46 -0700525 if !mod.compiler.nativeCoverage() {
526 return android.Paths{}
527 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400528 if library, ok := mod.compiler.(*libraryDecorator); ok {
529 if library.coverageFile != nil {
530 return android.Paths{library.coverageFile}
531 }
532 return android.Paths{}
533 }
534 }
535 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
536}
537
Ivan Lozano183a3212019-10-18 14:18:45 -0700538var _ cc.LinkableInterface = (*Module)(nil)
539
Ivan Lozanoffee3342019-08-27 12:03:00 -0700540func (mod *Module) Init() android.Module {
541 mod.AddProperties(&mod.Properties)
542
543 if mod.compiler != nil {
544 mod.AddProperties(mod.compiler.compilerProps()...)
545 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400546 if mod.coverage != nil {
547 mod.AddProperties(mod.coverage.props()...)
548 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200549 if mod.clippy != nil {
550 mod.AddProperties(mod.clippy.props()...)
551 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400552 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700553 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400554 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400555
Ivan Lozanoffee3342019-08-27 12:03:00 -0700556 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
557
558 android.InitDefaultableModule(mod)
559
Ivan Lozanode252912019-09-06 15:29:52 -0700560 // Explicitly disable unsupported targets.
561 android.AddLoadHook(mod, func(ctx android.LoadHookContext) {
562 disableTargets := struct {
563 Target struct {
Ivan Lozanode252912019-09-06 15:29:52 -0700564 Linux_bionic struct {
565 Enabled *bool
566 }
567 }
568 }{}
Ivan Lozanode252912019-09-06 15:29:52 -0700569 disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false)
570
571 ctx.AppendProperties(&disableTargets)
572 })
573
Ivan Lozanoffee3342019-08-27 12:03:00 -0700574 return mod
575}
576
577func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
578 return &Module{
579 hod: hod,
580 multilib: multilib,
581 }
582}
583func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
584 module := newBaseModule(hod, multilib)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400585 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200586 module.clippy = &clippy{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700587 return module
588}
589
590type ModuleContext interface {
591 android.ModuleContext
592 ModuleContextIntf
593}
594
595type BaseModuleContext interface {
596 android.BaseModuleContext
597 ModuleContextIntf
598}
599
600type DepsContext interface {
601 android.BottomUpMutatorContext
602 ModuleContextIntf
603}
604
605type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200606 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700607 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700608}
609
610type depsContext struct {
611 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700612}
613
614type moduleContext struct {
615 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700616}
617
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200618type baseModuleContext struct {
619 android.BaseModuleContext
620}
621
622func (ctx *moduleContext) RustModule() *Module {
623 return ctx.Module().(*Module)
624}
625
626func (ctx *moduleContext) toolchain() config.Toolchain {
627 return ctx.RustModule().toolchain(ctx)
628}
629
630func (ctx *depsContext) RustModule() *Module {
631 return ctx.Module().(*Module)
632}
633
634func (ctx *depsContext) toolchain() config.Toolchain {
635 return ctx.RustModule().toolchain(ctx)
636}
637
638func (ctx *baseModuleContext) RustModule() *Module {
639 return ctx.Module().(*Module)
640}
641
642func (ctx *baseModuleContext) toolchain() config.Toolchain {
643 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400644}
645
646func (mod *Module) nativeCoverage() bool {
647 return mod.compiler != nil && mod.compiler.nativeCoverage()
648}
649
Ivan Lozanoffee3342019-08-27 12:03:00 -0700650func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
651 if mod.cachedToolchain == nil {
652 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
653 }
654 return mod.cachedToolchain
655}
656
657func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
658}
659
660func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
661 ctx := &moduleContext{
662 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700663 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700664
665 toolchain := mod.toolchain(ctx)
666
667 if !toolchain.Supported() {
668 // This toolchain's unsupported, there's nothing to do for this mod.
669 return
670 }
671
672 deps := mod.depsToPaths(ctx)
673 flags := Flags{
674 Toolchain: toolchain,
675 }
676
677 if mod.compiler != nil {
678 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400679 }
680 if mod.coverage != nil {
681 flags, deps = mod.coverage.flags(ctx, flags, deps)
682 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200683 if mod.clippy != nil {
684 flags, deps = mod.clippy.flags(ctx, flags, deps)
685 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400686
Andrei Homescuc7767922020-08-05 06:36:19 -0700687 // SourceProvider needs to call GenerateSource() before compiler calls compile() so it can provide the source.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400688 // TODO(b/162588681) This shouldn't have to run for every variant.
689 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700690 generatedFile := mod.sourceProvider.GenerateSource(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400691 mod.generatedFile = android.OptionalPathForPath(generatedFile)
692 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
693 }
694
695 if mod.compiler != nil && !mod.compiler.Disabled() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700696 outputFile := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400697
Ivan Lozanoffee3342019-08-27 12:03:00 -0700698 mod.outputFile = android.OptionalPathForPath(outputFile)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400699 if mod.outputFile.Valid() && !mod.Properties.PreventInstall {
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400700 mod.compiler.install(ctx, mod.outputFile.Path())
701 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700702 }
703}
704
705func (mod *Module) deps(ctx DepsContext) Deps {
706 deps := Deps{}
707
708 if mod.compiler != nil {
709 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400710 }
711 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700712 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700713 }
714
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400715 if mod.coverage != nil {
716 deps = mod.coverage.deps(ctx, deps)
717 }
718
Ivan Lozanoffee3342019-08-27 12:03:00 -0700719 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
720 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700721 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700722 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
723 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
724 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
725
726 return deps
727
728}
729
Ivan Lozanoffee3342019-08-27 12:03:00 -0700730type dependencyTag struct {
731 blueprint.BaseDependencyTag
732 name string
733 library bool
734 proc_macro bool
735}
736
737var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -0400738 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
739 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
740 dylibDepTag = dependencyTag{name: "dylib", library: true}
741 procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
742 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700743)
744
Matthew Maurer0f003b12020-06-29 14:34:06 -0700745type autoDep struct {
746 variation string
747 depTag dependencyTag
748}
749
750var (
751 rlibAutoDep = autoDep{variation: "rlib", depTag: rlibDepTag}
752 dylibAutoDep = autoDep{variation: "dylib", depTag: dylibDepTag}
753)
754
755type autoDeppable interface {
756 autoDep() autoDep
757}
758
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400759func (mod *Module) begin(ctx BaseModuleContext) {
760 if mod.coverage != nil {
761 mod.coverage.begin(ctx)
762 }
763}
764
Ivan Lozanoffee3342019-08-27 12:03:00 -0700765func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
766 var depPaths PathDeps
767
768 directRlibDeps := []*Module{}
769 directDylibDeps := []*Module{}
770 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700771 directSharedLibDeps := [](cc.LinkableInterface){}
772 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400773 directSrcProvidersDeps := []*Module{}
774 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700775
776 ctx.VisitDirectDeps(func(dep android.Module) {
777 depName := ctx.OtherModuleName(dep)
778 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozano89435d12020-07-31 11:01:18 -0400779 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700780 //Handle Rust Modules
Ivan Lozano70e0a072019-09-13 14:23:15 -0700781
Ivan Lozanoffee3342019-08-27 12:03:00 -0700782 switch depTag {
783 case dylibDepTag:
784 dylib, ok := rustDep.compiler.(libraryInterface)
785 if !ok || !dylib.dylib() {
786 ctx.ModuleErrorf("mod %q not an dylib library", depName)
787 return
788 }
789 directDylibDeps = append(directDylibDeps, rustDep)
790 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
791 case rlibDepTag:
792 rlib, ok := rustDep.compiler.(libraryInterface)
793 if !ok || !rlib.rlib() {
794 ctx.ModuleErrorf("mod %q not an rlib library", depName)
795 return
796 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400797 depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700798 directRlibDeps = append(directRlibDeps, rustDep)
799 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
800 case procMacroDepTag:
801 directProcMacroDeps = append(directProcMacroDeps, rustDep)
802 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400803 case android.SourceDepTag:
804 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
805 // OS/Arch variant is used.
806 var helper string
807 if ctx.Host() {
808 helper = "missing 'host_supported'?"
809 } else {
810 helper = "device module defined?"
811 }
812
813 if dep.Target().Os != ctx.Os() {
814 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
815 return
816 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
817 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
818 return
819 }
820 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700821 }
822
Ivan Lozano2bbcacf2020-08-07 09:00:50 -0400823 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
824 if lib, ok := rustDep.compiler.(exportedFlagsProducer); ok && depTag != procMacroDepTag {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700825 depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedLinkDirs()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700826 depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
Ivan Lozano2093af22020-08-25 12:48:19 -0400827 depPaths.linkObjects = append(depPaths.linkObjects, lib.exportedLinkObjects()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700828 }
829
Ivan Lozanoffee3342019-08-27 12:03:00 -0700830 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400831 linkFile := rustDep.outputFile
832 if !linkFile.Valid() {
833 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
834 depName, ctx.ModuleName())
835 return
836 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700837 linkDir := linkPathFromFilePath(linkFile.Path())
Matthew Maurerbb3add12020-06-25 09:34:12 -0700838 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
839 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700840 }
841 }
842
Ivan Lozano89435d12020-07-31 11:01:18 -0400843 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -0700844 //Handle C dependencies
845 if _, ok := ccDep.(*Module); !ok {
846 if ccDep.Module().Target().Os != ctx.Os() {
847 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
848 return
849 }
850 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
851 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
852 return
853 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700854 }
Ivan Lozano2093af22020-08-25 12:48:19 -0400855 linkObject := ccDep.OutputFile()
856 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -0500857
Ivan Lozano2093af22020-08-25 12:48:19 -0400858 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700859 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
860 }
861
862 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -0700863 switch {
864 case cc.IsStaticDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700865 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400866 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano45901ed2020-07-24 16:05:01 -0400867 depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
868 if mod, ok := ccDep.(*cc.Module); ok {
869 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
870 depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
871 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400872 depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700873 directStaticLibDeps = append(directStaticLibDeps, ccDep)
874 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
Colin Cross6e511a92020-07-27 21:26:48 -0700875 case cc.IsSharedDepTag(depTag):
Ivan Lozanoffee3342019-08-27 12:03:00 -0700876 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400877 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano45901ed2020-07-24 16:05:01 -0400878 depPaths.depIncludePaths = append(depPaths.depIncludePaths, ccDep.IncludeDirs()...)
879 if mod, ok := ccDep.(*cc.Module); ok {
880 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, mod.ExportedSystemIncludeDirs()...)
881 depPaths.depClangFlags = append(depPaths.depClangFlags, mod.ExportedFlags()...)
882 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700883 directSharedLibDeps = append(directSharedLibDeps, ccDep)
884 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
885 exportDep = true
Colin Cross6e511a92020-07-27 21:26:48 -0700886 case depTag == cc.CrtBeginDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400887 depPaths.CrtBegin = linkObject
Colin Cross6e511a92020-07-27 21:26:48 -0700888 case depTag == cc.CrtEndDepTag:
Ivan Lozano2093af22020-08-25 12:48:19 -0400889 depPaths.CrtEnd = linkObject
Ivan Lozanoffee3342019-08-27 12:03:00 -0700890 }
891
892 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -0700893 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
894 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -0400895 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700896 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700897 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400898
899 if srcDep, ok := dep.(android.SourceFileProducer); ok {
900 switch depTag {
901 case android.SourceDepTag:
902 // These are usually genrules which don't have per-target variants.
903 directSrcDeps = append(directSrcDeps, srcDep)
904 }
905 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700906 })
907
908 var rlibDepFiles RustLibraries
909 for _, dep := range directRlibDeps {
910 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
911 }
912 var dylibDepFiles RustLibraries
913 for _, dep := range directDylibDeps {
914 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
915 }
916 var procMacroDepFiles RustLibraries
917 for _, dep := range directProcMacroDeps {
918 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
919 }
920
921 var staticLibDepFiles android.Paths
922 for _, dep := range directStaticLibDeps {
923 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
924 }
925
926 var sharedLibDepFiles android.Paths
927 for _, dep := range directSharedLibDeps {
928 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
929 }
930
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400931 var srcProviderDepFiles android.Paths
932 for _, dep := range directSrcProvidersDeps {
933 srcs, _ := dep.OutputFiles("")
934 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
935 }
936 for _, dep := range directSrcDeps {
937 srcs := dep.Srcs()
938 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
939 }
940
Ivan Lozanoffee3342019-08-27 12:03:00 -0700941 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
942 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
943 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
944 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
945 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -0400946 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700947
948 // Dedup exported flags from dependencies
949 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
950 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -0400951 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
952 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
953 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700954
955 return depPaths
956}
957
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800958func (mod *Module) InstallInData() bool {
959 if mod.compiler == nil {
960 return false
961 }
962 return mod.compiler.inData()
963}
964
Ivan Lozanoffee3342019-08-27 12:03:00 -0700965func linkPathFromFilePath(filepath android.Path) string {
966 return strings.Split(filepath.String(), filepath.Base())[0]
967}
Ivan Lozanod648c432020-02-06 12:05:10 -0500968
Ivan Lozanoffee3342019-08-27 12:03:00 -0700969func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
970 ctx := &depsContext{
971 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700972 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700973
974 deps := mod.deps(ctx)
Ivan Lozano52767be2019-10-18 14:49:46 -0700975 commonDepVariations := []blueprint.Variation{}
Jooyung Han624d35c2020-04-10 12:57:24 +0900976 if cc.VersionVariantAvailable(mod) {
977 commonDepVariations = append(commonDepVariations,
978 blueprint.Variation{Mutator: "version", Variation: ""})
979 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700980 if !mod.Host() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700981 commonDepVariations = append(commonDepVariations,
Colin Cross7228ecd2019-11-18 16:00:16 -0800982 blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
Ivan Lozanoffee3342019-08-27 12:03:00 -0700983 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700984 actx.AddVariationDependencies(
985 append(commonDepVariations, []blueprint.Variation{
Ivan Lozano89435d12020-07-31 11:01:18 -0400986 {Mutator: "rust_libraries", Variation: "rlib"}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -0700987 rlibDepTag, deps.Rlibs...)
988 actx.AddVariationDependencies(
989 append(commonDepVariations, []blueprint.Variation{
Ivan Lozano89435d12020-07-31 11:01:18 -0400990 {Mutator: "rust_libraries", Variation: "dylib"}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -0700991 dylibDepTag, deps.Dylibs...)
992
Matthew Maurer0f003b12020-06-29 14:34:06 -0700993 if deps.Rustlibs != nil {
994 autoDep := mod.compiler.(autoDeppable).autoDep()
995 actx.AddVariationDependencies(
996 append(commonDepVariations, []blueprint.Variation{
Ivan Lozano89435d12020-07-31 11:01:18 -0400997 {Mutator: "rust_libraries", Variation: autoDep.variation}}...),
Matthew Maurer0f003b12020-06-29 14:34:06 -0700998 autoDep.depTag, deps.Rustlibs...)
999 }
1000
Ivan Lozano52767be2019-10-18 14:49:46 -07001001 actx.AddVariationDependencies(append(commonDepVariations,
1002 blueprint.Variation{Mutator: "link", Variation: "shared"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001003 cc.SharedDepTag(), deps.SharedLibs...)
Ivan Lozano52767be2019-10-18 14:49:46 -07001004 actx.AddVariationDependencies(append(commonDepVariations,
1005 blueprint.Variation{Mutator: "link", Variation: "static"}),
Colin Cross6e511a92020-07-27 21:26:48 -07001006 cc.StaticDepTag(), deps.StaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001007
Dan Albert92fe7402020-07-15 13:33:30 -07001008 crtVariations := append(cc.GetCrtVariations(ctx, mod), commonDepVariations...)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001009 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001010 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001011 }
1012 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001013 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -07001014 }
1015
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001016 if mod.sourceProvider != nil {
1017 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1018 bindgen.Properties.Custom_bindgen != "" {
1019 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1020 bindgen.Properties.Custom_bindgen)
1021 }
1022 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001023 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001024 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001025}
1026
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001027func BeginMutator(ctx android.BottomUpMutatorContext) {
1028 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1029 mod.beginMutator(ctx)
1030 }
1031}
1032
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001033func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1034 ctx := &baseModuleContext{
1035 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001036 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001037
1038 mod.begin(ctx)
1039}
1040
Ivan Lozanoffee3342019-08-27 12:03:00 -07001041func (mod *Module) Name() string {
1042 name := mod.ModuleBase.Name()
1043 if p, ok := mod.compiler.(interface {
1044 Name(string) string
1045 }); ok {
1046 name = p.Name(name)
1047 }
1048 return name
1049}
1050
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001051func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001052 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001053 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001054 }
1055}
1056
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001057var _ android.HostToolProvider = (*Module)(nil)
1058
1059func (mod *Module) HostToolPath() android.OptionalPath {
1060 if !mod.Host() {
1061 return android.OptionalPath{}
1062 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001063 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1064 return android.OptionalPathForPath(binary.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001065 }
1066 return android.OptionalPath{}
1067}
1068
Ivan Lozanoffee3342019-08-27 12:03:00 -07001069var Bool = proptools.Bool
1070var BoolDefault = proptools.BoolDefault
1071var String = proptools.String
1072var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001073
1074var _ android.OutputFileProducer = (*Module)(nil)