blob: ce81b91524ed13ac37638f26083bba25e433b074 [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()
42 })
43 pctx.Import("android/soong/rust/config")
44}
45
46type Flags struct {
Ivan Lozanof1c84332019-09-20 11:00:37 -070047 GlobalRustFlags []string // Flags that apply globally to rust
48 GlobalLinkFlags []string // Flags that apply globally to linker
49 RustFlags []string // Flags that apply to rust
50 LinkFlags []string // Flags that apply to linker
51 RustFlagsDeps android.Paths // Files depended on by compiler flags
52 Toolchain config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -070053}
54
55type BaseProperties struct {
56 AndroidMkRlibs []string
57 AndroidMkDylibs []string
58 AndroidMkProcMacroLibs []string
59 AndroidMkSharedLibs []string
60 AndroidMkStaticLibs []string
61}
62
63type Module struct {
64 android.ModuleBase
65 android.DefaultableModuleBase
66
67 Properties BaseProperties
68
69 hod android.HostOrDeviceSupported
70 multilib android.Multilib
71
72 compiler compiler
73 cachedToolchain config.Toolchain
74 subAndroidMkOnce map[subAndroidMkProvider]bool
75 outputFile android.OptionalPath
76}
77
Ivan Lozano52767be2019-10-18 14:49:46 -070078func (mod *Module) BuildStubs() bool {
79 return false
80}
81
82func (mod *Module) HasStubsVariants() bool {
83 return false
84}
85
86func (mod *Module) SelectedStl() string {
87 return ""
88}
89
90func (mod *Module) ApiLevel() string {
91 panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName()))
92}
93
94func (mod *Module) Static() bool {
95 if mod.compiler != nil {
96 if library, ok := mod.compiler.(libraryInterface); ok {
97 return library.static()
98 }
99 }
100 panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
101}
102
103func (mod *Module) Shared() bool {
104 if mod.compiler != nil {
105 if library, ok := mod.compiler.(libraryInterface); ok {
106 return library.static()
107 }
108 }
109 panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
110}
111
112func (mod *Module) Toc() android.OptionalPath {
113 if mod.compiler != nil {
114 if _, ok := mod.compiler.(libraryInterface); ok {
115 return android.OptionalPath{}
116 }
117 }
118 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
119}
120
121func (mod *Module) OnlyInRecovery() bool {
122 return false
123}
124
125func (mod *Module) UseVndk() bool {
126 return false
127}
128
129func (mod *Module) MustUseVendorVariant() bool {
130 return false
131}
132
133func (mod *Module) IsVndk() bool {
134 return false
135}
136
137func (mod *Module) HasVendorVariant() bool {
138 return false
139}
140
141func (mod *Module) SdkVersion() string {
142 return ""
143}
144
145func (mod *Module) ToolchainLibrary() bool {
146 return false
147}
148
149func (mod *Module) NdkPrebuiltStl() bool {
150 return false
151}
152
153func (mod *Module) StubDecorator() bool {
154 return false
155}
156
Ivan Lozanoffee3342019-08-27 12:03:00 -0700157type Deps struct {
158 Dylibs []string
159 Rlibs []string
160 ProcMacros []string
161 SharedLibs []string
162 StaticLibs []string
163
164 CrtBegin, CrtEnd string
165}
166
167type PathDeps struct {
168 DyLibs RustLibraries
169 RLibs RustLibraries
170 SharedLibs android.Paths
171 StaticLibs android.Paths
172 ProcMacros RustLibraries
173 linkDirs []string
174 depFlags []string
175 //ReexportedDeps android.Paths
Ivan Lozanof1c84332019-09-20 11:00:37 -0700176
177 CrtBegin android.OptionalPath
178 CrtEnd android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700179}
180
181type RustLibraries []RustLibrary
182
183type RustLibrary struct {
184 Path android.Path
185 CrateName string
186}
187
188type compiler interface {
189 compilerFlags(ctx ModuleContext, flags Flags) Flags
190 compilerProps() []interface{}
191 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
192 compilerDeps(ctx DepsContext, deps Deps) Deps
193 crateName() string
194
195 install(ctx ModuleContext, path android.Path)
196 relativeInstallPath() string
197}
198
199func defaultsFactory() android.Module {
200 return DefaultsFactory()
201}
202
203type Defaults struct {
204 android.ModuleBase
205 android.DefaultsModuleBase
206}
207
208func DefaultsFactory(props ...interface{}) android.Module {
209 module := &Defaults{}
210
211 module.AddProperties(props...)
212 module.AddProperties(
213 &BaseProperties{},
214 &BaseCompilerProperties{},
215 &BinaryCompilerProperties{},
216 &LibraryCompilerProperties{},
217 &ProcMacroCompilerProperties{},
218 &PrebuiltProperties{},
219 )
220
221 android.InitDefaultsModule(module)
222 return module
223}
224
225func (mod *Module) CrateName() string {
226 if mod.compiler != nil && mod.compiler.crateName() != "" {
227 return mod.compiler.crateName()
228 }
229 // Default crate names replace '-' in the name to '_'
230 return strings.Replace(mod.BaseModuleName(), "-", "_", -1)
231}
232
Ivan Lozano183a3212019-10-18 14:18:45 -0700233func (mod *Module) CcLibrary() bool {
234 if mod.compiler != nil {
235 if _, ok := mod.compiler.(*libraryDecorator); ok {
236 return true
237 }
238 }
239 return false
240}
241
242func (mod *Module) CcLibraryInterface() bool {
243 if mod.compiler != nil {
244 if _, ok := mod.compiler.(libraryInterface); ok {
245 return true
246 }
247 }
248 return false
249}
250
Ivan Lozano52767be2019-10-18 14:49:46 -0700251func (mod *Module) IncludeDirs(ctx android.BaseModuleContext) android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700252 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700253 if library, ok := mod.compiler.(*libraryDecorator); ok {
254 return android.PathsForSource(ctx, library.Properties.Include_dirs)
Ivan Lozano183a3212019-10-18 14:18:45 -0700255 }
256 }
257 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
258}
259
260func (mod *Module) SetStatic() {
261 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700262 if library, ok := mod.compiler.(libraryInterface); ok {
263 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700264 return
265 }
266 }
267 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
268}
269
270func (mod *Module) SetShared() {
271 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700272 if library, ok := mod.compiler.(libraryInterface); ok {
273 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700274 return
275 }
276 }
277 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
278}
279
280func (mod *Module) SetBuildStubs() {
281 panic("SetBuildStubs not yet implemented for rust modules")
282}
283
284func (mod *Module) SetStubsVersions(string) {
285 panic("SetStubsVersions not yet implemented for rust modules")
286}
287
288func (mod *Module) BuildStaticVariant() bool {
289 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700290 if library, ok := mod.compiler.(libraryInterface); ok {
291 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700292 }
293 }
294 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
295}
296
297func (mod *Module) BuildSharedVariant() bool {
298 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700299 if library, ok := mod.compiler.(libraryInterface); ok {
300 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700301 }
302 }
303 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
304}
305
306// Rust module deps don't have a link order (?)
307func (mod *Module) SetDepsInLinkOrder([]android.Path) {}
308
309func (mod *Module) GetDepsInLinkOrder() []android.Path {
310 return []android.Path{}
311}
312
313func (mod *Module) GetStaticVariant() cc.LinkableInterface {
314 return nil
315}
316
317func (mod *Module) Module() android.Module {
318 return mod
319}
320
321func (mod *Module) StubsVersions() []string {
322 // For now, Rust has no stubs versions.
323 if mod.compiler != nil {
324 if _, ok := mod.compiler.(*libraryDecorator); ok {
325 return []string{}
326 }
327 }
328 panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName()))
329}
330
331func (mod *Module) OutputFile() android.OptionalPath {
332 return mod.outputFile
333}
334
335func (mod *Module) InRecovery() bool {
336 // For now, Rust has no notion of the recovery image
337 return false
338}
339func (mod *Module) HasStaticVariant() bool {
340 if mod.GetStaticVariant() != nil {
341 return true
342 }
343 return false
344}
345
346var _ cc.LinkableInterface = (*Module)(nil)
347
Ivan Lozanoffee3342019-08-27 12:03:00 -0700348func (mod *Module) Init() android.Module {
349 mod.AddProperties(&mod.Properties)
350
351 if mod.compiler != nil {
352 mod.AddProperties(mod.compiler.compilerProps()...)
353 }
354 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
355
356 android.InitDefaultableModule(mod)
357
Ivan Lozanode252912019-09-06 15:29:52 -0700358 // Explicitly disable unsupported targets.
359 android.AddLoadHook(mod, func(ctx android.LoadHookContext) {
360 disableTargets := struct {
361 Target struct {
Ivan Lozanode252912019-09-06 15:29:52 -0700362 Linux_bionic struct {
363 Enabled *bool
364 }
365 }
366 }{}
Ivan Lozanode252912019-09-06 15:29:52 -0700367 disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false)
368
369 ctx.AppendProperties(&disableTargets)
370 })
371
Ivan Lozanoffee3342019-08-27 12:03:00 -0700372 return mod
373}
374
375func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
376 return &Module{
377 hod: hod,
378 multilib: multilib,
379 }
380}
381func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
382 module := newBaseModule(hod, multilib)
383 return module
384}
385
386type ModuleContext interface {
387 android.ModuleContext
388 ModuleContextIntf
389}
390
391type BaseModuleContext interface {
392 android.BaseModuleContext
393 ModuleContextIntf
394}
395
396type DepsContext interface {
397 android.BottomUpMutatorContext
398 ModuleContextIntf
399}
400
401type ModuleContextIntf interface {
402 toolchain() config.Toolchain
403 baseModuleName() string
404 CrateName() string
405}
406
407type depsContext struct {
408 android.BottomUpMutatorContext
409 moduleContextImpl
410}
411
412type moduleContext struct {
413 android.ModuleContext
414 moduleContextImpl
415}
416
417type moduleContextImpl struct {
418 mod *Module
419 ctx BaseModuleContext
420}
421
422func (ctx *moduleContextImpl) toolchain() config.Toolchain {
423 return ctx.mod.toolchain(ctx.ctx)
424}
425
426func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
427 if mod.cachedToolchain == nil {
428 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
429 }
430 return mod.cachedToolchain
431}
432
433func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
434}
435
436func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
437 ctx := &moduleContext{
438 ModuleContext: actx,
439 moduleContextImpl: moduleContextImpl{
440 mod: mod,
441 },
442 }
443 ctx.ctx = ctx
444
445 toolchain := mod.toolchain(ctx)
446
447 if !toolchain.Supported() {
448 // This toolchain's unsupported, there's nothing to do for this mod.
449 return
450 }
451
452 deps := mod.depsToPaths(ctx)
453 flags := Flags{
454 Toolchain: toolchain,
455 }
456
457 if mod.compiler != nil {
458 flags = mod.compiler.compilerFlags(ctx, flags)
459 outputFile := mod.compiler.compile(ctx, flags, deps)
460 mod.outputFile = android.OptionalPathForPath(outputFile)
461 mod.compiler.install(ctx, mod.outputFile.Path())
462 }
463}
464
465func (mod *Module) deps(ctx DepsContext) Deps {
466 deps := Deps{}
467
468 if mod.compiler != nil {
469 deps = mod.compiler.compilerDeps(ctx, deps)
470 }
471
472 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
473 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
474 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
475 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
476 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
477
478 return deps
479
480}
481
482func (ctx *moduleContextImpl) baseModuleName() string {
483 return ctx.mod.ModuleBase.BaseModuleName()
484}
485
486func (ctx *moduleContextImpl) CrateName() string {
487 return ctx.mod.CrateName()
488}
489
490type dependencyTag struct {
491 blueprint.BaseDependencyTag
492 name string
493 library bool
494 proc_macro bool
495}
496
497var (
498 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
499 dylibDepTag = dependencyTag{name: "dylib", library: true}
500 procMacroDepTag = dependencyTag{name: "procMacro", proc_macro: true}
501)
502
503func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
504 var depPaths PathDeps
505
506 directRlibDeps := []*Module{}
507 directDylibDeps := []*Module{}
508 directProcMacroDeps := []*Module{}
Ivan Lozano52767be2019-10-18 14:49:46 -0700509 directSharedLibDeps := [](cc.LinkableInterface){}
510 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700511
512 ctx.VisitDirectDeps(func(dep android.Module) {
513 depName := ctx.OtherModuleName(dep)
514 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700515 if rustDep, ok := dep.(*Module); ok {
516 //Handle Rust Modules
Ivan Lozano70e0a072019-09-13 14:23:15 -0700517
Ivan Lozanoffee3342019-08-27 12:03:00 -0700518 linkFile := rustDep.outputFile
519 if !linkFile.Valid() {
520 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
521 }
522
523 switch depTag {
524 case dylibDepTag:
525 dylib, ok := rustDep.compiler.(libraryInterface)
526 if !ok || !dylib.dylib() {
527 ctx.ModuleErrorf("mod %q not an dylib library", depName)
528 return
529 }
530 directDylibDeps = append(directDylibDeps, rustDep)
531 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
532 case rlibDepTag:
533 rlib, ok := rustDep.compiler.(libraryInterface)
534 if !ok || !rlib.rlib() {
535 ctx.ModuleErrorf("mod %q not an rlib library", depName)
536 return
537 }
538 directRlibDeps = append(directRlibDeps, rustDep)
539 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
540 case procMacroDepTag:
541 directProcMacroDeps = append(directProcMacroDeps, rustDep)
542 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
543 }
544
545 //Append the dependencies exportedDirs
546 if lib, ok := rustDep.compiler.(*libraryDecorator); ok {
547 depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...)
548 depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700549 }
550
551 // Append this dependencies output to this mod's linkDirs so they can be exported to dependencies
552 // This can be probably be refactored by defining a common exporter interface similar to cc's
553 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
554 linkDir := linkPathFromFilePath(linkFile.Path())
555 if lib, ok := mod.compiler.(*libraryDecorator); ok {
556 lib.linkDirs = append(lib.linkDirs, linkDir)
557 } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok {
558 procMacro.linkDirs = append(procMacro.linkDirs, linkDir)
559 }
560 }
561
Ivan Lozano52767be2019-10-18 14:49:46 -0700562 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700563
Ivan Lozano52767be2019-10-18 14:49:46 -0700564 if ccDep, ok := dep.(cc.LinkableInterface); ok {
565 //Handle C dependencies
566 if _, ok := ccDep.(*Module); !ok {
567 if ccDep.Module().Target().Os != ctx.Os() {
568 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
569 return
570 }
571 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
572 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
573 return
574 }
Ivan Lozano70e0a072019-09-13 14:23:15 -0700575 }
576
Ivan Lozanoffee3342019-08-27 12:03:00 -0700577 linkFile := ccDep.OutputFile()
578 linkPath := linkPathFromFilePath(linkFile.Path())
579 libName := libNameFromFilePath(linkFile.Path())
580 if !linkFile.Valid() {
581 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
582 }
583
584 exportDep := false
585
586 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -0700587 case cc.StaticDepTag:
Ivan Lozanoffee3342019-08-27 12:03:00 -0700588 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
589 depPaths.depFlags = append(depPaths.depFlags, "-l"+libName)
590 directStaticLibDeps = append(directStaticLibDeps, ccDep)
591 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
Ivan Lozano183a3212019-10-18 14:18:45 -0700592 case cc.SharedDepTag:
Ivan Lozanoffee3342019-08-27 12:03:00 -0700593 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
594 depPaths.depFlags = append(depPaths.depFlags, "-l"+libName)
595 directSharedLibDeps = append(directSharedLibDeps, ccDep)
596 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
597 exportDep = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700598 case cc.CrtBeginDepTag:
Ivan Lozanof1c84332019-09-20 11:00:37 -0700599 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700600 case cc.CrtEndDepTag:
Ivan Lozanof1c84332019-09-20 11:00:37 -0700601 depPaths.CrtEnd = linkFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700602 }
603
604 // Make sure these dependencies are propagated
Ivan Lozano52767be2019-10-18 14:49:46 -0700605 if lib, ok := mod.compiler.(*libraryDecorator); ok && exportDep {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700606 lib.linkDirs = append(lib.linkDirs, linkPath)
607 lib.depFlags = append(lib.depFlags, "-l"+libName)
608 } else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok && exportDep {
609 procMacro.linkDirs = append(procMacro.linkDirs, linkPath)
610 procMacro.depFlags = append(procMacro.depFlags, "-l"+libName)
611 }
612
613 }
614 })
615
616 var rlibDepFiles RustLibraries
617 for _, dep := range directRlibDeps {
618 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
619 }
620 var dylibDepFiles RustLibraries
621 for _, dep := range directDylibDeps {
622 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
623 }
624 var procMacroDepFiles RustLibraries
625 for _, dep := range directProcMacroDeps {
626 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
627 }
628
629 var staticLibDepFiles android.Paths
630 for _, dep := range directStaticLibDeps {
631 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
632 }
633
634 var sharedLibDepFiles android.Paths
635 for _, dep := range directSharedLibDeps {
636 sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
637 }
638
639 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
640 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
641 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
642 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
643 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
644
645 // Dedup exported flags from dependencies
646 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
647 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
648
649 return depPaths
650}
651
652func linkPathFromFilePath(filepath android.Path) string {
653 return strings.Split(filepath.String(), filepath.Base())[0]
654}
655func libNameFromFilePath(filepath android.Path) string {
656 libName := strings.Split(filepath.Base(), filepath.Ext())[0]
Ivan Lozano52767be2019-10-18 14:49:46 -0700657 if strings.HasPrefix(libName, "lib") {
658 libName = libName[3:]
Ivan Lozanoffee3342019-08-27 12:03:00 -0700659 }
660 return libName
661}
662func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
663 ctx := &depsContext{
664 BottomUpMutatorContext: actx,
665 moduleContextImpl: moduleContextImpl{
666 mod: mod,
667 },
668 }
669 ctx.ctx = ctx
670
671 deps := mod.deps(ctx)
Ivan Lozano52767be2019-10-18 14:49:46 -0700672 commonDepVariations := []blueprint.Variation{}
673 commonDepVariations = append(commonDepVariations,
674 blueprint.Variation{Mutator: "version", Variation: ""})
Ivan Lozanoffee3342019-08-27 12:03:00 -0700675 if !mod.Host() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700676 commonDepVariations = append(commonDepVariations,
677 blueprint.Variation{Mutator: "image", Variation: "core"})
Ivan Lozanoffee3342019-08-27 12:03:00 -0700678 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700679
680 actx.AddVariationDependencies(
681 append(commonDepVariations, []blueprint.Variation{
682 {Mutator: "rust_libraries", Variation: "rlib"},
683 {Mutator: "link", Variation: ""}}...),
684 rlibDepTag, deps.Rlibs...)
685 actx.AddVariationDependencies(
686 append(commonDepVariations, []blueprint.Variation{
687 {Mutator: "rust_libraries", Variation: "dylib"},
688 {Mutator: "link", Variation: ""}}...),
689 dylibDepTag, deps.Dylibs...)
690
691 actx.AddVariationDependencies(append(commonDepVariations,
692 blueprint.Variation{Mutator: "link", Variation: "shared"}),
693 cc.SharedDepTag, deps.SharedLibs...)
694 actx.AddVariationDependencies(append(commonDepVariations,
695 blueprint.Variation{Mutator: "link", Variation: "static"}),
696 cc.StaticDepTag, deps.StaticLibs...)
Ivan Lozano5ca5ef62019-09-23 10:10:40 -0700697
Ivan Lozanof1c84332019-09-20 11:00:37 -0700698 if deps.CrtBegin != "" {
Ivan Lozano52767be2019-10-18 14:49:46 -0700699 actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin)
Ivan Lozanof1c84332019-09-20 11:00:37 -0700700 }
701 if deps.CrtEnd != "" {
Ivan Lozano52767be2019-10-18 14:49:46 -0700702 actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd)
Ivan Lozanof1c84332019-09-20 11:00:37 -0700703 }
704
Ivan Lozano5ca5ef62019-09-23 10:10:40 -0700705 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700706 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700707}
708
709func (mod *Module) Name() string {
710 name := mod.ModuleBase.Name()
711 if p, ok := mod.compiler.(interface {
712 Name(string) string
713 }); ok {
714 name = p.Name(name)
715 }
716 return name
717}
718
719var Bool = proptools.Bool
720var BoolDefault = proptools.BoolDefault
721var String = proptools.String
722var StringPtr = proptools.StringPtr