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