blob: d5d492971101801b5d92c0c031237bbb288d1fe7 [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 (
Sasha Smundaka76acba2022-04-18 20:12:56 -070018 "android/soong/bloaty"
Ivan Lozano183a3212019-10-18 14:18:45 -070019 "fmt"
Ivan Lozanoffee3342019-08-27 12:03:00 -070020 "strings"
21
22 "github.com/google/blueprint"
23 "github.com/google/blueprint/proptools"
24
25 "android/soong/android"
26 "android/soong/cc"
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +020027 cc_config "android/soong/cc/config"
hamzehc0a671f2021-07-22 12:05:08 -070028 "android/soong/fuzz"
Ivan Lozanoffee3342019-08-27 12:03:00 -070029 "android/soong/rust/config"
Ivan Lozano872d5792022-03-23 17:31:39 -040030 "android/soong/snapshot"
Ivan Lozanoffee3342019-08-27 12:03:00 -070031)
32
33var pctx = android.NewPackageContext("android/soong/rust")
34
35func init() {
36 // Only allow rust modules to be defined for certain projects
Ivan Lozanoffee3342019-08-27 12:03:00 -070037
38 android.AddNeverAllowRules(
39 android.NeverAllow().
Ivan Lozano03a94c42021-06-28 11:27:11 -040040 NotIn(append(config.RustAllowedPaths, config.DownstreamRustAllowedPaths...)...).
Ivan Lozanoe169ad72019-09-18 08:42:54 -070041 ModuleType(config.RustModuleTypes...))
Ivan Lozanoffee3342019-08-27 12:03:00 -070042
43 android.RegisterModuleType("rust_defaults", defaultsFactory)
44 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
45 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -040046 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040047 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano6cd99e62020-02-11 08:24:25 -050048
49 })
50 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
51 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070052 })
53 pctx.Import("android/soong/rust/config")
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020054 pctx.ImportAs("cc_config", "android/soong/cc/config")
Sasha Smundaka76acba2022-04-18 20:12:56 -070055 android.InitRegistrationContext.RegisterSingletonType("kythe_rust_extract", kytheExtractRustFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070056}
57
58type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040059 GlobalRustFlags []string // Flags that apply globally to rust
60 GlobalLinkFlags []string // Flags that apply globally to linker
61 RustFlags []string // Flags that apply to rust
62 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020063 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Dan Albert06feee92021-03-19 15:06:02 -070064 RustdocFlags []string // Flags that apply to rustdoc
Ivan Lozanof1c84332019-09-20 11:00:37 -070065 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040066 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020067 Clippy bool
Sasha Smundaka76acba2022-04-18 20:12:56 -070068 EmitXrefs bool // If true, emit rules to aid cross-referencing
Ivan Lozanoffee3342019-08-27 12:03:00 -070069}
70
71type BaseProperties struct {
72 AndroidMkRlibs []string
73 AndroidMkDylibs []string
74 AndroidMkProcMacroLibs []string
75 AndroidMkSharedLibs []string
76 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040077
Ivan Lozano6a884432020-12-02 09:15:16 -050078 ImageVariationPrefix string `blueprint:"mutated"`
79 VndkVersion string `blueprint:"mutated"`
80 SubName string `blueprint:"mutated"`
81
Ivan Lozanoc08897c2021-04-02 12:41:32 -040082 // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
83 // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be
84 // appended before SubName.
85 RustSubName string `blueprint:"mutated"`
86
Ivan Lozano6a884432020-12-02 09:15:16 -050087 // Set by imageMutator
Ivan Lozanoe6d30982021-02-05 10:57:43 -050088 CoreVariantNeeded bool `blueprint:"mutated"`
89 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurerc6868382021-07-13 14:12:37 -070090 RamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurer460ee942021-02-11 12:31:46 -080091 RecoveryVariantNeeded bool `blueprint:"mutated"`
Ivan Lozanoe6d30982021-02-05 10:57:43 -050092 ExtraVariants []string `blueprint:"mutated"`
93
Ivan Lozanoa2268632021-07-22 10:52:06 -040094 // Allows this module to use non-APEX version of libraries. Useful
95 // for building binaries that are started before APEXes are activated.
96 Bootstrap *bool
97
Ivan Lozano1921e802021-05-20 13:39:16 -040098 // Used by vendor snapshot to record dependencies from snapshot modules.
99 SnapshotSharedLibs []string `blueprint:"mutated"`
Justin Yun5e035862021-06-29 20:50:37 +0900100 SnapshotStaticLibs []string `blueprint:"mutated"`
Ivan Lozano1921e802021-05-20 13:39:16 -0400101
Matthew Maurerc6868382021-07-13 14:12:37 -0700102 // Make this module available when building for ramdisk.
103 // On device without a dedicated recovery partition, the module is only
104 // available after switching root into
105 // /first_stage_ramdisk. To expose the module before switching root, install
106 // the recovery variant instead.
107 Ramdisk_available *bool
108
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500109 // Make this module available when building for vendor ramdisk.
110 // On device without a dedicated recovery partition, the module is only
111 // available after switching root into
112 // /first_stage_ramdisk. To expose the module before switching root, install
Matthew Maurer460ee942021-02-11 12:31:46 -0800113 // the recovery variant instead
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500114 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400115
Ivan Lozano1921e802021-05-20 13:39:16 -0400116 // Normally Soong uses the directory structure to decide which modules
117 // should be included (framework) or excluded (non-framework) from the
118 // different snapshots (vendor, recovery, etc.), but this property
119 // allows a partner to exclude a module normally thought of as a
120 // framework module from the vendor snapshot.
121 Exclude_from_vendor_snapshot *bool
122
123 // Normally Soong uses the directory structure to decide which modules
124 // should be included (framework) or excluded (non-framework) from the
125 // different snapshots (vendor, recovery, etc.), but this property
126 // allows a partner to exclude a module normally thought of as a
127 // framework module from the recovery snapshot.
128 Exclude_from_recovery_snapshot *bool
129
Matthew Maurer460ee942021-02-11 12:31:46 -0800130 // Make this module available when building for recovery
131 Recovery_available *bool
132
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500133 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
134 Min_sdk_version *string
135
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900136 HideFromMake bool `blueprint:"mutated"`
137 PreventInstall bool `blueprint:"mutated"`
138
139 Installable *bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700140}
141
142type Module struct {
hamzehc0a671f2021-07-22 12:05:08 -0700143 fuzz.FuzzModule
Ivan Lozanoffee3342019-08-27 12:03:00 -0700144
Ivan Lozano6a884432020-12-02 09:15:16 -0500145 VendorProperties cc.VendorProperties
146
Ivan Lozanoffee3342019-08-27 12:03:00 -0700147 Properties BaseProperties
148
149 hod android.HostOrDeviceSupported
150 multilib android.Multilib
151
Ivan Lozano6a884432020-12-02 09:15:16 -0500152 makeLinkType string
153
Yi Kong46c6e592022-01-20 22:55:00 +0800154 afdo *afdo
Ivan Lozanoffee3342019-08-27 12:03:00 -0700155 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400156 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200157 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500158 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700159 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400160 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700161 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400162
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400163 // Output file to be installed, may be stripped or unstripped.
164 outputFile android.OptionalPath
165
Sasha Smundaka76acba2022-04-18 20:12:56 -0700166 // Cross-reference input file
167 kytheFiles android.Paths
168
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400169 docTimestampFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900170
171 hideApexVariantFromMake bool
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500172
173 // For apex variants, this is set as apex.min_sdk_version
174 apexSdkVersion android.ApiLevel
Ivan Lozanoffee3342019-08-27 12:03:00 -0700175}
176
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500177func (mod *Module) Header() bool {
178 //TODO: If Rust libraries provide header variants, this needs to be updated.
179 return false
180}
181
182func (mod *Module) SetPreventInstall() {
183 mod.Properties.PreventInstall = true
184}
185
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500186func (mod *Module) SetHideFromMake() {
187 mod.Properties.HideFromMake = true
188}
189
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900190func (mod *Module) HiddenFromMake() bool {
191 return mod.Properties.HideFromMake
Ivan Lozanod7586b62021-04-01 09:49:36 -0400192}
193
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500194func (mod *Module) SanitizePropDefined() bool {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500195 // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
196 // nil since we need compiler to actually sanitize.
197 return mod.sanitize != nil && mod.compiler != nil
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500198}
199
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500200func (mod *Module) IsPrebuilt() bool {
201 if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
202 return true
203 }
204 return false
205}
206
Ivan Lozano43845682020-07-09 21:03:28 -0400207func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
208 switch tag {
209 case "":
Andrei Homescu5db69cc2020-08-06 15:27:45 -0700210 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
Ivan Lozano43845682020-07-09 21:03:28 -0400211 return mod.sourceProvider.Srcs(), nil
212 } else {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900213 if mod.OutputFile().Valid() {
214 return android.Paths{mod.OutputFile().Path()}, nil
Ivan Lozano43845682020-07-09 21:03:28 -0400215 }
216 return android.Paths{}, nil
217 }
218 default:
219 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
220 }
221}
222
Ivan Lozano52767be2019-10-18 14:49:46 -0700223func (mod *Module) SelectedStl() string {
224 return ""
225}
226
Ivan Lozano2b262972019-11-21 12:30:50 -0800227func (mod *Module) NonCcVariants() bool {
228 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400229 if _, ok := mod.compiler.(libraryInterface); ok {
230 return false
Ivan Lozano2b262972019-11-21 12:30:50 -0800231 }
232 }
233 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
234}
235
Ivan Lozano52767be2019-10-18 14:49:46 -0700236func (mod *Module) Static() bool {
237 if mod.compiler != nil {
238 if library, ok := mod.compiler.(libraryInterface); ok {
239 return library.static()
240 }
241 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400242 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700243}
244
245func (mod *Module) Shared() bool {
246 if mod.compiler != nil {
247 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400248 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700249 }
250 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400251 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700252}
253
Ivan Lozanod7586b62021-04-01 09:49:36 -0400254func (mod *Module) Dylib() bool {
255 if mod.compiler != nil {
256 if library, ok := mod.compiler.(libraryInterface); ok {
257 return library.dylib()
258 }
259 }
260 return false
261}
262
263func (mod *Module) Rlib() bool {
264 if mod.compiler != nil {
265 if library, ok := mod.compiler.(libraryInterface); ok {
266 return library.rlib()
267 }
268 }
269 return false
270}
271
272func (mod *Module) Binary() bool {
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400273 if binary, ok := mod.compiler.(binaryInterface); ok {
274 return binary.binary()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400275 }
276 return false
277}
278
Justin Yun5e035862021-06-29 20:50:37 +0900279func (mod *Module) StaticExecutable() bool {
280 if !mod.Binary() {
281 return false
282 }
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400283 return mod.StaticallyLinked()
Justin Yun5e035862021-06-29 20:50:37 +0900284}
285
Ivan Lozanod7586b62021-04-01 09:49:36 -0400286func (mod *Module) Object() bool {
287 // Rust has no modules which produce only object files.
288 return false
289}
290
Ivan Lozano52767be2019-10-18 14:49:46 -0700291func (mod *Module) Toc() android.OptionalPath {
292 if mod.compiler != nil {
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400293 if lib, ok := mod.compiler.(libraryInterface); ok {
294 return lib.toc()
Ivan Lozano52767be2019-10-18 14:49:46 -0700295 }
296 }
297 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
298}
299
Colin Crossc511bc52020-04-07 16:50:32 +0000300func (mod *Module) UseSdk() bool {
301 return false
302}
303
Ivan Lozanod7586b62021-04-01 09:49:36 -0400304func (mod *Module) RelativeInstallPath() string {
305 if mod.compiler != nil {
306 return mod.compiler.relativeInstallPath()
307 }
308 return ""
309}
310
Ivan Lozano52767be2019-10-18 14:49:46 -0700311func (mod *Module) UseVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500312 return mod.Properties.VndkVersion != ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700313}
314
Jiyong Park7d55b612021-06-11 17:22:09 +0900315func (mod *Module) Bootstrap() bool {
Ivan Lozanoa2268632021-07-22 10:52:06 -0400316 return Bool(mod.Properties.Bootstrap)
Jiyong Park7d55b612021-06-11 17:22:09 +0900317}
318
Ivan Lozano52767be2019-10-18 14:49:46 -0700319func (mod *Module) MustUseVendorVariant() bool {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400320 return true
321}
322
323func (mod *Module) SubName() string {
324 return mod.Properties.SubName
Ivan Lozano52767be2019-10-18 14:49:46 -0700325}
326
327func (mod *Module) IsVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500328 // TODO(b/165791368)
Ivan Lozano52767be2019-10-18 14:49:46 -0700329 return false
330}
331
Ivan Lozanof9e21722020-12-02 09:00:51 -0500332func (mod *Module) IsVndkExt() bool {
333 return false
334}
335
Ivan Lozanod7586b62021-04-01 09:49:36 -0400336func (mod *Module) IsVndkSp() bool {
337 return false
338}
339
Ivan Lozanof1868af2022-04-12 13:08:36 -0400340func (mod *Module) IsVndkPrebuiltLibrary() bool {
341 // Rust modules do not provide VNDK prebuilts
342 return false
343}
344
345func (mod *Module) IsVendorPublicLibrary() bool {
346 return mod.VendorProperties.IsVendorPublicLibrary
347}
348
349func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool {
350 // Rust modules to not provide Sdk variants
351 return false
352}
353
Colin Cross127bb8b2020-12-16 16:46:01 -0800354func (c *Module) IsVndkPrivate() bool {
355 return false
356}
357
358func (c *Module) IsLlndk() bool {
359 return false
360}
361
362func (c *Module) IsLlndkPublic() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500363 return false
364}
365
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400366func (mod *Module) KernelHeadersDecorator() bool {
367 return false
368}
369
Colin Cross1f3f1302021-04-26 18:37:44 -0700370func (m *Module) NeedsLlndkVariants() bool {
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400371 return false
372}
373
Colin Cross5271fea2021-04-27 13:06:04 -0700374func (m *Module) NeedsVendorPublicLibraryVariants() bool {
375 return false
376}
377
Ivan Lozanod7586b62021-04-01 09:49:36 -0400378func (mod *Module) HasLlndkStubs() bool {
379 return false
380}
381
382func (mod *Module) StubsVersion() string {
383 panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName()))
384}
385
Ivan Lozano52767be2019-10-18 14:49:46 -0700386func (mod *Module) SdkVersion() string {
387 return ""
388}
389
Colin Crossc511bc52020-04-07 16:50:32 +0000390func (mod *Module) AlwaysSdk() bool {
391 return false
392}
393
Jiyong Park2286afd2020-06-16 21:58:53 +0900394func (mod *Module) IsSdkVariant() bool {
395 return false
396}
397
Colin Cross1348ce32020-10-01 13:37:16 -0700398func (mod *Module) SplitPerApiLevel() bool {
399 return false
400}
401
Sasha Smundaka76acba2022-04-18 20:12:56 -0700402func (mod *Module) XrefRustFiles() android.Paths {
403 return mod.kytheFiles
404}
405
Ivan Lozanoffee3342019-08-27 12:03:00 -0700406type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400407 Dylibs []string
408 Rlibs []string
409 Rustlibs []string
410 Stdlibs []string
411 ProcMacros []string
412 SharedLibs []string
413 StaticLibs []string
414 WholeStaticLibs []string
415 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700416
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400417 // Used for data dependencies adjacent to tests
418 DataLibs []string
419 DataBins []string
420
Colin Crossfe605e12022-01-23 20:46:16 -0800421 CrtBegin, CrtEnd []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700422}
423
424type PathDeps struct {
Ivan Lozanoec6e9912021-01-21 15:23:29 -0500425 DyLibs RustLibraries
426 RLibs RustLibraries
427 SharedLibs android.Paths
428 SharedLibDeps android.Paths
429 StaticLibs android.Paths
430 ProcMacros RustLibraries
Yi Kong46c6e592022-01-20 22:55:00 +0800431 AfdoProfiles android.Paths
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500432
433 // depFlags and depLinkFlags are rustc and linker (clang) flags.
434 depFlags []string
435 depLinkFlags []string
436
437 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
438 // Both of these are exported and propagate to dependencies.
439 linkDirs []string
440 linkObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700441
Ivan Lozano45901ed2020-07-24 16:05:01 -0400442 // Used by bindgen modules which call clang
443 depClangFlags []string
444 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400445 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400446 depSystemIncludePaths android.Paths
447
Colin Crossfe605e12022-01-23 20:46:16 -0800448 CrtBegin android.Paths
449 CrtEnd android.Paths
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700450
451 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500452 SrcDeps android.Paths
453 srcProviderFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700454}
455
456type RustLibraries []RustLibrary
457
458type RustLibrary struct {
459 Path android.Path
460 CrateName string
461}
462
463type compiler interface {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100464 initialize(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700465 compilerFlags(ctx ModuleContext, flags Flags) Flags
Ivan Lozano67eada32021-09-23 11:50:33 -0400466 cfgFlags(ctx ModuleContext, flags Flags) Flags
467 featureFlags(ctx ModuleContext, flags Flags) Flags
Ivan Lozanoffee3342019-08-27 12:03:00 -0700468 compilerProps() []interface{}
Sasha Smundaka76acba2022-04-18 20:12:56 -0700469 compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput
Ivan Lozanoffee3342019-08-27 12:03:00 -0700470 compilerDeps(ctx DepsContext, deps Deps) Deps
471 crateName() string
Dan Albert06feee92021-03-19 15:06:02 -0700472 rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700473
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100474 // Output directory in which source-generated code from dependencies is
475 // copied. This is equivalent to Cargo's OUT_DIR variable.
476 CargoOutDir() android.OptionalPath
Dan Albert06feee92021-03-19 15:06:02 -0700477
Ivan Lozanoa9a1fc02021-08-11 15:13:43 -0400478 // CargoPkgVersion returns the value of the Cargo_pkg_version property.
479 CargoPkgVersion() string
480
481 // CargoEnvCompat returns whether Cargo environment variables should be used.
482 CargoEnvCompat() bool
483
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800484 inData() bool
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200485 install(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700486 relativeInstallPath() string
Ivan Lozanod7586b62021-04-01 09:49:36 -0400487 everInstallable() bool
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400488
489 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400490
491 Disabled() bool
492 SetDisabled()
Ivan Lozano042504f2020-08-18 14:31:23 -0400493
Ivan Lozanodd055472020-09-28 13:22:45 -0400494 stdLinkage(ctx *depsContext) RustLinkage
Jiyong Parke54f07e2021-04-07 15:08:04 +0900495
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400496 unstrippedOutputFilePath() android.Path
Jiyong Parke54f07e2021-04-07 15:08:04 +0900497 strippedOutputFilePath() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400498}
499
Matthew Maurerbb3add12020-06-25 09:34:12 -0700500type exportedFlagsProducer interface {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700501 exportLinkDirs(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400502 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700503}
504
Sasha Smundaka76acba2022-04-18 20:12:56 -0700505type xref interface {
506 XrefRustFiles() android.Paths
507}
508
Matthew Maurerbb3add12020-06-25 09:34:12 -0700509type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400510 linkDirs []string
511 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700512}
513
Matthew Maurerbb3add12020-06-25 09:34:12 -0700514func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
515 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
516}
517
Ivan Lozano2093af22020-08-25 12:48:19 -0400518func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
519 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
520}
521
Colin Cross0de8a1e2020-09-18 14:15:30 -0700522func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
523 ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700524 LinkDirs: flagExporter.linkDirs,
525 LinkObjects: flagExporter.linkObjects,
526 })
527}
528
Matthew Maurerbb3add12020-06-25 09:34:12 -0700529var _ exportedFlagsProducer = (*flagExporter)(nil)
530
531func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700532 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700533}
534
Colin Cross0de8a1e2020-09-18 14:15:30 -0700535type FlagExporterInfo struct {
536 Flags []string
537 LinkDirs []string // TODO: this should be android.Paths
538 LinkObjects []string // TODO: this should be android.Paths
539}
540
541var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
542
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400543func (mod *Module) isCoverageVariant() bool {
544 return mod.coverage.Properties.IsCoverageVariant
545}
546
547var _ cc.Coverage = (*Module)(nil)
548
549func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
550 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
551}
552
Ivan Lozanod7586b62021-04-01 09:49:36 -0400553func (mod *Module) VndkVersion() string {
554 return mod.Properties.VndkVersion
555}
556
557func (mod *Module) PreventInstall() bool {
558 return mod.Properties.PreventInstall
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400559}
560
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400561func (mod *Module) MarkAsCoverageVariant(coverage bool) {
562 mod.coverage.Properties.IsCoverageVariant = coverage
563}
564
565func (mod *Module) EnableCoverageIfNeeded() {
566 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700567}
568
569func defaultsFactory() android.Module {
570 return DefaultsFactory()
571}
572
573type Defaults struct {
574 android.ModuleBase
575 android.DefaultsModuleBase
576}
577
578func DefaultsFactory(props ...interface{}) android.Module {
579 module := &Defaults{}
580
581 module.AddProperties(props...)
582 module.AddProperties(
583 &BaseProperties{},
Yi Kong46c6e592022-01-20 22:55:00 +0800584 &cc.AfdoProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500585 &cc.VendorProperties{},
Jakub Kotur1d640d02021-01-06 12:40:43 +0100586 &BenchmarkProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400587 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700588 &BaseCompilerProperties{},
589 &BinaryCompilerProperties{},
590 &LibraryCompilerProperties{},
591 &ProcMacroCompilerProperties{},
592 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400593 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700594 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400595 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400596 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200597 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500598 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700599 )
600
601 android.InitDefaultsModule(module)
602 return module
603}
604
605func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700606 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700607}
608
Ivan Lozano183a3212019-10-18 14:18:45 -0700609func (mod *Module) CcLibrary() bool {
610 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -0500611 if _, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700612 return true
613 }
614 }
615 return false
616}
617
618func (mod *Module) CcLibraryInterface() bool {
619 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400620 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
621 // VariantIs{Static,Shared} is set.
622 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700623 return true
624 }
625 }
626 return false
627}
628
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400629func (mod *Module) UnstrippedOutputFile() android.Path {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400630 if mod.compiler != nil {
631 return mod.compiler.unstrippedOutputFilePath()
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400632 }
633 return nil
634}
635
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800636func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700637 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700638 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800639 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700640 }
641 }
642 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
643}
644
645func (mod *Module) SetStatic() {
646 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700647 if library, ok := mod.compiler.(libraryInterface); ok {
648 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700649 return
650 }
651 }
652 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
653}
654
655func (mod *Module) SetShared() {
656 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700657 if library, ok := mod.compiler.(libraryInterface); ok {
658 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700659 return
660 }
661 }
662 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
663}
664
Ivan Lozano183a3212019-10-18 14:18:45 -0700665func (mod *Module) BuildStaticVariant() bool {
666 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700667 if library, ok := mod.compiler.(libraryInterface); ok {
668 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700669 }
670 }
671 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
672}
673
674func (mod *Module) BuildSharedVariant() bool {
675 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700676 if library, ok := mod.compiler.(libraryInterface); ok {
677 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700678 }
679 }
680 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
681}
682
Ivan Lozano183a3212019-10-18 14:18:45 -0700683func (mod *Module) Module() android.Module {
684 return mod
685}
686
Ivan Lozano183a3212019-10-18 14:18:45 -0700687func (mod *Module) OutputFile() android.OptionalPath {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400688 return mod.outputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700689}
690
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400691func (mod *Module) CoverageFiles() android.Paths {
692 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800693 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400694 }
695 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
696}
697
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400698// Rust does not produce gcno files, and therefore does not produce a coverage archive.
699func (mod *Module) CoverageOutputFile() android.OptionalPath {
700 return android.OptionalPath{}
701}
702
703func (mod *Module) IsNdk(config android.Config) bool {
704 return false
705}
706
707func (mod *Module) IsStubs() bool {
708 return false
709}
710
Jiyong Park459feca2020-12-15 11:02:21 +0900711func (mod *Module) installable(apexInfo android.ApexInfo) bool {
Jiyong Park2811e072021-09-30 17:25:21 +0900712 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
Jiyong Parkbf8147a2021-05-17 13:19:33 +0900713 return false
714 }
715
Jiyong Park459feca2020-12-15 11:02:21 +0900716 // The apex variant is not installable because it is included in the APEX and won't appear
717 // in the system partition as a standalone file.
718 if !apexInfo.IsForPlatform() {
719 return false
720 }
721
Jiyong Parke54f07e2021-04-07 15:08:04 +0900722 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900723}
724
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500725func (ctx moduleContext) apexVariationName() string {
726 return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
727}
728
Ivan Lozano183a3212019-10-18 14:18:45 -0700729var _ cc.LinkableInterface = (*Module)(nil)
730
Ivan Lozanoffee3342019-08-27 12:03:00 -0700731func (mod *Module) Init() android.Module {
732 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500733 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700734
Yi Kong46c6e592022-01-20 22:55:00 +0800735 if mod.afdo != nil {
736 mod.AddProperties(mod.afdo.props()...)
737 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700738 if mod.compiler != nil {
739 mod.AddProperties(mod.compiler.compilerProps()...)
740 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400741 if mod.coverage != nil {
742 mod.AddProperties(mod.coverage.props()...)
743 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200744 if mod.clippy != nil {
745 mod.AddProperties(mod.clippy.props()...)
746 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400747 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700748 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400749 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500750 if mod.sanitize != nil {
751 mod.AddProperties(mod.sanitize.props()...)
752 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400753
Ivan Lozanoffee3342019-08-27 12:03:00 -0700754 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900755 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700756
757 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700758 return mod
759}
760
761func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
762 return &Module{
763 hod: hod,
764 multilib: multilib,
765 }
766}
767func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
768 module := newBaseModule(hod, multilib)
Yi Kong46c6e592022-01-20 22:55:00 +0800769 module.afdo = &afdo{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400770 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200771 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500772 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700773 return module
774}
775
776type ModuleContext interface {
777 android.ModuleContext
778 ModuleContextIntf
779}
780
781type BaseModuleContext interface {
782 android.BaseModuleContext
783 ModuleContextIntf
784}
785
786type DepsContext interface {
787 android.BottomUpMutatorContext
788 ModuleContextIntf
789}
790
791type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200792 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700793 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700794}
795
796type depsContext struct {
797 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700798}
799
800type moduleContext struct {
801 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700802}
803
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200804type baseModuleContext struct {
805 android.BaseModuleContext
806}
807
808func (ctx *moduleContext) RustModule() *Module {
809 return ctx.Module().(*Module)
810}
811
812func (ctx *moduleContext) toolchain() config.Toolchain {
813 return ctx.RustModule().toolchain(ctx)
814}
815
816func (ctx *depsContext) RustModule() *Module {
817 return ctx.Module().(*Module)
818}
819
820func (ctx *depsContext) toolchain() config.Toolchain {
821 return ctx.RustModule().toolchain(ctx)
822}
823
824func (ctx *baseModuleContext) RustModule() *Module {
825 return ctx.Module().(*Module)
826}
827
828func (ctx *baseModuleContext) toolchain() config.Toolchain {
829 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400830}
831
832func (mod *Module) nativeCoverage() bool {
Matthew Maurera61e31f2021-05-27 11:09:11 -0700833 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
834 if mod.Target().NativeBridge == android.NativeBridgeEnabled {
835 return false
836 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400837 return mod.compiler != nil && mod.compiler.nativeCoverage()
838}
839
Ivan Lozanod7586b62021-04-01 09:49:36 -0400840func (mod *Module) EverInstallable() bool {
841 return mod.compiler != nil &&
842 // Check to see whether the module is actually ever installable.
843 mod.compiler.everInstallable()
844}
845
846func (mod *Module) Installable() *bool {
847 return mod.Properties.Installable
848}
849
Ivan Lozano872d5792022-03-23 17:31:39 -0400850func (mod *Module) ProcMacro() bool {
851 if pm, ok := mod.compiler.(procMacroInterface); ok {
852 return pm.ProcMacro()
853 }
854 return false
855}
856
Ivan Lozanoffee3342019-08-27 12:03:00 -0700857func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
858 if mod.cachedToolchain == nil {
859 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
860 }
861 return mod.cachedToolchain
862}
863
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200864func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
865 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
866}
867
Ivan Lozanoffee3342019-08-27 12:03:00 -0700868func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
869}
870
871func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
872 ctx := &moduleContext{
873 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700874 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700875
Jiyong Park99644e92020-11-17 22:21:02 +0900876 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
877 if !apexInfo.IsForPlatform() {
878 mod.hideApexVariantFromMake = true
879 }
880
Ivan Lozanoffee3342019-08-27 12:03:00 -0700881 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500882 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
883
Ivan Lozanof1868af2022-04-12 13:08:36 -0400884 mod.Properties.SubName = cc.GetSubnameProperty(actx, mod)
Matthew Maurera61e31f2021-05-27 11:09:11 -0700885
Ivan Lozanoffee3342019-08-27 12:03:00 -0700886 if !toolchain.Supported() {
887 // This toolchain's unsupported, there's nothing to do for this mod.
888 return
889 }
890
891 deps := mod.depsToPaths(ctx)
892 flags := Flags{
893 Toolchain: toolchain,
894 }
895
Ivan Lozano67eada32021-09-23 11:50:33 -0400896 // Calculate rustc flags
Yi Kong46c6e592022-01-20 22:55:00 +0800897 if mod.afdo != nil {
898 flags, deps = mod.afdo.flags(ctx, flags, deps)
899 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700900 if mod.compiler != nil {
901 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -0400902 flags = mod.compiler.cfgFlags(ctx, flags)
903 flags = mod.compiler.featureFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400904 }
905 if mod.coverage != nil {
906 flags, deps = mod.coverage.flags(ctx, flags, deps)
907 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200908 if mod.clippy != nil {
909 flags, deps = mod.clippy.flags(ctx, flags, deps)
910 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500911 if mod.sanitize != nil {
912 flags, deps = mod.sanitize.flags(ctx, flags, deps)
913 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400914
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200915 // SourceProvider needs to call GenerateSource() before compiler calls
916 // compile() so it can provide the source. A SourceProvider has
917 // multiple variants (e.g. source, rlib, dylib). Only the "source"
918 // variant is responsible for effectively generating the source. The
919 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400920 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200921 if mod.compiler.(libraryInterface).source() {
922 mod.sourceProvider.GenerateSource(ctx, deps)
923 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
924 } else {
925 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
926 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700927 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200928 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400929 }
930
931 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100932 mod.compiler.initialize(ctx)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700933 buildOutput := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400934 if ctx.Failed() {
935 return
936 }
Sasha Smundaka76acba2022-04-18 20:12:56 -0700937 mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile)
938 if buildOutput.kytheFile != nil {
939 mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile)
940 }
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400941 bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
Jiyong Park459feca2020-12-15 11:02:21 +0900942
Dan Albert06feee92021-03-19 15:06:02 -0700943 mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
Matthew Maurere3803632021-12-10 21:57:21 +0000944 if mod.docTimestampFile.Valid() {
945 ctx.CheckbuildFile(mod.docTimestampFile.Path())
946 }
Dan Albert06feee92021-03-19 15:06:02 -0700947
Ivan Lozano1921e802021-05-20 13:39:16 -0400948 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
949 // RECOVERY_SNAPSHOT_VERSION is current.
950 if lib, ok := mod.compiler.(snapshotLibraryInterface); ok {
951 if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) {
952 lib.collectHeadersForSnapshot(ctx, deps)
953 }
954 }
955
Jiyong Park459feca2020-12-15 11:02:21 +0900956 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
Ivan Lozano872d5792022-03-23 17:31:39 -0400957 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900958 // If the module has been specifically configure to not be installed then
959 // hide from make as otherwise it will break when running inside make as the
960 // output path to install will not be specified. Not all uninstallable
961 // modules can be hidden from make as some are needed for resolving make
Ivan Lozano872d5792022-03-23 17:31:39 -0400962 // side dependencies. In particular, proc-macros need to be captured in the
963 // host snapshot.
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900964 mod.HideFromMake()
965 } else if !mod.installable(apexInfo) {
966 mod.SkipInstall()
967 }
968
969 // Still call install though, the installs will be stored as PackageSpecs to allow
970 // using the outputs in a genrule.
971 if mod.OutputFile().Valid() {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200972 mod.compiler.install(ctx)
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900973 if ctx.Failed() {
974 return
975 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400976 }
Chris Wailes74be7642021-07-22 16:20:28 -0700977
978 ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700979 }
980}
981
982func (mod *Module) deps(ctx DepsContext) Deps {
983 deps := Deps{}
984
985 if mod.compiler != nil {
986 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400987 }
988 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700989 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700990 }
991
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400992 if mod.coverage != nil {
993 deps = mod.coverage.deps(ctx, deps)
994 }
995
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500996 if mod.sanitize != nil {
997 deps = mod.sanitize.deps(ctx, deps)
998 }
999
Ivan Lozanoffee3342019-08-27 12:03:00 -07001000 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
1001 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -07001002 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001003 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
1004 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1005 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Andrew Walbran797e4be2022-03-07 15:41:53 +00001006 deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001007 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001008 return deps
1009
1010}
1011
Ivan Lozanoffee3342019-08-27 12:03:00 -07001012type dependencyTag struct {
1013 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001014 name string
1015 library bool
1016 procMacro bool
Colin Cross65cb3142021-12-10 23:05:02 +00001017 dynamic bool
Ivan Lozanoffee3342019-08-27 12:03:00 -07001018}
1019
Jiyong Park65b62242020-11-25 12:44:59 +09001020// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
1021// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
1022func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001023 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +09001024}
1025
1026var _ android.InstallNeededDependencyTag = dependencyTag{}
1027
Colin Cross65cb3142021-12-10 23:05:02 +00001028func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
1029 if d.library && d.dynamic {
1030 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
1031 }
1032 return nil
1033}
1034
1035var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
1036
Ivan Lozanoffee3342019-08-27 12:03:00 -07001037var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001038 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
1039 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
Colin Cross65cb3142021-12-10 23:05:02 +00001040 dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001041 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001042 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001043 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001044 dataLibDepTag = dependencyTag{name: "data lib"}
1045 dataBinDepTag = dependencyTag{name: "data bin"}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001046)
1047
Jiyong Park99644e92020-11-17 22:21:02 +09001048func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
1049 tag, ok := depTag.(dependencyTag)
1050 return ok && tag == dylibDepTag
1051}
1052
Jiyong Park94e22fd2021-04-08 18:19:15 +09001053func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
1054 tag, ok := depTag.(dependencyTag)
1055 return ok && tag == rlibDepTag
1056}
1057
Matthew Maurer0f003b12020-06-29 14:34:06 -07001058type autoDep struct {
1059 variation string
1060 depTag dependencyTag
1061}
1062
1063var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001064 rlibVariation = "rlib"
1065 dylibVariation = "dylib"
1066 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
1067 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -07001068)
1069
1070type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -05001071 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -07001072}
1073
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001074func (mod *Module) begin(ctx BaseModuleContext) {
1075 if mod.coverage != nil {
1076 mod.coverage.begin(ctx)
1077 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001078 if mod.sanitize != nil {
1079 mod.sanitize.begin(ctx)
1080 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001081}
1082
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001083func (mod *Module) Prebuilt() *android.Prebuilt {
Ivan Lozano872d5792022-03-23 17:31:39 -04001084 if p, ok := mod.compiler.(rustPrebuilt); ok {
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001085 return p.prebuilt()
1086 }
1087 return nil
1088}
1089
Ivan Lozanoffee3342019-08-27 12:03:00 -07001090func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
1091 var depPaths PathDeps
1092
1093 directRlibDeps := []*Module{}
1094 directDylibDeps := []*Module{}
1095 directProcMacroDeps := []*Module{}
Jiyong Park7d55b612021-06-11 17:22:09 +09001096 directSharedLibDeps := []cc.SharedLibraryInfo{}
Ivan Lozano52767be2019-10-18 14:49:46 -07001097 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001098 directSrcProvidersDeps := []*Module{}
1099 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001100
Ivan Lozanoe950cda2021-11-09 11:26:04 -05001101 // For the dependency from platform to apex, use the latest stubs
1102 mod.apexSdkVersion = android.FutureApiLevel
1103 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1104 if !apexInfo.IsForPlatform() {
1105 mod.apexSdkVersion = apexInfo.MinSdkVersion
1106 }
1107
1108 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
1109 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
1110 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
1111 // (b/144430859)
1112 mod.apexSdkVersion = android.FutureApiLevel
1113 }
1114
Ivan Lozanoffee3342019-08-27 12:03:00 -07001115 ctx.VisitDirectDeps(func(dep android.Module) {
1116 depName := ctx.OtherModuleName(dep)
1117 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001118
Ivan Lozano89435d12020-07-31 11:01:18 -04001119 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001120 //Handle Rust Modules
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001121 makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -07001122
Ivan Lozanoffee3342019-08-27 12:03:00 -07001123 switch depTag {
1124 case dylibDepTag:
1125 dylib, ok := rustDep.compiler.(libraryInterface)
1126 if !ok || !dylib.dylib() {
1127 ctx.ModuleErrorf("mod %q not an dylib library", depName)
1128 return
1129 }
1130 directDylibDeps = append(directDylibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001131 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001132 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -04001133
Ivan Lozanoffee3342019-08-27 12:03:00 -07001134 rlib, ok := rustDep.compiler.(libraryInterface)
1135 if !ok || !rlib.rlib() {
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001136 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001137 return
1138 }
1139 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001140 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001141 case procMacroDepTag:
1142 directProcMacroDeps = append(directProcMacroDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001143 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Paul Duffind5cf92e2021-07-09 17:38:55 +01001144 }
1145
1146 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001147 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
1148 // OS/Arch variant is used.
1149 var helper string
1150 if ctx.Host() {
1151 helper = "missing 'host_supported'?"
1152 } else {
1153 helper = "device module defined?"
1154 }
1155
1156 if dep.Target().Os != ctx.Os() {
1157 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
1158 return
1159 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
1160 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
1161 return
1162 }
1163 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001164 }
1165
Ivan Lozano2bbcacf2020-08-07 09:00:50 -04001166 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -07001167 if depTag != procMacroDepTag {
1168 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
1169 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
1170 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
1171 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001172 }
1173
Ivan Lozanoffee3342019-08-27 12:03:00 -07001174 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001175 linkFile := rustDep.UnstrippedOutputFile()
1176 linkDir := linkPathFromFilePath(linkFile)
Matthew Maurerbb3add12020-06-25 09:34:12 -07001177 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
1178 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001179 }
1180 }
1181
Ivan Lozano89435d12020-07-31 11:01:18 -04001182 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07001183 //Handle C dependencies
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001184 makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
Ivan Lozano52767be2019-10-18 14:49:46 -07001185 if _, ok := ccDep.(*Module); !ok {
1186 if ccDep.Module().Target().Os != ctx.Os() {
1187 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1188 return
1189 }
1190 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
1191 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
1192 return
1193 }
Ivan Lozano70e0a072019-09-13 14:23:15 -07001194 }
Ivan Lozano2093af22020-08-25 12:48:19 -04001195 linkObject := ccDep.OutputFile()
1196 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -05001197
Ivan Lozano2093af22020-08-25 12:48:19 -04001198 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001199 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
1200 }
1201
1202 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -07001203 switch {
1204 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -04001205 if cc.IsWholeStaticLib(depTag) {
1206 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
1207 // if the library is not prefixed by "lib".
Ivan Lozanofdadcd72021-11-01 09:04:23 -04001208 if mod.Binary() {
1209 // Binaries may sometimes need to link whole static libraries that don't start with 'lib'.
1210 // Since binaries don't need to 'rebundle' these like libraries and only use these for the
1211 // final linkage, pass the args directly to the linker to handle these cases.
1212 depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
1213 } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
Ivan Lozanofb6f36f2021-02-05 12:27:08 -05001214 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001215 } else {
1216 ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName())
Ivan Lozanofb6f36f2021-02-05 12:27:08 -05001217 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001218 }
1219
1220 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
1221 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -04001222 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001223 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
1224
Colin Cross0de8a1e2020-09-18 14:15:30 -07001225 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1226 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1227 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1228 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1229 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001230 directStaticLibDeps = append(directStaticLibDeps, ccDep)
Justin Yun2b3ed642022-02-16 08:15:07 +09001231
1232 // Record baseLibName for snapshots.
1233 mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName))
1234
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001235 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07001236 case cc.IsSharedDepTag(depTag):
Jiyong Park7d55b612021-06-11 17:22:09 +09001237 // For the shared lib dependencies, we may link to the stub variant
1238 // of the dependency depending on the context (e.g. if this
1239 // dependency crosses the APEX boundaries).
1240 sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep)
1241
1242 // Re-get linkObject as ChooseStubOrImpl actually tells us which
1243 // object (either from stub or non-stub) to use.
1244 linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
1245 linkPath = linkPathFromFilePath(linkObject.Path())
1246
Ivan Lozanoffee3342019-08-27 12:03:00 -07001247 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001248 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -07001249 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1250 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1251 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1252 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Jiyong Park7d55b612021-06-11 17:22:09 +09001253 directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo)
Ivan Lozano1921e802021-05-20 13:39:16 -04001254
1255 // Record baseLibName for snapshots.
1256 mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName))
1257
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001258 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001259 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -08001260 case cc.IsHeaderDepTag(depTag):
1261 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1262 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1263 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1264 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -07001265 case depTag == cc.CrtBeginDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001266 depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07001267 case depTag == cc.CrtEndDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001268 depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001269 }
1270
1271 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001272 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1273 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001274 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001275 }
Colin Cross018cbeb2022-01-24 17:22:45 -08001276 } else {
1277 switch {
1278 case depTag == cc.CrtBeginDepTag:
1279 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
1280 case depTag == cc.CrtEndDepTag:
1281 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
1282 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001283 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001284
1285 if srcDep, ok := dep.(android.SourceFileProducer); ok {
Paul Duffind5cf92e2021-07-09 17:38:55 +01001286 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano89435d12020-07-31 11:01:18 -04001287 // These are usually genrules which don't have per-target variants.
1288 directSrcDeps = append(directSrcDeps, srcDep)
1289 }
1290 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001291 })
1292
1293 var rlibDepFiles RustLibraries
1294 for _, dep := range directRlibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001295 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001296 }
1297 var dylibDepFiles RustLibraries
1298 for _, dep := range directDylibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001299 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001300 }
1301 var procMacroDepFiles RustLibraries
1302 for _, dep := range directProcMacroDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001303 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001304 }
1305
1306 var staticLibDepFiles android.Paths
1307 for _, dep := range directStaticLibDeps {
1308 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1309 }
1310
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001311 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001312 var sharedLibDepFiles android.Paths
1313 for _, dep := range directSharedLibDeps {
Jiyong Park7d55b612021-06-11 17:22:09 +09001314 sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary)
1315 if dep.TableOfContents.Valid() {
1316 sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path())
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001317 } else {
Jiyong Park7d55b612021-06-11 17:22:09 +09001318 sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001319 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001320 }
1321
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001322 var srcProviderDepFiles android.Paths
1323 for _, dep := range directSrcProvidersDeps {
1324 srcs, _ := dep.OutputFiles("")
1325 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1326 }
1327 for _, dep := range directSrcDeps {
1328 srcs := dep.Srcs()
1329 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1330 }
1331
Ivan Lozanoffee3342019-08-27 12:03:00 -07001332 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1333 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1334 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001335 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001336 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1337 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001338 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001339
1340 // Dedup exported flags from dependencies
1341 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001342 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001343 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001344 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1345 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1346 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001347
1348 return depPaths
1349}
1350
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001351func (mod *Module) InstallInData() bool {
1352 if mod.compiler == nil {
1353 return false
1354 }
1355 return mod.compiler.inData()
1356}
1357
Matthew Maurer9f59e8d2021-08-19 13:10:05 -07001358func (mod *Module) InstallInRamdisk() bool {
1359 return mod.InRamdisk()
1360}
1361
1362func (mod *Module) InstallInVendorRamdisk() bool {
1363 return mod.InVendorRamdisk()
1364}
1365
1366func (mod *Module) InstallInRecovery() bool {
1367 return mod.InRecovery()
1368}
1369
Ivan Lozanoffee3342019-08-27 12:03:00 -07001370func linkPathFromFilePath(filepath android.Path) string {
1371 return strings.Split(filepath.String(), filepath.Base())[0]
1372}
Ivan Lozanod648c432020-02-06 12:05:10 -05001373
Ivan Lozanoffee3342019-08-27 12:03:00 -07001374func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1375 ctx := &depsContext{
1376 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001377 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001378
1379 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001380 var commonDepVariations []blueprint.Variation
Ivan Lozano1921e802021-05-20 13:39:16 -04001381 var snapshotInfo *cc.SnapshotInfo
1382
1383 if ctx.Os() == android.Android {
1384 deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
1385 }
Ivan Lozanodd055472020-09-28 13:22:45 -04001386
Ivan Lozano2b081132020-09-08 12:46:52 -04001387 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001388 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001389 stdLinkage = "rlib-std"
1390 }
1391
1392 rlibDepVariations := commonDepVariations
Ivan Lozano1921e802021-05-20 13:39:16 -04001393
Ivan Lozano2b081132020-09-08 12:46:52 -04001394 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1395 rlibDepVariations = append(rlibDepVariations,
1396 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1397 }
1398
Ivan Lozano1921e802021-05-20 13:39:16 -04001399 // rlibs
Ivan Lozano2d407632022-04-07 12:59:11 -04001400 rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001401 for _, lib := range deps.Rlibs {
1402 depTag := rlibDepTag
1403 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1404
Ivan Lozano2d407632022-04-07 12:59:11 -04001405 actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001406 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001407
1408 // dylibs
Ivan Lozano52767be2019-10-18 14:49:46 -07001409 actx.AddVariationDependencies(
1410 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001411 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001412 dylibDepTag, deps.Dylibs...)
1413
Ivan Lozano1921e802021-05-20 13:39:16 -04001414 // rustlibs
Ivan Lozano042504f2020-08-18 14:31:23 -04001415 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1416 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2d407632022-04-07 12:59:11 -04001417 for _, lib := range deps.Rustlibs {
1418 if autoDep.depTag == rlibDepTag {
1419 // Handle the rlib deptag case
1420 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1421 } else {
1422 // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
1423 // Check for the existence of the dylib deptag variant. Select it if available,
1424 // otherwise select the rlib variant.
1425 autoDepVariations := append(commonDepVariations,
1426 blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
1427 if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
1428 actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
1429 } else {
1430 // If there's no dylib dependency available, try to add the rlib dependency instead.
1431 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1432 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001433 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001434 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001435 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001436 // stdlibs
Ivan Lozano2b081132020-09-08 12:46:52 -04001437 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001438 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001439 for _, lib := range deps.Stdlibs {
1440 depTag := rlibDepTag
1441 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1442
1443 actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
1444 depTag, lib)
1445 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001446 } else {
1447 actx.AddVariationDependencies(
1448 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1449 dylibDepTag, deps.Stdlibs...)
1450 }
1451 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001452
1453 for _, lib := range deps.SharedLibs {
1454 depTag := cc.SharedDepTag()
1455 name, version := cc.StubsLibNameAndVersion(lib)
1456
1457 variations := []blueprint.Variation{
1458 {Mutator: "link", Variation: "shared"},
1459 }
1460 cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
1461 }
1462
1463 for _, lib := range deps.WholeStaticLibs {
1464 depTag := cc.StaticDepTag(true)
1465 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
1466
1467 actx.AddVariationDependencies([]blueprint.Variation{
1468 {Mutator: "link", Variation: "static"},
1469 }, depTag, lib)
1470 }
1471
1472 for _, lib := range deps.StaticLibs {
1473 depTag := cc.StaticDepTag(false)
1474 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
1475
1476 actx.AddVariationDependencies([]blueprint.Variation{
1477 {Mutator: "link", Variation: "static"},
1478 }, depTag, lib)
1479 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001480
Zach Johnson3df4e632020-11-06 11:56:27 -08001481 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1482
Colin Cross565cafd2020-09-25 18:47:38 -07001483 crtVariations := cc.GetCrtVariations(ctx, mod)
Colin Crossfe605e12022-01-23 20:46:16 -08001484 for _, crt := range deps.CrtBegin {
Ivan Lozano1921e802021-05-20 13:39:16 -04001485 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag,
Colin Crossfe605e12022-01-23 20:46:16 -08001486 cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001487 }
Colin Crossfe605e12022-01-23 20:46:16 -08001488 for _, crt := range deps.CrtEnd {
Ivan Lozano1921e802021-05-20 13:39:16 -04001489 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag,
Colin Crossfe605e12022-01-23 20:46:16 -08001490 cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001491 }
1492
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001493 if mod.sourceProvider != nil {
1494 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1495 bindgen.Properties.Custom_bindgen != "" {
1496 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1497 bindgen.Properties.Custom_bindgen)
1498 }
1499 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001500
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001501 actx.AddVariationDependencies([]blueprint.Variation{
1502 {Mutator: "link", Variation: "shared"},
1503 }, dataLibDepTag, deps.DataLibs...)
1504
1505 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
1506
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001507 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001508 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001509}
1510
Ivan Lozano2d407632022-04-07 12:59:11 -04001511// addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available.
1512func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo *cc.SnapshotInfo, variations []blueprint.Variation) {
1513 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1514 actx.AddVariationDependencies(variations, rlibDepTag, lib)
1515}
1516
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001517func BeginMutator(ctx android.BottomUpMutatorContext) {
1518 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1519 mod.beginMutator(ctx)
1520 }
1521}
1522
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001523func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1524 ctx := &baseModuleContext{
1525 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001526 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001527
1528 mod.begin(ctx)
1529}
1530
Ivan Lozanoffee3342019-08-27 12:03:00 -07001531func (mod *Module) Name() string {
1532 name := mod.ModuleBase.Name()
1533 if p, ok := mod.compiler.(interface {
1534 Name(string) string
1535 }); ok {
1536 name = p.Name(name)
1537 }
1538 return name
1539}
1540
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001541func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001542 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001543 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001544 }
1545}
1546
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001547var _ android.HostToolProvider = (*Module)(nil)
Ivan Lozano872d5792022-03-23 17:31:39 -04001548var _ snapshot.RelativeInstallPath = (*Module)(nil)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001549
1550func (mod *Module) HostToolPath() android.OptionalPath {
1551 if !mod.Host() {
1552 return android.OptionalPath{}
1553 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001554 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1555 return android.OptionalPathForPath(binary.baseCompiler.path)
Ivan Lozano872d5792022-03-23 17:31:39 -04001556 } else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
1557 // Even though proc-macros aren't strictly "tools", since they target the compiler
1558 // and act as compiler plugins, we treat them similarly.
1559 return android.OptionalPathForPath(pm.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001560 }
1561 return android.OptionalPath{}
1562}
1563
Jiyong Park99644e92020-11-17 22:21:02 +09001564var _ android.ApexModule = (*Module)(nil)
1565
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001566func (mod *Module) MinSdkVersion() string {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001567 return String(mod.Properties.Min_sdk_version)
1568}
1569
Jiyong Park45bf82e2020-12-15 22:29:02 +09001570// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001571func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001572 minSdkVersion := mod.MinSdkVersion()
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001573 if minSdkVersion == "apex_inherit" {
1574 return nil
1575 }
1576 if minSdkVersion == "" {
1577 return fmt.Errorf("min_sdk_version is not specificed")
1578 }
1579
1580 // Not using nativeApiLevelFromUser because the context here is not
1581 // necessarily a native context.
1582 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1583 if err != nil {
1584 return err
1585 }
1586
1587 if ver.GreaterThan(sdkVersion) {
1588 return fmt.Errorf("newer SDK(%v)", ver)
1589 }
Jiyong Park99644e92020-11-17 22:21:02 +09001590 return nil
1591}
1592
Jiyong Park45bf82e2020-12-15 22:29:02 +09001593// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001594func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1595 depTag := ctx.OtherModuleDependencyTag(dep)
1596
1597 if ccm, ok := dep.(*cc.Module); ok {
1598 if ccm.HasStubsVariants() {
1599 if cc.IsSharedDepTag(depTag) {
1600 // dynamic dep to a stubs lib crosses APEX boundary
1601 return false
1602 }
1603 if cc.IsRuntimeDepTag(depTag) {
1604 // runtime dep to a stubs lib also crosses APEX boundary
1605 return false
1606 }
1607
1608 if cc.IsHeaderDepTag(depTag) {
1609 return false
1610 }
1611 }
1612 if mod.Static() && cc.IsSharedDepTag(depTag) {
1613 // shared_lib dependency from a static lib is considered as crossing
1614 // the APEX boundary because the dependency doesn't actually is
1615 // linked; the dependency is used only during the compilation phase.
1616 return false
1617 }
1618 }
1619
1620 if depTag == procMacroDepTag {
1621 return false
1622 }
1623
1624 return true
1625}
1626
1627// Overrides ApexModule.IsInstallabeToApex()
1628func (mod *Module) IsInstallableToApex() bool {
1629 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -05001630 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) {
Jiyong Park99644e92020-11-17 22:21:02 +09001631 return true
1632 }
1633 if _, ok := mod.compiler.(*binaryDecorator); ok {
1634 return true
1635 }
1636 }
1637 return false
1638}
1639
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001640// If a library file has a "lib" prefix, extract the library name without the prefix.
1641func libNameFromFilePath(filepath android.Path) (string, bool) {
1642 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1643 if strings.HasPrefix(libName, "lib") {
1644 libName = libName[3:]
1645 return libName, true
1646 }
1647 return "", false
1648}
1649
Sasha Smundaka76acba2022-04-18 20:12:56 -07001650func kytheExtractRustFactory() android.Singleton {
1651 return &kytheExtractRustSingleton{}
1652}
1653
1654type kytheExtractRustSingleton struct {
1655}
1656
1657func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) {
1658 var xrefTargets android.Paths
1659 ctx.VisitAllModules(func(module android.Module) {
1660 if rustModule, ok := module.(xref); ok {
1661 xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...)
1662 }
1663 })
1664 if len(xrefTargets) > 0 {
1665 ctx.Phony("xref_rust", xrefTargets...)
1666 }
1667}
1668
Ivan Lozanoffee3342019-08-27 12:03:00 -07001669var Bool = proptools.Bool
1670var BoolDefault = proptools.BoolDefault
1671var String = proptools.String
1672var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001673
1674var _ android.OutputFileProducer = (*Module)(nil)