Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 18 | "android/soong/bloaty" |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 19 | "fmt" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
| 22 | "github.com/google/blueprint" |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 27 | cc_config "android/soong/cc/config" |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 28 | "android/soong/fuzz" |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 29 | "android/soong/multitree" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 30 | "android/soong/rust/config" |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 31 | "android/soong/snapshot" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | var pctx = android.NewPackageContext("android/soong/rust") |
| 35 | |
| 36 | func init() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 38 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 39 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 40 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 41 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 42 | }) |
| 43 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 44 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 45 | }) |
| 46 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 47 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 48 | android.InitRegistrationContext.RegisterSingletonType("kythe_rust_extract", kytheExtractRustFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 52 | GlobalRustFlags []string // Flags that apply globally to rust |
| 53 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 54 | RustFlags []string // Flags that apply to rust |
| 55 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 56 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 57 | RustdocFlags []string // Flags that apply to rustdoc |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 58 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 59 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 60 | Clippy bool |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 61 | EmitXrefs bool // If true, emit rules to aid cross-referencing |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | type BaseProperties struct { |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 65 | AndroidMkRlibs []string `blueprint:"mutated"` |
| 66 | AndroidMkDylibs []string `blueprint:"mutated"` |
| 67 | AndroidMkProcMacroLibs []string `blueprint:"mutated"` |
| 68 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
| 69 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 70 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 71 | ImageVariationPrefix string `blueprint:"mutated"` |
| 72 | VndkVersion string `blueprint:"mutated"` |
| 73 | SubName string `blueprint:"mutated"` |
| 74 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 75 | // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific |
| 76 | // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be |
| 77 | // appended before SubName. |
| 78 | RustSubName string `blueprint:"mutated"` |
| 79 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 80 | // Set by imageMutator |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 81 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 82 | VendorRamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 83 | RamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 84 | RecoveryVariantNeeded bool `blueprint:"mutated"` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 85 | ExtraVariants []string `blueprint:"mutated"` |
| 86 | |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 87 | // Allows this module to use non-APEX version of libraries. Useful |
| 88 | // for building binaries that are started before APEXes are activated. |
| 89 | Bootstrap *bool |
| 90 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 91 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 92 | SnapshotSharedLibs []string `blueprint:"mutated"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 93 | SnapshotStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 94 | |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 95 | // Make this module available when building for ramdisk. |
| 96 | // On device without a dedicated recovery partition, the module is only |
| 97 | // available after switching root into |
| 98 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 99 | // the recovery variant instead. |
| 100 | Ramdisk_available *bool |
| 101 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 102 | // Make this module available when building for vendor ramdisk. |
| 103 | // On device without a dedicated recovery partition, the module is only |
| 104 | // available after switching root into |
| 105 | // /first_stage_ramdisk. To expose the module before switching root, install |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 106 | // the recovery variant instead |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 107 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 108 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 109 | // Normally Soong uses the directory structure to decide which modules |
| 110 | // should be included (framework) or excluded (non-framework) from the |
| 111 | // different snapshots (vendor, recovery, etc.), but this property |
| 112 | // allows a partner to exclude a module normally thought of as a |
| 113 | // framework module from the vendor snapshot. |
| 114 | Exclude_from_vendor_snapshot *bool |
| 115 | |
| 116 | // Normally Soong uses the directory structure to decide which modules |
| 117 | // should be included (framework) or excluded (non-framework) from the |
| 118 | // different snapshots (vendor, recovery, etc.), but this property |
| 119 | // allows a partner to exclude a module normally thought of as a |
| 120 | // framework module from the recovery snapshot. |
| 121 | Exclude_from_recovery_snapshot *bool |
| 122 | |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 123 | // Make this module available when building for recovery |
| 124 | Recovery_available *bool |
| 125 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 126 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 127 | Min_sdk_version *string |
| 128 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 129 | HideFromMake bool `blueprint:"mutated"` |
| 130 | PreventInstall bool `blueprint:"mutated"` |
| 131 | |
| 132 | Installable *bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | type Module struct { |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 136 | fuzz.FuzzModule |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 137 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 138 | VendorProperties cc.VendorProperties |
| 139 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 140 | Properties BaseProperties |
| 141 | |
| 142 | hod android.HostOrDeviceSupported |
| 143 | multilib android.Multilib |
| 144 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 145 | makeLinkType string |
| 146 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 147 | afdo *afdo |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 148 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 149 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 150 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 151 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 152 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 153 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 154 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 155 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 156 | // Output file to be installed, may be stripped or unstripped. |
| 157 | outputFile android.OptionalPath |
| 158 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 159 | // Cross-reference input file |
| 160 | kytheFiles android.Paths |
| 161 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 162 | docTimestampFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 163 | |
| 164 | hideApexVariantFromMake bool |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 165 | |
| 166 | // For apex variants, this is set as apex.min_sdk_version |
| 167 | apexSdkVersion android.ApiLevel |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 170 | func (mod *Module) Header() bool { |
| 171 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 172 | return false |
| 173 | } |
| 174 | |
| 175 | func (mod *Module) SetPreventInstall() { |
| 176 | mod.Properties.PreventInstall = true |
| 177 | } |
| 178 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 179 | func (mod *Module) SetHideFromMake() { |
| 180 | mod.Properties.HideFromMake = true |
| 181 | } |
| 182 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 183 | func (mod *Module) HiddenFromMake() bool { |
| 184 | return mod.Properties.HideFromMake |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 187 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 188 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 189 | // nil since we need compiler to actually sanitize. |
| 190 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 191 | } |
| 192 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 193 | func (mod *Module) IsPrebuilt() bool { |
| 194 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 195 | return true |
| 196 | } |
| 197 | return false |
| 198 | } |
| 199 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 200 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 201 | switch tag { |
| 202 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 203 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 204 | return mod.sourceProvider.Srcs(), nil |
| 205 | } else { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 206 | if mod.OutputFile().Valid() { |
| 207 | return android.Paths{mod.OutputFile().Path()}, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 208 | } |
| 209 | return android.Paths{}, nil |
| 210 | } |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 211 | case "unstripped": |
| 212 | if mod.compiler != nil { |
| 213 | return android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), nil |
| 214 | } |
| 215 | return nil, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 216 | default: |
| 217 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 218 | } |
| 219 | } |
| 220 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 221 | func (mod *Module) SelectedStl() string { |
| 222 | return "" |
| 223 | } |
| 224 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 225 | func (mod *Module) NonCcVariants() bool { |
| 226 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 227 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 228 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 232 | } |
| 233 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 234 | func (mod *Module) Static() bool { |
| 235 | if mod.compiler != nil { |
| 236 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 237 | return library.static() |
| 238 | } |
| 239 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 240 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | func (mod *Module) Shared() bool { |
| 244 | if mod.compiler != nil { |
| 245 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 246 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 249 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 252 | func (mod *Module) Dylib() bool { |
| 253 | if mod.compiler != nil { |
| 254 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 255 | return library.dylib() |
| 256 | } |
| 257 | } |
| 258 | return false |
| 259 | } |
| 260 | |
| 261 | func (mod *Module) Rlib() bool { |
| 262 | if mod.compiler != nil { |
| 263 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 264 | return library.rlib() |
| 265 | } |
| 266 | } |
| 267 | return false |
| 268 | } |
| 269 | |
| 270 | func (mod *Module) Binary() bool { |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 271 | if binary, ok := mod.compiler.(binaryInterface); ok { |
| 272 | return binary.binary() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 273 | } |
| 274 | return false |
| 275 | } |
| 276 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 277 | func (mod *Module) StaticExecutable() bool { |
| 278 | if !mod.Binary() { |
| 279 | return false |
| 280 | } |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 281 | return mod.StaticallyLinked() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 282 | } |
| 283 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 284 | func (mod *Module) Object() bool { |
| 285 | // Rust has no modules which produce only object files. |
| 286 | return false |
| 287 | } |
| 288 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 289 | func (mod *Module) Toc() android.OptionalPath { |
| 290 | if mod.compiler != nil { |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 291 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 292 | return lib.toc() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 296 | } |
| 297 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 298 | func (mod *Module) UseSdk() bool { |
| 299 | return false |
| 300 | } |
| 301 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 302 | func (mod *Module) RelativeInstallPath() string { |
| 303 | if mod.compiler != nil { |
| 304 | return mod.compiler.relativeInstallPath() |
| 305 | } |
| 306 | return "" |
| 307 | } |
| 308 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 309 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 310 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 313 | func (mod *Module) Bootstrap() bool { |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 314 | return Bool(mod.Properties.Bootstrap) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 315 | } |
| 316 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 317 | func (mod *Module) MustUseVendorVariant() bool { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 318 | return true |
| 319 | } |
| 320 | |
| 321 | func (mod *Module) SubName() string { |
| 322 | return mod.Properties.SubName |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 326 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 327 | return false |
| 328 | } |
| 329 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 330 | func (mod *Module) IsVndkExt() bool { |
| 331 | return false |
| 332 | } |
| 333 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 334 | func (mod *Module) IsVndkSp() bool { |
| 335 | return false |
| 336 | } |
| 337 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 338 | func (mod *Module) IsVndkPrebuiltLibrary() bool { |
| 339 | // Rust modules do not provide VNDK prebuilts |
| 340 | return false |
| 341 | } |
| 342 | |
| 343 | func (mod *Module) IsVendorPublicLibrary() bool { |
| 344 | return mod.VendorProperties.IsVendorPublicLibrary |
| 345 | } |
| 346 | |
| 347 | func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool { |
| 348 | // Rust modules to not provide Sdk variants |
| 349 | return false |
| 350 | } |
| 351 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 352 | func (c *Module) IsVndkPrivate() bool { |
| 353 | return false |
| 354 | } |
| 355 | |
| 356 | func (c *Module) IsLlndk() bool { |
| 357 | return false |
| 358 | } |
| 359 | |
| 360 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 361 | return false |
| 362 | } |
| 363 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 364 | func (mod *Module) KernelHeadersDecorator() bool { |
| 365 | return false |
| 366 | } |
| 367 | |
Colin Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame] | 368 | func (m *Module) NeedsLlndkVariants() bool { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 369 | return false |
| 370 | } |
| 371 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 372 | func (m *Module) NeedsVendorPublicLibraryVariants() bool { |
| 373 | return false |
| 374 | } |
| 375 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 376 | func (mod *Module) HasLlndkStubs() bool { |
| 377 | return false |
| 378 | } |
| 379 | |
| 380 | func (mod *Module) StubsVersion() string { |
| 381 | panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName())) |
| 382 | } |
| 383 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 384 | func (mod *Module) SdkVersion() string { |
| 385 | return "" |
| 386 | } |
| 387 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 388 | func (mod *Module) AlwaysSdk() bool { |
| 389 | return false |
| 390 | } |
| 391 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 392 | func (mod *Module) IsSdkVariant() bool { |
| 393 | return false |
| 394 | } |
| 395 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 396 | func (mod *Module) SplitPerApiLevel() bool { |
| 397 | return false |
| 398 | } |
| 399 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 400 | func (mod *Module) XrefRustFiles() android.Paths { |
| 401 | return mod.kytheFiles |
| 402 | } |
| 403 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 404 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 405 | Dylibs []string |
| 406 | Rlibs []string |
| 407 | Rustlibs []string |
| 408 | Stdlibs []string |
| 409 | ProcMacros []string |
| 410 | SharedLibs []string |
| 411 | StaticLibs []string |
| 412 | WholeStaticLibs []string |
| 413 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 414 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 415 | // Used for data dependencies adjacent to tests |
| 416 | DataLibs []string |
| 417 | DataBins []string |
| 418 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 419 | CrtBegin, CrtEnd []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | type PathDeps struct { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 423 | DyLibs RustLibraries |
| 424 | RLibs RustLibraries |
| 425 | LibDeps android.Paths |
| 426 | WholeStaticLibs android.Paths |
| 427 | ProcMacros RustLibraries |
| 428 | AfdoProfiles android.Paths |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 429 | |
| 430 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 431 | depFlags []string |
| 432 | depLinkFlags []string |
| 433 | |
| 434 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. |
| 435 | // Both of these are exported and propagate to dependencies. |
| 436 | linkDirs []string |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 437 | linkObjects android.Paths |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 438 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 439 | // Used by bindgen modules which call clang |
| 440 | depClangFlags []string |
| 441 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 442 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 443 | depSystemIncludePaths android.Paths |
| 444 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 445 | CrtBegin android.Paths |
| 446 | CrtEnd android.Paths |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 447 | |
| 448 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 449 | SrcDeps android.Paths |
| 450 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | type RustLibraries []RustLibrary |
| 454 | |
| 455 | type RustLibrary struct { |
| 456 | Path android.Path |
| 457 | CrateName string |
| 458 | } |
| 459 | |
| 460 | type compiler interface { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 461 | initialize(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 462 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 463 | cfgFlags(ctx ModuleContext, flags Flags) Flags |
| 464 | featureFlags(ctx ModuleContext, flags Flags) Flags |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 465 | compilerProps() []interface{} |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 466 | compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 467 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 468 | crateName() string |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 469 | rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 470 | |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 471 | // Output directory in which source-generated code from dependencies is |
| 472 | // copied. This is equivalent to Cargo's OUT_DIR variable. |
| 473 | CargoOutDir() android.OptionalPath |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 474 | |
Ivan Lozano | a9a1fc0 | 2021-08-11 15:13:43 -0400 | [diff] [blame] | 475 | // CargoPkgVersion returns the value of the Cargo_pkg_version property. |
| 476 | CargoPkgVersion() string |
| 477 | |
| 478 | // CargoEnvCompat returns whether Cargo environment variables should be used. |
| 479 | CargoEnvCompat() bool |
| 480 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 481 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 482 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 483 | relativeInstallPath() string |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 484 | everInstallable() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 485 | |
| 486 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 487 | |
| 488 | Disabled() bool |
| 489 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 490 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 491 | stdLinkage(ctx *depsContext) RustLinkage |
Ivan Lozano | 9ef9cb8 | 2023-02-14 10:56:14 -0500 | [diff] [blame] | 492 | noStdlibs() bool |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 493 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 494 | unstrippedOutputFilePath() android.Path |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 495 | strippedOutputFilePath() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 496 | } |
| 497 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 498 | type exportedFlagsProducer interface { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 499 | exportLinkDirs(...string) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 500 | exportLinkObjects(...android.Path) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 503 | type xref interface { |
| 504 | XrefRustFiles() android.Paths |
| 505 | } |
| 506 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 507 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 508 | linkDirs []string |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 509 | linkObjects android.Paths |
| 510 | libDeps android.Paths |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 513 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 514 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 515 | } |
| 516 | |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 517 | func (flagExporter *flagExporter) exportLinkObjects(flags ...android.Path) { |
| 518 | flagExporter.linkObjects = android.FirstUniquePaths(append(flagExporter.linkObjects, flags...)) |
| 519 | } |
| 520 | |
| 521 | func (flagExporter *flagExporter) exportLibDeps(paths ...android.Path) { |
| 522 | flagExporter.libDeps = android.FirstUniquePaths(append(flagExporter.libDeps, paths...)) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 523 | } |
| 524 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 525 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 526 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 527 | LinkDirs: flagExporter.linkDirs, |
| 528 | LinkObjects: flagExporter.linkObjects, |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 529 | LibDeps: flagExporter.libDeps, |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 530 | }) |
| 531 | } |
| 532 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 533 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 534 | |
| 535 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 536 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 539 | type FlagExporterInfo struct { |
| 540 | Flags []string |
| 541 | LinkDirs []string // TODO: this should be android.Paths |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 542 | LinkObjects android.Paths |
| 543 | LibDeps android.Paths |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 547 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 548 | func (mod *Module) isCoverageVariant() bool { |
| 549 | return mod.coverage.Properties.IsCoverageVariant |
| 550 | } |
| 551 | |
| 552 | var _ cc.Coverage = (*Module)(nil) |
| 553 | |
| 554 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 555 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 556 | } |
| 557 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 558 | func (mod *Module) VndkVersion() string { |
| 559 | return mod.Properties.VndkVersion |
| 560 | } |
| 561 | |
| 562 | func (mod *Module) PreventInstall() bool { |
| 563 | return mod.Properties.PreventInstall |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 566 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 567 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 568 | } |
| 569 | |
| 570 | func (mod *Module) EnableCoverageIfNeeded() { |
| 571 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | func defaultsFactory() android.Module { |
| 575 | return DefaultsFactory() |
| 576 | } |
| 577 | |
| 578 | type Defaults struct { |
| 579 | android.ModuleBase |
| 580 | android.DefaultsModuleBase |
| 581 | } |
| 582 | |
| 583 | func DefaultsFactory(props ...interface{}) android.Module { |
| 584 | module := &Defaults{} |
| 585 | |
| 586 | module.AddProperties(props...) |
| 587 | module.AddProperties( |
| 588 | &BaseProperties{}, |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 589 | &cc.AfdoProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 590 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 591 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 592 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 593 | &BaseCompilerProperties{}, |
| 594 | &BinaryCompilerProperties{}, |
| 595 | &LibraryCompilerProperties{}, |
| 596 | &ProcMacroCompilerProperties{}, |
| 597 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 598 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 599 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 600 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 601 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 602 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 603 | &SanitizeProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 604 | ) |
| 605 | |
| 606 | android.InitDefaultsModule(module) |
| 607 | return module |
| 608 | } |
| 609 | |
| 610 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 611 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 614 | func (mod *Module) CcLibrary() bool { |
| 615 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 616 | if _, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 617 | return true |
| 618 | } |
| 619 | } |
| 620 | return false |
| 621 | } |
| 622 | |
| 623 | func (mod *Module) CcLibraryInterface() bool { |
| 624 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 625 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 626 | // VariantIs{Static,Shared} is set. |
| 627 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 628 | return true |
| 629 | } |
| 630 | } |
| 631 | return false |
| 632 | } |
| 633 | |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 634 | func (mod *Module) IsFuzzModule() bool { |
| 635 | if _, ok := mod.compiler.(*fuzzDecorator); ok { |
| 636 | return true |
| 637 | } |
| 638 | return false |
| 639 | } |
| 640 | |
| 641 | func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule { |
| 642 | return mod.FuzzModule |
| 643 | } |
| 644 | |
| 645 | func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { |
| 646 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 647 | return fuzzer.fuzzPackagedModule |
| 648 | } |
| 649 | panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName())) |
| 650 | } |
| 651 | |
Hamzeh Zawawy | 3891749 | 2023-04-05 22:08:46 +0000 | [diff] [blame^] | 652 | func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 653 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 654 | return fuzzer.sharedLibraries |
| 655 | } |
| 656 | panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName())) |
| 657 | } |
| 658 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 659 | func (mod *Module) UnstrippedOutputFile() android.Path { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 660 | if mod.compiler != nil { |
| 661 | return mod.compiler.unstrippedOutputFilePath() |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 662 | } |
| 663 | return nil |
| 664 | } |
| 665 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 666 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 667 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 668 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 669 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 673 | } |
| 674 | |
| 675 | func (mod *Module) SetStatic() { |
| 676 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 677 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 678 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 679 | return |
| 680 | } |
| 681 | } |
| 682 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 683 | } |
| 684 | |
| 685 | func (mod *Module) SetShared() { |
| 686 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 687 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 688 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 689 | return |
| 690 | } |
| 691 | } |
| 692 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 693 | } |
| 694 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 695 | func (mod *Module) BuildStaticVariant() bool { |
| 696 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 697 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 698 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 702 | } |
| 703 | |
| 704 | func (mod *Module) BuildSharedVariant() bool { |
| 705 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 706 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 707 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 711 | } |
| 712 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 713 | func (mod *Module) Module() android.Module { |
| 714 | return mod |
| 715 | } |
| 716 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 717 | func (mod *Module) OutputFile() android.OptionalPath { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 718 | return mod.outputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 721 | func (mod *Module) CoverageFiles() android.Paths { |
| 722 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 723 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 724 | } |
| 725 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 726 | } |
| 727 | |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 728 | // Rust does not produce gcno files, and therefore does not produce a coverage archive. |
| 729 | func (mod *Module) CoverageOutputFile() android.OptionalPath { |
| 730 | return android.OptionalPath{} |
| 731 | } |
| 732 | |
| 733 | func (mod *Module) IsNdk(config android.Config) bool { |
| 734 | return false |
| 735 | } |
| 736 | |
| 737 | func (mod *Module) IsStubs() bool { |
| 738 | return false |
| 739 | } |
| 740 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 741 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
Jiyong Park | 2811e07 | 2021-09-30 17:25:21 +0900 | [diff] [blame] | 742 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) { |
Jiyong Park | bf8147a | 2021-05-17 13:19:33 +0900 | [diff] [blame] | 743 | return false |
| 744 | } |
| 745 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 746 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 747 | // in the system partition as a standalone file. |
| 748 | if !apexInfo.IsForPlatform() { |
| 749 | return false |
| 750 | } |
| 751 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 752 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 753 | } |
| 754 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 755 | func (ctx moduleContext) apexVariationName() string { |
| 756 | return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName |
| 757 | } |
| 758 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 759 | var _ cc.LinkableInterface = (*Module)(nil) |
| 760 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 761 | func (mod *Module) Init() android.Module { |
| 762 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 763 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 764 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 765 | if mod.afdo != nil { |
| 766 | mod.AddProperties(mod.afdo.props()...) |
| 767 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 768 | if mod.compiler != nil { |
| 769 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 770 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 771 | if mod.coverage != nil { |
| 772 | mod.AddProperties(mod.coverage.props()...) |
| 773 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 774 | if mod.clippy != nil { |
| 775 | mod.AddProperties(mod.clippy.props()...) |
| 776 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 777 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 778 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 779 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 780 | if mod.sanitize != nil { |
| 781 | mod.AddProperties(mod.sanitize.props()...) |
| 782 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 783 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 784 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 785 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 786 | |
| 787 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 788 | return mod |
| 789 | } |
| 790 | |
| 791 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 792 | return &Module{ |
| 793 | hod: hod, |
| 794 | multilib: multilib, |
| 795 | } |
| 796 | } |
| 797 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 798 | module := newBaseModule(hod, multilib) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 799 | module.afdo = &afdo{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 800 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 801 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 802 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 803 | return module |
| 804 | } |
| 805 | |
| 806 | type ModuleContext interface { |
| 807 | android.ModuleContext |
| 808 | ModuleContextIntf |
| 809 | } |
| 810 | |
| 811 | type BaseModuleContext interface { |
| 812 | android.BaseModuleContext |
| 813 | ModuleContextIntf |
| 814 | } |
| 815 | |
| 816 | type DepsContext interface { |
| 817 | android.BottomUpMutatorContext |
| 818 | ModuleContextIntf |
| 819 | } |
| 820 | |
| 821 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 822 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 823 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | type depsContext struct { |
| 827 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | type moduleContext struct { |
| 831 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 834 | type baseModuleContext struct { |
| 835 | android.BaseModuleContext |
| 836 | } |
| 837 | |
| 838 | func (ctx *moduleContext) RustModule() *Module { |
| 839 | return ctx.Module().(*Module) |
| 840 | } |
| 841 | |
| 842 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 843 | return ctx.RustModule().toolchain(ctx) |
| 844 | } |
| 845 | |
| 846 | func (ctx *depsContext) RustModule() *Module { |
| 847 | return ctx.Module().(*Module) |
| 848 | } |
| 849 | |
| 850 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 851 | return ctx.RustModule().toolchain(ctx) |
| 852 | } |
| 853 | |
| 854 | func (ctx *baseModuleContext) RustModule() *Module { |
| 855 | return ctx.Module().(*Module) |
| 856 | } |
| 857 | |
| 858 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 859 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | func (mod *Module) nativeCoverage() bool { |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 863 | // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage |
| 864 | if mod.Target().NativeBridge == android.NativeBridgeEnabled { |
| 865 | return false |
| 866 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 867 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 868 | } |
| 869 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 870 | func (mod *Module) EverInstallable() bool { |
| 871 | return mod.compiler != nil && |
| 872 | // Check to see whether the module is actually ever installable. |
| 873 | mod.compiler.everInstallable() |
| 874 | } |
| 875 | |
| 876 | func (mod *Module) Installable() *bool { |
| 877 | return mod.Properties.Installable |
| 878 | } |
| 879 | |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 880 | func (mod *Module) ProcMacro() bool { |
| 881 | if pm, ok := mod.compiler.(procMacroInterface); ok { |
| 882 | return pm.ProcMacro() |
| 883 | } |
| 884 | return false |
| 885 | } |
| 886 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 887 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 888 | if mod.cachedToolchain == nil { |
| 889 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 890 | } |
| 891 | return mod.cachedToolchain |
| 892 | } |
| 893 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 894 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 895 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 896 | } |
| 897 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 898 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 899 | } |
| 900 | |
| 901 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 902 | ctx := &moduleContext{ |
| 903 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 904 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 905 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 906 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 907 | if !apexInfo.IsForPlatform() { |
| 908 | mod.hideApexVariantFromMake = true |
| 909 | } |
| 910 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 911 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 912 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 913 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 914 | mod.Properties.SubName = cc.GetSubnameProperty(actx, mod) |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 915 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 916 | if !toolchain.Supported() { |
| 917 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 918 | return |
| 919 | } |
| 920 | |
| 921 | deps := mod.depsToPaths(ctx) |
| 922 | flags := Flags{ |
| 923 | Toolchain: toolchain, |
| 924 | } |
| 925 | |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 926 | // Calculate rustc flags |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 927 | if mod.afdo != nil { |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 928 | flags, deps = mod.afdo.flags(actx, flags, deps) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 929 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 930 | if mod.compiler != nil { |
| 931 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 932 | flags = mod.compiler.cfgFlags(ctx, flags) |
| 933 | flags = mod.compiler.featureFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 934 | } |
| 935 | if mod.coverage != nil { |
| 936 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 937 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 938 | if mod.clippy != nil { |
| 939 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 940 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 941 | if mod.sanitize != nil { |
| 942 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 943 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 944 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 945 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 946 | // compile() so it can provide the source. A SourceProvider has |
| 947 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 948 | // variant is responsible for effectively generating the source. The |
| 949 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 950 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 951 | if mod.compiler.(libraryInterface).source() { |
| 952 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 953 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 954 | } else { |
| 955 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 956 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 957 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 958 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 962 | mod.compiler.initialize(ctx) |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 963 | buildOutput := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 964 | if ctx.Failed() { |
| 965 | return |
| 966 | } |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 967 | mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile) |
| 968 | if buildOutput.kytheFile != nil { |
| 969 | mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile) |
| 970 | } |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 971 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath())) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 972 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 973 | mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps) |
Matthew Maurer | e380363 | 2021-12-10 21:57:21 +0000 | [diff] [blame] | 974 | if mod.docTimestampFile.Valid() { |
| 975 | ctx.CheckbuildFile(mod.docTimestampFile.Path()) |
| 976 | } |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 977 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 978 | // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or |
| 979 | // RECOVERY_SNAPSHOT_VERSION is current. |
| 980 | if lib, ok := mod.compiler.(snapshotLibraryInterface); ok { |
| 981 | if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) { |
| 982 | lib.collectHeadersForSnapshot(ctx, deps) |
| 983 | } |
| 984 | } |
| 985 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 986 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 987 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() { |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 988 | // If the module has been specifically configure to not be installed then |
| 989 | // hide from make as otherwise it will break when running inside make as the |
| 990 | // output path to install will not be specified. Not all uninstallable |
| 991 | // modules can be hidden from make as some are needed for resolving make |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 992 | // side dependencies. In particular, proc-macros need to be captured in the |
| 993 | // host snapshot. |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 994 | mod.HideFromMake() |
| 995 | } else if !mod.installable(apexInfo) { |
| 996 | mod.SkipInstall() |
| 997 | } |
| 998 | |
| 999 | // Still call install though, the installs will be stored as PackageSpecs to allow |
| 1000 | // using the outputs in a genrule. |
| 1001 | if mod.OutputFile().Valid() { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 1002 | mod.compiler.install(ctx) |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1003 | if ctx.Failed() { |
| 1004 | return |
| 1005 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1006 | } |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 1007 | |
| 1008 | ctx.Phony("rust", ctx.RustModule().OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 1013 | deps := Deps{} |
| 1014 | |
| 1015 | if mod.compiler != nil { |
| 1016 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1017 | } |
| 1018 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 1019 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1022 | if mod.coverage != nil { |
| 1023 | deps = mod.coverage.deps(ctx, deps) |
| 1024 | } |
| 1025 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1026 | if mod.sanitize != nil { |
| 1027 | deps = mod.sanitize.deps(ctx, deps) |
| 1028 | } |
| 1029 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1030 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 1031 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1032 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1033 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 1034 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1035 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Andrew Walbran | 797e4be | 2022-03-07 15:41:53 +0000 | [diff] [blame] | 1036 | deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1037 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1038 | return deps |
| 1039 | |
| 1040 | } |
| 1041 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1042 | type dependencyTag struct { |
| 1043 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1044 | name string |
| 1045 | library bool |
| 1046 | procMacro bool |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1047 | dynamic bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1050 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 1051 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 1052 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1053 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 1057 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1058 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 1059 | if d.library && d.dynamic { |
| 1060 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
| 1061 | } |
| 1062 | return nil |
| 1063 | } |
| 1064 | |
| 1065 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 1066 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1067 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1068 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 1069 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1070 | dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1071 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1072 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1073 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1074 | dataLibDepTag = dependencyTag{name: "data lib"} |
| 1075 | dataBinDepTag = dependencyTag{name: "data bin"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1076 | ) |
| 1077 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1078 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 1079 | tag, ok := depTag.(dependencyTag) |
| 1080 | return ok && tag == dylibDepTag |
| 1081 | } |
| 1082 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 1083 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 1084 | tag, ok := depTag.(dependencyTag) |
| 1085 | return ok && tag == rlibDepTag |
| 1086 | } |
| 1087 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1088 | type autoDep struct { |
| 1089 | variation string |
| 1090 | depTag dependencyTag |
| 1091 | } |
| 1092 | |
| 1093 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1094 | rlibVariation = "rlib" |
| 1095 | dylibVariation = "dylib" |
| 1096 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 1097 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1098 | ) |
| 1099 | |
| 1100 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1101 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1104 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 1105 | if mod.coverage != nil { |
| 1106 | mod.coverage.begin(ctx) |
| 1107 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1108 | if mod.sanitize != nil { |
| 1109 | mod.sanitize.begin(ctx) |
| 1110 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1113 | func (mod *Module) Prebuilt() *android.Prebuilt { |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1114 | if p, ok := mod.compiler.(rustPrebuilt); ok { |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1115 | return p.prebuilt() |
| 1116 | } |
| 1117 | return nil |
| 1118 | } |
| 1119 | |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1120 | func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.LinkableInterface, depName string) string { |
| 1121 | if rustDep, ok := dep.(*Module); ok { |
| 1122 | // Use base module name for snapshots when exporting to Makefile. |
| 1123 | if snapshotPrebuilt, ok := rustDep.compiler.(cc.SnapshotInterface); ok { |
| 1124 | baseName := rustDep.BaseModuleName() |
| 1125 | return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix() + rustDep.AndroidMkSuffix() |
| 1126 | } |
| 1127 | } |
| 1128 | return cc.MakeLibName(ctx, c, dep, depName) |
| 1129 | } |
| 1130 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1131 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 1132 | var depPaths PathDeps |
| 1133 | |
| 1134 | directRlibDeps := []*Module{} |
| 1135 | directDylibDeps := []*Module{} |
| 1136 | directProcMacroDeps := []*Module{} |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1137 | directSharedLibDeps := []cc.SharedLibraryInfo{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1138 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1139 | directSrcProvidersDeps := []*Module{} |
| 1140 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1141 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 1142 | // For the dependency from platform to apex, use the latest stubs |
| 1143 | mod.apexSdkVersion = android.FutureApiLevel |
| 1144 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1145 | if !apexInfo.IsForPlatform() { |
| 1146 | mod.apexSdkVersion = apexInfo.MinSdkVersion |
| 1147 | } |
| 1148 | |
| 1149 | if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { |
| 1150 | // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) |
| 1151 | // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). |
| 1152 | // (b/144430859) |
| 1153 | mod.apexSdkVersion = android.FutureApiLevel |
| 1154 | } |
| 1155 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1156 | skipModuleList := map[string]bool{} |
| 1157 | |
| 1158 | var apiImportInfo multitree.ApiImportInfo |
| 1159 | hasApiImportInfo := false |
| 1160 | |
| 1161 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1162 | if dep.Name() == "api_imports" { |
| 1163 | apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo) |
| 1164 | hasApiImportInfo = true |
| 1165 | } |
| 1166 | }) |
| 1167 | |
| 1168 | if hasApiImportInfo { |
| 1169 | targetStubModuleList := map[string]string{} |
| 1170 | targetOrigModuleList := map[string]string{} |
| 1171 | |
| 1172 | // Search for dependency which both original module and API imported library with APEX stub exists |
| 1173 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1174 | depName := ctx.OtherModuleName(dep) |
| 1175 | if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok { |
| 1176 | targetStubModuleList[apiLibrary] = depName |
| 1177 | } |
| 1178 | }) |
| 1179 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1180 | depName := ctx.OtherModuleName(dep) |
| 1181 | if origLibrary, ok := targetStubModuleList[depName]; ok { |
| 1182 | targetOrigModuleList[origLibrary] = depName |
| 1183 | } |
| 1184 | }) |
| 1185 | |
| 1186 | // Decide which library should be used between original and API imported library |
| 1187 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1188 | depName := ctx.OtherModuleName(dep) |
| 1189 | if apiLibrary, ok := targetOrigModuleList[depName]; ok { |
| 1190 | if cc.ShouldUseStubForApex(ctx, dep) { |
| 1191 | skipModuleList[depName] = true |
| 1192 | } else { |
| 1193 | skipModuleList[apiLibrary] = true |
| 1194 | } |
| 1195 | } |
| 1196 | }) |
| 1197 | } |
| 1198 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1199 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1200 | depName := ctx.OtherModuleName(dep) |
| 1201 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1202 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1203 | if _, exists := skipModuleList[depName]; exists { |
| 1204 | return |
| 1205 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1206 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1207 | //Handle Rust Modules |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1208 | makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName) |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1209 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1210 | switch depTag { |
| 1211 | case dylibDepTag: |
| 1212 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 1213 | if !ok || !dylib.dylib() { |
| 1214 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 1215 | return |
| 1216 | } |
| 1217 | directDylibDeps = append(directDylibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1218 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1219 | case rlibDepTag: |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1220 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1221 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 1222 | if !ok || !rlib.rlib() { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1223 | ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1224 | return |
| 1225 | } |
| 1226 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1227 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1228 | case procMacroDepTag: |
| 1229 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1230 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1234 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 1235 | // OS/Arch variant is used. |
| 1236 | var helper string |
| 1237 | if ctx.Host() { |
| 1238 | helper = "missing 'host_supported'?" |
| 1239 | } else { |
| 1240 | helper = "device module defined?" |
| 1241 | } |
| 1242 | |
| 1243 | if dep.Target().Os != ctx.Os() { |
| 1244 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1245 | return |
| 1246 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1247 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1248 | return |
| 1249 | } |
| 1250 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 1253 | //Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1254 | if depTag != procMacroDepTag { |
| 1255 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 1256 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 1257 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 1258 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1259 | depPaths.LibDeps = append(depPaths.LibDeps, exportedInfo.LibDeps...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1262 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1263 | linkFile := rustDep.UnstrippedOutputFile() |
| 1264 | linkDir := linkPathFromFilePath(linkFile) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1265 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 1266 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1270 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1271 | //Handle C dependencies |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1272 | makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1273 | if _, ok := ccDep.(*Module); !ok { |
| 1274 | if ccDep.Module().Target().Os != ctx.Os() { |
| 1275 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1276 | return |
| 1277 | } |
| 1278 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1279 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1280 | return |
| 1281 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1282 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1283 | linkObject := ccDep.OutputFile() |
| 1284 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 1285 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1286 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1287 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1288 | } |
| 1289 | |
| 1290 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1291 | switch { |
| 1292 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1293 | if cc.IsWholeStaticLib(depTag) { |
| 1294 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 1295 | // if the library is not prefixed by "lib". |
Ivan Lozano | fdadcd7 | 2021-11-01 09:04:23 -0400 | [diff] [blame] | 1296 | if mod.Binary() { |
| 1297 | // Binaries may sometimes need to link whole static libraries that don't start with 'lib'. |
| 1298 | // Since binaries don't need to 'rebundle' these like libraries and only use these for the |
| 1299 | // final linkage, pass the args directly to the linker to handle these cases. |
| 1300 | depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...) |
| 1301 | } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1302 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1303 | depPaths.WholeStaticLibs = append(depPaths.WholeStaticLibs, linkObject.Path()) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1304 | } else { |
| 1305 | 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 Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1306 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 1310 | // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant. |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1311 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1312 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 1313 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1314 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1315 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1316 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1317 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1318 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1319 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
Justin Yun | 2b3ed64 | 2022-02-16 08:15:07 +0900 | [diff] [blame] | 1320 | |
| 1321 | // Record baseLibName for snapshots. |
| 1322 | mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName)) |
| 1323 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1324 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1325 | case cc.IsSharedDepTag(depTag): |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1326 | // For the shared lib dependencies, we may link to the stub variant |
| 1327 | // of the dependency depending on the context (e.g. if this |
| 1328 | // dependency crosses the APEX boundaries). |
| 1329 | sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep) |
| 1330 | |
| 1331 | // Re-get linkObject as ChooseStubOrImpl actually tells us which |
| 1332 | // object (either from stub or non-stub) to use. |
| 1333 | linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary) |
| 1334 | linkPath = linkPathFromFilePath(linkObject.Path()) |
| 1335 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1336 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1337 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1338 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1339 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1340 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1341 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1342 | directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1343 | |
| 1344 | // Record baseLibName for snapshots. |
| 1345 | mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName)) |
| 1346 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1347 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1348 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1349 | case cc.IsHeaderDepTag(depTag): |
| 1350 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1351 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1352 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1353 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1354 | case depTag == cc.CrtBeginDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1355 | depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path()) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1356 | case depTag == cc.CrtEndDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1357 | depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1361 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 1362 | lib.exportLinkDirs(linkPath) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1363 | if linkObject.Valid() { |
| 1364 | lib.exportLinkObjects(linkObject.Path()) |
| 1365 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1366 | } |
Colin Cross | 018cbeb | 2022-01-24 17:22:45 -0800 | [diff] [blame] | 1367 | } else { |
| 1368 | switch { |
| 1369 | case depTag == cc.CrtBeginDepTag: |
| 1370 | depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, "")) |
| 1371 | case depTag == cc.CrtEndDepTag: |
| 1372 | depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, "")) |
| 1373 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1374 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1375 | |
| 1376 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1377 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1378 | // These are usually genrules which don't have per-target variants. |
| 1379 | directSrcDeps = append(directSrcDeps, srcDep) |
| 1380 | } |
| 1381 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1382 | }) |
| 1383 | |
| 1384 | var rlibDepFiles RustLibraries |
| 1385 | for _, dep := range directRlibDeps { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1386 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1387 | } |
| 1388 | var dylibDepFiles RustLibraries |
| 1389 | for _, dep := range directDylibDeps { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1390 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1391 | } |
| 1392 | var procMacroDepFiles RustLibraries |
| 1393 | for _, dep := range directProcMacroDeps { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1394 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1397 | var libDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1398 | for _, dep := range directStaticLibDeps { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1399 | libDepFiles = append(libDepFiles, dep.OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1402 | for _, dep := range directSharedLibDeps { |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1403 | if dep.TableOfContents.Valid() { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1404 | libDepFiles = append(libDepFiles, dep.TableOfContents.Path()) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1405 | } else { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1406 | libDepFiles = append(libDepFiles, dep.SharedLibrary) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1407 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1410 | var srcProviderDepFiles android.Paths |
| 1411 | for _, dep := range directSrcProvidersDeps { |
| 1412 | srcs, _ := dep.OutputFiles("") |
| 1413 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1414 | } |
| 1415 | for _, dep := range directSrcDeps { |
| 1416 | srcs := dep.Srcs() |
| 1417 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1418 | } |
| 1419 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1420 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1421 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1422 | depPaths.LibDeps = append(depPaths.LibDeps, libDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1423 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1424 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1425 | |
| 1426 | // Dedup exported flags from dependencies |
| 1427 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1428 | depPaths.linkObjects = android.FirstUniquePaths(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1429 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1430 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1431 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1432 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1433 | |
| 1434 | return depPaths |
| 1435 | } |
| 1436 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1437 | func (mod *Module) InstallInData() bool { |
| 1438 | if mod.compiler == nil { |
| 1439 | return false |
| 1440 | } |
| 1441 | return mod.compiler.inData() |
| 1442 | } |
| 1443 | |
Matthew Maurer | 9f59e8d | 2021-08-19 13:10:05 -0700 | [diff] [blame] | 1444 | func (mod *Module) InstallInRamdisk() bool { |
| 1445 | return mod.InRamdisk() |
| 1446 | } |
| 1447 | |
| 1448 | func (mod *Module) InstallInVendorRamdisk() bool { |
| 1449 | return mod.InVendorRamdisk() |
| 1450 | } |
| 1451 | |
| 1452 | func (mod *Module) InstallInRecovery() bool { |
| 1453 | return mod.InRecovery() |
| 1454 | } |
| 1455 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1456 | func linkPathFromFilePath(filepath android.Path) string { |
| 1457 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1458 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 1459 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1460 | // usePublicApi returns true if the rust variant should link against NDK (publicapi) |
| 1461 | func (r *Module) usePublicApi() bool { |
| 1462 | return r.Device() && r.UseSdk() |
| 1463 | } |
| 1464 | |
| 1465 | // useVendorApi returns true if the rust variant should link against LLNDK (vendorapi) |
| 1466 | func (r *Module) useVendorApi() bool { |
| 1467 | return r.Device() && (r.InVendor() || r.InProduct()) |
| 1468 | } |
| 1469 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1470 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1471 | ctx := &depsContext{ |
| 1472 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1473 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1474 | |
| 1475 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1476 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1477 | var snapshotInfo *cc.SnapshotInfo |
| 1478 | |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1479 | apiImportInfo := cc.GetApiImports(mod, actx) |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1480 | if mod.usePublicApi() || mod.useVendorApi() { |
| 1481 | for idx, lib := range deps.SharedLibs { |
| 1482 | deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs) |
| 1483 | } |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1484 | } |
| 1485 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1486 | if ctx.Os() == android.Android { |
| 1487 | deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs) |
| 1488 | } |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1489 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1490 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1491 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1492 | stdLinkage = "rlib-std" |
| 1493 | } |
| 1494 | |
| 1495 | rlibDepVariations := commonDepVariations |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1496 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1497 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1498 | rlibDepVariations = append(rlibDepVariations, |
| 1499 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1500 | } |
| 1501 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1502 | // rlibs |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1503 | rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation}) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1504 | for _, lib := range deps.Rlibs { |
| 1505 | depTag := rlibDepTag |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1506 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1507 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1508 | actx.AddVariationDependencies(rlibDepVariations, depTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1509 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1510 | |
| 1511 | // dylibs |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1512 | actx.AddVariationDependencies( |
| 1513 | append(commonDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1514 | {Mutator: "rust_libraries", Variation: dylibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1515 | dylibDepTag, deps.Dylibs...) |
| 1516 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1517 | // rustlibs |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1518 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1519 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1520 | for _, lib := range deps.Rustlibs { |
| 1521 | if autoDep.depTag == rlibDepTag { |
| 1522 | // Handle the rlib deptag case |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1523 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1524 | } else { |
| 1525 | // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. |
| 1526 | // Check for the existence of the dylib deptag variant. Select it if available, |
| 1527 | // otherwise select the rlib variant. |
| 1528 | autoDepVariations := append(commonDepVariations, |
| 1529 | blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) |
| 1530 | if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) { |
| 1531 | actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib) |
| 1532 | } else { |
| 1533 | // If there's no dylib dependency available, try to add the rlib dependency instead. |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1534 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1535 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1536 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1537 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1538 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1539 | // stdlibs |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1540 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1541 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1542 | for _, lib := range deps.Stdlibs { |
| 1543 | depTag := rlibDepTag |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1544 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1545 | |
| 1546 | actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), |
| 1547 | depTag, lib) |
| 1548 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1549 | } else { |
| 1550 | actx.AddVariationDependencies( |
| 1551 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), |
| 1552 | dylibDepTag, deps.Stdlibs...) |
| 1553 | } |
| 1554 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1555 | |
| 1556 | for _, lib := range deps.SharedLibs { |
| 1557 | depTag := cc.SharedDepTag() |
| 1558 | name, version := cc.StubsLibNameAndVersion(lib) |
| 1559 | |
| 1560 | variations := []blueprint.Variation{ |
| 1561 | {Mutator: "link", Variation: "shared"}, |
| 1562 | } |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1563 | // For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists) |
| 1564 | // GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary |
| 1565 | if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) { |
| 1566 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) |
| 1567 | } |
| 1568 | |
| 1569 | if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok { |
| 1570 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false) |
| 1571 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | for _, lib := range deps.WholeStaticLibs { |
| 1575 | depTag := cc.StaticDepTag(true) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1576 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1577 | |
| 1578 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1579 | {Mutator: "link", Variation: "static"}, |
| 1580 | }, depTag, lib) |
| 1581 | } |
| 1582 | |
| 1583 | for _, lib := range deps.StaticLibs { |
| 1584 | depTag := cc.StaticDepTag(false) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1585 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1586 | |
| 1587 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1588 | {Mutator: "link", Variation: "static"}, |
| 1589 | }, depTag, lib) |
| 1590 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1591 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1592 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1593 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1594 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1595 | for _, crt := range deps.CrtBegin { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1596 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1597 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1598 | } |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1599 | for _, crt := range deps.CrtEnd { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1600 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1601 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1604 | if mod.sourceProvider != nil { |
| 1605 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1606 | bindgen.Properties.Custom_bindgen != "" { |
| 1607 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1608 | bindgen.Properties.Custom_bindgen) |
| 1609 | } |
| 1610 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1611 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1612 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1613 | {Mutator: "link", Variation: "shared"}, |
| 1614 | }, dataLibDepTag, deps.DataLibs...) |
| 1615 | |
| 1616 | actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...) |
| 1617 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1618 | // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1619 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1620 | |
| 1621 | mod.afdo.addDep(ctx, actx) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1624 | // addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available. |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1625 | func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation) { |
| 1626 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Rlibs) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1627 | actx.AddVariationDependencies(variations, rlibDepTag, lib) |
| 1628 | } |
| 1629 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1630 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1631 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1632 | mod.beginMutator(ctx) |
| 1633 | } |
| 1634 | } |
| 1635 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1636 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1637 | ctx := &baseModuleContext{ |
| 1638 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1639 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1640 | |
| 1641 | mod.begin(ctx) |
| 1642 | } |
| 1643 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1644 | func (mod *Module) Name() string { |
| 1645 | name := mod.ModuleBase.Name() |
| 1646 | if p, ok := mod.compiler.(interface { |
| 1647 | Name(string) string |
| 1648 | }); ok { |
| 1649 | name = p.Name(name) |
| 1650 | } |
| 1651 | return name |
| 1652 | } |
| 1653 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1654 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1655 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1656 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1657 | } |
| 1658 | } |
| 1659 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1660 | var _ android.HostToolProvider = (*Module)(nil) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1661 | var _ snapshot.RelativeInstallPath = (*Module)(nil) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1662 | |
| 1663 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1664 | if !mod.Host() { |
| 1665 | return android.OptionalPath{} |
| 1666 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1667 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1668 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1669 | } else if pm, ok := mod.compiler.(*procMacroDecorator); ok { |
| 1670 | // Even though proc-macros aren't strictly "tools", since they target the compiler |
| 1671 | // and act as compiler plugins, we treat them similarly. |
| 1672 | return android.OptionalPathForPath(pm.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1673 | } |
| 1674 | return android.OptionalPath{} |
| 1675 | } |
| 1676 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1677 | var _ android.ApexModule = (*Module)(nil) |
| 1678 | |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1679 | func (mod *Module) MinSdkVersion() string { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1680 | return String(mod.Properties.Min_sdk_version) |
| 1681 | } |
| 1682 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1683 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1684 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1685 | minSdkVersion := mod.MinSdkVersion() |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1686 | if minSdkVersion == "apex_inherit" { |
| 1687 | return nil |
| 1688 | } |
| 1689 | if minSdkVersion == "" { |
| 1690 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1691 | } |
| 1692 | |
| 1693 | // Not using nativeApiLevelFromUser because the context here is not |
| 1694 | // necessarily a native context. |
| 1695 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1696 | if err != nil { |
| 1697 | return err |
| 1698 | } |
| 1699 | |
| 1700 | if ver.GreaterThan(sdkVersion) { |
| 1701 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1702 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1703 | return nil |
| 1704 | } |
| 1705 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1706 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1707 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1708 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1709 | |
| 1710 | if ccm, ok := dep.(*cc.Module); ok { |
| 1711 | if ccm.HasStubsVariants() { |
| 1712 | if cc.IsSharedDepTag(depTag) { |
| 1713 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1714 | return false |
| 1715 | } |
| 1716 | if cc.IsRuntimeDepTag(depTag) { |
| 1717 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1718 | return false |
| 1719 | } |
| 1720 | |
| 1721 | if cc.IsHeaderDepTag(depTag) { |
| 1722 | return false |
| 1723 | } |
| 1724 | } |
| 1725 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1726 | // shared_lib dependency from a static lib is considered as crossing |
| 1727 | // the APEX boundary because the dependency doesn't actually is |
| 1728 | // linked; the dependency is used only during the compilation phase. |
| 1729 | return false |
| 1730 | } |
| 1731 | } |
| 1732 | |
Matthew Maurer | 581b6d8 | 2022-09-29 16:46:25 -0700 | [diff] [blame] | 1733 | if depTag == procMacroDepTag || depTag == customBindgenDepTag { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1734 | return false |
| 1735 | } |
| 1736 | |
| 1737 | return true |
| 1738 | } |
| 1739 | |
| 1740 | // Overrides ApexModule.IsInstallabeToApex() |
| 1741 | func (mod *Module) IsInstallableToApex() bool { |
| 1742 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 1743 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1744 | return true |
| 1745 | } |
| 1746 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1747 | return true |
| 1748 | } |
| 1749 | } |
| 1750 | return false |
| 1751 | } |
| 1752 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1753 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1754 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1755 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1756 | if strings.HasPrefix(libName, "lib") { |
| 1757 | libName = libName[3:] |
| 1758 | return libName, true |
| 1759 | } |
| 1760 | return "", false |
| 1761 | } |
| 1762 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1763 | func kytheExtractRustFactory() android.Singleton { |
| 1764 | return &kytheExtractRustSingleton{} |
| 1765 | } |
| 1766 | |
| 1767 | type kytheExtractRustSingleton struct { |
| 1768 | } |
| 1769 | |
| 1770 | func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 1771 | var xrefTargets android.Paths |
| 1772 | ctx.VisitAllModules(func(module android.Module) { |
| 1773 | if rustModule, ok := module.(xref); ok { |
| 1774 | xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...) |
| 1775 | } |
| 1776 | }) |
| 1777 | if len(xrefTargets) > 0 { |
| 1778 | ctx.Phony("xref_rust", xrefTargets...) |
| 1779 | } |
| 1780 | } |
| 1781 | |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 1782 | func (c *Module) Partition() string { |
| 1783 | return "" |
| 1784 | } |
| 1785 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1786 | var Bool = proptools.Bool |
| 1787 | var BoolDefault = proptools.BoolDefault |
| 1788 | var String = proptools.String |
| 1789 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1790 | |
| 1791 | var _ android.OutputFileProducer = (*Module)(nil) |