blob: 54b5d92e39a1c52f84bad39cc496bd0907fce4a0 [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 (
Chris Parsons637458d2023-09-19 20:09:00 +000018 "fmt"
Wei Lia1aa2972024-06-21 13:08:51 -070019 "strconv"
Chris Parsons637458d2023-09-19 20:09:00 +000020 "strings"
21
Sasha Smundaka76acba2022-04-18 20:12:56 -070022 "android/soong/bloaty"
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +090023
Ivan Lozanoffee3342019-08-27 12:03:00 -070024 "github.com/google/blueprint"
Colin Crossa14fb6a2024-10-23 16:57:06 -070025 "github.com/google/blueprint/depset"
Ivan Lozanoffee3342019-08-27 12:03:00 -070026 "github.com/google/blueprint/proptools"
27
28 "android/soong/android"
29 "android/soong/cc"
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +020030 cc_config "android/soong/cc/config"
hamzehc0a671f2021-07-22 12:05:08 -070031 "android/soong/fuzz"
Ivan Lozanoffee3342019-08-27 12:03:00 -070032 "android/soong/rust/config"
33)
34
35var pctx = android.NewPackageContext("android/soong/rust")
36
Yu Liu8024b922024-12-20 23:31:32 +000037type LibraryInfo struct {
38 Rlib bool
39 Dylib bool
40}
41
42type CompilerInfo struct {
43 StdLinkageForDevice RustLinkage
44 StdLinkageForNonDevice RustLinkage
45 NoStdlibs bool
46 LibraryInfo *LibraryInfo
47}
48
49type ProtobufDecoratorInfo struct{}
50
51type SourceProviderInfo struct {
Yu Liu727204c2025-01-23 20:58:32 +000052 Srcs android.Paths
Yu Liu8024b922024-12-20 23:31:32 +000053 ProtobufDecoratorInfo *ProtobufDecoratorInfo
54}
55
56type RustInfo struct {
57 AndroidMkSuffix string
58 RustSubName string
59 TransitiveAndroidMkSharedLibs depset.DepSet[string]
60 CompilerInfo *CompilerInfo
61 SnapshotInfo *cc.SnapshotInfo
62 SourceProviderInfo *SourceProviderInfo
Yu Liu2a815b62025-02-21 20:46:25 +000063 XrefRustFiles android.Paths
Yu Liu88408122025-03-04 18:46:24 +000064 DocTimestampFile android.OptionalPath
Yu Liu8024b922024-12-20 23:31:32 +000065}
66
67var RustInfoProvider = blueprint.NewProvider[*RustInfo]()
68
Ivan Lozanoffee3342019-08-27 12:03:00 -070069func init() {
Ivan Lozanoffee3342019-08-27 12:03:00 -070070 android.RegisterModuleType("rust_defaults", defaultsFactory)
Colin Cross8a49a3d2024-05-20 12:22:27 -070071 android.PreDepsMutators(registerPreDepsMutators)
72 android.PostDepsMutators(registerPostDepsMutators)
Inseob Kim3b244062023-07-11 13:31:36 +090073 pctx.Import("android/soong/android")
Ivan Lozanoffee3342019-08-27 12:03:00 -070074 pctx.Import("android/soong/rust/config")
Thiébaud Weksteen682c9d72020-08-31 10:06:16 +020075 pctx.ImportAs("cc_config", "android/soong/cc/config")
LaMont Jones0c10e4d2023-05-16 00:58:37 +000076 android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070077}
78
Colin Cross8a49a3d2024-05-20 12:22:27 -070079func registerPreDepsMutators(ctx android.RegisterMutatorsContext) {
80 ctx.Transition("rust_libraries", &libraryTransitionMutator{})
81 ctx.Transition("rust_stdlinkage", &libstdTransitionMutator{})
Colin Cross8a962802024-10-09 15:29:27 -070082 ctx.BottomUp("rust_begin", BeginMutator)
Colin Cross8a49a3d2024-05-20 12:22:27 -070083}
84
85func registerPostDepsMutators(ctx android.RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -070086 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator)
Colin Cross8a49a3d2024-05-20 12:22:27 -070087}
88
Ivan Lozanoffee3342019-08-27 12:03:00 -070089type Flags struct {
Ivan Lozano8a23fa42020-06-16 10:26:57 -040090 GlobalRustFlags []string // Flags that apply globally to rust
91 GlobalLinkFlags []string // Flags that apply globally to linker
92 RustFlags []string // Flags that apply to rust
93 LinkFlags []string // Flags that apply to linker
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020094 ClippyFlags []string // Flags that apply to clippy-driver, during the linting
Dan Albert06feee92021-03-19 15:06:02 -070095 RustdocFlags []string // Flags that apply to rustdoc
Ivan Lozanof1c84332019-09-20 11:00:37 -070096 Toolchain config.Toolchain
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040097 Coverage bool
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +020098 Clippy bool
Sasha Smundaka76acba2022-04-18 20:12:56 -070099 EmitXrefs bool // If true, emit rules to aid cross-referencing
Ivan Lozanoffee3342019-08-27 12:03:00 -0700100}
101
102type BaseProperties struct {
Liz Kammer884fe9e2023-02-28 14:29:13 -0500103 AndroidMkRlibs []string `blueprint:"mutated"`
104 AndroidMkDylibs []string `blueprint:"mutated"`
105 AndroidMkProcMacroLibs []string `blueprint:"mutated"`
Liz Kammer884fe9e2023-02-28 14:29:13 -0500106 AndroidMkStaticLibs []string `blueprint:"mutated"`
Ivan Lozano1dbfa142024-03-29 14:48:11 +0000107 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Ivan Lozano43845682020-07-09 21:03:28 -0400108
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900109 ImageVariation string `blueprint:"mutated"`
110 VndkVersion string `blueprint:"mutated"`
111 SubName string `blueprint:"mutated"`
Ivan Lozano6a884432020-12-02 09:15:16 -0500112
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400113 // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
114 // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be
115 // appended before SubName.
116 RustSubName string `blueprint:"mutated"`
117
Ivan Lozano6a884432020-12-02 09:15:16 -0500118 // Set by imageMutator
Jihoon Kang47e91842024-06-19 00:51:16 +0000119 ProductVariantNeeded bool `blueprint:"mutated"`
120 VendorVariantNeeded bool `blueprint:"mutated"`
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500121 CoreVariantNeeded bool `blueprint:"mutated"`
122 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurerc6868382021-07-13 14:12:37 -0700123 RamdiskVariantNeeded bool `blueprint:"mutated"`
Matthew Maurer460ee942021-02-11 12:31:46 -0800124 RecoveryVariantNeeded bool `blueprint:"mutated"`
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500125 ExtraVariants []string `blueprint:"mutated"`
126
Ivan Lozanoa2268632021-07-22 10:52:06 -0400127 // Allows this module to use non-APEX version of libraries. Useful
128 // for building binaries that are started before APEXes are activated.
129 Bootstrap *bool
130
Ivan Lozano1921e802021-05-20 13:39:16 -0400131 // Used by vendor snapshot to record dependencies from snapshot modules.
132 SnapshotSharedLibs []string `blueprint:"mutated"`
Justin Yun5e035862021-06-29 20:50:37 +0900133 SnapshotStaticLibs []string `blueprint:"mutated"`
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400134 SnapshotRlibs []string `blueprint:"mutated"`
135 SnapshotDylibs []string `blueprint:"mutated"`
Ivan Lozano1921e802021-05-20 13:39:16 -0400136
Matthew Maurerc6868382021-07-13 14:12:37 -0700137 // Make this module available when building for ramdisk.
138 // On device without a dedicated recovery partition, the module is only
139 // available after switching root into
140 // /first_stage_ramdisk. To expose the module before switching root, install
141 // the recovery variant instead.
142 Ramdisk_available *bool
143
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500144 // Make this module available when building for vendor ramdisk.
145 // On device without a dedicated recovery partition, the module is only
146 // available after switching root into
147 // /first_stage_ramdisk. To expose the module before switching root, install
Matthew Maurer460ee942021-02-11 12:31:46 -0800148 // the recovery variant instead
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500149 Vendor_ramdisk_available *bool
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400150
Ivan Lozano1921e802021-05-20 13:39:16 -0400151 // Normally Soong uses the directory structure to decide which modules
152 // should be included (framework) or excluded (non-framework) from the
153 // different snapshots (vendor, recovery, etc.), but this property
154 // allows a partner to exclude a module normally thought of as a
155 // framework module from the vendor snapshot.
156 Exclude_from_vendor_snapshot *bool
157
158 // Normally Soong uses the directory structure to decide which modules
159 // should be included (framework) or excluded (non-framework) from the
160 // different snapshots (vendor, recovery, etc.), but this property
161 // allows a partner to exclude a module normally thought of as a
162 // framework module from the recovery snapshot.
163 Exclude_from_recovery_snapshot *bool
164
Matthew Maurer460ee942021-02-11 12:31:46 -0800165 // Make this module available when building for recovery
166 Recovery_available *bool
167
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000168 // The API level that this module is built against. The APIs of this API level will be
169 // visible at build time, but use of any APIs newer than min_sdk_version will render the
170 // module unloadable on older devices. In the future it will be possible to weakly-link new
171 // APIs, making the behavior match Java: such modules will load on older devices, but
172 // calling new APIs on devices that do not support them will result in a crash.
173 //
174 // This property has the same behavior as sdk_version does for Java modules. For those
175 // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion
176 // does for Java code.
177 //
178 // In addition, setting this property causes two variants to be built, one for the platform
179 // and one for apps.
180 Sdk_version *string
181
182 // Minimum OS API level supported by this C or C++ module. This property becomes the value
183 // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK,
184 // this property is also used to ensure that the min_sdk_version of the containing module is
185 // not older (i.e. less) than this module's min_sdk_version. When not set, this property
186 // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks
187 // min_sdk_version of the containing APEX. When the module
188 // is not built for an APEX, "apex_inherit" defaults to sdk_version.
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500189 Min_sdk_version *string
190
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000191 // Variant is an SDK variant created by sdkMutator
192 IsSdkVariant bool `blueprint:"mutated"`
193
194 // Set by factories of module types that can only be referenced from variants compiled against
195 // the SDK.
196 AlwaysSdk bool `blueprint:"mutated"`
197
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900198 HideFromMake bool `blueprint:"mutated"`
199 PreventInstall bool `blueprint:"mutated"`
200
201 Installable *bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700202}
203
204type Module struct {
hamzehc0a671f2021-07-22 12:05:08 -0700205 fuzz.FuzzModule
Ivan Lozanoffee3342019-08-27 12:03:00 -0700206
Ivan Lozano6a884432020-12-02 09:15:16 -0500207 VendorProperties cc.VendorProperties
208
Ivan Lozanoffee3342019-08-27 12:03:00 -0700209 Properties BaseProperties
210
Aditya Choudhary87b2ab22023-11-17 15:27:06 +0000211 hod android.HostOrDeviceSupported
212 multilib android.Multilib
213 testModule bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700214
Ivan Lozano6a884432020-12-02 09:15:16 -0500215 makeLinkType string
216
Yi Kong46c6e592022-01-20 22:55:00 +0800217 afdo *afdo
Ivan Lozanoffee3342019-08-27 12:03:00 -0700218 compiler compiler
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400219 coverage *coverage
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200220 clippy *clippy
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500221 sanitize *sanitize
Ivan Lozanoffee3342019-08-27 12:03:00 -0700222 cachedToolchain config.Toolchain
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400223 sourceProvider SourceProvider
Andrei Homescuc7767922020-08-05 06:36:19 -0700224 subAndroidMkOnce map[SubAndroidMkProvider]bool
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400225
Ivan Lozano0a468a42024-05-13 21:03:34 -0400226 exportedLinkDirs []string
227
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400228 // Output file to be installed, may be stripped or unstripped.
229 outputFile android.OptionalPath
230
Sasha Smundaka76acba2022-04-18 20:12:56 -0700231 // Cross-reference input file
232 kytheFiles android.Paths
233
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400234 docTimestampFile android.OptionalPath
Jiyong Park99644e92020-11-17 22:21:02 +0900235
236 hideApexVariantFromMake bool
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500237
238 // For apex variants, this is set as apex.min_sdk_version
239 apexSdkVersion android.ApiLevel
Cole Faustb6e6f992023-08-17 17:42:26 -0700240
Colin Crossa14fb6a2024-10-23 16:57:06 -0700241 transitiveAndroidMkSharedLibs depset.DepSet[string]
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000242
243 // Shared flags among stubs build rules of this module
244 sharedFlags cc.SharedFlags
Ivan Lozanoffee3342019-08-27 12:03:00 -0700245}
246
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500247func (mod *Module) Header() bool {
248 //TODO: If Rust libraries provide header variants, this needs to be updated.
249 return false
250}
251
252func (mod *Module) SetPreventInstall() {
253 mod.Properties.PreventInstall = true
254}
255
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500256func (mod *Module) SetHideFromMake() {
257 mod.Properties.HideFromMake = true
258}
259
Jiyong Parkd1e366a2021-10-05 09:12:41 +0900260func (mod *Module) HiddenFromMake() bool {
261 return mod.Properties.HideFromMake
Ivan Lozanod7586b62021-04-01 09:49:36 -0400262}
263
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500264func (mod *Module) SanitizePropDefined() bool {
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500265 // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not
266 // nil since we need compiler to actually sanitize.
267 return mod.sanitize != nil && mod.compiler != nil
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500268}
269
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500270func (mod *Module) IsPrebuilt() bool {
271 if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
272 return true
273 }
274 return false
275}
276
Ivan Lozano52767be2019-10-18 14:49:46 -0700277func (mod *Module) SelectedStl() string {
278 return ""
279}
280
Ivan Lozano2b262972019-11-21 12:30:50 -0800281func (mod *Module) NonCcVariants() bool {
282 if mod.compiler != nil {
Ivan Lozano0a468a42024-05-13 21:03:34 -0400283 if library, ok := mod.compiler.(libraryInterface); ok {
284 return library.buildRlib() || library.buildDylib()
Ivan Lozano2b262972019-11-21 12:30:50 -0800285 }
286 }
287 panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName()))
288}
289
Ivan Lozano52767be2019-10-18 14:49:46 -0700290func (mod *Module) Static() bool {
291 if mod.compiler != nil {
292 if library, ok := mod.compiler.(libraryInterface); ok {
293 return library.static()
294 }
295 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400296 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700297}
298
299func (mod *Module) Shared() bool {
300 if mod.compiler != nil {
301 if library, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano89435d12020-07-31 11:01:18 -0400302 return library.shared()
Ivan Lozano52767be2019-10-18 14:49:46 -0700303 }
304 }
Ivan Lozano89435d12020-07-31 11:01:18 -0400305 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700306}
307
Ivan Lozanod7586b62021-04-01 09:49:36 -0400308func (mod *Module) Dylib() bool {
309 if mod.compiler != nil {
310 if library, ok := mod.compiler.(libraryInterface); ok {
311 return library.dylib()
312 }
313 }
314 return false
315}
316
Ivan Lozanod106efe2023-09-21 23:30:26 -0400317func (mod *Module) Source() bool {
318 if mod.compiler != nil {
319 if library, ok := mod.compiler.(libraryInterface); ok && mod.sourceProvider != nil {
320 return library.source()
321 }
322 }
323 return false
324}
325
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400326func (mod *Module) RlibStd() bool {
327 if mod.compiler != nil {
328 if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() {
329 return library.rlibStd()
330 }
331 }
332 panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName()))
333}
334
Ivan Lozanod7586b62021-04-01 09:49:36 -0400335func (mod *Module) Rlib() bool {
336 if mod.compiler != nil {
337 if library, ok := mod.compiler.(libraryInterface); ok {
338 return library.rlib()
339 }
340 }
341 return false
342}
343
344func (mod *Module) Binary() bool {
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400345 if binary, ok := mod.compiler.(binaryInterface); ok {
346 return binary.binary()
Ivan Lozanod7586b62021-04-01 09:49:36 -0400347 }
348 return false
349}
350
Justin Yun5e035862021-06-29 20:50:37 +0900351func (mod *Module) StaticExecutable() bool {
352 if !mod.Binary() {
353 return false
354 }
Ivan Lozano21fa0a52021-11-01 09:19:45 -0400355 return mod.StaticallyLinked()
Justin Yun5e035862021-06-29 20:50:37 +0900356}
357
Ashutosh Agarwal46e4fad2024-08-27 17:13:12 +0000358func (mod *Module) ApexExclude() bool {
359 if mod.compiler != nil {
360 if library, ok := mod.compiler.(libraryInterface); ok {
361 return library.apexExclude()
362 }
363 }
364 return false
365}
366
Ivan Lozanod7586b62021-04-01 09:49:36 -0400367func (mod *Module) Object() bool {
368 // Rust has no modules which produce only object files.
369 return false
370}
371
Ivan Lozano52767be2019-10-18 14:49:46 -0700372func (mod *Module) Toc() android.OptionalPath {
373 if mod.compiler != nil {
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400374 if lib, ok := mod.compiler.(libraryInterface); ok {
375 return lib.toc()
Ivan Lozano52767be2019-10-18 14:49:46 -0700376 }
377 }
378 panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
379}
380
Colin Crossc511bc52020-04-07 16:50:32 +0000381func (mod *Module) UseSdk() bool {
382 return false
383}
384
Ivan Lozanod7586b62021-04-01 09:49:36 -0400385func (mod *Module) RelativeInstallPath() string {
386 if mod.compiler != nil {
387 return mod.compiler.relativeInstallPath()
388 }
389 return ""
390}
391
Ivan Lozano52767be2019-10-18 14:49:46 -0700392func (mod *Module) UseVndk() bool {
Ivan Lozano6a884432020-12-02 09:15:16 -0500393 return mod.Properties.VndkVersion != ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700394}
395
Jiyong Park7d55b612021-06-11 17:22:09 +0900396func (mod *Module) Bootstrap() bool {
Ivan Lozanoa2268632021-07-22 10:52:06 -0400397 return Bool(mod.Properties.Bootstrap)
Jiyong Park7d55b612021-06-11 17:22:09 +0900398}
399
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400400func (mod *Module) SubName() string {
401 return mod.Properties.SubName
Ivan Lozano52767be2019-10-18 14:49:46 -0700402}
403
Ivan Lozanof1868af2022-04-12 13:08:36 -0400404func (mod *Module) IsVndkPrebuiltLibrary() bool {
405 // Rust modules do not provide VNDK prebuilts
406 return false
407}
408
409func (mod *Module) IsVendorPublicLibrary() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000410 // Rust modules do not currently support vendor_public_library
411 return false
Ivan Lozanof1868af2022-04-12 13:08:36 -0400412}
413
414func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool {
415 // Rust modules to not provide Sdk variants
416 return false
417}
418
Colin Cross127bb8b2020-12-16 16:46:01 -0800419func (c *Module) IsVndkPrivate() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000420 // Rust modules do not currently support VNDK variants
Colin Cross127bb8b2020-12-16 16:46:01 -0800421 return false
422}
423
424func (c *Module) IsLlndk() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000425 // Rust modules do not currently support LLNDK variants
Colin Cross127bb8b2020-12-16 16:46:01 -0800426 return false
427}
428
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400429func (mod *Module) KernelHeadersDecorator() bool {
430 return false
431}
432
Colin Cross1f3f1302021-04-26 18:37:44 -0700433func (m *Module) NeedsLlndkVariants() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000434 // Rust modules do not currently support LLNDK variants
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400435 return false
436}
437
Colin Cross5271fea2021-04-27 13:06:04 -0700438func (m *Module) NeedsVendorPublicLibraryVariants() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000439 // Rust modules do not currently support vendor_public_library
Colin Cross5271fea2021-04-27 13:06:04 -0700440 return false
441}
442
Ivan Lozanod7586b62021-04-01 09:49:36 -0400443func (mod *Module) HasLlndkStubs() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000444 // Rust modules do not currently support LLNDK stubs
Ivan Lozanod7586b62021-04-01 09:49:36 -0400445 return false
446}
447
Ivan Lozano52767be2019-10-18 14:49:46 -0700448func (mod *Module) SdkVersion() string {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000449 return String(mod.Properties.Sdk_version)
Ivan Lozano52767be2019-10-18 14:49:46 -0700450}
451
Colin Crossc511bc52020-04-07 16:50:32 +0000452func (mod *Module) AlwaysSdk() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000453 return mod.Properties.AlwaysSdk
Colin Crossc511bc52020-04-07 16:50:32 +0000454}
455
Jiyong Park2286afd2020-06-16 21:58:53 +0900456func (mod *Module) IsSdkVariant() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000457 return mod.Properties.IsSdkVariant
Jiyong Park2286afd2020-06-16 21:58:53 +0900458}
459
Colin Cross1348ce32020-10-01 13:37:16 -0700460func (mod *Module) SplitPerApiLevel() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000461 return cc.CanUseSdk(mod) && mod.IsCrt()
Colin Cross1348ce32020-10-01 13:37:16 -0700462}
463
Sasha Smundaka76acba2022-04-18 20:12:56 -0700464func (mod *Module) XrefRustFiles() android.Paths {
465 return mod.kytheFiles
466}
467
Ivan Lozanoffee3342019-08-27 12:03:00 -0700468type Deps struct {
Ivan Lozano63bb7682021-03-23 15:53:44 -0400469 Dylibs []string
470 Rlibs []string
471 Rustlibs []string
472 Stdlibs []string
473 ProcMacros []string
474 SharedLibs []string
475 StaticLibs []string
476 WholeStaticLibs []string
477 HeaderLibs []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700478
Ivan Lozano4e5f07d2021-11-04 14:09:38 -0400479 // Used for data dependencies adjacent to tests
480 DataLibs []string
481 DataBins []string
482
Colin Crossfe605e12022-01-23 20:46:16 -0800483 CrtBegin, CrtEnd []string
Ivan Lozanoffee3342019-08-27 12:03:00 -0700484}
485
486type PathDeps struct {
Colin Cross004bd3f2023-10-02 11:39:17 -0700487 DyLibs RustLibraries
488 RLibs RustLibraries
489 SharedLibs android.Paths
490 SharedLibDeps android.Paths
491 StaticLibs android.Paths
492 ProcMacros RustLibraries
493 AfdoProfiles android.Paths
Ivan Lozanof4589012024-11-20 22:18:11 +0000494 LinkerDeps android.Paths
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500495
496 // depFlags and depLinkFlags are rustc and linker (clang) flags.
497 depFlags []string
498 depLinkFlags []string
499
Ivan Lozano85f00cf2025-02-11 20:19:19 +0000500 // track cc static-libs that have Rlib dependencies
Ivan Lozano610eb1a2025-02-12 21:36:49 +0000501 reexportedCcRlibDeps []cc.RustRlibDep
502 reexportedWholeCcRlibDeps []cc.RustRlibDep
503 ccRlibDeps []cc.RustRlibDep
Ivan Lozano85f00cf2025-02-11 20:19:19 +0000504
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400505 // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500506 // Both of these are exported and propagate to dependencies.
Ivan Lozano1f10f682024-11-08 16:16:50 +0000507 linkDirs []string
508 rustLibObjects []string
509 staticLibObjects []string
510 wholeStaticLibObjects []string
511 sharedLibObjects []string
Ivan Lozanof1c84332019-09-20 11:00:37 -0700512
Ivan Lozano0a468a42024-05-13 21:03:34 -0400513 // exportedLinkDirs are exported linkDirs for direct rlib dependencies to
514 // cc_library_static dependants of rlibs.
515 // Track them separately from linkDirs so superfluous -L flags don't get emitted.
516 exportedLinkDirs []string
517
Ivan Lozano45901ed2020-07-24 16:05:01 -0400518 // Used by bindgen modules which call clang
519 depClangFlags []string
520 depIncludePaths android.Paths
Ivan Lozanoddd0bdb2020-08-28 17:00:26 -0400521 depGeneratedHeaders android.Paths
Ivan Lozano45901ed2020-07-24 16:05:01 -0400522 depSystemIncludePaths android.Paths
523
Colin Crossfe605e12022-01-23 20:46:16 -0800524 CrtBegin android.Paths
525 CrtEnd android.Paths
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700526
527 // Paths to generated source files
Ivan Lozano9d74a522020-12-01 09:25:22 -0500528 SrcDeps android.Paths
529 srcProviderFiles android.Paths
Colin Crossb614cd42024-10-11 12:52:21 -0700530
531 directImplementationDeps android.Paths
532 transitiveImplementationDeps []depset.DepSet[android.Path]
Ivan Lozanoffee3342019-08-27 12:03:00 -0700533}
534
535type RustLibraries []RustLibrary
536
537type RustLibrary struct {
538 Path android.Path
539 CrateName string
540}
541
Matthew Maurerbb3add12020-06-25 09:34:12 -0700542type exportedFlagsProducer interface {
Wen-yi Chu41326c12023-09-22 03:58:59 +0000543 exportLinkDirs(...string)
Ivan Lozano1f10f682024-11-08 16:16:50 +0000544 exportRustLibs(...string)
545 exportStaticLibs(...string)
546 exportWholeStaticLibs(...string)
547 exportSharedLibs(...string)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700548}
549
Sasha Smundaka76acba2022-04-18 20:12:56 -0700550type xref interface {
551 XrefRustFiles() android.Paths
552}
553
Matthew Maurerbb3add12020-06-25 09:34:12 -0700554type flagExporter struct {
Ivan Lozano1f10f682024-11-08 16:16:50 +0000555 linkDirs []string
556 ccLinkDirs []string
557 rustLibPaths []string
558 staticLibObjects []string
559 sharedLibObjects []string
560 wholeStaticLibObjects []string
Ivan Lozano610eb1a2025-02-12 21:36:49 +0000561 wholeRustRlibDeps []cc.RustRlibDep
Matthew Maurerbb3add12020-06-25 09:34:12 -0700562}
563
Wen-yi Chu41326c12023-09-22 03:58:59 +0000564func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) {
565 flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...))
Matthew Maurerbb3add12020-06-25 09:34:12 -0700566}
567
Ivan Lozano1f10f682024-11-08 16:16:50 +0000568func (flagExporter *flagExporter) exportRustLibs(flags ...string) {
569 flagExporter.rustLibPaths = android.FirstUniqueStrings(append(flagExporter.rustLibPaths, flags...))
570}
571
572func (flagExporter *flagExporter) exportStaticLibs(flags ...string) {
573 flagExporter.staticLibObjects = android.FirstUniqueStrings(append(flagExporter.staticLibObjects, flags...))
574}
575
576func (flagExporter *flagExporter) exportSharedLibs(flags ...string) {
577 flagExporter.sharedLibObjects = android.FirstUniqueStrings(append(flagExporter.sharedLibObjects, flags...))
578}
579
580func (flagExporter *flagExporter) exportWholeStaticLibs(flags ...string) {
581 flagExporter.wholeStaticLibObjects = android.FirstUniqueStrings(append(flagExporter.wholeStaticLibObjects, flags...))
Ivan Lozano2093af22020-08-25 12:48:19 -0400582}
583
Ivan Lozano7fe65ca2025-02-05 02:22:33 +0000584func (flagExporter *flagExporter) setRustProvider(ctx ModuleContext) {
585 android.SetProvider(ctx, RustFlagExporterInfoProvider, RustFlagExporterInfo{
Ivan Lozano1f10f682024-11-08 16:16:50 +0000586 LinkDirs: flagExporter.linkDirs,
587 RustLibObjects: flagExporter.rustLibPaths,
588 StaticLibObjects: flagExporter.staticLibObjects,
589 WholeStaticLibObjects: flagExporter.wholeStaticLibObjects,
590 SharedLibPaths: flagExporter.sharedLibObjects,
Ivan Lozano610eb1a2025-02-12 21:36:49 +0000591 WholeRustRlibDeps: flagExporter.wholeRustRlibDeps,
Colin Cross0de8a1e2020-09-18 14:15:30 -0700592 })
593}
594
Matthew Maurerbb3add12020-06-25 09:34:12 -0700595var _ exportedFlagsProducer = (*flagExporter)(nil)
596
597func NewFlagExporter() *flagExporter {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700598 return &flagExporter{}
Matthew Maurerbb3add12020-06-25 09:34:12 -0700599}
600
Ivan Lozano7fe65ca2025-02-05 02:22:33 +0000601type RustFlagExporterInfo struct {
Ivan Lozano1f10f682024-11-08 16:16:50 +0000602 Flags []string
603 LinkDirs []string
604 RustLibObjects []string
605 StaticLibObjects []string
606 WholeStaticLibObjects []string
607 SharedLibPaths []string
Ivan Lozano610eb1a2025-02-12 21:36:49 +0000608 WholeRustRlibDeps []cc.RustRlibDep
Colin Cross0de8a1e2020-09-18 14:15:30 -0700609}
610
Ivan Lozano7fe65ca2025-02-05 02:22:33 +0000611var RustFlagExporterInfoProvider = blueprint.NewProvider[RustFlagExporterInfo]()
Colin Cross0de8a1e2020-09-18 14:15:30 -0700612
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400613func (mod *Module) isCoverageVariant() bool {
614 return mod.coverage.Properties.IsCoverageVariant
615}
616
617var _ cc.Coverage = (*Module)(nil)
618
Colin Crosse1a85552024-06-14 12:17:37 -0700619func (mod *Module) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool {
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400620 return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant
621}
622
Ivan Lozanod7586b62021-04-01 09:49:36 -0400623func (mod *Module) VndkVersion() string {
624 return mod.Properties.VndkVersion
625}
626
Ivan Lozano0a468a42024-05-13 21:03:34 -0400627func (mod *Module) ExportedCrateLinkDirs() []string {
628 return mod.exportedLinkDirs
629}
630
Ivan Lozanod7586b62021-04-01 09:49:36 -0400631func (mod *Module) PreventInstall() bool {
632 return mod.Properties.PreventInstall
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400633}
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000634func (c *Module) ForceDisableSanitizers() {
635 c.sanitize.Properties.ForceDisable = true
636}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400637
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400638func (mod *Module) MarkAsCoverageVariant(coverage bool) {
639 mod.coverage.Properties.IsCoverageVariant = coverage
640}
641
642func (mod *Module) EnableCoverageIfNeeded() {
643 mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild
Ivan Lozanoffee3342019-08-27 12:03:00 -0700644}
645
646func defaultsFactory() android.Module {
647 return DefaultsFactory()
648}
649
650type Defaults struct {
651 android.ModuleBase
652 android.DefaultsModuleBase
653}
654
655func DefaultsFactory(props ...interface{}) android.Module {
656 module := &Defaults{}
657
658 module.AddProperties(props...)
659 module.AddProperties(
660 &BaseProperties{},
Yi Kong46c6e592022-01-20 22:55:00 +0800661 &cc.AfdoProperties{},
Ivan Lozano6a884432020-12-02 09:15:16 -0500662 &cc.VendorProperties{},
Jakub Kotur1d640d02021-01-06 12:40:43 +0100663 &BenchmarkProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400664 &BindgenProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700665 &BaseCompilerProperties{},
666 &BinaryCompilerProperties{},
667 &LibraryCompilerProperties{},
668 &ProcMacroCompilerProperties{},
669 &PrebuiltProperties{},
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400670 &SourceProviderProperties{},
Chih-Hung Hsieh41805be2019-10-31 20:56:47 -0700671 &TestProperties{},
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400672 &cc.CoverageProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -0400673 &cc.RustBindgenClangProperties{},
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200674 &ClippyProperties{},
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500675 &SanitizeProperties{},
Pawan Waghccb75582023-08-16 23:58:25 +0000676 &fuzz.FuzzProperties{},
Ivan Lozanoffee3342019-08-27 12:03:00 -0700677 )
678
679 android.InitDefaultsModule(module)
680 return module
681}
682
683func (mod *Module) CrateName() string {
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700684 return mod.compiler.crateName()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700685}
686
Ivan Lozano183a3212019-10-18 14:18:45 -0700687func (mod *Module) CcLibrary() bool {
688 if mod.compiler != nil {
Ivan Lozano45e0e5b2021-11-13 07:42:36 -0500689 if _, ok := mod.compiler.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700690 return true
691 }
692 }
693 return false
694}
695
696func (mod *Module) CcLibraryInterface() bool {
697 if mod.compiler != nil {
Ivan Lozano89435d12020-07-31 11:01:18 -0400698 // use build{Static,Shared}() instead of {static,shared}() here because this might be called before
699 // VariantIs{Static,Shared} is set.
Ivan Lozano806efd32024-12-11 21:38:53 +0000700 if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic() || lib.buildRlib()) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700701 return true
702 }
703 }
704 return false
705}
706
Ivan Lozano61c02cc2023-06-09 14:06:44 -0400707func (mod *Module) RustLibraryInterface() bool {
708 if mod.compiler != nil {
709 if _, ok := mod.compiler.(libraryInterface); ok {
710 return true
711 }
712 }
713 return false
714}
715
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500716func (mod *Module) IsFuzzModule() bool {
717 if _, ok := mod.compiler.(*fuzzDecorator); ok {
718 return true
719 }
720 return false
721}
722
723func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule {
724 return mod.FuzzModule
725}
726
727func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule {
728 if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok {
729 return fuzzer.fuzzPackagedModule
730 }
731 panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName()))
732}
733
Hamzeh Zawawy38917492023-04-05 22:08:46 +0000734func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500735 if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok {
736 return fuzzer.sharedLibraries
737 }
738 panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName()))
739}
740
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400741func (mod *Module) UnstrippedOutputFile() android.Path {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400742 if mod.compiler != nil {
743 return mod.compiler.unstrippedOutputFilePath()
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400744 }
745 return nil
746}
747
Ivan Lozano183a3212019-10-18 14:18:45 -0700748func (mod *Module) SetStatic() {
749 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700750 if library, ok := mod.compiler.(libraryInterface); ok {
751 library.setStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700752 return
753 }
754 }
755 panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName()))
756}
757
758func (mod *Module) SetShared() {
759 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700760 if library, ok := mod.compiler.(libraryInterface); ok {
761 library.setShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700762 return
763 }
764 }
765 panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName()))
766}
767
Ivan Lozano183a3212019-10-18 14:18:45 -0700768func (mod *Module) BuildStaticVariant() bool {
769 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700770 if library, ok := mod.compiler.(libraryInterface); ok {
771 return library.buildStatic()
Ivan Lozano183a3212019-10-18 14:18:45 -0700772 }
773 }
774 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName()))
775}
776
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400777func (mod *Module) BuildRlibVariant() bool {
778 if mod.compiler != nil {
779 if library, ok := mod.compiler.(libraryInterface); ok {
780 return library.buildRlib()
781 }
782 }
783 panic(fmt.Errorf("BuildRlibVariant called on non-library module: %q", mod.BaseModuleName()))
784}
785
Ivan Lozano183a3212019-10-18 14:18:45 -0700786func (mod *Module) BuildSharedVariant() bool {
787 if mod.compiler != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700788 if library, ok := mod.compiler.(libraryInterface); ok {
789 return library.buildShared()
Ivan Lozano183a3212019-10-18 14:18:45 -0700790 }
791 }
792 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName()))
793}
794
Ivan Lozano183a3212019-10-18 14:18:45 -0700795func (mod *Module) Module() android.Module {
796 return mod
797}
798
Ivan Lozano183a3212019-10-18 14:18:45 -0700799func (mod *Module) OutputFile() android.OptionalPath {
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400800 return mod.outputFile
Ivan Lozano183a3212019-10-18 14:18:45 -0700801}
802
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400803func (mod *Module) CoverageFiles() android.Paths {
804 if mod.compiler != nil {
Joel Galensonfa049382021-01-14 16:03:18 -0800805 return android.Paths{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400806 }
807 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName()))
808}
809
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400810// Rust does not produce gcno files, and therefore does not produce a coverage archive.
811func (mod *Module) CoverageOutputFile() android.OptionalPath {
812 return android.OptionalPath{}
813}
814
815func (mod *Module) IsNdk(config android.Config) bool {
816 return false
817}
818
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000819func (mod *Module) IsStubs() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000820 if lib, ok := mod.compiler.(libraryInterface); ok {
821 return lib.BuildStubs()
822 }
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000823 return false
824}
825
Spandan Das10c41362024-12-03 01:33:09 +0000826func (mod *Module) HasStubsVariants() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000827 if lib, ok := mod.compiler.(libraryInterface); ok {
828 return lib.HasStubsVariants()
829 }
Spandan Das10c41362024-12-03 01:33:09 +0000830 return false
831}
832
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000833func (mod *Module) ApexSdkVersion() android.ApiLevel {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000834 return mod.apexSdkVersion
835}
836
837func (mod *Module) RustApexExclude() bool {
838 return mod.ApexExclude()
839}
840
841func (mod *Module) getSharedFlags() *cc.SharedFlags {
842 shared := &mod.sharedFlags
843 if shared.FlagsMap == nil {
844 shared.NumSharedFlags = 0
845 shared.FlagsMap = make(map[string]string)
846 }
847 return shared
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000848}
849
Yu Liu0a37d422025-02-13 02:05:00 +0000850func (mod *Module) ImplementationModuleNameForMake() string {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +0000851 name := mod.BaseModuleName()
852 if versioned, ok := mod.compiler.(cc.VersionedInterface); ok {
853 name = versioned.ImplementationModuleName(name)
854 }
855 return name
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000856}
857
858func (mod *Module) Multilib() string {
859 return mod.Arch().ArchType.Multilib
860}
861
862func (mod *Module) IsCrt() bool {
863 // Rust does not currently provide any crt modules.
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400864 return false
865}
866
Jiyong Park459feca2020-12-15 11:02:21 +0900867func (mod *Module) installable(apexInfo android.ApexInfo) bool {
Jiyong Park2811e072021-09-30 17:25:21 +0900868 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
Jiyong Parkbf8147a2021-05-17 13:19:33 +0900869 return false
870 }
871
Jiyong Park459feca2020-12-15 11:02:21 +0900872 // The apex variant is not installable because it is included in the APEX and won't appear
873 // in the system partition as a standalone file.
874 if !apexInfo.IsForPlatform() {
875 return false
876 }
877
Jiyong Parke54f07e2021-04-07 15:08:04 +0900878 return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
Jiyong Park459feca2020-12-15 11:02:21 +0900879}
880
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500881func (ctx moduleContext) apexVariationName() string {
Colin Crossff694a82023-12-13 15:54:49 -0800882 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
883 return apexInfo.ApexVariationName
Ivan Lozanoe950cda2021-11-09 11:26:04 -0500884}
885
Ivan Lozano183a3212019-10-18 14:18:45 -0700886var _ cc.LinkableInterface = (*Module)(nil)
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000887var _ cc.VersionedLinkableInterface = (*Module)(nil)
Ivan Lozano183a3212019-10-18 14:18:45 -0700888
Ivan Lozanoffee3342019-08-27 12:03:00 -0700889func (mod *Module) Init() android.Module {
890 mod.AddProperties(&mod.Properties)
Ivan Lozano6a884432020-12-02 09:15:16 -0500891 mod.AddProperties(&mod.VendorProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700892
Yi Kong46c6e592022-01-20 22:55:00 +0800893 if mod.afdo != nil {
894 mod.AddProperties(mod.afdo.props()...)
895 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700896 if mod.compiler != nil {
897 mod.AddProperties(mod.compiler.compilerProps()...)
898 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400899 if mod.coverage != nil {
900 mod.AddProperties(mod.coverage.props()...)
901 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200902 if mod.clippy != nil {
903 mod.AddProperties(mod.clippy.props()...)
904 }
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400905 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -0700906 mod.AddProperties(mod.sourceProvider.SourceProviderProps()...)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400907 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500908 if mod.sanitize != nil {
909 mod.AddProperties(mod.sanitize.props()...)
910 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400911
Ivan Lozanoffee3342019-08-27 12:03:00 -0700912 android.InitAndroidArchModule(mod, mod.hod, mod.multilib)
Jiyong Park99644e92020-11-17 22:21:02 +0900913 android.InitApexModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700914
915 android.InitDefaultableModule(mod)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700916 return mod
917}
918
919func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
920 return &Module{
921 hod: hod,
922 multilib: multilib,
923 }
924}
925func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
926 module := newBaseModule(hod, multilib)
Yi Kong46c6e592022-01-20 22:55:00 +0800927 module.afdo = &afdo{}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400928 module.coverage = &coverage{}
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +0200929 module.clippy = &clippy{}
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500930 module.sanitize = &sanitize{}
Ivan Lozanoffee3342019-08-27 12:03:00 -0700931 return module
932}
933
934type ModuleContext interface {
935 android.ModuleContext
936 ModuleContextIntf
937}
938
939type BaseModuleContext interface {
940 android.BaseModuleContext
941 ModuleContextIntf
942}
943
944type DepsContext interface {
945 android.BottomUpMutatorContext
946 ModuleContextIntf
947}
948
949type ModuleContextIntf interface {
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200950 RustModule() *Module
Ivan Lozanoffee3342019-08-27 12:03:00 -0700951 toolchain() config.Toolchain
Ivan Lozanoffee3342019-08-27 12:03:00 -0700952}
953
954type depsContext struct {
955 android.BottomUpMutatorContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700956}
957
958type moduleContext struct {
959 android.ModuleContext
Ivan Lozanoffee3342019-08-27 12:03:00 -0700960}
961
Thiébaud Weksteen1f7f70f2020-06-24 11:32:48 +0200962type baseModuleContext struct {
963 android.BaseModuleContext
964}
965
966func (ctx *moduleContext) RustModule() *Module {
967 return ctx.Module().(*Module)
968}
969
970func (ctx *moduleContext) toolchain() config.Toolchain {
971 return ctx.RustModule().toolchain(ctx)
972}
973
974func (ctx *depsContext) RustModule() *Module {
975 return ctx.Module().(*Module)
976}
977
978func (ctx *depsContext) toolchain() config.Toolchain {
979 return ctx.RustModule().toolchain(ctx)
980}
981
982func (ctx *baseModuleContext) RustModule() *Module {
983 return ctx.Module().(*Module)
984}
985
986func (ctx *baseModuleContext) toolchain() config.Toolchain {
987 return ctx.RustModule().toolchain(ctx)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400988}
989
990func (mod *Module) nativeCoverage() bool {
Matthew Maurera61e31f2021-05-27 11:09:11 -0700991 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
992 if mod.Target().NativeBridge == android.NativeBridgeEnabled {
993 return false
994 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400995 return mod.compiler != nil && mod.compiler.nativeCoverage()
996}
997
Ivan Lozano9eaacc82024-10-30 14:28:17 +0000998func (mod *Module) SetStl(s string) {
999 // STL is a CC concept; do nothing for Rust
1000}
1001
1002func (mod *Module) SetSdkVersion(s string) {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00001003 mod.Properties.Sdk_version = StringPtr(s)
Ivan Lozano9eaacc82024-10-30 14:28:17 +00001004}
1005
1006func (mod *Module) SetMinSdkVersion(s string) {
1007 mod.Properties.Min_sdk_version = StringPtr(s)
1008}
1009
1010func (mod *Module) VersionedInterface() cc.VersionedInterface {
1011 if _, ok := mod.compiler.(cc.VersionedInterface); ok {
1012 return mod.compiler.(cc.VersionedInterface)
1013 }
1014 return nil
1015}
1016
Ivan Lozanod7586b62021-04-01 09:49:36 -04001017func (mod *Module) EverInstallable() bool {
1018 return mod.compiler != nil &&
1019 // Check to see whether the module is actually ever installable.
1020 mod.compiler.everInstallable()
1021}
1022
1023func (mod *Module) Installable() *bool {
1024 return mod.Properties.Installable
1025}
1026
Ivan Lozano872d5792022-03-23 17:31:39 -04001027func (mod *Module) ProcMacro() bool {
1028 if pm, ok := mod.compiler.(procMacroInterface); ok {
1029 return pm.ProcMacro()
1030 }
1031 return false
1032}
1033
Ivan Lozanoffee3342019-08-27 12:03:00 -07001034func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
1035 if mod.cachedToolchain == nil {
1036 mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
1037 }
1038 return mod.cachedToolchain
1039}
1040
Thiébaud Weksteen31f1bb82020-08-27 13:37:29 +02001041func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain {
1042 return cc_config.FindToolchain(ctx.Os(), ctx.Arch())
1043}
1044
Ivan Lozanoffee3342019-08-27 12:03:00 -07001045func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
1046}
1047
1048func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
1049 ctx := &moduleContext{
1050 ModuleContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001051 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001052
Colin Crossff694a82023-12-13 15:54:49 -08001053 apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
Jiyong Park99644e92020-11-17 22:21:02 +09001054 if !apexInfo.IsForPlatform() {
1055 mod.hideApexVariantFromMake = true
1056 }
1057
Ivan Lozanoffee3342019-08-27 12:03:00 -07001058 toolchain := mod.toolchain(ctx)
Ivan Lozano6a884432020-12-02 09:15:16 -05001059 mod.makeLinkType = cc.GetMakeLinkType(actx, mod)
1060
Ivan Lozanof1868af2022-04-12 13:08:36 -04001061 mod.Properties.SubName = cc.GetSubnameProperty(actx, mod)
Matthew Maurera61e31f2021-05-27 11:09:11 -07001062
Ivan Lozanoffee3342019-08-27 12:03:00 -07001063 if !toolchain.Supported() {
1064 // This toolchain's unsupported, there's nothing to do for this mod.
1065 return
1066 }
1067
1068 deps := mod.depsToPaths(ctx)
Ivan Lozano0a468a42024-05-13 21:03:34 -04001069 // Export linkDirs for CC rust generatedlibs
1070 mod.exportedLinkDirs = append(mod.exportedLinkDirs, deps.exportedLinkDirs...)
1071 mod.exportedLinkDirs = append(mod.exportedLinkDirs, deps.linkDirs...)
1072
Ivan Lozanoffee3342019-08-27 12:03:00 -07001073 flags := Flags{
1074 Toolchain: toolchain,
1075 }
1076
Ivan Lozano67eada32021-09-23 11:50:33 -04001077 // Calculate rustc flags
Yi Kong46c6e592022-01-20 22:55:00 +08001078 if mod.afdo != nil {
Vinh Trancde10162023-03-09 22:07:19 -05001079 flags, deps = mod.afdo.flags(actx, flags, deps)
Yi Kong46c6e592022-01-20 22:55:00 +08001080 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001081 if mod.compiler != nil {
1082 flags = mod.compiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -04001083 flags = mod.compiler.cfgFlags(ctx, flags)
Jihoon Kang091ffd82024-10-03 01:13:24 +00001084 flags = mod.compiler.featureFlags(ctx, mod, flags)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001085 }
1086 if mod.coverage != nil {
1087 flags, deps = mod.coverage.flags(ctx, flags, deps)
1088 }
Thiébaud Weksteen92f703b2020-06-22 13:28:02 +02001089 if mod.clippy != nil {
1090 flags, deps = mod.clippy.flags(ctx, flags, deps)
1091 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001092 if mod.sanitize != nil {
1093 flags, deps = mod.sanitize.flags(ctx, flags, deps)
1094 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001095
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001096 // SourceProvider needs to call GenerateSource() before compiler calls
1097 // compile() so it can provide the source. A SourceProvider has
1098 // multiple variants (e.g. source, rlib, dylib). Only the "source"
1099 // variant is responsible for effectively generating the source. The
1100 // remaining variants relies on the "source" variant output.
Ivan Lozano26ecd6c2020-07-31 13:40:31 -04001101 if mod.sourceProvider != nil {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001102 if mod.compiler.(libraryInterface).source() {
1103 mod.sourceProvider.GenerateSource(ctx, deps)
1104 mod.sourceProvider.setSubName(ctx.ModuleSubDir())
1105 } else {
Yu Liu727204c2025-01-23 20:58:32 +00001106 sourceMod := actx.GetDirectDepProxyWithTag(mod.Name(), sourceDepTag)
1107 sourceLib := android.OtherModuleProviderOrDefault(ctx, sourceMod, RustInfoProvider).SourceProviderInfo
1108 mod.sourceProvider.setOutputFiles(sourceLib.Srcs)
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001109 }
Colin Crossa6182ab2024-08-21 10:47:44 -07001110 ctx.CheckbuildFile(mod.sourceProvider.Srcs()...)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -04001111 }
1112
1113 if mod.compiler != nil && !mod.compiler.Disabled() {
Thiébaud Weksteenee6a89b2021-02-25 16:30:57 +01001114 mod.compiler.initialize(ctx)
Sasha Smundaka76acba2022-04-18 20:12:56 -07001115 buildOutput := mod.compiler.compile(ctx, flags, deps)
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001116 if ctx.Failed() {
1117 return
1118 }
Sasha Smundaka76acba2022-04-18 20:12:56 -07001119 mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile)
Colin Crossa6182ab2024-08-21 10:47:44 -07001120 ctx.CheckbuildFile(buildOutput.outputFile)
Sasha Smundaka76acba2022-04-18 20:12:56 -07001121 if buildOutput.kytheFile != nil {
1122 mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile)
1123 }
Ivan Lozano8d10fc32021-11-05 16:36:47 -04001124 bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
Jiyong Park459feca2020-12-15 11:02:21 +09001125
Dan Albert06feee92021-03-19 15:06:02 -07001126 mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
1127
Colin Crossff694a82023-12-13 15:54:49 -08001128 apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
Ivan Lozano872d5792022-03-23 17:31:39 -04001129 if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
Jiyong Parkd1e366a2021-10-05 09:12:41 +09001130 // If the module has been specifically configure to not be installed then
1131 // hide from make as otherwise it will break when running inside make as the
1132 // output path to install will not be specified. Not all uninstallable
1133 // modules can be hidden from make as some are needed for resolving make
Ivan Lozano872d5792022-03-23 17:31:39 -04001134 // side dependencies. In particular, proc-macros need to be captured in the
1135 // host snapshot.
Jiyong Parkd1e366a2021-10-05 09:12:41 +09001136 mod.HideFromMake()
Spandan Das034af2c2024-10-30 21:45:09 +00001137 mod.SkipInstall()
Jiyong Parkd1e366a2021-10-05 09:12:41 +09001138 } else if !mod.installable(apexInfo) {
1139 mod.SkipInstall()
1140 }
1141
1142 // Still call install though, the installs will be stored as PackageSpecs to allow
1143 // using the outputs in a genrule.
1144 if mod.OutputFile().Valid() {
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +02001145 mod.compiler.install(ctx)
Jiyong Parkd1e366a2021-10-05 09:12:41 +09001146 if ctx.Failed() {
1147 return
1148 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04001149 // Export your own directory as a linkDir
1150 mod.exportedLinkDirs = append(mod.exportedLinkDirs, linkPathFromFilePath(mod.OutputFile().Path()))
1151
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001152 }
Chris Wailes74be7642021-07-22 16:20:28 -07001153
Colin Crossb614cd42024-10-11 12:52:21 -07001154 android.SetProvider(ctx, cc.ImplementationDepInfoProvider, &cc.ImplementationDepInfo{
1155 ImplementationDeps: depset.New(depset.PREORDER, deps.directImplementationDeps, deps.transitiveImplementationDeps),
1156 })
1157
Chris Wailes74be7642021-07-22 16:20:28 -07001158 ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001159 }
Wei Lia1aa2972024-06-21 13:08:51 -07001160
Yu Liuf6f85492025-01-13 21:02:36 +00001161 linkableInfo := cc.CreateCommonLinkableInfo(ctx, mod)
Yu Liu8024b922024-12-20 23:31:32 +00001162 linkableInfo.Static = mod.Static()
1163 linkableInfo.Shared = mod.Shared()
1164 linkableInfo.CrateName = mod.CrateName()
1165 linkableInfo.ExportedCrateLinkDirs = mod.ExportedCrateLinkDirs()
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00001166 if lib, ok := mod.compiler.(cc.VersionedInterface); ok {
1167 linkableInfo.StubsVersion = lib.StubsVersion()
1168 }
1169
Yu Liu8024b922024-12-20 23:31:32 +00001170 android.SetProvider(ctx, cc.LinkableInfoProvider, linkableInfo)
1171
1172 rustInfo := &RustInfo{
1173 AndroidMkSuffix: mod.AndroidMkSuffix(),
1174 RustSubName: mod.Properties.RustSubName,
1175 TransitiveAndroidMkSharedLibs: mod.transitiveAndroidMkSharedLibs,
Yu Liu2a815b62025-02-21 20:46:25 +00001176 XrefRustFiles: mod.XrefRustFiles(),
Yu Liu88408122025-03-04 18:46:24 +00001177 DocTimestampFile: mod.docTimestampFile,
Yu Liu8024b922024-12-20 23:31:32 +00001178 }
1179 if mod.compiler != nil {
1180 rustInfo.CompilerInfo = &CompilerInfo{
1181 NoStdlibs: mod.compiler.noStdlibs(),
1182 StdLinkageForDevice: mod.compiler.stdLinkage(true),
1183 StdLinkageForNonDevice: mod.compiler.stdLinkage(false),
1184 }
1185 if lib, ok := mod.compiler.(libraryInterface); ok {
1186 rustInfo.CompilerInfo.LibraryInfo = &LibraryInfo{
1187 Dylib: lib.dylib(),
1188 Rlib: lib.rlib(),
1189 }
1190 }
1191 if lib, ok := mod.compiler.(cc.SnapshotInterface); ok {
1192 rustInfo.SnapshotInfo = &cc.SnapshotInfo{
1193 SnapshotAndroidMkSuffix: lib.SnapshotAndroidMkSuffix(),
1194 }
1195 }
1196 }
1197 if mod.sourceProvider != nil {
Yu Liu727204c2025-01-23 20:58:32 +00001198 rustInfo.SourceProviderInfo = &SourceProviderInfo{
1199 Srcs: mod.sourceProvider.Srcs(),
1200 }
Yu Liu8024b922024-12-20 23:31:32 +00001201 if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
Yu Liu727204c2025-01-23 20:58:32 +00001202 rustInfo.SourceProviderInfo.ProtobufDecoratorInfo = &ProtobufDecoratorInfo{}
Yu Liu8024b922024-12-20 23:31:32 +00001203 }
1204 }
1205 android.SetProvider(ctx, RustInfoProvider, rustInfo)
Yu Liu986d98c2024-11-12 00:28:11 +00001206
Ivan Lozano9eaacc82024-10-30 14:28:17 +00001207 ccInfo := &cc.CcInfo{
1208 IsPrebuilt: mod.IsPrebuilt(),
1209 }
1210
Ivan Lozano9587f452025-01-08 03:17:19 +00001211 // Define the linker info if compiler != nil because Rust currently
1212 // does compilation and linking in one step. If this changes in the future,
1213 // move this as appropriate.
Cole Faustc9b88c92025-02-06 17:58:26 -08001214 baseCompilerProps := mod.compiler.baseCompilerProps()
Ivan Lozano9587f452025-01-08 03:17:19 +00001215 ccInfo.LinkerInfo = &cc.LinkerInfo{
Cole Faustc9b88c92025-02-06 17:58:26 -08001216 WholeStaticLibs: baseCompilerProps.Whole_static_libs.GetOrDefault(ctx, nil),
1217 StaticLibs: baseCompilerProps.Static_libs.GetOrDefault(ctx, nil),
1218 SharedLibs: baseCompilerProps.Shared_libs.GetOrDefault(ctx, nil),
Ivan Lozano9587f452025-01-08 03:17:19 +00001219 }
1220
Ivan Lozano9eaacc82024-10-30 14:28:17 +00001221 android.SetProvider(ctx, cc.CcInfoProvider, ccInfo)
1222
mrziwang0cbd3b02024-06-20 16:39:25 -07001223 mod.setOutputFiles(ctx)
Wei Lia1aa2972024-06-21 13:08:51 -07001224
1225 buildComplianceMetadataInfo(ctx, mod, deps)
Cole Faust58eef4f2025-01-29 15:14:17 -08001226
1227 moduleInfoJSON := ctx.ModuleInfoJSON()
1228 if mod.compiler != nil {
1229 mod.compiler.moduleInfoJSON(ctx, moduleInfoJSON)
1230 }
mrziwang0cbd3b02024-06-20 16:39:25 -07001231}
1232
1233func (mod *Module) setOutputFiles(ctx ModuleContext) {
1234 if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) {
1235 ctx.SetOutputFiles(mod.sourceProvider.Srcs(), "")
1236 } else if mod.OutputFile().Valid() {
1237 ctx.SetOutputFiles(android.Paths{mod.OutputFile().Path()}, "")
1238 } else {
1239 ctx.SetOutputFiles(android.Paths{}, "")
1240 }
1241 if mod.compiler != nil {
1242 ctx.SetOutputFiles(android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), "unstripped")
1243 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001244}
1245
Wei Lia1aa2972024-06-21 13:08:51 -07001246func buildComplianceMetadataInfo(ctx *moduleContext, mod *Module, deps PathDeps) {
1247 // Dump metadata that can not be done in android/compliance-metadata.go
1248 metadataInfo := ctx.ComplianceMetadataInfo()
1249 metadataInfo.SetStringValue(android.ComplianceMetadataProp.IS_STATIC_LIB, strconv.FormatBool(mod.Static()))
1250 metadataInfo.SetStringValue(android.ComplianceMetadataProp.BUILT_FILES, mod.outputFile.String())
1251
1252 // Static libs
Yu Liu727204c2025-01-23 20:58:32 +00001253 staticDeps := ctx.GetDirectDepsProxyWithTag(rlibDepTag)
Wei Lia1aa2972024-06-21 13:08:51 -07001254 staticDepNames := make([]string, 0, len(staticDeps))
1255 for _, dep := range staticDeps {
1256 staticDepNames = append(staticDepNames, dep.Name())
1257 }
Yu Liu727204c2025-01-23 20:58:32 +00001258 ccStaticDeps := ctx.GetDirectDepsProxyWithTag(cc.StaticDepTag(false))
Wei Lia1aa2972024-06-21 13:08:51 -07001259 for _, dep := range ccStaticDeps {
1260 staticDepNames = append(staticDepNames, dep.Name())
1261 }
1262
1263 staticDepPaths := make([]string, 0, len(deps.StaticLibs)+len(deps.RLibs))
1264 // C static libraries
1265 for _, dep := range deps.StaticLibs {
1266 staticDepPaths = append(staticDepPaths, dep.String())
1267 }
1268 // Rust static libraries
1269 for _, dep := range deps.RLibs {
1270 staticDepPaths = append(staticDepPaths, dep.Path.String())
1271 }
1272 metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames))
1273 metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.FirstUniqueStrings(staticDepPaths))
1274
1275 // C Whole static libs
Yu Liu727204c2025-01-23 20:58:32 +00001276 ccWholeStaticDeps := ctx.GetDirectDepsProxyWithTag(cc.StaticDepTag(true))
Wei Lia1aa2972024-06-21 13:08:51 -07001277 wholeStaticDepNames := make([]string, 0, len(ccWholeStaticDeps))
1278 for _, dep := range ccStaticDeps {
1279 wholeStaticDepNames = append(wholeStaticDepNames, dep.Name())
1280 }
1281 metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames))
1282}
1283
Ivan Lozanoffee3342019-08-27 12:03:00 -07001284func (mod *Module) deps(ctx DepsContext) Deps {
1285 deps := Deps{}
1286
1287 if mod.compiler != nil {
1288 deps = mod.compiler.compilerDeps(ctx, deps)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -04001289 }
1290 if mod.sourceProvider != nil {
Andrei Homescuc7767922020-08-05 06:36:19 -07001291 deps = mod.sourceProvider.SourceProviderDeps(ctx, deps)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001292 }
1293
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001294 if mod.coverage != nil {
1295 deps = mod.coverage.deps(ctx, deps)
1296 }
1297
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001298 if mod.sanitize != nil {
1299 deps = mod.sanitize.deps(ctx, deps)
1300 }
1301
Ivan Lozanoffee3342019-08-27 12:03:00 -07001302 deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
1303 deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
Matthew Maurer0f003b12020-06-29 14:34:06 -07001304 deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001305 deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
1306 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1307 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
Andrew Walbran797e4be2022-03-07 15:41:53 +00001308 deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs)
Ivan Lozano63bb7682021-03-23 15:53:44 -04001309 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001310 return deps
1311
1312}
1313
Ivan Lozanoffee3342019-08-27 12:03:00 -07001314type dependencyTag struct {
1315 blueprint.BaseDependencyTag
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001316 name string
1317 library bool
1318 procMacro bool
Colin Cross65cb3142021-12-10 23:05:02 +00001319 dynamic bool
Ivan Lozanoffee3342019-08-27 12:03:00 -07001320}
1321
Jiyong Park65b62242020-11-25 12:44:59 +09001322// InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive
1323// dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary.
1324func (d dependencyTag) InstallDepNeeded() bool {
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001325 return d.library || d.procMacro
Jiyong Park65b62242020-11-25 12:44:59 +09001326}
1327
1328var _ android.InstallNeededDependencyTag = dependencyTag{}
1329
Colin Cross65cb3142021-12-10 23:05:02 +00001330func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
1331 if d.library && d.dynamic {
1332 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
1333 }
1334 return nil
1335}
1336
Yu Liuc8884602024-03-15 18:48:38 +00001337func (d dependencyTag) PropagateAconfigValidation() bool {
1338 return d == rlibDepTag || d == sourceDepTag
1339}
1340
1341var _ android.PropagateAconfigValidationDependencyTag = dependencyTag{}
1342
Colin Cross65cb3142021-12-10 23:05:02 +00001343var _ android.LicenseAnnotationsDependencyTag = dependencyTag{}
1344
Ivan Lozanoffee3342019-08-27 12:03:00 -07001345var (
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04001346 customBindgenDepTag = dependencyTag{name: "customBindgenTag"}
1347 rlibDepTag = dependencyTag{name: "rlibTag", library: true}
Colin Cross65cb3142021-12-10 23:05:02 +00001348 dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true}
Jaewoong Jung18aefc12020-12-21 09:11:10 -08001349 procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +02001350 sourceDepTag = dependencyTag{name: "source"}
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04001351 dataLibDepTag = dependencyTag{name: "data lib"}
1352 dataBinDepTag = dependencyTag{name: "data bin"}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001353)
1354
Jiyong Park99644e92020-11-17 22:21:02 +09001355func IsDylibDepTag(depTag blueprint.DependencyTag) bool {
1356 tag, ok := depTag.(dependencyTag)
1357 return ok && tag == dylibDepTag
1358}
1359
Jiyong Park94e22fd2021-04-08 18:19:15 +09001360func IsRlibDepTag(depTag blueprint.DependencyTag) bool {
1361 tag, ok := depTag.(dependencyTag)
1362 return ok && tag == rlibDepTag
1363}
1364
Matthew Maurer0f003b12020-06-29 14:34:06 -07001365type autoDep struct {
1366 variation string
1367 depTag dependencyTag
1368}
1369
1370var (
Colin Cross8a49a3d2024-05-20 12:22:27 -07001371 sourceVariation = "source"
1372 rlibVariation = "rlib"
1373 dylibVariation = "dylib"
1374 rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag}
1375 dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag}
Matthew Maurer0f003b12020-06-29 14:34:06 -07001376)
1377
1378type autoDeppable interface {
Liz Kammer356f7d42021-01-26 09:18:53 -05001379 autoDep(ctx android.BottomUpMutatorContext) autoDep
Matthew Maurer0f003b12020-06-29 14:34:06 -07001380}
1381
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001382func (mod *Module) begin(ctx BaseModuleContext) {
1383 if mod.coverage != nil {
1384 mod.coverage.begin(ctx)
1385 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -05001386 if mod.sanitize != nil {
1387 mod.sanitize.begin(ctx)
1388 }
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00001389
1390 if mod.UseSdk() && mod.IsSdkVariant() {
1391 sdkVersion := ""
1392 if ctx.Device() {
1393 sdkVersion = mod.SdkVersion()
1394 }
1395 version, err := cc.NativeApiLevelFromUser(ctx, sdkVersion)
1396 if err != nil {
1397 ctx.PropertyErrorf("sdk_version", err.Error())
1398 mod.Properties.Sdk_version = nil
1399 } else {
1400 mod.Properties.Sdk_version = StringPtr(version.String())
1401 }
1402 }
1403
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001404}
1405
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001406func (mod *Module) Prebuilt() *android.Prebuilt {
Ivan Lozano872d5792022-03-23 17:31:39 -04001407 if p, ok := mod.compiler.(rustPrebuilt); ok {
Ivan Lozanofba2aa22021-11-11 09:29:07 -05001408 return p.prebuilt()
1409 }
1410 return nil
1411}
1412
Kiyoung Kim37693d02024-04-04 09:56:15 +09001413func (mod *Module) Symlinks() []string {
1414 // TODO update this to return the list of symlinks when Rust supports defining symlinks
1415 return nil
1416}
1417
Yu Liu8024b922024-12-20 23:31:32 +00001418func rustMakeLibName(rustInfo *RustInfo, linkableInfo *cc.LinkableInfo, commonInfo *android.CommonModuleInfo, depName string) string {
1419 if rustInfo != nil {
Justin Yun24b246a2023-03-16 10:36:16 +09001420 // Use base module name for snapshots when exporting to Makefile.
Yu Liu8024b922024-12-20 23:31:32 +00001421 if rustInfo.SnapshotInfo != nil {
Yu Liu0a37d422025-02-13 02:05:00 +00001422 baseName := commonInfo.BaseModuleName
Yu Liu8024b922024-12-20 23:31:32 +00001423 return baseName + rustInfo.SnapshotInfo.SnapshotAndroidMkSuffix + rustInfo.AndroidMkSuffix
Justin Yun24b246a2023-03-16 10:36:16 +09001424 }
1425 }
Yu Liu8024b922024-12-20 23:31:32 +00001426 return cc.MakeLibName(nil, linkableInfo, commonInfo, depName)
Justin Yun24b246a2023-03-16 10:36:16 +09001427}
1428
Yu Liu8024b922024-12-20 23:31:32 +00001429func collectIncludedProtos(mod *Module, rustInfo *RustInfo, linkableInfo *cc.LinkableInfo) {
Ivan Lozanod106efe2023-09-21 23:30:26 -04001430 if protoMod, ok := mod.sourceProvider.(*protobufDecorator); ok {
Yu Liu8024b922024-12-20 23:31:32 +00001431 if rustInfo.SourceProviderInfo.ProtobufDecoratorInfo != nil {
1432 protoMod.additionalCrates = append(protoMod.additionalCrates, linkableInfo.CrateName)
Ivan Lozanod106efe2023-09-21 23:30:26 -04001433 }
1434 }
1435}
Andrew Walbran52533232024-03-19 11:36:04 +00001436
Ivan Lozanoffee3342019-08-27 12:03:00 -07001437func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
1438 var depPaths PathDeps
1439
Yu Liu8024b922024-12-20 23:31:32 +00001440 directRlibDeps := []*cc.LinkableInfo{}
1441 directDylibDeps := []*cc.LinkableInfo{}
1442 directProcMacroDeps := []*cc.LinkableInfo{}
Jiyong Park7d55b612021-06-11 17:22:09 +09001443 directSharedLibDeps := []cc.SharedLibraryInfo{}
Yu Liu8024b922024-12-20 23:31:32 +00001444 directStaticLibDeps := [](*cc.LinkableInfo){}
1445 directSrcProvidersDeps := []*android.ModuleProxy{}
1446 directSrcDeps := []android.SourceFilesInfo{}
Ivan Lozanoffee3342019-08-27 12:03:00 -07001447
Ivan Lozanoe950cda2021-11-09 11:26:04 -05001448 // For the dependency from platform to apex, use the latest stubs
1449 mod.apexSdkVersion = android.FutureApiLevel
Colin Crossff694a82023-12-13 15:54:49 -08001450 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
Ivan Lozanoe950cda2021-11-09 11:26:04 -05001451 if !apexInfo.IsForPlatform() {
1452 mod.apexSdkVersion = apexInfo.MinSdkVersion
1453 }
1454
1455 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
1456 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
1457 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
1458 // (b/144430859)
1459 mod.apexSdkVersion = android.FutureApiLevel
1460 }
1461
Spandan Das604f3762023-03-16 22:51:40 +00001462 skipModuleList := map[string]bool{}
1463
Colin Crossa14fb6a2024-10-23 16:57:06 -07001464 var transitiveAndroidMkSharedLibs []depset.DepSet[string]
Cole Faustb6e6f992023-08-17 17:42:26 -07001465 var directAndroidMkSharedLibs []string
Wen-yi Chu41326c12023-09-22 03:58:59 +00001466
Yu Liu8024b922024-12-20 23:31:32 +00001467 ctx.VisitDirectDepsProxy(func(dep android.ModuleProxy) {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001468 depName := ctx.OtherModuleName(dep)
1469 depTag := ctx.OtherModuleDependencyTag(dep)
Ivan Lozano806efd32024-12-11 21:38:53 +00001470 modStdLinkage := mod.compiler.stdLinkage(ctx.Device())
1471
Spandan Das604f3762023-03-16 22:51:40 +00001472 if _, exists := skipModuleList[depName]; exists {
1473 return
1474 }
A. Cody Schuffelenc183e3a2023-08-14 21:09:47 -07001475
1476 if depTag == android.DarwinUniversalVariantTag {
1477 return
1478 }
1479
Yu Liu8024b922024-12-20 23:31:32 +00001480 rustInfo, hasRustInfo := android.OtherModuleProvider(ctx, dep, RustInfoProvider)
1481 ccInfo, _ := android.OtherModuleProvider(ctx, dep, cc.CcInfoProvider)
1482 linkableInfo, hasLinkableInfo := android.OtherModuleProvider(ctx, dep, cc.LinkableInfoProvider)
Yu Liuf22120f2025-03-13 18:36:35 +00001483 commonInfo := android.OtherModulePointerProviderOrDefault(ctx, dep, android.CommonModuleInfoProvider)
Yu Liu8024b922024-12-20 23:31:32 +00001484 if hasRustInfo && !linkableInfo.Static && !linkableInfo.Shared {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001485 //Handle Rust Modules
Yu Liuf22120f2025-03-13 18:36:35 +00001486 makeLibName := rustMakeLibName(rustInfo, linkableInfo, commonInfo, depName+rustInfo.RustSubName)
Ivan Lozano70e0a072019-09-13 14:23:15 -07001487
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001488 switch {
1489 case depTag == dylibDepTag:
Yu Liu8024b922024-12-20 23:31:32 +00001490 dylib := rustInfo.CompilerInfo.LibraryInfo
1491 if dylib == nil || !dylib.Dylib {
Ivan Lozanoffee3342019-08-27 12:03:00 -07001492 ctx.ModuleErrorf("mod %q not an dylib library", depName)
1493 return
1494 }
Yu Liu8024b922024-12-20 23:31:32 +00001495 directDylibDeps = append(directDylibDeps, linkableInfo)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001496 mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001497 mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
1498
Colin Crossb614cd42024-10-11 12:52:21 -07001499 depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, ""))
1500 if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok {
1501 depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps)
1502 }
1503
Yu Liu8024b922024-12-20 23:31:32 +00001504 if !rustInfo.CompilerInfo.NoStdlibs {
1505 rustDepStdLinkage := rustInfo.CompilerInfo.StdLinkageForNonDevice
1506 if ctx.Device() {
1507 rustDepStdLinkage = rustInfo.CompilerInfo.StdLinkageForDevice
1508 }
Ivan Lozano806efd32024-12-11 21:38:53 +00001509 if rustDepStdLinkage != modStdLinkage {
1510 ctx.ModuleErrorf("Rust dependency %q has the wrong StdLinkage; expected %#v, got %#v", depName, modStdLinkage, rustDepStdLinkage)
1511 return
1512 }
1513 }
1514
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001515 case depTag == rlibDepTag:
Yu Liu8024b922024-12-20 23:31:32 +00001516 rlib := rustInfo.CompilerInfo.LibraryInfo
1517 if rlib == nil || !rlib.Rlib {
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001518 ctx.ModuleErrorf("mod %q not an rlib library", makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001519 return
1520 }
Yu Liu8024b922024-12-20 23:31:32 +00001521 directRlibDeps = append(directRlibDeps, linkableInfo)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001522 mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001523 mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName))
1524
Ivan Lozano0a468a42024-05-13 21:03:34 -04001525 // rust_ffi rlibs may export include dirs, so collect those here.
1526 exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
1527 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
Yu Liu8024b922024-12-20 23:31:32 +00001528 depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(linkableInfo.OutputFile.Path()))
Ivan Lozano0a468a42024-05-13 21:03:34 -04001529
Colin Crossb614cd42024-10-11 12:52:21 -07001530 // rlibs are not installed, so don't add the output file to directImplementationDeps
1531 if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok {
1532 depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps)
1533 }
1534
Yu Liu8024b922024-12-20 23:31:32 +00001535 if !rustInfo.CompilerInfo.NoStdlibs {
1536 rustDepStdLinkage := rustInfo.CompilerInfo.StdLinkageForNonDevice
1537 if ctx.Device() {
1538 rustDepStdLinkage = rustInfo.CompilerInfo.StdLinkageForDevice
1539 }
Ivan Lozano806efd32024-12-11 21:38:53 +00001540 if rustDepStdLinkage != modStdLinkage {
1541 ctx.ModuleErrorf("Rust dependency %q has the wrong StdLinkage; expected %#v, got %#v", depName, modStdLinkage, rustDepStdLinkage)
1542 return
1543 }
1544 }
1545
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001546 if !mod.Rlib() {
1547 depPaths.ccRlibDeps = append(depPaths.ccRlibDeps, exportedInfo.RustRlibDeps...)
1548 } else {
1549 // rlibs need to reexport these
1550 depPaths.reexportedCcRlibDeps = append(depPaths.reexportedCcRlibDeps, exportedInfo.RustRlibDeps...)
1551 }
1552
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001553 case depTag == procMacroDepTag:
Yu Liu8024b922024-12-20 23:31:32 +00001554 directProcMacroDeps = append(directProcMacroDeps, linkableInfo)
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001555 mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
Ivan Lozano0a468a42024-05-13 21:03:34 -04001556 // proc_macro link dirs need to be exported, so collect those here.
Yu Liu8024b922024-12-20 23:31:32 +00001557 depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(linkableInfo.OutputFile.Path()))
Ivan Lozanod106efe2023-09-21 23:30:26 -04001558
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001559 case depTag == sourceDepTag:
Ivan Lozanod106efe2023-09-21 23:30:26 -04001560 if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
Yu Liu8024b922024-12-20 23:31:32 +00001561 collectIncludedProtos(mod, rustInfo, linkableInfo)
Ivan Lozanod106efe2023-09-21 23:30:26 -04001562 }
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001563 case cc.IsStaticDepTag(depTag):
1564 // Rust FFI rlibs should not be declared in a Rust modules
1565 // "static_libs" list as we can't handle them properly at the
1566 // moment (for example, they only produce an rlib-std variant).
1567 // Instead, a normal rust_library variant should be used.
1568 ctx.PropertyErrorf("static_libs",
1569 "found '%s' in static_libs; use a rust_library module in rustlibs instead of a rust_ffi module in static_libs",
1570 depName)
1571
Paul Duffind5cf92e2021-07-09 17:38:55 +01001572 }
1573
Yu Liu8024b922024-12-20 23:31:32 +00001574 transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustInfo.TransitiveAndroidMkSharedLibs)
Cole Faustb6e6f992023-08-17 17:42:26 -07001575
Paul Duffind5cf92e2021-07-09 17:38:55 +01001576 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001577 // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct
1578 // OS/Arch variant is used.
1579 var helper string
1580 if ctx.Host() {
1581 helper = "missing 'host_supported'?"
1582 } else {
1583 helper = "device module defined?"
1584 }
1585
Yu Liu8024b922024-12-20 23:31:32 +00001586 if commonInfo.Target.Os != ctx.Os() {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001587 ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper)
1588 return
Yu Liu8024b922024-12-20 23:31:32 +00001589 } else if commonInfo.Target.Arch.ArchType != ctx.Arch().ArchType {
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001590 ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper)
1591 return
1592 }
Yu Liu8024b922024-12-20 23:31:32 +00001593 directSrcProvidersDeps = append(directSrcProvidersDeps, &dep)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001594 }
1595
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001596 exportedRustInfo, _ := android.OtherModuleProvider(ctx, dep, RustFlagExporterInfoProvider)
Ivan Lozano7fe65ca2025-02-05 02:22:33 +00001597 exportedInfo, _ := android.OtherModuleProvider(ctx, dep, RustFlagExporterInfoProvider)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001598 //Append the dependencies exported objects, except for proc-macros which target a different arch/OS
Colin Cross0de8a1e2020-09-18 14:15:30 -07001599 if depTag != procMacroDepTag {
Colin Cross0de8a1e2020-09-18 14:15:30 -07001600 depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001601 depPaths.rustLibObjects = append(depPaths.rustLibObjects, exportedInfo.RustLibObjects...)
1602 depPaths.sharedLibObjects = append(depPaths.sharedLibObjects, exportedInfo.SharedLibPaths...)
1603 depPaths.staticLibObjects = append(depPaths.staticLibObjects, exportedInfo.StaticLibObjects...)
1604 depPaths.wholeStaticLibObjects = append(depPaths.wholeStaticLibObjects, exportedInfo.WholeStaticLibObjects...)
Ivan Lozano0a468a42024-05-13 21:03:34 -04001605 depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001606
1607 depPaths.reexportedWholeCcRlibDeps = append(depPaths.reexportedWholeCcRlibDeps, exportedRustInfo.WholeRustRlibDeps...)
1608 if !mod.Rlib() {
1609 depPaths.ccRlibDeps = append(depPaths.ccRlibDeps, exportedRustInfo.WholeRustRlibDeps...)
1610 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001611 }
1612
Ivan Lozanoffee3342019-08-27 12:03:00 -07001613 if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
Yu Liu8024b922024-12-20 23:31:32 +00001614 linkFile := linkableInfo.UnstrippedOutputFile
Wen-yi Chu41326c12023-09-22 03:58:59 +00001615 linkDir := linkPathFromFilePath(linkFile)
Matthew Maurerbb3add12020-06-25 09:34:12 -07001616 if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
Wen-yi Chu41326c12023-09-22 03:58:59 +00001617 lib.exportLinkDirs(linkDir)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001618 }
1619 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04001620
Ivan Lozanod106efe2023-09-21 23:30:26 -04001621 if depTag == sourceDepTag {
1622 if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() {
Yu Liu8024b922024-12-20 23:31:32 +00001623 if rustInfo.SourceProviderInfo.ProtobufDecoratorInfo != nil {
Colin Cross313aa542023-12-13 13:47:44 -08001624 exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
Ivan Lozanod106efe2023-09-21 23:30:26 -04001625 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1626 }
1627 }
1628 }
Yu Liu8024b922024-12-20 23:31:32 +00001629 } else if hasLinkableInfo {
Ivan Lozano52767be2019-10-18 14:49:46 -07001630 //Handle C dependencies
Yu Liuf22120f2025-03-13 18:36:35 +00001631 makeLibName := cc.MakeLibName(ccInfo, linkableInfo, commonInfo, depName)
Yu Liu8024b922024-12-20 23:31:32 +00001632 if !hasRustInfo {
1633 if commonInfo.Target.Os != ctx.Os() {
Ivan Lozano52767be2019-10-18 14:49:46 -07001634 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1635 return
1636 }
Yu Liu8024b922024-12-20 23:31:32 +00001637 if commonInfo.Target.Arch.ArchType != ctx.Arch().ArchType {
Ivan Lozano52767be2019-10-18 14:49:46 -07001638 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
1639 return
1640 }
Ivan Lozano70e0a072019-09-13 14:23:15 -07001641 }
Ivan Lozano1f10f682024-11-08 16:16:50 +00001642 ccLibPath := linkableInfo.OutputFile
1643 if !ccLibPath.Valid() {
Colin Crossa86ea0e2023-08-01 09:57:22 -07001644 if !ctx.Config().AllowMissingDependencies() {
1645 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
1646 } else {
1647 ctx.AddMissingDependencies([]string{depName})
1648 }
1649 return
Ivan Lozanoffee3342019-08-27 12:03:00 -07001650 }
1651
Ivan Lozano1f10f682024-11-08 16:16:50 +00001652 linkPath := linkPathFromFilePath(ccLibPath.Path())
Colin Crossa86ea0e2023-08-01 09:57:22 -07001653
Ivan Lozanoffee3342019-08-27 12:03:00 -07001654 exportDep := false
Colin Cross6e511a92020-07-27 21:26:48 -07001655 switch {
1656 case cc.IsStaticDepTag(depTag):
Ivan Lozano63bb7682021-03-23 15:53:44 -04001657 if cc.IsWholeStaticLib(depTag) {
1658 // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail
1659 // if the library is not prefixed by "lib".
Ivan Lozanofdadcd72021-11-01 09:04:23 -04001660 if mod.Binary() {
Ivan Lozanofdadcd72021-11-01 09:04:23 -04001661 // Since binaries don't need to 'rebundle' these like libraries and only use these for the
1662 // final linkage, pass the args directly to the linker to handle these cases.
Ivan Lozano1f10f682024-11-08 16:16:50 +00001663 depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", ccLibPath.Path().String(), "-Wl,--no-whole-archive"}...)
1664 } else if libName, ok := libNameFromFilePath(ccLibPath.Path()); ok {
1665 depPaths.depFlags = append(depPaths.depFlags, "-lstatic:+whole-archive="+libName)
1666 depPaths.depLinkFlags = append(depPaths.depLinkFlags, ccLibPath.Path().String())
Ivan Lozano63bb7682021-03-23 15:53:44 -04001667 } else {
1668 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 -05001669 }
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001670 }
1671
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001672 exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001673 if cc.IsWholeStaticLib(depTag) {
1674 // Add whole staticlibs to wholeStaticLibObjects to propagate to Rust all dependents.
1675 depPaths.wholeStaticLibObjects = append(depPaths.wholeStaticLibObjects, ccLibPath.String())
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001676
1677 // We also propagate forward whole-static'd cc staticlibs with rust_ffi_rlib dependencies
1678 // We don't need to check a hypothetical exportedRustInfo.WholeRustRlibDeps because we
1679 // wouldn't expect a rust_ffi_rlib to be listed in `static_libs` (Soong explicitly disallows this)
1680 depPaths.reexportedWholeCcRlibDeps = append(depPaths.reexportedWholeCcRlibDeps, exportedInfo.RustRlibDeps...)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001681 } else {
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001682 // If not whole_static, add to staticLibObjects, which only propagate through rlibs to their dependents.
Ivan Lozano1f10f682024-11-08 16:16:50 +00001683 depPaths.staticLibObjects = append(depPaths.staticLibObjects, ccLibPath.String())
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001684
1685 if mod.Rlib() {
1686 // rlibs propagate their inherited rust_ffi_rlibs forward.
1687 depPaths.reexportedCcRlibDeps = append(depPaths.reexportedCcRlibDeps, exportedInfo.RustRlibDeps...)
1688 }
Ivan Lozano1f10f682024-11-08 16:16:50 +00001689 }
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001690
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05001691 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Colin Cross0de8a1e2020-09-18 14:15:30 -07001692 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1693 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1694 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1695 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001696
1697 if !mod.Rlib() {
1698 // rlibs don't need to build the generated static library, so they don't need to track these.
1699 depPaths.ccRlibDeps = append(depPaths.ccRlibDeps, exportedInfo.RustRlibDeps...)
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001700 }
1701
Yu Liu8024b922024-12-20 23:31:32 +00001702 directStaticLibDeps = append(directStaticLibDeps, linkableInfo)
Justin Yun2b3ed642022-02-16 08:15:07 +09001703
1704 // Record baseLibName for snapshots.
1705 mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName))
1706
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001707 mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07001708 case cc.IsSharedDepTag(depTag):
Jiyong Park7d55b612021-06-11 17:22:09 +09001709 // For the shared lib dependencies, we may link to the stub variant
1710 // of the dependency depending on the context (e.g. if this
1711 // dependency crosses the APEX boundaries).
1712 sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep)
1713
Colin Crossb614cd42024-10-11 12:52:21 -07001714 if !sharedLibraryInfo.IsStubs {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00001715 // TODO(b/362509506): remove this additional check once all apex_exclude uses are switched to stubs.
1716 if !linkableInfo.RustApexExclude {
1717 depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, ""))
1718 if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok {
1719 depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps)
1720 }
Colin Crossb614cd42024-10-11 12:52:21 -07001721 }
1722 }
1723
Jiyong Park7d55b612021-06-11 17:22:09 +09001724 // Re-get linkObject as ChooseStubOrImpl actually tells us which
1725 // object (either from stub or non-stub) to use.
Ivan Lozano1f10f682024-11-08 16:16:50 +00001726 ccLibPath = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
1727 if !ccLibPath.Valid() {
Colin Crossa86ea0e2023-08-01 09:57:22 -07001728 if !ctx.Config().AllowMissingDependencies() {
1729 ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName())
1730 } else {
1731 ctx.AddMissingDependencies([]string{depName})
1732 }
1733 return
1734 }
Ivan Lozano1f10f682024-11-08 16:16:50 +00001735 linkPath = linkPathFromFilePath(ccLibPath.Path())
Jiyong Park7d55b612021-06-11 17:22:09 +09001736
Ivan Lozanoffee3342019-08-27 12:03:00 -07001737 depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001738 depPaths.sharedLibObjects = append(depPaths.sharedLibObjects, ccLibPath.String())
Colin Cross0de8a1e2020-09-18 14:15:30 -07001739 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1740 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1741 depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
1742 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Jiyong Park7d55b612021-06-11 17:22:09 +09001743 directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo)
Ivan Lozano1921e802021-05-20 13:39:16 -04001744
1745 // Record baseLibName for snapshots.
1746 mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName))
1747
Cole Faustb6e6f992023-08-17 17:42:26 -07001748 directAndroidMkSharedLibs = append(directAndroidMkSharedLibs, makeLibName)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001749 exportDep = true
Zach Johnson3df4e632020-11-06 11:56:27 -08001750 case cc.IsHeaderDepTag(depTag):
Colin Cross313aa542023-12-13 13:47:44 -08001751 exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
Zach Johnson3df4e632020-11-06 11:56:27 -08001752 depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
1753 depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
1754 depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
Ivan Lozano1dbfa142024-03-29 14:48:11 +00001755 mod.Properties.AndroidMkHeaderLibs = append(mod.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07001756 case depTag == cc.CrtBeginDepTag:
Ivan Lozano1f10f682024-11-08 16:16:50 +00001757 depPaths.CrtBegin = append(depPaths.CrtBegin, ccLibPath.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07001758 case depTag == cc.CrtEndDepTag:
Ivan Lozano1f10f682024-11-08 16:16:50 +00001759 depPaths.CrtEnd = append(depPaths.CrtEnd, ccLibPath.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001760 }
1761
Ivan Lozano1f10f682024-11-08 16:16:50 +00001762 // Make sure shared dependencies are propagated
Matthew Maurerbb3add12020-06-25 09:34:12 -07001763 if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep {
1764 lib.exportLinkDirs(linkPath)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001765 lib.exportSharedLibs(ccLibPath.String())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001766 }
Colin Cross018cbeb2022-01-24 17:22:45 -08001767 } else {
1768 switch {
1769 case depTag == cc.CrtBeginDepTag:
1770 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
1771 case depTag == cc.CrtEndDepTag:
1772 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
1773 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001774 }
Ivan Lozano89435d12020-07-31 11:01:18 -04001775
Yu Liuc41eae52025-01-14 01:03:08 +00001776 if srcDep, ok := android.OtherModuleProvider(ctx, dep, android.SourceFilesInfoProvider); ok {
Paul Duffind5cf92e2021-07-09 17:38:55 +01001777 if android.IsSourceDepTagWithOutputTag(depTag, "") {
Ivan Lozano89435d12020-07-31 11:01:18 -04001778 // These are usually genrules which don't have per-target variants.
1779 directSrcDeps = append(directSrcDeps, srcDep)
1780 }
1781 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001782 })
1783
Colin Crossa14fb6a2024-10-23 16:57:06 -07001784 mod.transitiveAndroidMkSharedLibs = depset.New[string](depset.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs)
Wen-yi Chu41326c12023-09-22 03:58:59 +00001785
1786 var rlibDepFiles RustLibraries
Andrew Walbran52533232024-03-19 11:36:04 +00001787 aliases := mod.compiler.Aliases()
Wen-yi Chu41326c12023-09-22 03:58:59 +00001788 for _, dep := range directRlibDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001789 crateName := dep.CrateName
Andrew Walbran52533232024-03-19 11:36:04 +00001790 if alias, aliased := aliases[crateName]; aliased {
1791 crateName = alias
1792 }
Yu Liu8024b922024-12-20 23:31:32 +00001793 rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName})
Wen-yi Chu41326c12023-09-22 03:58:59 +00001794 }
1795 var dylibDepFiles RustLibraries
1796 for _, dep := range directDylibDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001797 crateName := dep.CrateName
Andrew Walbran52533232024-03-19 11:36:04 +00001798 if alias, aliased := aliases[crateName]; aliased {
1799 crateName = alias
1800 }
Yu Liu8024b922024-12-20 23:31:32 +00001801 dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName})
Wen-yi Chu41326c12023-09-22 03:58:59 +00001802 }
1803 var procMacroDepFiles RustLibraries
1804 for _, dep := range directProcMacroDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001805 crateName := dep.CrateName
Andrew Walbran52533232024-03-19 11:36:04 +00001806 if alias, aliased := aliases[crateName]; aliased {
1807 crateName = alias
1808 }
Yu Liu8024b922024-12-20 23:31:32 +00001809 procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName})
Wen-yi Chu41326c12023-09-22 03:58:59 +00001810 }
1811
Colin Cross004bd3f2023-10-02 11:39:17 -07001812 var staticLibDepFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001813 for _, dep := range directStaticLibDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001814 staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile.Path())
Ivan Lozanoffee3342019-08-27 12:03:00 -07001815 }
1816
Colin Cross004bd3f2023-10-02 11:39:17 -07001817 var sharedLibFiles android.Paths
1818 var sharedLibDepFiles android.Paths
Ivan Lozanoffee3342019-08-27 12:03:00 -07001819 for _, dep := range directSharedLibDeps {
Colin Cross004bd3f2023-10-02 11:39:17 -07001820 sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary)
Jiyong Park7d55b612021-06-11 17:22:09 +09001821 if dep.TableOfContents.Valid() {
Colin Cross004bd3f2023-10-02 11:39:17 -07001822 sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path())
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001823 } else {
Colin Cross004bd3f2023-10-02 11:39:17 -07001824 sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary)
Ivan Lozanoec6e9912021-01-21 15:23:29 -05001825 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001826 }
1827
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001828 var srcProviderDepFiles android.Paths
1829 for _, dep := range directSrcProvidersDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001830 srcs := android.OutputFilesForModule(ctx, *dep, "")
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001831 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1832 }
1833 for _, dep := range directSrcDeps {
Yu Liu8024b922024-12-20 23:31:32 +00001834 srcs := dep.Srcs
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001835 srcProviderDepFiles = append(srcProviderDepFiles, srcs...)
1836 }
1837
Wen-yi Chu41326c12023-09-22 03:58:59 +00001838 depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...)
1839 depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...)
Colin Cross004bd3f2023-10-02 11:39:17 -07001840 depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibFiles...)
1841 depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...)
1842 depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...)
Wen-yi Chu41326c12023-09-22 03:58:59 +00001843 depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...)
Ivan Lozano07cbaf42020-07-22 16:09:13 -04001844 depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001845
1846 // Dedup exported flags from dependencies
Wen-yi Chu41326c12023-09-22 03:58:59 +00001847 depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs)
Ivan Lozano1f10f682024-11-08 16:16:50 +00001848 depPaths.rustLibObjects = android.FirstUniqueStrings(depPaths.rustLibObjects)
1849 depPaths.staticLibObjects = android.FirstUniqueStrings(depPaths.staticLibObjects)
1850 depPaths.wholeStaticLibObjects = android.FirstUniqueStrings(depPaths.wholeStaticLibObjects)
1851 depPaths.sharedLibObjects = android.FirstUniqueStrings(depPaths.sharedLibObjects)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001852 depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags)
Ivan Lozano45901ed2020-07-24 16:05:01 -04001853 depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags)
1854 depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths)
1855 depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths)
Ivan Lozanoad7ba592025-01-23 01:23:43 +00001856 depPaths.depLinkFlags = android.FirstUniqueStrings(depPaths.depLinkFlags)
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001857 depPaths.reexportedCcRlibDeps = android.FirstUniqueFunc(depPaths.reexportedCcRlibDeps, cc.EqRustRlibDeps)
Ivan Lozano610eb1a2025-02-12 21:36:49 +00001858 depPaths.reexportedWholeCcRlibDeps = android.FirstUniqueFunc(depPaths.reexportedWholeCcRlibDeps, cc.EqRustRlibDeps)
Ivan Lozano85f00cf2025-02-11 20:19:19 +00001859 depPaths.ccRlibDeps = android.FirstUniqueFunc(depPaths.ccRlibDeps, cc.EqRustRlibDeps)
Ivan Lozanoffee3342019-08-27 12:03:00 -07001860
1861 return depPaths
1862}
1863
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -08001864func (mod *Module) InstallInData() bool {
1865 if mod.compiler == nil {
1866 return false
1867 }
1868 return mod.compiler.inData()
1869}
1870
Matthew Maurer9f59e8d2021-08-19 13:10:05 -07001871func (mod *Module) InstallInRamdisk() bool {
1872 return mod.InRamdisk()
1873}
1874
1875func (mod *Module) InstallInVendorRamdisk() bool {
1876 return mod.InVendorRamdisk()
1877}
1878
1879func (mod *Module) InstallInRecovery() bool {
1880 return mod.InRecovery()
1881}
1882
Wen-yi Chu41326c12023-09-22 03:58:59 +00001883func linkPathFromFilePath(filepath android.Path) string {
1884 return strings.Split(filepath.String(), filepath.Base())[0]
1885}
1886
Spandan Das604f3762023-03-16 22:51:40 +00001887// usePublicApi returns true if the rust variant should link against NDK (publicapi)
1888func (r *Module) usePublicApi() bool {
1889 return r.Device() && r.UseSdk()
1890}
1891
1892// useVendorApi returns true if the rust variant should link against LLNDK (vendorapi)
1893func (r *Module) useVendorApi() bool {
1894 return r.Device() && (r.InVendor() || r.InProduct())
1895}
1896
Ivan Lozanoffee3342019-08-27 12:03:00 -07001897func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
1898 ctx := &depsContext{
1899 BottomUpMutatorContext: actx,
Ivan Lozanoffee3342019-08-27 12:03:00 -07001900 }
Ivan Lozanoffee3342019-08-27 12:03:00 -07001901
1902 deps := mod.deps(ctx)
Colin Cross3146c5c2020-09-30 15:34:40 -07001903 var commonDepVariations []blueprint.Variation
Ivan Lozano1921e802021-05-20 13:39:16 -04001904
1905 if ctx.Os() == android.Android {
Kiyoung Kim37693d02024-04-04 09:56:15 +09001906 deps.SharedLibs, _ = cc.FilterNdkLibs(mod, ctx.Config(), deps.SharedLibs)
Ivan Lozano1921e802021-05-20 13:39:16 -04001907 }
Ivan Lozanodd055472020-09-28 13:22:45 -04001908
Ivan Lozano2b081132020-09-08 12:46:52 -04001909 stdLinkage := "dylib-std"
Ivan Lozano806efd32024-12-11 21:38:53 +00001910 if mod.compiler.stdLinkage(ctx.Device()) == RlibLinkage {
Ivan Lozano2b081132020-09-08 12:46:52 -04001911 stdLinkage = "rlib-std"
1912 }
1913
1914 rlibDepVariations := commonDepVariations
Ivan Lozano1921e802021-05-20 13:39:16 -04001915
Ivan Lozano2b081132020-09-08 12:46:52 -04001916 if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() {
1917 rlibDepVariations = append(rlibDepVariations,
1918 blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage})
1919 }
1920
Ivan Lozano1921e802021-05-20 13:39:16 -04001921 // rlibs
Ivan Lozano2d407632022-04-07 12:59:11 -04001922 rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001923 for _, lib := range deps.Rlibs {
1924 depTag := rlibDepTag
Ivan Lozano2d407632022-04-07 12:59:11 -04001925 actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001926 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001927
1928 // dylibs
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001929 dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
Ivan Lozano0a468a42024-05-13 21:03:34 -04001930
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001931 for _, lib := range deps.Dylibs {
Kiyoung Kim37693d02024-04-04 09:56:15 +09001932 actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib)
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001933 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001934
Ivan Lozano1921e802021-05-20 13:39:16 -04001935 // rustlibs
Ivan Lozanod106efe2023-09-21 23:30:26 -04001936 if deps.Rustlibs != nil {
1937 if !mod.compiler.Disabled() {
1938 for _, lib := range deps.Rustlibs {
1939 autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
1940 if autoDep.depTag == rlibDepTag {
1941 // Handle the rlib deptag case
Kiyoung Kim37693d02024-04-04 09:56:15 +09001942 actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib)
1943
Ivan Lozanod106efe2023-09-21 23:30:26 -04001944 } else {
1945 // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
1946 // Check for the existence of the dylib deptag variant. Select it if available,
1947 // otherwise select the rlib variant.
1948 autoDepVariations := append(commonDepVariations,
1949 blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
Kiyoung Kim37693d02024-04-04 09:56:15 +09001950 if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
1951 actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
Ivan Lozanod106efe2023-09-21 23:30:26 -04001952
Ivan Lozanod106efe2023-09-21 23:30:26 -04001953 } else {
1954 // If there's no dylib dependency available, try to add the rlib dependency instead.
Kiyoung Kim37693d02024-04-04 09:56:15 +09001955 actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib)
1956
Ivan Lozanod106efe2023-09-21 23:30:26 -04001957 }
1958 }
1959 }
1960 } else if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
1961 for _, lib := range deps.Rustlibs {
Ivan Lozanod106efe2023-09-21 23:30:26 -04001962 srcProviderVariations := append(commonDepVariations,
Colin Cross8a49a3d2024-05-20 12:22:27 -07001963 blueprint.Variation{Mutator: "rust_libraries", Variation: sourceVariation})
Ivan Lozanod106efe2023-09-21 23:30:26 -04001964
Ivan Lozano0a468a42024-05-13 21:03:34 -04001965 // Only add rustlib dependencies if they're source providers themselves.
1966 // This is used to track which crate names need to be added to the source generated
1967 // in the rust_protobuf mod.rs.
Kiyoung Kim37693d02024-04-04 09:56:15 +09001968 if actx.OtherModuleDependencyVariantExists(srcProviderVariations, lib) {
Ivan Lozanod106efe2023-09-21 23:30:26 -04001969 actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib)
Ivan Lozano2d407632022-04-07 12:59:11 -04001970 }
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001971 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001972 }
Matthew Maurer0f003b12020-06-29 14:34:06 -07001973 }
Ivan Lozanod106efe2023-09-21 23:30:26 -04001974
Ivan Lozano1921e802021-05-20 13:39:16 -04001975 // stdlibs
Ivan Lozano2b081132020-09-08 12:46:52 -04001976 if deps.Stdlibs != nil {
Ivan Lozano806efd32024-12-11 21:38:53 +00001977 if mod.compiler.stdLinkage(ctx.Device()) == RlibLinkage {
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001978 for _, lib := range deps.Stdlibs {
Colin Cross8a49a3d2024-05-20 12:22:27 -07001979 actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001980 rlibDepTag, lib)
Ivan Lozano3149e6e2021-06-01 15:09:53 -04001981 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001982 } else {
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001983 for _, lib := range deps.Stdlibs {
Kiyoung Kim37693d02024-04-04 09:56:15 +09001984 actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib)
1985
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001986 }
Ivan Lozano2b081132020-09-08 12:46:52 -04001987 }
1988 }
Ivan Lozano1921e802021-05-20 13:39:16 -04001989
1990 for _, lib := range deps.SharedLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08001991 depTag := cc.SharedDepTag()
Ivan Lozano1921e802021-05-20 13:39:16 -04001992 name, version := cc.StubsLibNameAndVersion(lib)
1993
1994 variations := []blueprint.Variation{
1995 {Mutator: "link", Variation: "shared"},
1996 }
Spandan Dasff665182024-09-11 18:48:44 +00001997 cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false)
Ivan Lozano1921e802021-05-20 13:39:16 -04001998 }
1999
2000 for _, lib := range deps.WholeStaticLibs {
2001 depTag := cc.StaticDepTag(true)
Ivan Lozano1921e802021-05-20 13:39:16 -04002002
2003 actx.AddVariationDependencies([]blueprint.Variation{
2004 {Mutator: "link", Variation: "static"},
2005 }, depTag, lib)
2006 }
2007
2008 for _, lib := range deps.StaticLibs {
2009 depTag := cc.StaticDepTag(false)
Ivan Lozano1921e802021-05-20 13:39:16 -04002010
2011 actx.AddVariationDependencies([]blueprint.Variation{
2012 {Mutator: "link", Variation: "static"},
2013 }, depTag, lib)
2014 }
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07002015
Zach Johnson3df4e632020-11-06 11:56:27 -08002016 actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
2017
Colin Cross565cafd2020-09-25 18:47:38 -07002018 crtVariations := cc.GetCrtVariations(ctx, mod)
Colin Crossfe605e12022-01-23 20:46:16 -08002019 for _, crt := range deps.CrtBegin {
Kiyoung Kim37693d02024-04-04 09:56:15 +09002020 actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, crt)
Ivan Lozanof1c84332019-09-20 11:00:37 -07002021 }
Colin Crossfe605e12022-01-23 20:46:16 -08002022 for _, crt := range deps.CrtEnd {
Kiyoung Kim37693d02024-04-04 09:56:15 +09002023 actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, crt)
Ivan Lozanof1c84332019-09-20 11:00:37 -07002024 }
2025
Ivan Lozanoc564d2d2020-08-04 15:43:37 -04002026 if mod.sourceProvider != nil {
2027 if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok &&
2028 bindgen.Properties.Custom_bindgen != "" {
2029 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag,
2030 bindgen.Properties.Custom_bindgen)
2031 }
2032 }
Ivan Lozano1921e802021-05-20 13:39:16 -04002033
Ivan Lozano4e5f07d2021-11-04 14:09:38 -04002034 actx.AddVariationDependencies([]blueprint.Variation{
2035 {Mutator: "link", Variation: "shared"},
2036 }, dataLibDepTag, deps.DataLibs...)
2037
2038 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
2039
Ivan Lozano5ca5ef62019-09-23 10:10:40 -07002040 // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002041 actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
Vinh Trancde10162023-03-09 22:07:19 -05002042
2043 mod.afdo.addDep(ctx, actx)
Ivan Lozanoffee3342019-08-27 12:03:00 -07002044}
2045
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002046func BeginMutator(ctx android.BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -07002047 if mod, ok := ctx.Module().(*Module); ok && mod.Enabled(ctx) {
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002048 mod.beginMutator(ctx)
2049 }
2050}
2051
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002052func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) {
2053 ctx := &baseModuleContext{
2054 BaseModuleContext: actx,
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002055 }
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002056
2057 mod.begin(ctx)
2058}
2059
Ivan Lozanoffee3342019-08-27 12:03:00 -07002060func (mod *Module) Name() string {
2061 name := mod.ModuleBase.Name()
2062 if p, ok := mod.compiler.(interface {
2063 Name(string) string
2064 }); ok {
2065 name = p.Name(name)
2066 }
2067 return name
2068}
2069
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02002070func (mod *Module) disableClippy() {
Ivan Lozano32267c82020-08-04 16:27:16 -04002071 if mod.clippy != nil {
Thiébaud Weksteen9e8451e2020-08-13 12:55:59 +02002072 mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none")
Ivan Lozano32267c82020-08-04 16:27:16 -04002073 }
2074}
2075
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07002076var _ android.HostToolProvider = (*Module)(nil)
2077
2078func (mod *Module) HostToolPath() android.OptionalPath {
2079 if !mod.Host() {
2080 return android.OptionalPath{}
2081 }
Chih-Hung Hsieha7562702020-08-10 21:50:43 -07002082 if binary, ok := mod.compiler.(*binaryDecorator); ok {
2083 return android.OptionalPathForPath(binary.baseCompiler.path)
Ivan Lozano872d5792022-03-23 17:31:39 -04002084 } else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
2085 // Even though proc-macros aren't strictly "tools", since they target the compiler
2086 // and act as compiler plugins, we treat them similarly.
2087 return android.OptionalPathForPath(pm.baseCompiler.path)
Chih-Hung Hsieh5c4e4892020-05-15 17:36:30 -07002088 }
2089 return android.OptionalPath{}
2090}
2091
Jiyong Park99644e92020-11-17 22:21:02 +09002092var _ android.ApexModule = (*Module)(nil)
2093
Ivan Lozano24cf0362024-10-04 16:02:38 +00002094// If a module is marked for exclusion from apexes, don't provide apex variants.
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002095// TODO(b/362509506): remove this once all apex_exclude usages are removed.
Ivan Lozano24cf0362024-10-04 16:02:38 +00002096func (m *Module) CanHaveApexVariants() bool {
2097 if m.ApexExclude() {
2098 return false
2099 } else {
2100 return m.ApexModuleBase.CanHaveApexVariants()
2101 }
2102}
2103
Ivan Lozanoa91ba252022-01-11 12:02:06 -05002104func (mod *Module) MinSdkVersion() string {
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002105 return String(mod.Properties.Min_sdk_version)
2106}
2107
Jiyong Park45bf82e2020-12-15 22:29:02 +09002108// Implements android.ApexModule
Yu Liudf0b8392025-02-12 18:27:03 +00002109func (mod *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel {
Ivan Lozanoa91ba252022-01-11 12:02:06 -05002110 minSdkVersion := mod.MinSdkVersion()
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002111 if minSdkVersion == "apex_inherit" {
Yu Liudf0b8392025-02-12 18:27:03 +00002112 return android.MinApiLevel
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002113 }
2114
Yu Liudf0b8392025-02-12 18:27:03 +00002115 if minSdkVersion == "" {
2116 return android.NoneApiLevel
2117 }
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002118 // Not using nativeApiLevelFromUser because the context here is not
2119 // necessarily a native context.
Yu Liudf0b8392025-02-12 18:27:03 +00002120 ver, err := android.ApiLevelFromUserWithConfig(ctx.Config(), minSdkVersion)
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002121 if err != nil {
Yu Liudf0b8392025-02-12 18:27:03 +00002122 return android.NoneApiLevel
Ivan Lozano3e9f9e42020-12-04 15:05:43 -05002123 }
2124
Yu Liudf0b8392025-02-12 18:27:03 +00002125 return ver
Jiyong Park99644e92020-11-17 22:21:02 +09002126}
2127
Jiyong Park45bf82e2020-12-15 22:29:02 +09002128// Implements android.ApexModule
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002129func (mod *Module) AlwaysRequiresPlatformApexVariant() bool {
2130 // stub libraries and native bridge libraries are always available to platform
2131 // TODO(b/362509506): remove the ApexExclude() check once all apex_exclude uses are switched to stubs.
2132 return mod.IsStubs() || mod.Target().NativeBridge == android.NativeBridgeEnabled || mod.ApexExclude()
2133}
2134
2135// Implements android.ApexModule
Yu Liuf1806032025-02-07 00:23:34 +00002136type RustDepInSameApexChecker struct {
2137 Static bool
2138 HasStubsVariants bool
2139 ApexExclude bool
2140 Host bool
2141}
2142
2143func (mod *Module) GetDepInSameApexChecker() android.DepInSameApexChecker {
2144 return RustDepInSameApexChecker{
2145 Static: mod.Static(),
2146 HasStubsVariants: mod.HasStubsVariants(),
2147 ApexExclude: mod.ApexExclude(),
2148 Host: mod.Host(),
2149 }
2150}
2151
2152func (r RustDepInSameApexChecker) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
Matthew Maurer581b6d82022-09-29 16:46:25 -07002153 if depTag == procMacroDepTag || depTag == customBindgenDepTag {
Jiyong Park99644e92020-11-17 22:21:02 +09002154 return false
2155 }
2156
Yu Liuf1806032025-02-07 00:23:34 +00002157 if r.Static && cc.IsSharedDepTag(depTag) {
Colin Cross8acea3e2024-12-12 14:53:30 -08002158 // shared_lib dependency from a static lib is considered as crossing
2159 // the APEX boundary because the dependency doesn't actually is
2160 // linked; the dependency is used only during the compilation phase.
2161 return false
2162 }
2163
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002164 if depTag == cc.StubImplDepTag {
2165 // We don't track from an implementation library to its stubs.
2166 return false
2167 }
2168
2169 if cc.ExcludeInApexDepTag(depTag) {
2170 return false
2171 }
2172
2173 // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs.
Yu Liuf1806032025-02-07 00:23:34 +00002174 if r.ApexExclude {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002175 return false
2176 }
2177
Jiyong Park99644e92020-11-17 22:21:02 +09002178 return true
2179}
2180
Yu Liuf1806032025-02-07 00:23:34 +00002181func (r RustDepInSameApexChecker) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
2182 if r.Host {
Colin Cross1cea5302024-12-03 16:40:08 -08002183 return false
2184 }
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002185 // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs.
Yu Liuf1806032025-02-07 00:23:34 +00002186 if r.ApexExclude {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002187 return false
2188 }
2189
Yu Liuf1806032025-02-07 00:23:34 +00002190 if r.HasStubsVariants {
Colin Crossbd930bc2025-02-03 12:17:42 -08002191 if cc.IsSharedDepTag(depTag) && !cc.IsExplicitImplSharedDepTag(depTag) {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002192 // dynamic dep to a stubs lib crosses APEX boundary
2193 return false
2194 }
2195 if cc.IsRuntimeDepTag(depTag) {
2196 // runtime dep to a stubs lib also crosses APEX boundary
2197 return false
2198 }
2199 if cc.IsHeaderDepTag(depTag) {
2200 return false
2201 }
2202 }
2203 return true
Colin Crossf7bbd2f2024-12-05 13:57:10 -08002204}
2205
Jiyong Park99644e92020-11-17 22:21:02 +09002206// Overrides ApexModule.IsInstallabeToApex()
2207func (mod *Module) IsInstallableToApex() bool {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002208 // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs.
2209 if mod.ApexExclude() {
2210 return false
2211 }
2212
Jiyong Park99644e92020-11-17 22:21:02 +09002213 if mod.compiler != nil {
Ivan Lozanoa8a1fa12024-10-30 18:15:59 +00002214 if lib, ok := mod.compiler.(libraryInterface); ok {
2215 return (lib.shared() || lib.dylib()) && !lib.BuildStubs()
Jiyong Park99644e92020-11-17 22:21:02 +09002216 }
2217 if _, ok := mod.compiler.(*binaryDecorator); ok {
2218 return true
2219 }
2220 }
2221 return false
2222}
2223
Ivan Lozano3dfa12d2021-02-04 11:29:41 -05002224// If a library file has a "lib" prefix, extract the library name without the prefix.
2225func libNameFromFilePath(filepath android.Path) (string, bool) {
2226 libName := strings.TrimSuffix(filepath.Base(), filepath.Ext())
2227 if strings.HasPrefix(libName, "lib") {
2228 libName = libName[3:]
2229 return libName, true
2230 }
2231 return "", false
2232}
2233
Sasha Smundaka76acba2022-04-18 20:12:56 -07002234func kytheExtractRustFactory() android.Singleton {
2235 return &kytheExtractRustSingleton{}
2236}
2237
2238type kytheExtractRustSingleton struct {
2239}
2240
2241func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2242 var xrefTargets android.Paths
Yu Liu2a815b62025-02-21 20:46:25 +00002243 ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
2244 if rustModule, ok := android.OtherModuleProvider(ctx, module, RustInfoProvider); ok {
2245 xrefTargets = append(xrefTargets, rustModule.XrefRustFiles...)
Sasha Smundaka76acba2022-04-18 20:12:56 -07002246 }
2247 })
2248 if len(xrefTargets) > 0 {
2249 ctx.Phony("xref_rust", xrefTargets...)
2250 }
2251}
2252
Jihoon Kangf78a8902022-09-01 22:47:07 +00002253func (c *Module) Partition() string {
2254 return ""
2255}
2256
Ivan Lozanoffee3342019-08-27 12:03:00 -07002257var Bool = proptools.Bool
2258var BoolDefault = proptools.BoolDefault
2259var String = proptools.String
2260var StringPtr = proptools.StringPtr