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