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