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