blob: 48419eb8ecacc9fffb88782e07e7556ce47dce74 [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
Jiyong Park459feca2020-12-15 11:02:21 +0900698func (mod *Module) installable(apexInfo android.ApexInfo) bool {
Jiyong Park2811e072021-09-30 17:25:21 +0900699 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
Jiyong Parkbf8147a2021-05-17 13:19:33 +0900700 return false
701 }
702
Jiyong Park459feca2020-12-15 11:02:21 +0900703 // The apex variant is not installable because it is included in the APEX and won't appear
704 // in the system partition as a standalone file.
705 if !apexInfo.IsForPlatform() {
706 return false
707 }
708
Jiyong Parke54f07e2021-04-07 15:08:04 +0900709 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900710}
711
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500712func (ctx moduleContext) apexVariationName() string {
713 return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
714}
715
Ivan Lozano183a3212019-10-18 14:18:45 -0700716var _ cc.LinkableInterface = (*Module)(nil)
717
Ivan Lozanoffee3342019-08-27 12:03:00 -0700718func (mod *Module) Init() android.Module {
719 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500720 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700721
Yi Kong46c6e592022-01-20 22:55:00 +0800722 if mod.afdo != nil {
723 mod.AddProperties(mod.afdo.props()...)
724 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700725 if mod.compiler != nil {
726 mod.AddProperties(mod.compiler.compilerProps()...)
727 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400728 if mod.coverage != nil {
729 mod.AddProperties(mod.coverage.props()...)
730 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200731 if mod.clippy != nil {
732 mod.AddProperties(mod.clippy.props()...)
733 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400734 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700735 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400736 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500737 if mod.sanitize != nil {
738 mod.AddProperties(mod.sanitize.props()...)
739 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400740
Ivan Lozanoffee3342019-08-27 12:03:00 -0700741 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900742 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700743
744 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700745 return mod
746}
747
748func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
749 return &Module{
750 hod: hod,
751 multilib: multilib,
752 }
753}
754func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
755 module := newBaseModule(hod, multilib)
Yi Kong46c6e592022-01-20 22:55:00 +0800756 module.afdo = &afdo{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400757 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200758 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500759 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700760 return module
761}
762
763type ModuleContext interface {
764 android.ModuleContext
765 ModuleContextIntf
766}
767
768type BaseModuleContext interface {
769 android.BaseModuleContext
770 ModuleContextIntf
771}
772
773type DepsContext interface {
774 android.BottomUpMutatorContext
775 ModuleContextIntf
776}
777
778type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200779 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700780 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700781}
782
783type depsContext struct {
784 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700785}
786
787type moduleContext struct {
788 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700789}
790
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200791type baseModuleContext struct {
792 android.BaseModuleContext
793}
794
795func (ctx *moduleContext) RustModule() *Module {
796 return ctx.Module().(*Module)
797}
798
799func (ctx *moduleContext) toolchain() config.Toolchain {
800 return ctx.RustModule().toolchain(ctx)
801}
802
803func (ctx *depsContext) RustModule() *Module {
804 return ctx.Module().(*Module)
805}
806
807func (ctx *depsContext) toolchain() config.Toolchain {
808 return ctx.RustModule().toolchain(ctx)
809}
810
811func (ctx *baseModuleContext) RustModule() *Module {
812 return ctx.Module().(*Module)
813}
814
815func (ctx *baseModuleContext) toolchain() config.Toolchain {
816 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400817}
818
819func (mod *Module) nativeCoverage() bool {
Matthew Maurera61e31f2021-05-27 11:09:11 -0700820 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
821 if mod.Target().NativeBridge == android.NativeBridgeEnabled {
822 return false
823 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400824 return mod.compiler != nil && mod.compiler.nativeCoverage()
825}
826
Ivan Lozanod7586b62021-04-01 09:49:36 -0400827func (mod *Module) EverInstallable() bool {
828 return mod.compiler != nil &&
829 // Check to see whether the module is actually ever installable.
830 mod.compiler.everInstallable()
831}
832
833func (mod *Module) Installable() *bool {
834 return mod.Properties.Installable
835}
836
Ivan Lozano872d5792022-03-23 17:31:39 -0400837func (mod *Module) ProcMacro() bool {
838 if pm, ok := mod.compiler.(procMacroInterface); ok {
839 return pm.ProcMacro()
840 }
841 return false
842}
843
Ivan Lozanoffee3342019-08-27 12:03:00 -0700844func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
845 if mod.cachedToolchain == nil {
846 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
847 }
848 return mod.cachedToolchain
849}
850
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200851func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
852 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
853}
854
Ivan Lozanoffee3342019-08-27 12:03:00 -0700855func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
856}
857
858func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
859 ctx := &moduleContext{
860 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700861 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700862
Jiyong Park99644e92020-11-17 22:21:02 +0900863 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
864 if !apexInfo.IsForPlatform() {
865 mod.hideApexVariantFromMake = true
866 }
867
Ivan Lozanoffee3342019-08-27 12:03:00 -0700868 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500869 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
870
Ivan Lozanof1868af2022-04-12 13:08:36 -0400871 mod.Properties.SubName = cc.GetSubnameProperty(actx, mod)
Matthew Maurera61e31f2021-05-27 11:09:11 -0700872
Ivan Lozanoffee3342019-08-27 12:03:00 -0700873 if !toolchain.Supported() {
874 // This toolchain's unsupported, there's nothing to do for this mod.
875 return
876 }
877
878 deps := mod.depsToPaths(ctx)
879 flags := Flags{
880 Toolchain: toolchain,
881 }
882
Ivan Lozano67eada32021-09-23 11:50:33 -0400883 // Calculate rustc flags
Yi Kong46c6e592022-01-20 22:55:00 +0800884 if mod.afdo != nil {
885 flags, deps = mod.afdo.flags(ctx, flags, deps)
886 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700887 if mod.compiler != nil {
888 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -0400889 flags = mod.compiler.cfgFlags(ctx, flags)
890 flags = mod.compiler.featureFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400891 }
892 if mod.coverage != nil {
893 flags, deps = mod.coverage.flags(ctx, flags, deps)
894 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200895 if mod.clippy != nil {
896 flags, deps = mod.clippy.flags(ctx, flags, deps)
897 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500898 if mod.sanitize != nil {
899 flags, deps = mod.sanitize.flags(ctx, flags, deps)
900 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400901
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200902 // SourceProvider needs to call GenerateSource() before compiler calls
903 // compile() so it can provide the source. A SourceProvider has
904 // multiple variants (e.g. source, rlib, dylib). Only the "source"
905 // variant is responsible for effectively generating the source. The
906 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400907 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200908 if mod.compiler.(libraryInterface).source() {
909 mod.sourceProvider.GenerateSource(ctx, deps)
910 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
911 } else {
912 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
913 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700914 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200915 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400916 }
917
918 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100919 mod.compiler.initialize(ctx)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700920 buildOutput := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400921 if ctx.Failed() {
922 return
923 }
Sasha Smundaka76acba2022-04-18 20:12:56 -0700924 mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile)
925 if buildOutput.kytheFile != nil {
926 mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile)
927 }
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400928 bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
Jiyong Park459feca2020-12-15 11:02:21 +0900929
Dan Albert06feee92021-03-19 15:06:02 -0700930 mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
Matthew Maurere3803632021-12-10 21:57:21 +0000931 if mod.docTimestampFile.Valid() {
932 ctx.CheckbuildFile(mod.docTimestampFile.Path())
933 }
Dan Albert06feee92021-03-19 15:06:02 -0700934
Ivan Lozano1921e802021-05-20 13:39:16 -0400935 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
936 // RECOVERY_SNAPSHOT_VERSION is current.
937 if lib, ok := mod.compiler.(snapshotLibraryInterface); ok {
938 if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) {
939 lib.collectHeadersForSnapshot(ctx, deps)
940 }
941 }
942
Jiyong Park459feca2020-12-15 11:02:21 +0900943 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
Ivan Lozano872d5792022-03-23 17:31:39 -0400944 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900945 // If the module has been specifically configure to not be installed then
946 // hide from make as otherwise it will break when running inside make as the
947 // output path to install will not be specified. Not all uninstallable
948 // modules can be hidden from make as some are needed for resolving make
Ivan Lozano872d5792022-03-23 17:31:39 -0400949 // side dependencies. In particular, proc-macros need to be captured in the
950 // host snapshot.
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900951 mod.HideFromMake()
952 } else if !mod.installable(apexInfo) {
953 mod.SkipInstall()
954 }
955
956 // Still call install though, the installs will be stored as PackageSpecs to allow
957 // using the outputs in a genrule.
958 if mod.OutputFile().Valid() {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200959 mod.compiler.install(ctx)
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900960 if ctx.Failed() {
961 return
962 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400963 }
Chris Wailes74be7642021-07-22 16:20:28 -0700964
965 ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700966 }
967}
968
969func (mod *Module) deps(ctx DepsContext) Deps {
970 deps := Deps{}
971
972 if mod.compiler != nil {
973 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400974 }
975 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700976 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700977 }
978
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400979 if mod.coverage != nil {
980 deps = mod.coverage.deps(ctx, deps)
981 }
982
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500983 if mod.sanitize != nil {
984 deps = mod.sanitize.deps(ctx, deps)
985 }
986
Ivan Lozanoffee3342019-08-27 12:03:00 -0700987 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
988 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700989 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700990 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
991 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
992 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Andrew Walbran797e4be2022-03-07 15:41:53 +0000993 deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -0400994 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700995 return deps
996
997}
998
Ivan Lozanoffee3342019-08-27 12:03:00 -0700999type dependencyTag struct {
1000 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001001 name string
1002 library bool
1003 procMacro bool
Colin Cross65cb3142021-12-10 23:05:02 +00001004 dynamic bool
Ivan Lozanoffee3342019-08-27 12:03:00 -07001005}
1006
Jiyong Park65b62242020-11-25 12:44:59 +09001007// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
1008// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
1009func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001010 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +09001011}
1012
1013var _ android.InstallNeededDependencyTag = dependencyTag{}
1014
Colin Cross65cb3142021-12-10 23:05:02 +00001015func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
1016 if d.library && d.dynamic {
1017 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
1018 }
1019 return nil
1020}
1021
1022var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
1023
Ivan Lozanoffee3342019-08-27 12:03:00 -07001024var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001025 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
1026 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
Colin Cross65cb3142021-12-10 23:05:02 +00001027 dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001028 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001029 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001030 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001031 dataLibDepTag = dependencyTag{name: "data lib"}
1032 dataBinDepTag = dependencyTag{name: "data bin"}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001033)
1034
Jiyong Park99644e92020-11-17 22:21:02 +09001035func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
1036 tag, ok := depTag.(dependencyTag)
1037 return ok && tag == dylibDepTag
1038}
1039
Jiyong Park94e22fd2021-04-08 18:19:15 +09001040func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
1041 tag, ok := depTag.(dependencyTag)
1042 return ok && tag == rlibDepTag
1043}
1044
Matthew Maurer0f003b12020-06-29 14:34:06 -07001045type autoDep struct {
1046 variation string
1047 depTag dependencyTag
1048}
1049
1050var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001051 rlibVariation = "rlib"
1052 dylibVariation = "dylib"
1053 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
1054 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -07001055)
1056
1057type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -05001058 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -07001059}
1060
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001061func (mod *Module) begin(ctx BaseModuleContext) {
1062 if mod.coverage != nil {
1063 mod.coverage.begin(ctx)
1064 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001065 if mod.sanitize != nil {
1066 mod.sanitize.begin(ctx)
1067 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001068}
1069
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001070func (mod *Module) Prebuilt() *android.Prebuilt {
Ivan Lozano872d5792022-03-23 17:31:39 -04001071 if p, ok := mod.compiler.(rustPrebuilt); ok {
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001072 return p.prebuilt()
1073 }
1074 return nil
1075}
1076
Ivan Lozanoffee3342019-08-27 12:03:00 -07001077func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
1078 var depPaths PathDeps
1079
1080 directRlibDeps := []*Module{}
1081 directDylibDeps := []*Module{}
1082 directProcMacroDeps := []*Module{}
Jiyong Park7d55b612021-06-11 17:22:09 +09001083 directSharedLibDeps := []cc.SharedLibraryInfo{}
Ivan Lozano52767be2019-10-18 14:49:46 -07001084 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001085 directSrcProvidersDeps := []*Module{}
1086 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001087
Ivan Lozanoe950cda2021-11-09 11:26:04 -05001088 // For the dependency from platform to apex, use the latest stubs
1089 mod.apexSdkVersion = android.FutureApiLevel
1090 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1091 if !apexInfo.IsForPlatform() {
1092 mod.apexSdkVersion = apexInfo.MinSdkVersion
1093 }
1094
1095 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
1096 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
1097 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
1098 // (b/144430859)
1099 mod.apexSdkVersion = android.FutureApiLevel
1100 }
1101
Ivan Lozanoffee3342019-08-27 12:03:00 -07001102 ctx.VisitDirectDeps(func(dep android.Module) {
1103 depName := ctx.OtherModuleName(dep)
1104 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001105
Ivan Lozano89435d12020-07-31 11:01:18 -04001106 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001107 //Handle Rust Modules
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001108 makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -07001109
Ivan Lozanoffee3342019-08-27 12:03:00 -07001110 switch depTag {
1111 case dylibDepTag:
1112 dylib, ok := rustDep.compiler.(libraryInterface)
1113 if !ok || !dylib.dylib() {
1114 ctx.ModuleErrorf("mod %q not an dylib library", depName)
1115 return
1116 }
1117 directDylibDeps = append(directDylibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001118 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001119 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -04001120
Ivan Lozanoffee3342019-08-27 12:03:00 -07001121 rlib, ok := rustDep.compiler.(libraryInterface)
1122 if !ok || !rlib.rlib() {
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001123 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001124 return
1125 }
1126 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001127 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001128 case procMacroDepTag:
1129 directProcMacroDeps = append(directProcMacroDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001130 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Paul Duffind5cf92e2021-07-09 17:38:55 +01001131 }
1132
1133 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001134 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
1135 // OS/Arch variant is used.
1136 var helper string
1137 if ctx.Host() {
1138 helper = "missing 'host_supported'?"
1139 } else {
1140 helper = "device module defined?"
1141 }
1142
1143 if dep.Target().Os != ctx.Os() {
1144 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
1145 return
1146 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
1147 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
1148 return
1149 }
1150 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001151 }
1152
Ivan Lozano2bbcacf2020-08-07 09:00:50 -04001153 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -07001154 if depTag != procMacroDepTag {
1155 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
1156 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
1157 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
1158 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001159 }
1160
Ivan Lozanoffee3342019-08-27 12:03:00 -07001161 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001162 linkFile := rustDep.UnstrippedOutputFile()
1163 linkDir := linkPathFromFilePath(linkFile)
Matthew Maurerbb3add12020-06-25 09:34:12 -07001164 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
1165 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001166 }
1167 }
1168
Ivan Lozano89435d12020-07-31 11:01:18 -04001169 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07001170 //Handle C dependencies
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001171 makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
Ivan Lozano52767be2019-10-18 14:49:46 -07001172 if _, ok := ccDep.(*Module); !ok {
1173 if ccDep.Module().Target().Os != ctx.Os() {
1174 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1175 return
1176 }
1177 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
1178 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
1179 return
1180 }
Ivan Lozano70e0a072019-09-13 14:23:15 -07001181 }
Ivan Lozano2093af22020-08-25 12:48:19 -04001182 linkObject := ccDep.OutputFile()
1183 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -05001184
Ivan Lozano2093af22020-08-25 12:48:19 -04001185 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001186 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
1187 }
1188
1189 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -07001190 switch {
1191 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -04001192 if cc.IsWholeStaticLib(depTag) {
1193 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
1194 // if the library is not prefixed by "lib".
Ivan Lozanofdadcd72021-11-01 09:04:23 -04001195 if mod.Binary() {
1196 // Binaries may sometimes need to link whole static libraries that don't start with 'lib'.
1197 // Since binaries don't need to 'rebundle' these like libraries and only use these for the
1198 // final linkage, pass the args directly to the linker to handle these cases.
1199 depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
1200 } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
Ivan Lozanofb6f36f2021-02-05 12:27:08 -05001201 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001202 } else {
1203 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 -05001204 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001205 }
1206
1207 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
1208 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -04001209 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001210 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
1211
Colin Cross0de8a1e2020-09-18 14:15:30 -07001212 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1213 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1214 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1215 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1216 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001217 directStaticLibDeps = append(directStaticLibDeps, ccDep)
Justin Yun2b3ed642022-02-16 08:15:07 +09001218
1219 // Record baseLibName for snapshots.
1220 mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName))
1221
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001222 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07001223 case cc.IsSharedDepTag(depTag):
Jiyong Park7d55b612021-06-11 17:22:09 +09001224 // For the shared lib dependencies, we may link to the stub variant
1225 // of the dependency depending on the context (e.g. if this
1226 // dependency crosses the APEX boundaries).
1227 sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep)
1228
1229 // Re-get linkObject as ChooseStubOrImpl actually tells us which
1230 // object (either from stub or non-stub) to use.
1231 linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
1232 linkPath = linkPathFromFilePath(linkObject.Path())
1233
Ivan Lozanoffee3342019-08-27 12:03:00 -07001234 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001235 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -07001236 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1237 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1238 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1239 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Jiyong Park7d55b612021-06-11 17:22:09 +09001240 directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo)
Ivan Lozano1921e802021-05-20 13:39:16 -04001241
1242 // Record baseLibName for snapshots.
1243 mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName))
1244
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001245 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001246 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -08001247 case cc.IsHeaderDepTag(depTag):
1248 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1249 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1250 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1251 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -07001252 case depTag == cc.CrtBeginDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001253 depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07001254 case depTag == cc.CrtEndDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001255 depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001256 }
1257
1258 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001259 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1260 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001261 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001262 }
Colin Cross018cbeb2022-01-24 17:22:45 -08001263 } else {
1264 switch {
1265 case depTag == cc.CrtBeginDepTag:
1266 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
1267 case depTag == cc.CrtEndDepTag:
1268 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
1269 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001270 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001271
1272 if srcDep, ok := dep.(android.SourceFileProducer); ok {
Paul Duffind5cf92e2021-07-09 17:38:55 +01001273 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano89435d12020-07-31 11:01:18 -04001274 // These are usually genrules which don't have per-target variants.
1275 directSrcDeps = append(directSrcDeps, srcDep)
1276 }
1277 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001278 })
1279
1280 var rlibDepFiles RustLibraries
1281 for _, dep := range directRlibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001282 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001283 }
1284 var dylibDepFiles RustLibraries
1285 for _, dep := range directDylibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001286 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001287 }
1288 var procMacroDepFiles RustLibraries
1289 for _, dep := range directProcMacroDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001290 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001291 }
1292
1293 var staticLibDepFiles android.Paths
1294 for _, dep := range directStaticLibDeps {
1295 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1296 }
1297
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001298 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001299 var sharedLibDepFiles android.Paths
1300 for _, dep := range directSharedLibDeps {
Jiyong Park7d55b612021-06-11 17:22:09 +09001301 sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary)
1302 if dep.TableOfContents.Valid() {
1303 sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path())
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001304 } else {
Jiyong Park7d55b612021-06-11 17:22:09 +09001305 sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001306 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001307 }
1308
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001309 var srcProviderDepFiles android.Paths
1310 for _, dep := range directSrcProvidersDeps {
1311 srcs, _ := dep.OutputFiles("")
1312 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1313 }
1314 for _, dep := range directSrcDeps {
1315 srcs := dep.Srcs()
1316 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1317 }
1318
Ivan Lozanoffee3342019-08-27 12:03:00 -07001319 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1320 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1321 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001322 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001323 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1324 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001325 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001326
1327 // Dedup exported flags from dependencies
1328 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001329 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001330 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001331 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1332 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1333 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001334
1335 return depPaths
1336}
1337
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001338func (mod *Module) InstallInData() bool {
1339 if mod.compiler == nil {
1340 return false
1341 }
1342 return mod.compiler.inData()
1343}
1344
Matthew Maurer9f59e8d2021-08-19 13:10:05 -07001345func (mod *Module) InstallInRamdisk() bool {
1346 return mod.InRamdisk()
1347}
1348
1349func (mod *Module) InstallInVendorRamdisk() bool {
1350 return mod.InVendorRamdisk()
1351}
1352
1353func (mod *Module) InstallInRecovery() bool {
1354 return mod.InRecovery()
1355}
1356
Ivan Lozanoffee3342019-08-27 12:03:00 -07001357func linkPathFromFilePath(filepath android.Path) string {
1358 return strings.Split(filepath.String(), filepath.Base())[0]
1359}
Ivan Lozanod648c432020-02-06 12:05:10 -05001360
Ivan Lozanoffee3342019-08-27 12:03:00 -07001361func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1362 ctx := &depsContext{
1363 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001364 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001365
1366 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001367 var commonDepVariations []blueprint.Variation
Ivan Lozano1921e802021-05-20 13:39:16 -04001368 var snapshotInfo *cc.SnapshotInfo
1369
1370 if ctx.Os() == android.Android {
1371 deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
1372 }
Ivan Lozanodd055472020-09-28 13:22:45 -04001373
Ivan Lozano2b081132020-09-08 12:46:52 -04001374 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001375 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001376 stdLinkage = "rlib-std"
1377 }
1378
1379 rlibDepVariations := commonDepVariations
Ivan Lozano1921e802021-05-20 13:39:16 -04001380
Ivan Lozano2b081132020-09-08 12:46:52 -04001381 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1382 rlibDepVariations = append(rlibDepVariations,
1383 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1384 }
1385
Ivan Lozano1921e802021-05-20 13:39:16 -04001386 // rlibs
Ivan Lozano2d407632022-04-07 12:59:11 -04001387 rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001388 for _, lib := range deps.Rlibs {
1389 depTag := rlibDepTag
1390 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1391
Ivan Lozano2d407632022-04-07 12:59:11 -04001392 actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001393 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001394
1395 // dylibs
Ivan Lozano52767be2019-10-18 14:49:46 -07001396 actx.AddVariationDependencies(
1397 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001398 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001399 dylibDepTag, deps.Dylibs...)
1400
Ivan Lozano1921e802021-05-20 13:39:16 -04001401 // rustlibs
Ivan Lozano042504f2020-08-18 14:31:23 -04001402 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1403 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2d407632022-04-07 12:59:11 -04001404 for _, lib := range deps.Rustlibs {
1405 if autoDep.depTag == rlibDepTag {
1406 // Handle the rlib deptag case
1407 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1408 } else {
1409 // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
1410 // Check for the existence of the dylib deptag variant. Select it if available,
1411 // otherwise select the rlib variant.
1412 autoDepVariations := append(commonDepVariations,
1413 blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
1414 if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
1415 actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
1416 } else {
1417 // If there's no dylib dependency available, try to add the rlib dependency instead.
1418 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1419 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001420 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001421 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001422 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001423 // stdlibs
Ivan Lozano2b081132020-09-08 12:46:52 -04001424 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001425 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001426 for _, lib := range deps.Stdlibs {
1427 depTag := rlibDepTag
1428 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1429
1430 actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
1431 depTag, lib)
1432 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001433 } else {
1434 actx.AddVariationDependencies(
1435 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1436 dylibDepTag, deps.Stdlibs...)
1437 }
1438 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001439
1440 for _, lib := range deps.SharedLibs {
1441 depTag := cc.SharedDepTag()
1442 name, version := cc.StubsLibNameAndVersion(lib)
1443
1444 variations := []blueprint.Variation{
1445 {Mutator: "link", Variation: "shared"},
1446 }
1447 cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
1448 }
1449
1450 for _, lib := range deps.WholeStaticLibs {
1451 depTag := cc.StaticDepTag(true)
1452 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
1453
1454 actx.AddVariationDependencies([]blueprint.Variation{
1455 {Mutator: "link", Variation: "static"},
1456 }, depTag, lib)
1457 }
1458
1459 for _, lib := range deps.StaticLibs {
1460 depTag := cc.StaticDepTag(false)
1461 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
1462
1463 actx.AddVariationDependencies([]blueprint.Variation{
1464 {Mutator: "link", Variation: "static"},
1465 }, depTag, lib)
1466 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001467
Zach Johnson3df4e632020-11-06 11:56:27 -08001468 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1469
Colin Cross565cafd2020-09-25 18:47:38 -07001470 crtVariations := cc.GetCrtVariations(ctx, mod)
Colin Crossfe605e12022-01-23 20:46:16 -08001471 for _, crt := range deps.CrtBegin {
Ivan Lozano1921e802021-05-20 13:39:16 -04001472 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag,
Colin Crossfe605e12022-01-23 20:46:16 -08001473 cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001474 }
Colin Crossfe605e12022-01-23 20:46:16 -08001475 for _, crt := range deps.CrtEnd {
Ivan Lozano1921e802021-05-20 13:39:16 -04001476 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag,
Colin Crossfe605e12022-01-23 20:46:16 -08001477 cc.RewriteSnapshotLib(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001478 }
1479
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001480 if mod.sourceProvider != nil {
1481 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1482 bindgen.Properties.Custom_bindgen != "" {
1483 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1484 bindgen.Properties.Custom_bindgen)
1485 }
1486 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001487
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001488 actx.AddVariationDependencies([]blueprint.Variation{
1489 {Mutator: "link", Variation: "shared"},
1490 }, dataLibDepTag, deps.DataLibs...)
1491
1492 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
1493
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001494 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001495 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001496}
1497
Ivan Lozano2d407632022-04-07 12:59:11 -04001498// addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available.
1499func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo *cc.SnapshotInfo, variations []blueprint.Variation) {
1500 lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
1501 actx.AddVariationDependencies(variations, rlibDepTag, lib)
1502}
1503
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001504func BeginMutator(ctx android.BottomUpMutatorContext) {
1505 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1506 mod.beginMutator(ctx)
1507 }
1508}
1509
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001510func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1511 ctx := &baseModuleContext{
1512 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001513 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001514
1515 mod.begin(ctx)
1516}
1517
Ivan Lozanoffee3342019-08-27 12:03:00 -07001518func (mod *Module) Name() string {
1519 name := mod.ModuleBase.Name()
1520 if p, ok := mod.compiler.(interface {
1521 Name(string) string
1522 }); ok {
1523 name = p.Name(name)
1524 }
1525 return name
1526}
1527
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001528func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001529 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001530 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001531 }
1532}
1533
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001534var _ android.HostToolProvider = (*Module)(nil)
Ivan Lozano872d5792022-03-23 17:31:39 -04001535var _ snapshot.RelativeInstallPath = (*Module)(nil)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001536
1537func (mod *Module) HostToolPath() android.OptionalPath {
1538 if !mod.Host() {
1539 return android.OptionalPath{}
1540 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001541 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1542 return android.OptionalPathForPath(binary.baseCompiler.path)
Ivan Lozano872d5792022-03-23 17:31:39 -04001543 } else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
1544 // Even though proc-macros aren't strictly "tools", since they target the compiler
1545 // and act as compiler plugins, we treat them similarly.
1546 return android.OptionalPathForPath(pm.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001547 }
1548 return android.OptionalPath{}
1549}
1550
Jiyong Park99644e92020-11-17 22:21:02 +09001551var _ android.ApexModule = (*Module)(nil)
1552
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001553func (mod *Module) MinSdkVersion() string {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001554 return String(mod.Properties.Min_sdk_version)
1555}
1556
Jiyong Park45bf82e2020-12-15 22:29:02 +09001557// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001558func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001559 minSdkVersion := mod.MinSdkVersion()
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001560 if minSdkVersion == "apex_inherit" {
1561 return nil
1562 }
1563 if minSdkVersion == "" {
1564 return fmt.Errorf("min_sdk_version is not specificed")
1565 }
1566
1567 // Not using nativeApiLevelFromUser because the context here is not
1568 // necessarily a native context.
1569 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1570 if err != nil {
1571 return err
1572 }
1573
1574 if ver.GreaterThan(sdkVersion) {
1575 return fmt.Errorf("newer SDK(%v)", ver)
1576 }
Jiyong Park99644e92020-11-17 22:21:02 +09001577 return nil
1578}
1579
Jiyong Park45bf82e2020-12-15 22:29:02 +09001580// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001581func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1582 depTag := ctx.OtherModuleDependencyTag(dep)
1583
1584 if ccm, ok := dep.(*cc.Module); ok {
1585 if ccm.HasStubsVariants() {
1586 if cc.IsSharedDepTag(depTag) {
1587 // dynamic dep to a stubs lib crosses APEX boundary
1588 return false
1589 }
1590 if cc.IsRuntimeDepTag(depTag) {
1591 // runtime dep to a stubs lib also crosses APEX boundary
1592 return false
1593 }
1594
1595 if cc.IsHeaderDepTag(depTag) {
1596 return false
1597 }
1598 }
1599 if mod.Static() && cc.IsSharedDepTag(depTag) {
1600 // shared_lib dependency from a static lib is considered as crossing
1601 // the APEX boundary because the dependency doesn't actually is
1602 // linked; the dependency is used only during the compilation phase.
1603 return false
1604 }
1605 }
1606
1607 if depTag == procMacroDepTag {
1608 return false
1609 }
1610
1611 return true
1612}
1613
1614// Overrides ApexModule.IsInstallabeToApex()
1615func (mod *Module) IsInstallableToApex() bool {
1616 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -05001617 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) {
Jiyong Park99644e92020-11-17 22:21:02 +09001618 return true
1619 }
1620 if _, ok := mod.compiler.(*binaryDecorator); ok {
1621 return true
1622 }
1623 }
1624 return false
1625}
1626
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001627// If a library file has a "lib" prefix, extract the library name without the prefix.
1628func libNameFromFilePath(filepath android.Path) (string, bool) {
1629 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1630 if strings.HasPrefix(libName, "lib") {
1631 libName = libName[3:]
1632 return libName, true
1633 }
1634 return "", false
1635}
1636
Sasha Smundaka76acba2022-04-18 20:12:56 -07001637func kytheExtractRustFactory() android.Singleton {
1638 return &kytheExtractRustSingleton{}
1639}
1640
1641type kytheExtractRustSingleton struct {
1642}
1643
1644func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) {
1645 var xrefTargets android.Paths
1646 ctx.VisitAllModules(func(module android.Module) {
1647 if rustModule, ok := module.(xref); ok {
1648 xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...)
1649 }
1650 })
1651 if len(xrefTargets) > 0 {
1652 ctx.Phony("xref_rust", xrefTargets...)
1653 }
1654}
1655
Ivan Lozanoffee3342019-08-27 12:03:00 -07001656var Bool = proptools.Bool
1657var BoolDefault = proptools.BoolDefault
1658var String = proptools.String
1659var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001660
1661var _ android.OutputFileProducer = (*Module)(nil)