blob: ffe54732cdb0ef097ea1269a300765f403c8d0b7 [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() {
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 android.RegisterModuleType("rust_defaults", defaultsFactory)
37 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
38 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -040039 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040040 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano6cd99e62020-02-11 08:24:25 -050041
42 })
43 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
44 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
Ivan Lozanoffee3342019-08-27 12:03:00 -070045 })
46 pctx.Import("android/soong/rust/config")
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020047 pctx.ImportAs("cc_config", "android/soong/cc/config")
Sasha Smundaka76acba2022-04-18 20:12:56 -070048 android.InitRegistrationContext.RegisterSingletonType("kythe_rust_extract", kytheExtractRustFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070049}
50
51type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040052 GlobalRustFlags []string // Flags that apply globally to rust
53 GlobalLinkFlags []string // Flags that apply globally to linker
54 RustFlags []string // Flags that apply to rust
55 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020056 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Dan Albert06feee92021-03-19 15:06:02 -070057 RustdocFlags []string // Flags that apply to rustdoc
Ivan Lozanof1c84332019-09-20 11:00:37 -070058 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040059 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020060 Clippy bool
Sasha Smundaka76acba2022-04-18 20:12:56 -070061 EmitXrefs bool // If true, emit rules to aid cross-referencing
Ivan Lozanoffee3342019-08-27 12:03:00 -070062}
63
64type BaseProperties struct {
65 AndroidMkRlibs []string
66 AndroidMkDylibs []string
67 AndroidMkProcMacroLibs []string
68 AndroidMkSharedLibs []string
69 AndroidMkStaticLibs []string
Ivan Lozano43845682020-07-09 21:03:28 -040070
Ivan Lozano6a884432020-12-02 09:15:16 -050071 ImageVariationPrefix string `blueprint:"mutated"`
72 VndkVersion string `blueprint:"mutated"`
73 SubName string `blueprint:"mutated"`
74
Ivan Lozanoc08897c2021-04-02 12:41:32 -040075 // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
76 // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be
77 // appended before SubName.
78 RustSubName string `blueprint:"mutated"`
79
Ivan Lozano6a884432020-12-02 09:15:16 -050080 // Set by imageMutator
Ivan Lozanoe6d30982021-02-05 10:57:43 -050081 CoreVariantNeeded bool `blueprint:"mutated"`
82 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurerc6868382021-07-13 14:12:37 -070083 RamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurer460ee942021-02-11 12:31:46 -080084 RecoveryVariantNeeded bool `blueprint:"mutated"`
Ivan Lozanoe6d30982021-02-05 10:57:43 -050085 ExtraVariants []string `blueprint:"mutated"`
86
Ivan Lozanoa2268632021-07-22 10:52:06 -040087 // Allows this module to use non-APEX version of libraries. Useful
88 // for building binaries that are started before APEXes are activated.
89 Bootstrap *bool
90
Ivan Lozano1921e802021-05-20 13:39:16 -040091 // Used by vendor snapshot to record dependencies from snapshot modules.
92 SnapshotSharedLibs []string `blueprint:"mutated"`
Justin Yun5e035862021-06-29 20:50:37 +090093 SnapshotStaticLibs []string `blueprint:"mutated"`
Ivan Lozano1921e802021-05-20 13:39:16 -040094
Matthew Maurerc6868382021-07-13 14:12:37 -070095 // Make this module available when building for ramdisk.
96 // On device without a dedicated recovery partition, the module is only
97 // available after switching root into
98 // /first_stage_ramdisk. To expose the module before switching root, install
99 // the recovery variant instead.
100 Ramdisk_available *bool
101
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500102 // Make this module available when building for vendor 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
Matthew Maurer460ee942021-02-11 12:31:46 -0800106 // the recovery variant instead
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500107 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400108
Ivan Lozano1921e802021-05-20 13:39:16 -0400109 // Normally Soong uses the directory structure to decide which modules
110 // should be included (framework) or excluded (non-framework) from the
111 // different snapshots (vendor, recovery, etc.), but this property
112 // allows a partner to exclude a module normally thought of as a
113 // framework module from the vendor snapshot.
114 Exclude_from_vendor_snapshot *bool
115
116 // 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 recovery snapshot.
121 Exclude_from_recovery_snapshot *bool
122
Matthew Maurer460ee942021-02-11 12:31:46 -0800123 // Make this module available when building for recovery
124 Recovery_available *bool
125
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500126 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
127 Min_sdk_version *string
128
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900129 HideFromMake bool `blueprint:"mutated"`
130 PreventInstall bool `blueprint:"mutated"`
131
132 Installable *bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700133}
134
135type Module struct {
hamzehc0a671f2021-07-22 12:05:08 -0700136 fuzz.FuzzModule
Ivan Lozanoffee3342019-08-27 12:03:00 -0700137
Ivan Lozano6a884432020-12-02 09:15:16 -0500138 VendorProperties cc.VendorProperties
139
Ivan Lozanoffee3342019-08-27 12:03:00 -0700140 Properties BaseProperties
141
142 hod android.HostOrDeviceSupported
143 multilib android.Multilib
144
Ivan Lozano6a884432020-12-02 09:15:16 -0500145 makeLinkType string
146
Yi Kong46c6e592022-01-20 22:55:00 +0800147 afdo *afdo
Ivan Lozanoffee3342019-08-27 12:03:00 -0700148 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400149 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200150 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500151 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700152 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400153 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700154 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400155
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400156 // Output file to be installed, may be stripped or unstripped.
157 outputFile android.OptionalPath
158
Sasha Smundaka76acba2022-04-18 20:12:56 -0700159 // Cross-reference input file
160 kytheFiles android.Paths
161
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400162 docTimestampFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900163
164 hideApexVariantFromMake bool
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500165
166 // For apex variants, this is set as apex.min_sdk_version
167 apexSdkVersion android.ApiLevel
Ivan Lozanoffee3342019-08-27 12:03:00 -0700168}
169
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500170func (mod *Module) Header() bool {
171 //TODO: If Rust libraries provide header variants, this needs to be updated.
172 return false
173}
174
175func (mod *Module) SetPreventInstall() {
176 mod.Properties.PreventInstall = true
177}
178
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500179func (mod *Module) SetHideFromMake() {
180 mod.Properties.HideFromMake = true
181}
182
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900183func (mod *Module) HiddenFromMake() bool {
184 return mod.Properties.HideFromMake
Ivan Lozanod7586b62021-04-01 09:49:36 -0400185}
186
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500187func (mod *Module) SanitizePropDefined() bool {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500188 // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
189 // nil since we need compiler to actually sanitize.
190 return mod.sanitize != nil && mod.compiler != nil
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500191}
192
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500193func (mod *Module) IsPrebuilt() bool {
194 if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
195 return true
196 }
197 return false
198}
199
Ivan Lozano43845682020-07-09 21:03:28 -0400200func (mod *Module) OutputFiles(tag string) (android.Paths, error) {
201 switch tag {
202 case "":
Andrei Homescu5db69cc2020-08-06 15:27:45 -0700203 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
Ivan Lozano43845682020-07-09 21:03:28 -0400204 return mod.sourceProvider.Srcs(), nil
205 } else {
Jiyong Parke54f07e2021-04-07 15:08:04 +0900206 if mod.OutputFile().Valid() {
207 return android.Paths{mod.OutputFile().Path()}, nil
Ivan Lozano43845682020-07-09 21:03:28 -0400208 }
209 return android.Paths{}, nil
210 }
211 default:
212 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
213 }
214}
215
Ivan Lozano52767be2019-10-18 14:49:46 -0700216func (mod *Module) SelectedStl() string {
217 return ""
218}
219
Ivan Lozano2b262972019-11-21 12:30:50 -0800220func (mod *Module) NonCcVariants() bool {
221 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400222 if _, ok := mod.compiler.(libraryInterface); ok {
223 return false
Ivan Lozano2b262972019-11-21 12:30:50 -0800224 }
225 }
226 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
227}
228
Ivan Lozano52767be2019-10-18 14:49:46 -0700229func (mod *Module) Static() bool {
230 if mod.compiler != nil {
231 if library, ok := mod.compiler.(libraryInterface); ok {
232 return library.static()
233 }
234 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400235 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700236}
237
238func (mod *Module) Shared() bool {
239 if mod.compiler != nil {
240 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400241 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700242 }
243 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400244 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700245}
246
Ivan Lozanod7586b62021-04-01 09:49:36 -0400247func (mod *Module) Dylib() bool {
248 if mod.compiler != nil {
249 if library, ok := mod.compiler.(libraryInterface); ok {
250 return library.dylib()
251 }
252 }
253 return false
254}
255
256func (mod *Module) Rlib() bool {
257 if mod.compiler != nil {
258 if library, ok := mod.compiler.(libraryInterface); ok {
259 return library.rlib()
260 }
261 }
262 return false
263}
264
265func (mod *Module) Binary() bool {
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400266 if binary, ok := mod.compiler.(binaryInterface); ok {
267 return binary.binary()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400268 }
269 return false
270}
271
Justin Yun5e035862021-06-29 20:50:37 +0900272func (mod *Module) StaticExecutable() bool {
273 if !mod.Binary() {
274 return false
275 }
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400276 return mod.StaticallyLinked()
Justin Yun5e035862021-06-29 20:50:37 +0900277}
278
Ivan Lozanod7586b62021-04-01 09:49:36 -0400279func (mod *Module) Object() bool {
280 // Rust has no modules which produce only object files.
281 return false
282}
283
Ivan Lozano52767be2019-10-18 14:49:46 -0700284func (mod *Module) Toc() android.OptionalPath {
285 if mod.compiler != nil {
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400286 if lib, ok := mod.compiler.(libraryInterface); ok {
287 return lib.toc()
Ivan Lozano52767be2019-10-18 14:49:46 -0700288 }
289 }
290 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
291}
292
Colin Crossc511bc52020-04-07 16:50:32 +0000293func (mod *Module) UseSdk() bool {
294 return false
295}
296
Ivan Lozanod7586b62021-04-01 09:49:36 -0400297func (mod *Module) RelativeInstallPath() string {
298 if mod.compiler != nil {
299 return mod.compiler.relativeInstallPath()
300 }
301 return ""
302}
303
Ivan Lozano52767be2019-10-18 14:49:46 -0700304func (mod *Module) UseVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500305 return mod.Properties.VndkVersion != ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700306}
307
Jiyong Park7d55b612021-06-11 17:22:09 +0900308func (mod *Module) Bootstrap() bool {
Ivan Lozanoa2268632021-07-22 10:52:06 -0400309 return Bool(mod.Properties.Bootstrap)
Jiyong Park7d55b612021-06-11 17:22:09 +0900310}
311
Ivan Lozano52767be2019-10-18 14:49:46 -0700312func (mod *Module) MustUseVendorVariant() bool {
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400313 return true
314}
315
316func (mod *Module) SubName() string {
317 return mod.Properties.SubName
Ivan Lozano52767be2019-10-18 14:49:46 -0700318}
319
320func (mod *Module) IsVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500321 // TODO(b/165791368)
Ivan Lozano52767be2019-10-18 14:49:46 -0700322 return false
323}
324
Ivan Lozanof9e21722020-12-02 09:00:51 -0500325func (mod *Module) IsVndkExt() bool {
326 return false
327}
328
Ivan Lozanod7586b62021-04-01 09:49:36 -0400329func (mod *Module) IsVndkSp() bool {
330 return false
331}
332
Ivan Lozanof1868af2022-04-12 13:08:36 -0400333func (mod *Module) IsVndkPrebuiltLibrary() bool {
334 // Rust modules do not provide VNDK prebuilts
335 return false
336}
337
338func (mod *Module) IsVendorPublicLibrary() bool {
339 return mod.VendorProperties.IsVendorPublicLibrary
340}
341
342func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool {
343 // Rust modules to not provide Sdk variants
344 return false
345}
346
Colin Cross127bb8b2020-12-16 16:46:01 -0800347func (c *Module) IsVndkPrivate() bool {
348 return false
349}
350
351func (c *Module) IsLlndk() bool {
352 return false
353}
354
355func (c *Module) IsLlndkPublic() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500356 return false
357}
358
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400359func (mod *Module) KernelHeadersDecorator() bool {
360 return false
361}
362
Colin Cross1f3f1302021-04-26 18:37:44 -0700363func (m *Module) NeedsLlndkVariants() bool {
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400364 return false
365}
366
Colin Cross5271fea2021-04-27 13:06:04 -0700367func (m *Module) NeedsVendorPublicLibraryVariants() bool {
368 return false
369}
370
Ivan Lozanod7586b62021-04-01 09:49:36 -0400371func (mod *Module) HasLlndkStubs() bool {
372 return false
373}
374
375func (mod *Module) StubsVersion() string {
376 panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName()))
377}
378
Ivan Lozano52767be2019-10-18 14:49:46 -0700379func (mod *Module) SdkVersion() string {
380 return ""
381}
382
Colin Crossc511bc52020-04-07 16:50:32 +0000383func (mod *Module) AlwaysSdk() bool {
384 return false
385}
386
Jiyong Park2286afd2020-06-16 21:58:53 +0900387func (mod *Module) IsSdkVariant() bool {
388 return false
389}
390
Colin Cross1348ce32020-10-01 13:37:16 -0700391func (mod *Module) SplitPerApiLevel() bool {
392 return false
393}
394
Sasha Smundaka76acba2022-04-18 20:12:56 -0700395func (mod *Module) XrefRustFiles() android.Paths {
396 return mod.kytheFiles
397}
398
Ivan Lozanoffee3342019-08-27 12:03:00 -0700399type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400400 Dylibs []string
401 Rlibs []string
402 Rustlibs []string
403 Stdlibs []string
404 ProcMacros []string
405 SharedLibs []string
406 StaticLibs []string
407 WholeStaticLibs []string
408 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700409
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400410 // Used for data dependencies adjacent to tests
411 DataLibs []string
412 DataBins []string
413
Colin Crossfe605e12022-01-23 20:46:16 -0800414 CrtBegin, CrtEnd []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700415}
416
417type PathDeps struct {
Ivan Lozanoec6e9912021-01-21 15:23:29 -0500418 DyLibs RustLibraries
419 RLibs RustLibraries
420 SharedLibs android.Paths
421 SharedLibDeps android.Paths
422 StaticLibs android.Paths
423 ProcMacros RustLibraries
Yi Kong46c6e592022-01-20 22:55:00 +0800424 AfdoProfiles android.Paths
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500425
426 // depFlags and depLinkFlags are rustc and linker (clang) flags.
427 depFlags []string
428 depLinkFlags []string
429
430 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker.
431 // Both of these are exported and propagate to dependencies.
432 linkDirs []string
433 linkObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700434
Ivan Lozano45901ed2020-07-24 16:05:01 -0400435 // Used by bindgen modules which call clang
436 depClangFlags []string
437 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400438 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400439 depSystemIncludePaths android.Paths
440
Colin Crossfe605e12022-01-23 20:46:16 -0800441 CrtBegin android.Paths
442 CrtEnd android.Paths
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700443
444 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500445 SrcDeps android.Paths
446 srcProviderFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700447}
448
449type RustLibraries []RustLibrary
450
451type RustLibrary struct {
452 Path android.Path
453 CrateName string
454}
455
456type compiler interface {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100457 initialize(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700458 compilerFlags(ctx ModuleContext, flags Flags) Flags
Ivan Lozano67eada32021-09-23 11:50:33 -0400459 cfgFlags(ctx ModuleContext, flags Flags) Flags
460 featureFlags(ctx ModuleContext, flags Flags) Flags
Ivan Lozanoffee3342019-08-27 12:03:00 -0700461 compilerProps() []interface{}
Sasha Smundaka76acba2022-04-18 20:12:56 -0700462 compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput
Ivan Lozanoffee3342019-08-27 12:03:00 -0700463 compilerDeps(ctx DepsContext, deps Deps) Deps
464 crateName() string
Dan Albert06feee92021-03-19 15:06:02 -0700465 rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700466
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100467 // Output directory in which source-generated code from dependencies is
468 // copied. This is equivalent to Cargo's OUT_DIR variable.
469 CargoOutDir() android.OptionalPath
Dan Albert06feee92021-03-19 15:06:02 -0700470
Ivan Lozanoa9a1fc02021-08-11 15:13:43 -0400471 // CargoPkgVersion returns the value of the Cargo_pkg_version property.
472 CargoPkgVersion() string
473
474 // CargoEnvCompat returns whether Cargo environment variables should be used.
475 CargoEnvCompat() bool
476
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800477 inData() bool
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200478 install(ctx ModuleContext)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700479 relativeInstallPath() string
Ivan Lozanod7586b62021-04-01 09:49:36 -0400480 everInstallable() bool
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400481
482 nativeCoverage() bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400483
484 Disabled() bool
485 SetDisabled()
Ivan Lozano042504f2020-08-18 14:31:23 -0400486
Ivan Lozanodd055472020-09-28 13:22:45 -0400487 stdLinkage(ctx *depsContext) RustLinkage
Jiyong Parke54f07e2021-04-07 15:08:04 +0900488
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400489 unstrippedOutputFilePath() android.Path
Jiyong Parke54f07e2021-04-07 15:08:04 +0900490 strippedOutputFilePath() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400491}
492
Matthew Maurerbb3add12020-06-25 09:34:12 -0700493type exportedFlagsProducer interface {
Matthew Maurerbb3add12020-06-25 09:34:12 -0700494 exportLinkDirs(...string)
Ivan Lozano2093af22020-08-25 12:48:19 -0400495 exportLinkObjects(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700496}
497
Sasha Smundaka76acba2022-04-18 20:12:56 -0700498type xref interface {
499 XrefRustFiles() android.Paths
500}
501
Matthew Maurerbb3add12020-06-25 09:34:12 -0700502type flagExporter struct {
Ivan Lozano2093af22020-08-25 12:48:19 -0400503 linkDirs []string
504 linkObjects []string
Matthew Maurerbb3add12020-06-25 09:34:12 -0700505}
506
Matthew Maurerbb3add12020-06-25 09:34:12 -0700507func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
508 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
509}
510
Ivan Lozano2093af22020-08-25 12:48:19 -0400511func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
512 flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...))
513}
514
Colin Cross0de8a1e2020-09-18 14:15:30 -0700515func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
516 ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700517 LinkDirs: flagExporter.linkDirs,
518 LinkObjects: flagExporter.linkObjects,
519 })
520}
521
Matthew Maurerbb3add12020-06-25 09:34:12 -0700522var _ exportedFlagsProducer = (*flagExporter)(nil)
523
524func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700525 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700526}
527
Colin Cross0de8a1e2020-09-18 14:15:30 -0700528type FlagExporterInfo struct {
529 Flags []string
530 LinkDirs []string // TODO: this should be android.Paths
531 LinkObjects []string // TODO: this should be android.Paths
532}
533
534var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
535
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400536func (mod *Module) isCoverageVariant() bool {
537 return mod.coverage.Properties.IsCoverageVariant
538}
539
540var _ cc.Coverage = (*Module)(nil)
541
542func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
543 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
544}
545
Ivan Lozanod7586b62021-04-01 09:49:36 -0400546func (mod *Module) VndkVersion() string {
547 return mod.Properties.VndkVersion
548}
549
550func (mod *Module) PreventInstall() bool {
551 return mod.Properties.PreventInstall
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400552}
553
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400554func (mod *Module) MarkAsCoverageVariant(coverage bool) {
555 mod.coverage.Properties.IsCoverageVariant = coverage
556}
557
558func (mod *Module) EnableCoverageIfNeeded() {
559 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700560}
561
562func defaultsFactory() android.Module {
563 return DefaultsFactory()
564}
565
566type Defaults struct {
567 android.ModuleBase
568 android.DefaultsModuleBase
569}
570
571func DefaultsFactory(props ...interface{}) android.Module {
572 module := &Defaults{}
573
574 module.AddProperties(props...)
575 module.AddProperties(
576 &BaseProperties{},
Yi Kong46c6e592022-01-20 22:55:00 +0800577 &cc.AfdoProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500578 &cc.VendorProperties{},
Jakub Kotur1d640d02021-01-06 12:40:43 +0100579 &BenchmarkProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400580 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700581 &BaseCompilerProperties{},
582 &BinaryCompilerProperties{},
583 &LibraryCompilerProperties{},
584 &ProcMacroCompilerProperties{},
585 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400586 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700587 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400588 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400589 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200590 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500591 &SanitizeProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700592 )
593
594 android.InitDefaultsModule(module)
595 return module
596}
597
598func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700599 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700600}
601
Ivan Lozano183a3212019-10-18 14:18:45 -0700602func (mod *Module) CcLibrary() bool {
603 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -0500604 if _, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700605 return true
606 }
607 }
608 return false
609}
610
611func (mod *Module) CcLibraryInterface() bool {
612 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400613 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
614 // VariantIs{Static,Shared} is set.
615 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700616 return true
617 }
618 }
619 return false
620}
621
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400622func (mod *Module) UnstrippedOutputFile() android.Path {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400623 if mod.compiler != nil {
624 return mod.compiler.unstrippedOutputFilePath()
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400625 }
626 return nil
627}
628
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800629func (mod *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700630 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700631 if library, ok := mod.compiler.(*libraryDecorator); ok {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800632 return library.includeDirs
Ivan Lozano183a3212019-10-18 14:18:45 -0700633 }
634 }
635 panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName()))
636}
637
638func (mod *Module) SetStatic() {
639 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700640 if library, ok := mod.compiler.(libraryInterface); ok {
641 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700642 return
643 }
644 }
645 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
646}
647
648func (mod *Module) SetShared() {
649 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700650 if library, ok := mod.compiler.(libraryInterface); ok {
651 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700652 return
653 }
654 }
655 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
656}
657
Ivan Lozano183a3212019-10-18 14:18:45 -0700658func (mod *Module) BuildStaticVariant() bool {
659 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700660 if library, ok := mod.compiler.(libraryInterface); ok {
661 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700662 }
663 }
664 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
665}
666
667func (mod *Module) BuildSharedVariant() bool {
668 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700669 if library, ok := mod.compiler.(libraryInterface); ok {
670 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700671 }
672 }
673 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
674}
675
Ivan Lozano183a3212019-10-18 14:18:45 -0700676func (mod *Module) Module() android.Module {
677 return mod
678}
679
Ivan Lozano183a3212019-10-18 14:18:45 -0700680func (mod *Module) OutputFile() android.OptionalPath {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400681 return mod.outputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700682}
683
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400684func (mod *Module) CoverageFiles() android.Paths {
685 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800686 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400687 }
688 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
689}
690
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400691// Rust does not produce gcno files, and therefore does not produce a coverage archive.
692func (mod *Module) CoverageOutputFile() android.OptionalPath {
693 return android.OptionalPath{}
694}
695
696func (mod *Module) IsNdk(config android.Config) bool {
697 return false
698}
699
700func (mod *Module) IsStubs() bool {
701 return false
702}
703
Jiyong Park459feca2020-12-15 11:02:21 +0900704func (mod *Module) installable(apexInfo android.ApexInfo) bool {
Jiyong Park2811e072021-09-30 17:25:21 +0900705 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
Jiyong Parkbf8147a2021-05-17 13:19:33 +0900706 return false
707 }
708
Jiyong Park459feca2020-12-15 11:02:21 +0900709 // The apex variant is not installable because it is included in the APEX and won't appear
710 // in the system partition as a standalone file.
711 if !apexInfo.IsForPlatform() {
712 return false
713 }
714
Jiyong Parke54f07e2021-04-07 15:08:04 +0900715 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900716}
717
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500718func (ctx moduleContext) apexVariationName() string {
719 return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
720}
721
Ivan Lozano183a3212019-10-18 14:18:45 -0700722var _ cc.LinkableInterface = (*Module)(nil)
723
Ivan Lozanoffee3342019-08-27 12:03:00 -0700724func (mod *Module) Init() android.Module {
725 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500726 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700727
Yi Kong46c6e592022-01-20 22:55:00 +0800728 if mod.afdo != nil {
729 mod.AddProperties(mod.afdo.props()...)
730 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700731 if mod.compiler != nil {
732 mod.AddProperties(mod.compiler.compilerProps()...)
733 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400734 if mod.coverage != nil {
735 mod.AddProperties(mod.coverage.props()...)
736 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200737 if mod.clippy != nil {
738 mod.AddProperties(mod.clippy.props()...)
739 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400740 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700741 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400742 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500743 if mod.sanitize != nil {
744 mod.AddProperties(mod.sanitize.props()...)
745 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400746
Ivan Lozanoffee3342019-08-27 12:03:00 -0700747 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900748 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700749
750 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700751 return mod
752}
753
754func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
755 return &Module{
756 hod: hod,
757 multilib: multilib,
758 }
759}
760func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
761 module := newBaseModule(hod, multilib)
Yi Kong46c6e592022-01-20 22:55:00 +0800762 module.afdo = &afdo{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400763 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200764 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500765 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700766 return module
767}
768
769type ModuleContext interface {
770 android.ModuleContext
771 ModuleContextIntf
772}
773
774type BaseModuleContext interface {
775 android.BaseModuleContext
776 ModuleContextIntf
777}
778
779type DepsContext interface {
780 android.BottomUpMutatorContext
781 ModuleContextIntf
782}
783
784type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200785 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700786 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700787}
788
789type depsContext struct {
790 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700791}
792
793type moduleContext struct {
794 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700795}
796
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200797type baseModuleContext struct {
798 android.BaseModuleContext
799}
800
801func (ctx *moduleContext) RustModule() *Module {
802 return ctx.Module().(*Module)
803}
804
805func (ctx *moduleContext) toolchain() config.Toolchain {
806 return ctx.RustModule().toolchain(ctx)
807}
808
809func (ctx *depsContext) RustModule() *Module {
810 return ctx.Module().(*Module)
811}
812
813func (ctx *depsContext) toolchain() config.Toolchain {
814 return ctx.RustModule().toolchain(ctx)
815}
816
817func (ctx *baseModuleContext) RustModule() *Module {
818 return ctx.Module().(*Module)
819}
820
821func (ctx *baseModuleContext) toolchain() config.Toolchain {
822 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400823}
824
825func (mod *Module) nativeCoverage() bool {
Matthew Maurera61e31f2021-05-27 11:09:11 -0700826 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
827 if mod.Target().NativeBridge == android.NativeBridgeEnabled {
828 return false
829 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400830 return mod.compiler != nil && mod.compiler.nativeCoverage()
831}
832
Ivan Lozanod7586b62021-04-01 09:49:36 -0400833func (mod *Module) EverInstallable() bool {
834 return mod.compiler != nil &&
835 // Check to see whether the module is actually ever installable.
836 mod.compiler.everInstallable()
837}
838
839func (mod *Module) Installable() *bool {
840 return mod.Properties.Installable
841}
842
Ivan Lozano872d5792022-03-23 17:31:39 -0400843func (mod *Module) ProcMacro() bool {
844 if pm, ok := mod.compiler.(procMacroInterface); ok {
845 return pm.ProcMacro()
846 }
847 return false
848}
849
Ivan Lozanoffee3342019-08-27 12:03:00 -0700850func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
851 if mod.cachedToolchain == nil {
852 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
853 }
854 return mod.cachedToolchain
855}
856
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +0200857func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
858 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
859}
860
Ivan Lozanoffee3342019-08-27 12:03:00 -0700861func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
862}
863
864func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
865 ctx := &moduleContext{
866 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700867 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700868
Jiyong Park99644e92020-11-17 22:21:02 +0900869 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
870 if !apexInfo.IsForPlatform() {
871 mod.hideApexVariantFromMake = true
872 }
873
Ivan Lozanoffee3342019-08-27 12:03:00 -0700874 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -0500875 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
876
Ivan Lozanof1868af2022-04-12 13:08:36 -0400877 mod.Properties.SubName = cc.GetSubnameProperty(actx, mod)
Matthew Maurera61e31f2021-05-27 11:09:11 -0700878
Ivan Lozanoffee3342019-08-27 12:03:00 -0700879 if !toolchain.Supported() {
880 // This toolchain's unsupported, there's nothing to do for this mod.
881 return
882 }
883
884 deps := mod.depsToPaths(ctx)
885 flags := Flags{
886 Toolchain: toolchain,
887 }
888
Ivan Lozano67eada32021-09-23 11:50:33 -0400889 // Calculate rustc flags
Yi Kong46c6e592022-01-20 22:55:00 +0800890 if mod.afdo != nil {
891 flags, deps = mod.afdo.flags(ctx, flags, deps)
892 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700893 if mod.compiler != nil {
894 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -0400895 flags = mod.compiler.cfgFlags(ctx, flags)
896 flags = mod.compiler.featureFlags(ctx, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400897 }
898 if mod.coverage != nil {
899 flags, deps = mod.coverage.flags(ctx, flags, deps)
900 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200901 if mod.clippy != nil {
902 flags, deps = mod.clippy.flags(ctx, flags, deps)
903 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500904 if mod.sanitize != nil {
905 flags, deps = mod.sanitize.flags(ctx, flags, deps)
906 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400907
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200908 // SourceProvider needs to call GenerateSource() before compiler calls
909 // compile() so it can provide the source. A SourceProvider has
910 // multiple variants (e.g. source, rlib, dylib). Only the "source"
911 // variant is responsible for effectively generating the source. The
912 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400913 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200914 if mod.compiler.(libraryInterface).source() {
915 mod.sourceProvider.GenerateSource(ctx, deps)
916 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
917 } else {
918 sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag)
919 sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
Chih-Hung Hsiehc49649c2020-10-01 21:25:05 -0700920 mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200921 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400922 }
923
924 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +0100925 mod.compiler.initialize(ctx)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700926 buildOutput := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400927 if ctx.Failed() {
928 return
929 }
Sasha Smundaka76acba2022-04-18 20:12:56 -0700930 mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile)
931 if buildOutput.kytheFile != nil {
932 mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile)
933 }
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400934 bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
Jiyong Park459feca2020-12-15 11:02:21 +0900935
Dan Albert06feee92021-03-19 15:06:02 -0700936 mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
Matthew Maurere3803632021-12-10 21:57:21 +0000937 if mod.docTimestampFile.Valid() {
938 ctx.CheckbuildFile(mod.docTimestampFile.Path())
939 }
Dan Albert06feee92021-03-19 15:06:02 -0700940
Ivan Lozano1921e802021-05-20 13:39:16 -0400941 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
942 // RECOVERY_SNAPSHOT_VERSION is current.
943 if lib, ok := mod.compiler.(snapshotLibraryInterface); ok {
944 if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) {
945 lib.collectHeadersForSnapshot(ctx, deps)
946 }
947 }
948
Jiyong Park459feca2020-12-15 11:02:21 +0900949 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
Ivan Lozano872d5792022-03-23 17:31:39 -0400950 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900951 // If the module has been specifically configure to not be installed then
952 // hide from make as otherwise it will break when running inside make as the
953 // output path to install will not be specified. Not all uninstallable
954 // modules can be hidden from make as some are needed for resolving make
Ivan Lozano872d5792022-03-23 17:31:39 -0400955 // side dependencies. In particular, proc-macros need to be captured in the
956 // host snapshot.
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900957 mod.HideFromMake()
958 } else if !mod.installable(apexInfo) {
959 mod.SkipInstall()
960 }
961
962 // Still call install though, the installs will be stored as PackageSpecs to allow
963 // using the outputs in a genrule.
964 if mod.OutputFile().Valid() {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200965 mod.compiler.install(ctx)
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900966 if ctx.Failed() {
967 return
968 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400969 }
Chris Wailes74be7642021-07-22 16:20:28 -0700970
971 ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -0700972 }
973}
974
975func (mod *Module) deps(ctx DepsContext) Deps {
976 deps := Deps{}
977
978 if mod.compiler != nil {
979 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400980 }
981 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700982 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700983 }
984
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400985 if mod.coverage != nil {
986 deps = mod.coverage.deps(ctx, deps)
987 }
988
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500989 if mod.sanitize != nil {
990 deps = mod.sanitize.deps(ctx, deps)
991 }
992
Ivan Lozanoffee3342019-08-27 12:03:00 -0700993 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
994 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -0700995 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700996 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
997 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
998 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Andrew Walbran797e4be2022-03-07 15:41:53 +0000999 deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001000 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001001 return deps
1002
1003}
1004
Ivan Lozanoffee3342019-08-27 12:03:00 -07001005type dependencyTag struct {
1006 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001007 name string
1008 library bool
1009 procMacro bool
Colin Cross65cb3142021-12-10 23:05:02 +00001010 dynamic bool
Ivan Lozanoffee3342019-08-27 12:03:00 -07001011}
1012
Jiyong Park65b62242020-11-25 12:44:59 +09001013// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
1014// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
1015func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001016 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +09001017}
1018
1019var _ android.InstallNeededDependencyTag = dependencyTag{}
1020
Colin Cross65cb3142021-12-10 23:05:02 +00001021func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
1022 if d.library && d.dynamic {
1023 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
1024 }
1025 return nil
1026}
1027
1028var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
1029
Ivan Lozanoffee3342019-08-27 12:03:00 -07001030var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001031 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
1032 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
Colin Cross65cb3142021-12-10 23:05:02 +00001033 dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001034 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001035 testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001036 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001037 dataLibDepTag = dependencyTag{name: "data lib"}
1038 dataBinDepTag = dependencyTag{name: "data bin"}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001039)
1040
Jiyong Park99644e92020-11-17 22:21:02 +09001041func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
1042 tag, ok := depTag.(dependencyTag)
1043 return ok && tag == dylibDepTag
1044}
1045
Jiyong Park94e22fd2021-04-08 18:19:15 +09001046func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
1047 tag, ok := depTag.(dependencyTag)
1048 return ok && tag == rlibDepTag
1049}
1050
Matthew Maurer0f003b12020-06-29 14:34:06 -07001051type autoDep struct {
1052 variation string
1053 depTag dependencyTag
1054}
1055
1056var (
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001057 rlibVariation = "rlib"
1058 dylibVariation = "dylib"
1059 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
1060 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -07001061)
1062
1063type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -05001064 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -07001065}
1066
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001067func (mod *Module) begin(ctx BaseModuleContext) {
1068 if mod.coverage != nil {
1069 mod.coverage.begin(ctx)
1070 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001071 if mod.sanitize != nil {
1072 mod.sanitize.begin(ctx)
1073 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001074}
1075
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001076func (mod *Module) Prebuilt() *android.Prebuilt {
Ivan Lozano872d5792022-03-23 17:31:39 -04001077 if p, ok := mod.compiler.(rustPrebuilt); ok {
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001078 return p.prebuilt()
1079 }
1080 return nil
1081}
1082
Ivan Lozanoffee3342019-08-27 12:03:00 -07001083func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
1084 var depPaths PathDeps
1085
1086 directRlibDeps := []*Module{}
1087 directDylibDeps := []*Module{}
1088 directProcMacroDeps := []*Module{}
Jiyong Park7d55b612021-06-11 17:22:09 +09001089 directSharedLibDeps := []cc.SharedLibraryInfo{}
Ivan Lozano52767be2019-10-18 14:49:46 -07001090 directStaticLibDeps := [](cc.LinkableInterface){}
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001091 directSrcProvidersDeps := []*Module{}
1092 directSrcDeps := [](android.SourceFileProducer){}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001093
Ivan Lozanoe950cda2021-11-09 11:26:04 -05001094 // For the dependency from platform to apex, use the latest stubs
1095 mod.apexSdkVersion = android.FutureApiLevel
1096 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1097 if !apexInfo.IsForPlatform() {
1098 mod.apexSdkVersion = apexInfo.MinSdkVersion
1099 }
1100
1101 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
1102 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
1103 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
1104 // (b/144430859)
1105 mod.apexSdkVersion = android.FutureApiLevel
1106 }
1107
Ivan Lozanoffee3342019-08-27 12:03:00 -07001108 ctx.VisitDirectDeps(func(dep android.Module) {
1109 depName := ctx.OtherModuleName(dep)
1110 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001111
Ivan Lozano89435d12020-07-31 11:01:18 -04001112 if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001113 //Handle Rust Modules
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001114 makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -07001115
Ivan Lozanoffee3342019-08-27 12:03:00 -07001116 switch depTag {
1117 case dylibDepTag:
1118 dylib, ok := rustDep.compiler.(libraryInterface)
1119 if !ok || !dylib.dylib() {
1120 ctx.ModuleErrorf("mod %q not an dylib library", depName)
1121 return
1122 }
1123 directDylibDeps = append(directDylibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001124 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001125 case rlibDepTag:
Ivan Lozano2b081132020-09-08 12:46:52 -04001126
Ivan Lozanoffee3342019-08-27 12:03:00 -07001127 rlib, ok := rustDep.compiler.(libraryInterface)
1128 if !ok || !rlib.rlib() {
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001129 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001130 return
1131 }
1132 directRlibDeps = append(directRlibDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001133 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001134 case procMacroDepTag:
1135 directProcMacroDeps = append(directProcMacroDeps, rustDep)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001136 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Paul Duffind5cf92e2021-07-09 17:38:55 +01001137 }
1138
1139 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001140 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
1141 // OS/Arch variant is used.
1142 var helper string
1143 if ctx.Host() {
1144 helper = "missing 'host_supported'?"
1145 } else {
1146 helper = "device module defined?"
1147 }
1148
1149 if dep.Target().Os != ctx.Os() {
1150 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
1151 return
1152 } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
1153 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
1154 return
1155 }
1156 directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001157 }
1158
Ivan Lozano2bbcacf2020-08-07 09:00:50 -04001159 //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -07001160 if depTag != procMacroDepTag {
1161 exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
1162 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
1163 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
1164 depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001165 }
1166
Ivan Lozanoffee3342019-08-27 12:03:00 -07001167 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001168 linkFile := rustDep.UnstrippedOutputFile()
1169 linkDir := linkPathFromFilePath(linkFile)
Matthew Maurerbb3add12020-06-25 09:34:12 -07001170 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
1171 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001172 }
1173 }
1174
Ivan Lozano89435d12020-07-31 11:01:18 -04001175 } else if ccDep, ok := dep.(cc.LinkableInterface); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07001176 //Handle C dependencies
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001177 makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName)
Ivan Lozano52767be2019-10-18 14:49:46 -07001178 if _, ok := ccDep.(*Module); !ok {
1179 if ccDep.Module().Target().Os != ctx.Os() {
1180 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1181 return
1182 }
1183 if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType {
1184 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
1185 return
1186 }
Ivan Lozano70e0a072019-09-13 14:23:15 -07001187 }
Ivan Lozano2093af22020-08-25 12:48:19 -04001188 linkObject := ccDep.OutputFile()
1189 linkPath := linkPathFromFilePath(linkObject.Path())
Ivan Lozano6aa66022020-02-06 13:22:43 -05001190
Ivan Lozano2093af22020-08-25 12:48:19 -04001191 if !linkObject.Valid() {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001192 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
1193 }
1194
1195 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -07001196 switch {
1197 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -04001198 if cc.IsWholeStaticLib(depTag) {
1199 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
1200 // if the library is not prefixed by "lib".
Ivan Lozanofdadcd72021-11-01 09:04:23 -04001201 if mod.Binary() {
1202 // Binaries may sometimes need to link whole static libraries that don't start with 'lib'.
1203 // Since binaries don't need to 'rebundle' these like libraries and only use these for the
1204 // final linkage, pass the args directly to the linker to handle these cases.
1205 depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...)
1206 } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
Ivan Lozanofb6f36f2021-02-05 12:27:08 -05001207 depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001208 } else {
1209 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 -05001210 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001211 }
1212
1213 // Add this to linkObjects to pass the library directly to the linker as well. This propagates
1214 // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant.
Ivan Lozano2093af22020-08-25 12:48:19 -04001215 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001216 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
1217
Colin Cross0de8a1e2020-09-18 14:15:30 -07001218 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1219 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1220 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1221 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1222 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001223 directStaticLibDeps = append(directStaticLibDeps, ccDep)
Justin Yun2b3ed642022-02-16 08:15:07 +09001224
1225 // Record baseLibName for snapshots.
1226 mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName))
1227
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001228 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07001229 case cc.IsSharedDepTag(depTag):
Jiyong Park7d55b612021-06-11 17:22:09 +09001230 // For the shared lib dependencies, we may link to the stub variant
1231 // of the dependency depending on the context (e.g. if this
1232 // dependency crosses the APEX boundaries).
1233 sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep)
1234
1235 // Re-get linkObject as ChooseStubOrImpl actually tells us which
1236 // object (either from stub or non-stub) to use.
1237 linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
1238 linkPath = linkPathFromFilePath(linkObject.Path())
1239
Ivan Lozanoffee3342019-08-27 12:03:00 -07001240 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001241 depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -07001242 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1243 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1244 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1245 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Jiyong Park7d55b612021-06-11 17:22:09 +09001246 directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo)
Ivan Lozano1921e802021-05-20 13:39:16 -04001247
1248 // Record baseLibName for snapshots.
1249 mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName))
1250
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001251 mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001252 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -08001253 case cc.IsHeaderDepTag(depTag):
1254 exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
1255 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1256 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1257 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Colin Cross6e511a92020-07-27 21:26:48 -07001258 case depTag == cc.CrtBeginDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001259 depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07001260 case depTag == cc.CrtEndDepTag:
Colin Crossfe605e12022-01-23 20:46:16 -08001261 depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001262 }
1263
1264 // Make sure these dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001265 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1266 lib.exportLinkDirs(linkPath)
Ivan Lozano2093af22020-08-25 12:48:19 -04001267 lib.exportLinkObjects(linkObject.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001268 }
Colin Cross018cbeb2022-01-24 17:22:45 -08001269 } else {
1270 switch {
1271 case depTag == cc.CrtBeginDepTag:
1272 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
1273 case depTag == cc.CrtEndDepTag:
1274 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
1275 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001276 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001277
1278 if srcDep, ok := dep.(android.SourceFileProducer); ok {
Paul Duffind5cf92e2021-07-09 17:38:55 +01001279 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano89435d12020-07-31 11:01:18 -04001280 // These are usually genrules which don't have per-target variants.
1281 directSrcDeps = append(directSrcDeps, srcDep)
1282 }
1283 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001284 })
1285
1286 var rlibDepFiles RustLibraries
1287 for _, dep := range directRlibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001288 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001289 }
1290 var dylibDepFiles RustLibraries
1291 for _, dep := range directDylibDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001292 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001293 }
1294 var procMacroDepFiles RustLibraries
1295 for _, dep := range directProcMacroDeps {
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001296 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
Ivan Lozanoffee3342019-08-27 12:03:00 -07001297 }
1298
1299 var staticLibDepFiles android.Paths
1300 for _, dep := range directStaticLibDeps {
1301 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path())
1302 }
1303
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001304 var sharedLibFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001305 var sharedLibDepFiles android.Paths
1306 for _, dep := range directSharedLibDeps {
Jiyong Park7d55b612021-06-11 17:22:09 +09001307 sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary)
1308 if dep.TableOfContents.Valid() {
1309 sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path())
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001310 } else {
Jiyong Park7d55b612021-06-11 17:22:09 +09001311 sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001312 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001313 }
1314
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001315 var srcProviderDepFiles android.Paths
1316 for _, dep := range directSrcProvidersDeps {
1317 srcs, _ := dep.OutputFiles("")
1318 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1319 }
1320 for _, dep := range directSrcDeps {
1321 srcs := dep.Srcs()
1322 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1323 }
1324
Ivan Lozanoffee3342019-08-27 12:03:00 -07001325 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1326 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
1327 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001328 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001329 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
1330 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001331 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001332
1333 // Dedup exported flags from dependencies
1334 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001335 depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001336 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001337 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1338 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1339 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001340
1341 return depPaths
1342}
1343
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001344func (mod *Module) InstallInData() bool {
1345 if mod.compiler == nil {
1346 return false
1347 }
1348 return mod.compiler.inData()
1349}
1350
Matthew Maurer9f59e8d2021-08-19 13:10:05 -07001351func (mod *Module) InstallInRamdisk() bool {
1352 return mod.InRamdisk()
1353}
1354
1355func (mod *Module) InstallInVendorRamdisk() bool {
1356 return mod.InVendorRamdisk()
1357}
1358
1359func (mod *Module) InstallInRecovery() bool {
1360 return mod.InRecovery()
1361}
1362
Ivan Lozanoffee3342019-08-27 12:03:00 -07001363func linkPathFromFilePath(filepath android.Path) string {
1364 return strings.Split(filepath.String(), filepath.Base())[0]
1365}
Ivan Lozanod648c432020-02-06 12:05:10 -05001366
Ivan Lozanoffee3342019-08-27 12:03:00 -07001367func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1368 ctx := &depsContext{
1369 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001370 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001371
1372 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001373 var commonDepVariations []blueprint.Variation
Ivan Lozano1921e802021-05-20 13:39:16 -04001374 var snapshotInfo *cc.SnapshotInfo
1375
Kiyoung Kim487689e2022-07-26 09:48:22 +09001376 apiImportInfo := cc.GetApiImports(mod, actx)
1377 for idx, lib := range deps.SharedLibs {
1378 deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs)
1379 }
1380
Ivan Lozano1921e802021-05-20 13:39:16 -04001381 if ctx.Os() == android.Android {
1382 deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
1383 }
Ivan Lozanodd055472020-09-28 13:22:45 -04001384
Ivan Lozano2b081132020-09-08 12:46:52 -04001385 stdLinkage := "dylib-std"
Ivan Lozanodd055472020-09-28 13:22:45 -04001386 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001387 stdLinkage = "rlib-std"
1388 }
1389
1390 rlibDepVariations := commonDepVariations
Ivan Lozano1921e802021-05-20 13:39:16 -04001391
Ivan Lozano2b081132020-09-08 12:46:52 -04001392 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1393 rlibDepVariations = append(rlibDepVariations,
1394 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1395 }
1396
Ivan Lozano1921e802021-05-20 13:39:16 -04001397 // rlibs
Ivan Lozano2d407632022-04-07 12:59:11 -04001398 rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001399 for _, lib := range deps.Rlibs {
1400 depTag := rlibDepTag
Kiyoung Kim487689e2022-07-26 09:48:22 +09001401 lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001402
Ivan Lozano2d407632022-04-07 12:59:11 -04001403 actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001404 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001405
1406 // dylibs
Ivan Lozano52767be2019-10-18 14:49:46 -07001407 actx.AddVariationDependencies(
1408 append(commonDepVariations, []blueprint.Variation{
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001409 {Mutator: "rust_libraries", Variation: dylibVariation}}...),
Ivan Lozano52767be2019-10-18 14:49:46 -07001410 dylibDepTag, deps.Dylibs...)
1411
Ivan Lozano1921e802021-05-20 13:39:16 -04001412 // rustlibs
Ivan Lozano042504f2020-08-18 14:31:23 -04001413 if deps.Rustlibs != nil && !mod.compiler.Disabled() {
1414 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
Ivan Lozano2d407632022-04-07 12:59:11 -04001415 for _, lib := range deps.Rustlibs {
1416 if autoDep.depTag == rlibDepTag {
1417 // Handle the rlib deptag case
1418 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1419 } else {
1420 // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
1421 // Check for the existence of the dylib deptag variant. Select it if available,
1422 // otherwise select the rlib variant.
1423 autoDepVariations := append(commonDepVariations,
1424 blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
1425 if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
1426 actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
1427 } else {
1428 // If there's no dylib dependency available, try to add the rlib dependency instead.
1429 addRlibDependency(actx, lib, mod, snapshotInfo, rlibDepVariations)
1430 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001431 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001432 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001433 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001434 // stdlibs
Ivan Lozano2b081132020-09-08 12:46:52 -04001435 if deps.Stdlibs != nil {
Ivan Lozanodd055472020-09-28 13:22:45 -04001436 if mod.compiler.stdLinkage(ctx) == RlibLinkage {
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001437 for _, lib := range deps.Stdlibs {
1438 depTag := rlibDepTag
Kiyoung Kim487689e2022-07-26 09:48:22 +09001439 lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001440
1441 actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
1442 depTag, lib)
1443 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001444 } else {
1445 actx.AddVariationDependencies(
1446 append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
1447 dylibDepTag, deps.Stdlibs...)
1448 }
1449 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001450
1451 for _, lib := range deps.SharedLibs {
1452 depTag := cc.SharedDepTag()
1453 name, version := cc.StubsLibNameAndVersion(lib)
1454
1455 variations := []blueprint.Variation{
1456 {Mutator: "link", Variation: "shared"},
1457 }
1458 cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
1459 }
1460
1461 for _, lib := range deps.WholeStaticLibs {
1462 depTag := cc.StaticDepTag(true)
Kiyoung Kim487689e2022-07-26 09:48:22 +09001463 lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
Ivan Lozano1921e802021-05-20 13:39:16 -04001464
1465 actx.AddVariationDependencies([]blueprint.Variation{
1466 {Mutator: "link", Variation: "static"},
1467 }, depTag, lib)
1468 }
1469
1470 for _, lib := range deps.StaticLibs {
1471 depTag := cc.StaticDepTag(false)
Kiyoung Kim487689e2022-07-26 09:48:22 +09001472 lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
Ivan Lozano1921e802021-05-20 13:39:16 -04001473
1474 actx.AddVariationDependencies([]blueprint.Variation{
1475 {Mutator: "link", Variation: "static"},
1476 }, depTag, lib)
1477 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001478
Zach Johnson3df4e632020-11-06 11:56:27 -08001479 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
1480
Colin Cross565cafd2020-09-25 18:47:38 -07001481 crtVariations := cc.GetCrtVariations(ctx, mod)
Colin Crossfe605e12022-01-23 20:46:16 -08001482 for _, crt := range deps.CrtBegin {
Ivan Lozano1921e802021-05-20 13:39:16 -04001483 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag,
Kiyoung Kim487689e2022-07-26 09:48:22 +09001484 cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001485 }
Colin Crossfe605e12022-01-23 20:46:16 -08001486 for _, crt := range deps.CrtEnd {
Ivan Lozano1921e802021-05-20 13:39:16 -04001487 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag,
Kiyoung Kim487689e2022-07-26 09:48:22 +09001488 cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
Ivan Lozanof1c84332019-09-20 11:00:37 -07001489 }
1490
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001491 if mod.sourceProvider != nil {
1492 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
1493 bindgen.Properties.Custom_bindgen != "" {
1494 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
1495 bindgen.Properties.Custom_bindgen)
1496 }
1497 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001498
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001499 actx.AddVariationDependencies([]blueprint.Variation{
1500 {Mutator: "link", Variation: "shared"},
1501 }, dataLibDepTag, deps.DataLibs...)
1502
1503 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
1504
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07001505 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001506 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001507}
1508
Ivan Lozano2d407632022-04-07 12:59:11 -04001509// addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available.
1510func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo *cc.SnapshotInfo, variations []blueprint.Variation) {
Kiyoung Kim487689e2022-07-26 09:48:22 +09001511 lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
Ivan Lozano2d407632022-04-07 12:59:11 -04001512 actx.AddVariationDependencies(variations, rlibDepTag, lib)
1513}
1514
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001515func BeginMutator(ctx android.BottomUpMutatorContext) {
1516 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
1517 mod.beginMutator(ctx)
1518 }
1519}
1520
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001521func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
1522 ctx := &baseModuleContext{
1523 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001524 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001525
1526 mod.begin(ctx)
1527}
1528
Ivan Lozanoffee3342019-08-27 12:03:00 -07001529func (mod *Module) Name() string {
1530 name := mod.ModuleBase.Name()
1531 if p, ok := mod.compiler.(interface {
1532 Name(string) string
1533 }); ok {
1534 name = p.Name(name)
1535 }
1536 return name
1537}
1538
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001539func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04001540 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02001541 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04001542 }
1543}
1544
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001545var _ android.HostToolProvider = (*Module)(nil)
Ivan Lozano872d5792022-03-23 17:31:39 -04001546var _ snapshot.RelativeInstallPath = (*Module)(nil)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001547
1548func (mod *Module) HostToolPath() android.OptionalPath {
1549 if !mod.Host() {
1550 return android.OptionalPath{}
1551 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07001552 if binary, ok := mod.compiler.(*binaryDecorator); ok {
1553 return android.OptionalPathForPath(binary.baseCompiler.path)
Ivan Lozano872d5792022-03-23 17:31:39 -04001554 } else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
1555 // Even though proc-macros aren't strictly "tools", since they target the compiler
1556 // and act as compiler plugins, we treat them similarly.
1557 return android.OptionalPathForPath(pm.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07001558 }
1559 return android.OptionalPath{}
1560}
1561
Jiyong Park99644e92020-11-17 22:21:02 +09001562var _ android.ApexModule = (*Module)(nil)
1563
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001564func (mod *Module) MinSdkVersion() string {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001565 return String(mod.Properties.Min_sdk_version)
1566}
1567
Jiyong Park45bf82e2020-12-15 22:29:02 +09001568// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001569func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
Ivan Lozanoa91ba252022-01-11 12:02:06 -05001570 minSdkVersion := mod.MinSdkVersion()
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05001571 if minSdkVersion == "apex_inherit" {
1572 return nil
1573 }
1574 if minSdkVersion == "" {
1575 return fmt.Errorf("min_sdk_version is not specificed")
1576 }
1577
1578 // Not using nativeApiLevelFromUser because the context here is not
1579 // necessarily a native context.
1580 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
1581 if err != nil {
1582 return err
1583 }
1584
1585 if ver.GreaterThan(sdkVersion) {
1586 return fmt.Errorf("newer SDK(%v)", ver)
1587 }
Jiyong Park99644e92020-11-17 22:21:02 +09001588 return nil
1589}
1590
Jiyong Park45bf82e2020-12-15 22:29:02 +09001591// Implements android.ApexModule
Jiyong Park99644e92020-11-17 22:21:02 +09001592func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
1593 depTag := ctx.OtherModuleDependencyTag(dep)
1594
1595 if ccm, ok := dep.(*cc.Module); ok {
1596 if ccm.HasStubsVariants() {
1597 if cc.IsSharedDepTag(depTag) {
1598 // dynamic dep to a stubs lib crosses APEX boundary
1599 return false
1600 }
1601 if cc.IsRuntimeDepTag(depTag) {
1602 // runtime dep to a stubs lib also crosses APEX boundary
1603 return false
1604 }
1605
1606 if cc.IsHeaderDepTag(depTag) {
1607 return false
1608 }
1609 }
1610 if mod.Static() && cc.IsSharedDepTag(depTag) {
1611 // shared_lib dependency from a static lib is considered as crossing
1612 // the APEX boundary because the dependency doesn't actually is
1613 // linked; the dependency is used only during the compilation phase.
1614 return false
1615 }
1616 }
1617
1618 if depTag == procMacroDepTag {
1619 return false
1620 }
1621
1622 return true
1623}
1624
1625// Overrides ApexModule.IsInstallabeToApex()
1626func (mod *Module) IsInstallableToApex() bool {
1627 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -05001628 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) {
Jiyong Park99644e92020-11-17 22:21:02 +09001629 return true
1630 }
1631 if _, ok := mod.compiler.(*binaryDecorator); ok {
1632 return true
1633 }
1634 }
1635 return false
1636}
1637
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001638// If a library file has a "lib" prefix, extract the library name without the prefix.
1639func libNameFromFilePath(filepath android.Path) (string, bool) {
1640 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
1641 if strings.HasPrefix(libName, "lib") {
1642 libName = libName[3:]
1643 return libName, true
1644 }
1645 return "", false
1646}
1647
Sasha Smundaka76acba2022-04-18 20:12:56 -07001648func kytheExtractRustFactory() android.Singleton {
1649 return &kytheExtractRustSingleton{}
1650}
1651
1652type kytheExtractRustSingleton struct {
1653}
1654
1655func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) {
1656 var xrefTargets android.Paths
1657 ctx.VisitAllModules(func(module android.Module) {
1658 if rustModule, ok := module.(xref); ok {
1659 xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...)
1660 }
1661 })
1662 if len(xrefTargets) > 0 {
1663 ctx.Phony("xref_rust", xrefTargets...)
1664 }
1665}
1666
Jihoon Kangf78a8902022-09-01 22:47:07 +00001667func (c *Module) Partition() string {
1668 return ""
1669}
1670
Ivan Lozanoffee3342019-08-27 12:03:00 -07001671var Bool = proptools.Bool
1672var BoolDefault = proptools.BoolDefault
1673var String = proptools.String
1674var StringPtr = proptools.StringPtr
Ivan Lozano43845682020-07-09 21:03:28 -04001675
1676var _ android.OutputFileProducer = (*Module)(nil)