• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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 (
18	"fmt"
19	"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
33
34	android.AddNeverAllowRules(
35		android.NeverAllow().
36			NotIn(config.RustAllowedPaths...).
37			ModuleType(config.RustModuleTypes...))
38
39	android.RegisterModuleType("rust_defaults", defaultsFactory)
40	android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
41		ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
42		ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel()
43	})
44	pctx.Import("android/soong/rust/config")
45}
46
47type Flags struct {
48	GlobalRustFlags []string      // Flags that apply globally to rust
49	GlobalLinkFlags []string      // Flags that apply globally to linker
50	RustFlags       []string      // Flags that apply to rust
51	LinkFlags       []string      // Flags that apply to linker
52	RustFlagsDeps   android.Paths // Files depended on by compiler flags
53	Toolchain       config.Toolchain
54}
55
56type BaseProperties struct {
57	AndroidMkRlibs         []string
58	AndroidMkDylibs        []string
59	AndroidMkProcMacroLibs []string
60	AndroidMkSharedLibs    []string
61	AndroidMkStaticLibs    []string
62	SubName                string `blueprint:"mutated"`
63}
64
65type Module struct {
66	android.ModuleBase
67	android.DefaultableModuleBase
68
69	Properties BaseProperties
70
71	hod      android.HostOrDeviceSupported
72	multilib android.Multilib
73
74	compiler         compiler
75	cachedToolchain  config.Toolchain
76	subAndroidMkOnce map[subAndroidMkProvider]bool
77	outputFile       android.OptionalPath
78}
79
80var _ android.ImageInterface = (*Module)(nil)
81
82func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {}
83
84func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
85	return true
86}
87
88func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool {
89	return mod.InRamdisk()
90}
91
92func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool {
93	return mod.InRecovery()
94}
95
96func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
97	return nil
98}
99
100func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
101}
102
103func (mod *Module) BuildStubs() bool {
104	return false
105}
106
107func (mod *Module) HasStubsVariants() bool {
108	return false
109}
110
111func (mod *Module) SelectedStl() string {
112	return ""
113}
114
115func (mod *Module) NonCcVariants() bool {
116	if mod.compiler != nil {
117		if library, ok := mod.compiler.(libraryInterface); ok {
118			if library.buildRlib() || library.buildDylib() {
119				return true
120			} else {
121				return false
122			}
123		}
124	}
125	panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
126}
127
128func (mod *Module) ApiLevel() string {
129	panic(fmt.Errorf("Called ApiLevel on Rust module %q; stubs libraries are not yet supported.", mod.BaseModuleName()))
130}
131
132func (mod *Module) Static() bool {
133	if mod.compiler != nil {
134		if library, ok := mod.compiler.(libraryInterface); ok {
135			return library.static()
136		}
137	}
138	panic(fmt.Errorf("Static called on non-library module: %q", mod.BaseModuleName()))
139}
140
141func (mod *Module) Shared() bool {
142	if mod.compiler != nil {
143		if library, ok := mod.compiler.(libraryInterface); ok {
144			return library.static()
145		}
146	}
147	panic(fmt.Errorf("Shared called on non-library module: %q", mod.BaseModuleName()))
148}
149
150func (mod *Module) Toc() android.OptionalPath {
151	if mod.compiler != nil {
152		if _, ok := mod.compiler.(libraryInterface); ok {
153			return android.OptionalPath{}
154		}
155	}
156	panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
157}
158
159func (mod *Module) OnlyInRamdisk() bool {
160	return false
161}
162
163func (mod *Module) OnlyInRecovery() bool {
164	return false
165}
166
167func (mod *Module) UseSdk() bool {
168	return false
169}
170
171func (mod *Module) UseVndk() bool {
172	return false
173}
174
175func (mod *Module) MustUseVendorVariant() bool {
176	return false
177}
178
179func (mod *Module) IsVndk() bool {
180	return false
181}
182
183func (mod *Module) HasVendorVariant() bool {
184	return false
185}
186
187func (mod *Module) SdkVersion() string {
188	return ""
189}
190
191func (mod *Module) AlwaysSdk() bool {
192	return false
193}
194
195func (mod *Module) ToolchainLibrary() bool {
196	return false
197}
198
199func (mod *Module) NdkPrebuiltStl() bool {
200	return false
201}
202
203func (mod *Module) StubDecorator() bool {
204	return false
205}
206
207type Deps struct {
208	Dylibs     []string
209	Rlibs      []string
210	ProcMacros []string
211	SharedLibs []string
212	StaticLibs []string
213
214	CrtBegin, CrtEnd string
215}
216
217type PathDeps struct {
218	DyLibs     RustLibraries
219	RLibs      RustLibraries
220	SharedLibs android.Paths
221	StaticLibs android.Paths
222	ProcMacros RustLibraries
223	linkDirs   []string
224	depFlags   []string
225	//ReexportedDeps android.Paths
226
227	CrtBegin android.OptionalPath
228	CrtEnd   android.OptionalPath
229}
230
231type RustLibraries []RustLibrary
232
233type RustLibrary struct {
234	Path      android.Path
235	CrateName string
236}
237
238type compiler interface {
239	compilerFlags(ctx ModuleContext, flags Flags) Flags
240	compilerProps() []interface{}
241	compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path
242	compilerDeps(ctx DepsContext, deps Deps) Deps
243	crateName() string
244
245	inData() bool
246	install(ctx ModuleContext, path android.Path)
247	relativeInstallPath() string
248}
249
250func defaultsFactory() android.Module {
251	return DefaultsFactory()
252}
253
254type Defaults struct {
255	android.ModuleBase
256	android.DefaultsModuleBase
257}
258
259func DefaultsFactory(props ...interface{}) android.Module {
260	module := &Defaults{}
261
262	module.AddProperties(props...)
263	module.AddProperties(
264		&BaseProperties{},
265		&BaseCompilerProperties{},
266		&BinaryCompilerProperties{},
267		&LibraryCompilerProperties{},
268		&ProcMacroCompilerProperties{},
269		&PrebuiltProperties{},
270		&TestProperties{},
271	)
272
273	android.InitDefaultsModule(module)
274	return module
275}
276
277func (mod *Module) CrateName() string {
278	return mod.compiler.crateName()
279}
280
281func (mod *Module) CcLibrary() bool {
282	if mod.compiler != nil {
283		if _, ok := mod.compiler.(*libraryDecorator); ok {
284			return true
285		}
286	}
287	return false
288}
289
290func (mod *Module) CcLibraryInterface() bool {
291	if mod.compiler != nil {
292		if _, ok := mod.compiler.(libraryInterface); ok {
293			return true
294		}
295	}
296	return false
297}
298
299func (mod *Module) IncludeDirs() android.Paths {
300	if mod.compiler != nil {
301		if library, ok := mod.compiler.(*libraryDecorator); ok {
302			return library.includeDirs
303		}
304	}
305	panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
306}
307
308func (mod *Module) SetStatic() {
309	if mod.compiler != nil {
310		if library, ok := mod.compiler.(libraryInterface); ok {
311			library.setStatic()
312			return
313		}
314	}
315	panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
316}
317
318func (mod *Module) SetShared() {
319	if mod.compiler != nil {
320		if library, ok := mod.compiler.(libraryInterface); ok {
321			library.setShared()
322			return
323		}
324	}
325	panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
326}
327
328func (mod *Module) SetBuildStubs() {
329	panic("SetBuildStubs not yet implemented for rust modules")
330}
331
332func (mod *Module) SetStubsVersions(string) {
333	panic("SetStubsVersions not yet implemented for rust modules")
334}
335
336func (mod *Module) StubsVersion() string {
337	panic("SetStubsVersions not yet implemented for rust modules")
338}
339
340func (mod *Module) BuildStaticVariant() bool {
341	if mod.compiler != nil {
342		if library, ok := mod.compiler.(libraryInterface); ok {
343			return library.buildStatic()
344		}
345	}
346	panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
347}
348
349func (mod *Module) BuildSharedVariant() bool {
350	if mod.compiler != nil {
351		if library, ok := mod.compiler.(libraryInterface); ok {
352			return library.buildShared()
353		}
354	}
355	panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
356}
357
358// Rust module deps don't have a link order (?)
359func (mod *Module) SetDepsInLinkOrder([]android.Path) {}
360
361func (mod *Module) GetDepsInLinkOrder() []android.Path {
362	return []android.Path{}
363}
364
365func (mod *Module) GetStaticVariant() cc.LinkableInterface {
366	return nil
367}
368
369func (mod *Module) Module() android.Module {
370	return mod
371}
372
373func (mod *Module) StubsVersions() []string {
374	// For now, Rust has no stubs versions.
375	if mod.compiler != nil {
376		if _, ok := mod.compiler.(*libraryDecorator); ok {
377			return []string{}
378		}
379	}
380	panic(fmt.Errorf("StubsVersions called on non-library module: %q", mod.BaseModuleName()))
381}
382
383func (mod *Module) OutputFile() android.OptionalPath {
384	return mod.outputFile
385}
386
387func (mod *Module) InRecovery() bool {
388	// For now, Rust has no notion of the recovery image
389	return false
390}
391func (mod *Module) HasStaticVariant() bool {
392	if mod.GetStaticVariant() != nil {
393		return true
394	}
395	return false
396}
397
398var _ cc.LinkableInterface = (*Module)(nil)
399
400func (mod *Module) Init() android.Module {
401	mod.AddProperties(&mod.Properties)
402
403	if mod.compiler != nil {
404		mod.AddProperties(mod.compiler.compilerProps()...)
405	}
406	android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
407
408	android.InitDefaultableModule(mod)
409
410	// Explicitly disable unsupported targets.
411	android.AddLoadHook(mod, func(ctx android.LoadHookContext) {
412		disableTargets := struct {
413			Target struct {
414				Linux_bionic struct {
415					Enabled *bool
416				}
417			}
418		}{}
419		disableTargets.Target.Linux_bionic.Enabled = proptools.BoolPtr(false)
420
421		ctx.AppendProperties(&disableTargets)
422	})
423
424	return mod
425}
426
427func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
428	return &Module{
429		hod:      hod,
430		multilib: multilib,
431	}
432}
433func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
434	module := newBaseModule(hod, multilib)
435	return module
436}
437
438type ModuleContext interface {
439	android.ModuleContext
440	ModuleContextIntf
441}
442
443type BaseModuleContext interface {
444	android.BaseModuleContext
445	ModuleContextIntf
446}
447
448type DepsContext interface {
449	android.BottomUpMutatorContext
450	ModuleContextIntf
451}
452
453type ModuleContextIntf interface {
454	toolchain() config.Toolchain
455	baseModuleName() string
456	CrateName() string
457}
458
459type depsContext struct {
460	android.BottomUpMutatorContext
461	moduleContextImpl
462}
463
464type moduleContext struct {
465	android.ModuleContext
466	moduleContextImpl
467}
468
469type moduleContextImpl struct {
470	mod *Module
471	ctx BaseModuleContext
472}
473
474func (ctx *moduleContextImpl) toolchain() config.Toolchain {
475	return ctx.mod.toolchain(ctx.ctx)
476}
477
478func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
479	if mod.cachedToolchain == nil {
480		mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
481	}
482	return mod.cachedToolchain
483}
484
485func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
486}
487
488func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
489	ctx := &moduleContext{
490		ModuleContext: actx,
491		moduleContextImpl: moduleContextImpl{
492			mod: mod,
493		},
494	}
495	ctx.ctx = ctx
496
497	toolchain := mod.toolchain(ctx)
498
499	if !toolchain.Supported() {
500		// This toolchain's unsupported, there's nothing to do for this mod.
501		return
502	}
503
504	deps := mod.depsToPaths(ctx)
505	flags := Flags{
506		Toolchain: toolchain,
507	}
508
509	if mod.compiler != nil {
510		flags = mod.compiler.compilerFlags(ctx, flags)
511		outputFile := mod.compiler.compile(ctx, flags, deps)
512		mod.outputFile = android.OptionalPathForPath(outputFile)
513		mod.compiler.install(ctx, mod.outputFile.Path())
514	}
515}
516
517func (mod *Module) deps(ctx DepsContext) Deps {
518	deps := Deps{}
519
520	if mod.compiler != nil {
521		deps = mod.compiler.compilerDeps(ctx, deps)
522	}
523
524	deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
525	deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
526	deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
527	deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
528	deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
529
530	return deps
531
532}
533
534func (ctx *moduleContextImpl) baseModuleName() string {
535	return ctx.mod.ModuleBase.BaseModuleName()
536}
537
538func (ctx *moduleContextImpl) CrateName() string {
539	return ctx.mod.CrateName()
540}
541
542type dependencyTag struct {
543	blueprint.BaseDependencyTag
544	name       string
545	library    bool
546	proc_macro bool
547}
548
549var (
550	rlibDepTag       = dependencyTag{name: "rlibTag", library: true}
551	dylibDepTag      = dependencyTag{name: "dylib", library: true}
552	procMacroDepTag  = dependencyTag{name: "procMacro", proc_macro: true}
553	testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
554)
555
556func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
557	var depPaths PathDeps
558
559	directRlibDeps := []*Module{}
560	directDylibDeps := []*Module{}
561	directProcMacroDeps := []*Module{}
562	directSharedLibDeps := [](cc.LinkableInterface){}
563	directStaticLibDeps := [](cc.LinkableInterface){}
564
565	ctx.VisitDirectDeps(func(dep android.Module) {
566		depName := ctx.OtherModuleName(dep)
567		depTag := ctx.OtherModuleDependencyTag(dep)
568		if rustDep, ok := dep.(*Module); ok {
569			//Handle Rust Modules
570
571			linkFile := rustDep.outputFile
572			if !linkFile.Valid() {
573				ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
574			}
575
576			switch depTag {
577			case dylibDepTag:
578				dylib, ok := rustDep.compiler.(libraryInterface)
579				if !ok || !dylib.dylib() {
580					ctx.ModuleErrorf("mod %q not an dylib library", depName)
581					return
582				}
583				directDylibDeps = append(directDylibDeps, rustDep)
584				mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName)
585			case rlibDepTag:
586				rlib, ok := rustDep.compiler.(libraryInterface)
587				if !ok || !rlib.rlib() {
588					ctx.ModuleErrorf("mod %q not an rlib library", depName)
589					return
590				}
591				directRlibDeps = append(directRlibDeps, rustDep)
592				mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName)
593			case procMacroDepTag:
594				directProcMacroDeps = append(directProcMacroDeps, rustDep)
595				mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName)
596			}
597
598			//Append the dependencies exportedDirs
599			if lib, ok := rustDep.compiler.(*libraryDecorator); ok {
600				depPaths.linkDirs = append(depPaths.linkDirs, lib.exportedDirs()...)
601				depPaths.depFlags = append(depPaths.depFlags, lib.exportedDepFlags()...)
602			}
603
604			// Append this dependencies output to this mod's linkDirs so they can be exported to dependencies
605			// This can be probably be refactored by defining a common exporter interface similar to cc's
606			if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
607				linkDir := linkPathFromFilePath(linkFile.Path())
608				if lib, ok := mod.compiler.(*libraryDecorator); ok {
609					lib.linkDirs = append(lib.linkDirs, linkDir)
610				} else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok {
611					procMacro.linkDirs = append(procMacro.linkDirs, linkDir)
612				}
613			}
614
615		}
616
617		if ccDep, ok := dep.(cc.LinkableInterface); ok {
618			//Handle C dependencies
619			if _, ok := ccDep.(*Module); !ok {
620				if ccDep.Module().Target().Os != ctx.Os() {
621					ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
622					return
623				}
624				if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
625					ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
626					return
627				}
628			}
629
630			linkFile := ccDep.OutputFile()
631			linkPath := linkPathFromFilePath(linkFile.Path())
632			libName := libNameFromFilePath(linkFile.Path())
633			depFlag := "-l" + libName
634
635			if !linkFile.Valid() {
636				ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
637			}
638
639			exportDep := false
640			switch depTag {
641			case cc.StaticDepTag:
642				depFlag = "-lstatic=" + libName
643				depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
644				depPaths.depFlags = append(depPaths.depFlags, depFlag)
645				directStaticLibDeps = append(directStaticLibDeps, ccDep)
646				mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName)
647			case cc.SharedDepTag:
648				depFlag = "-ldylib=" + libName
649				depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
650				depPaths.depFlags = append(depPaths.depFlags, depFlag)
651				directSharedLibDeps = append(directSharedLibDeps, ccDep)
652				mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
653				exportDep = true
654			case cc.CrtBeginDepTag:
655				depPaths.CrtBegin = linkFile
656			case cc.CrtEndDepTag:
657				depPaths.CrtEnd = linkFile
658			}
659
660			// Make sure these dependencies are propagated
661			if lib, ok := mod.compiler.(*libraryDecorator); ok && exportDep {
662				lib.linkDirs = append(lib.linkDirs, linkPath)
663				lib.depFlags = append(lib.depFlags, depFlag)
664			} else if procMacro, ok := mod.compiler.(*procMacroDecorator); ok && exportDep {
665				procMacro.linkDirs = append(procMacro.linkDirs, linkPath)
666				procMacro.depFlags = append(procMacro.depFlags, depFlag)
667			}
668
669		}
670	})
671
672	var rlibDepFiles RustLibraries
673	for _, dep := range directRlibDeps {
674		rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
675	}
676	var dylibDepFiles RustLibraries
677	for _, dep := range directDylibDeps {
678		dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
679	}
680	var procMacroDepFiles RustLibraries
681	for _, dep := range directProcMacroDeps {
682		procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()})
683	}
684
685	var staticLibDepFiles android.Paths
686	for _, dep := range directStaticLibDeps {
687		staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
688	}
689
690	var sharedLibDepFiles android.Paths
691	for _, dep := range directSharedLibDeps {
692		sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path())
693	}
694
695	depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
696	depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
697	depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
698	depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
699	depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
700
701	// Dedup exported flags from dependencies
702	depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
703	depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
704
705	return depPaths
706}
707
708func (mod *Module) InstallInData() bool {
709	if mod.compiler == nil {
710		return false
711	}
712	return mod.compiler.inData()
713}
714
715func linkPathFromFilePath(filepath android.Path) string {
716	return strings.Split(filepath.String(), filepath.Base())[0]
717}
718
719func libNameFromFilePath(filepath android.Path) string {
720	libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
721	if strings.HasPrefix(libName, "lib") {
722		libName = libName[3:]
723	}
724	return libName
725}
726
727func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
728	ctx := &depsContext{
729		BottomUpMutatorContext: actx,
730		moduleContextImpl: moduleContextImpl{
731			mod: mod,
732		},
733	}
734	ctx.ctx = ctx
735
736	deps := mod.deps(ctx)
737	commonDepVariations := []blueprint.Variation{}
738	if cc.VersionVariantAvailable(mod) {
739		commonDepVariations = append(commonDepVariations,
740			blueprint.Variation{Mutator: "version", Variation: ""})
741	}
742	if !mod.Host() {
743		commonDepVariations = append(commonDepVariations,
744			blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
745	}
746	actx.AddVariationDependencies(
747		append(commonDepVariations, []blueprint.Variation{
748			{Mutator: "rust_libraries", Variation: "rlib"},
749			{Mutator: "link", Variation: ""}}...),
750		rlibDepTag, deps.Rlibs...)
751	actx.AddVariationDependencies(
752		append(commonDepVariations, []blueprint.Variation{
753			{Mutator: "rust_libraries", Variation: "dylib"},
754			{Mutator: "link", Variation: ""}}...),
755		dylibDepTag, deps.Dylibs...)
756
757	actx.AddVariationDependencies(append(commonDepVariations,
758		blueprint.Variation{Mutator: "link", Variation: "shared"}),
759		cc.SharedDepTag, deps.SharedLibs...)
760	actx.AddVariationDependencies(append(commonDepVariations,
761		blueprint.Variation{Mutator: "link", Variation: "static"}),
762		cc.StaticDepTag, deps.StaticLibs...)
763
764	if deps.CrtBegin != "" {
765		actx.AddVariationDependencies(commonDepVariations, cc.CrtBeginDepTag, deps.CrtBegin)
766	}
767	if deps.CrtEnd != "" {
768		actx.AddVariationDependencies(commonDepVariations, cc.CrtEndDepTag, deps.CrtEnd)
769	}
770
771	// proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
772	actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
773}
774
775func (mod *Module) Name() string {
776	name := mod.ModuleBase.Name()
777	if p, ok := mod.compiler.(interface {
778		Name(string) string
779	}); ok {
780		name = p.Name(name)
781	}
782	return name
783}
784
785var Bool = proptools.Bool
786var BoolDefault = proptools.BoolDefault
787var String = proptools.String
788var StringPtr = proptools.StringPtr
789