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