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