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