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 { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame^] | 323 | initialize(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 324 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 325 | compilerProps() []interface{} |
| 326 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 327 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 328 | crateName() string |
| 329 | |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame^] | 330 | // Output directory in which source-generated code from dependencies is |
| 331 | // copied. This is equivalent to Cargo's OUT_DIR variable. |
| 332 | CargoOutDir() android.OptionalPath |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 333 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 334 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 335 | relativeInstallPath() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 336 | |
| 337 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 338 | |
| 339 | Disabled() bool |
| 340 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 341 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 342 | stdLinkage(ctx *depsContext) RustLinkage |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 343 | isDependencyRoot() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 344 | } |
| 345 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 346 | type exportedFlagsProducer interface { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 347 | exportLinkDirs(...string) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 348 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 352 | linkDirs []string |
| 353 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 356 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 357 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 358 | } |
| 359 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 360 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 361 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
| 362 | } |
| 363 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 364 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 365 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 366 | LinkDirs: flagExporter.linkDirs, |
| 367 | LinkObjects: flagExporter.linkObjects, |
| 368 | }) |
| 369 | } |
| 370 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 371 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 372 | |
| 373 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 374 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 377 | type FlagExporterInfo struct { |
| 378 | Flags []string |
| 379 | LinkDirs []string // TODO: this should be android.Paths |
| 380 | LinkObjects []string // TODO: this should be android.Paths |
| 381 | } |
| 382 | |
| 383 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 384 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 385 | func (mod *Module) isCoverageVariant() bool { |
| 386 | return mod.coverage.Properties.IsCoverageVariant |
| 387 | } |
| 388 | |
| 389 | var _ cc.Coverage = (*Module)(nil) |
| 390 | |
| 391 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 392 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 393 | } |
| 394 | |
| 395 | func (mod *Module) PreventInstall() { |
| 396 | mod.Properties.PreventInstall = true |
| 397 | } |
| 398 | |
| 399 | func (mod *Module) HideFromMake() { |
| 400 | mod.Properties.HideFromMake = true |
| 401 | } |
| 402 | |
| 403 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 404 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 405 | } |
| 406 | |
| 407 | func (mod *Module) EnableCoverageIfNeeded() { |
| 408 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | func defaultsFactory() android.Module { |
| 412 | return DefaultsFactory() |
| 413 | } |
| 414 | |
| 415 | type Defaults struct { |
| 416 | android.ModuleBase |
| 417 | android.DefaultsModuleBase |
| 418 | } |
| 419 | |
| 420 | func DefaultsFactory(props ...interface{}) android.Module { |
| 421 | module := &Defaults{} |
| 422 | |
| 423 | module.AddProperties(props...) |
| 424 | module.AddProperties( |
| 425 | &BaseProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 426 | &cc.VendorProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 427 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 428 | &BaseCompilerProperties{}, |
| 429 | &BinaryCompilerProperties{}, |
| 430 | &LibraryCompilerProperties{}, |
| 431 | &ProcMacroCompilerProperties{}, |
| 432 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 433 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 434 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 435 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 436 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 437 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 438 | &SanitizeProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 439 | ) |
| 440 | |
| 441 | android.InitDefaultsModule(module) |
| 442 | return module |
| 443 | } |
| 444 | |
| 445 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 446 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 449 | func (mod *Module) CcLibrary() bool { |
| 450 | if mod.compiler != nil { |
| 451 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 452 | return true |
| 453 | } |
| 454 | } |
| 455 | return false |
| 456 | } |
| 457 | |
| 458 | func (mod *Module) CcLibraryInterface() bool { |
| 459 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 460 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 461 | // VariantIs{Static,Shared} is set. |
| 462 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 463 | return true |
| 464 | } |
| 465 | } |
| 466 | return false |
| 467 | } |
| 468 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 469 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 470 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 471 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 472 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 476 | } |
| 477 | |
| 478 | func (mod *Module) SetStatic() { |
| 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.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 482 | return |
| 483 | } |
| 484 | } |
| 485 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 486 | } |
| 487 | |
| 488 | func (mod *Module) SetShared() { |
| 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 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 492 | return |
| 493 | } |
| 494 | } |
| 495 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 496 | } |
| 497 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 498 | func (mod *Module) BuildStaticVariant() bool { |
| 499 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 500 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 501 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 505 | } |
| 506 | |
| 507 | func (mod *Module) BuildSharedVariant() bool { |
| 508 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 509 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 510 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 514 | } |
| 515 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 516 | func (mod *Module) Module() android.Module { |
| 517 | return mod |
| 518 | } |
| 519 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 520 | func (mod *Module) OutputFile() android.OptionalPath { |
| 521 | return mod.outputFile |
| 522 | } |
| 523 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 524 | func (mod *Module) CoverageFiles() android.Paths { |
| 525 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 526 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 527 | } |
| 528 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 529 | } |
| 530 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 531 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
| 532 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 533 | // in the system partition as a standalone file. |
| 534 | if !apexInfo.IsForPlatform() { |
| 535 | return false |
| 536 | } |
| 537 | |
| 538 | return mod.outputFile.Valid() && !mod.Properties.PreventInstall |
| 539 | } |
| 540 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 541 | var _ cc.LinkableInterface = (*Module)(nil) |
| 542 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 543 | func (mod *Module) Init() android.Module { |
| 544 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 545 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 546 | |
| 547 | if mod.compiler != nil { |
| 548 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 549 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 550 | if mod.coverage != nil { |
| 551 | mod.AddProperties(mod.coverage.props()...) |
| 552 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 553 | if mod.clippy != nil { |
| 554 | mod.AddProperties(mod.clippy.props()...) |
| 555 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 556 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 557 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 558 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 559 | if mod.sanitize != nil { |
| 560 | mod.AddProperties(mod.sanitize.props()...) |
| 561 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 562 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 563 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 564 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 565 | |
| 566 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 567 | return mod |
| 568 | } |
| 569 | |
| 570 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 571 | return &Module{ |
| 572 | hod: hod, |
| 573 | multilib: multilib, |
| 574 | } |
| 575 | } |
| 576 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 577 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 578 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 579 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 580 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 581 | return module |
| 582 | } |
| 583 | |
| 584 | type ModuleContext interface { |
| 585 | android.ModuleContext |
| 586 | ModuleContextIntf |
| 587 | } |
| 588 | |
| 589 | type BaseModuleContext interface { |
| 590 | android.BaseModuleContext |
| 591 | ModuleContextIntf |
| 592 | } |
| 593 | |
| 594 | type DepsContext interface { |
| 595 | android.BottomUpMutatorContext |
| 596 | ModuleContextIntf |
| 597 | } |
| 598 | |
| 599 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 600 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 601 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | type depsContext struct { |
| 605 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | type moduleContext struct { |
| 609 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 612 | type baseModuleContext struct { |
| 613 | android.BaseModuleContext |
| 614 | } |
| 615 | |
| 616 | func (ctx *moduleContext) RustModule() *Module { |
| 617 | return ctx.Module().(*Module) |
| 618 | } |
| 619 | |
| 620 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 621 | return ctx.RustModule().toolchain(ctx) |
| 622 | } |
| 623 | |
| 624 | func (ctx *depsContext) RustModule() *Module { |
| 625 | return ctx.Module().(*Module) |
| 626 | } |
| 627 | |
| 628 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 629 | return ctx.RustModule().toolchain(ctx) |
| 630 | } |
| 631 | |
| 632 | func (ctx *baseModuleContext) RustModule() *Module { |
| 633 | return ctx.Module().(*Module) |
| 634 | } |
| 635 | |
| 636 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 637 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | func (mod *Module) nativeCoverage() bool { |
| 641 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 642 | } |
| 643 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 644 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 645 | if mod.cachedToolchain == nil { |
| 646 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 647 | } |
| 648 | return mod.cachedToolchain |
| 649 | } |
| 650 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 651 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 652 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 653 | } |
| 654 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 655 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 656 | } |
| 657 | |
| 658 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 659 | ctx := &moduleContext{ |
| 660 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 661 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 662 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 663 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 664 | if !apexInfo.IsForPlatform() { |
| 665 | mod.hideApexVariantFromMake = true |
| 666 | } |
| 667 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 668 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 669 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 670 | |
| 671 | // Differentiate static libraries that are vendor available |
| 672 | if mod.UseVndk() { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 673 | mod.Properties.SubName += cc.VendorSuffix |
| 674 | } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() { |
| 675 | mod.Properties.SubName += cc.VendorRamdiskSuffix |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 676 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 677 | |
| 678 | if !toolchain.Supported() { |
| 679 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 680 | return |
| 681 | } |
| 682 | |
| 683 | deps := mod.depsToPaths(ctx) |
| 684 | flags := Flags{ |
| 685 | Toolchain: toolchain, |
| 686 | } |
| 687 | |
| 688 | if mod.compiler != nil { |
| 689 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 690 | } |
| 691 | if mod.coverage != nil { |
| 692 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 693 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 694 | if mod.clippy != nil { |
| 695 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 696 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 697 | if mod.sanitize != nil { |
| 698 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 699 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 700 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 701 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 702 | // compile() so it can provide the source. A SourceProvider has |
| 703 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 704 | // variant is responsible for effectively generating the source. The |
| 705 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 706 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 707 | if mod.compiler.(libraryInterface).source() { |
| 708 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 709 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 710 | } else { |
| 711 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 712 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 713 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 714 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame^] | 718 | mod.compiler.initialize(ctx) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 719 | outputFile := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 720 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 721 | mod.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 722 | |
| 723 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 724 | if mod.installable(apexInfo) { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 725 | mod.compiler.install(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 726 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
| 730 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 731 | deps := Deps{} |
| 732 | |
| 733 | if mod.compiler != nil { |
| 734 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 735 | } |
| 736 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 737 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 740 | if mod.coverage != nil { |
| 741 | deps = mod.coverage.deps(ctx, deps) |
| 742 | } |
| 743 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 744 | if mod.sanitize != nil { |
| 745 | deps = mod.sanitize.deps(ctx, deps) |
| 746 | } |
| 747 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 748 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 749 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 750 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 751 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 752 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 753 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 754 | |
| 755 | return deps |
| 756 | |
| 757 | } |
| 758 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 759 | type dependencyTag struct { |
| 760 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 761 | name string |
| 762 | library bool |
| 763 | procMacro bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 766 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 767 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 768 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 769 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 773 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 774 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 775 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 776 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 777 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 778 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 779 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 780 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 781 | ) |
| 782 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 783 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 784 | tag, ok := depTag.(dependencyTag) |
| 785 | return ok && tag == dylibDepTag |
| 786 | } |
| 787 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 788 | type autoDep struct { |
| 789 | variation string |
| 790 | depTag dependencyTag |
| 791 | } |
| 792 | |
| 793 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 794 | rlibVariation = "rlib" |
| 795 | dylibVariation = "dylib" |
| 796 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 797 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 798 | ) |
| 799 | |
| 800 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 801 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 804 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 805 | if mod.coverage != nil { |
| 806 | mod.coverage.begin(ctx) |
| 807 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 808 | if mod.sanitize != nil { |
| 809 | mod.sanitize.begin(ctx) |
| 810 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 811 | } |
| 812 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 813 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 814 | var depPaths PathDeps |
| 815 | |
| 816 | directRlibDeps := []*Module{} |
| 817 | directDylibDeps := []*Module{} |
| 818 | directProcMacroDeps := []*Module{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 819 | directSharedLibDeps := [](cc.LinkableInterface){} |
| 820 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 821 | directSrcProvidersDeps := []*Module{} |
| 822 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 823 | |
| 824 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 825 | depName := ctx.OtherModuleName(dep) |
| 826 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 827 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 828 | //Handle Rust Modules |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 829 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 830 | switch depTag { |
| 831 | case dylibDepTag: |
| 832 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 833 | if !ok || !dylib.dylib() { |
| 834 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 835 | return |
| 836 | } |
| 837 | directDylibDeps = append(directDylibDeps, rustDep) |
| 838 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName) |
| 839 | case rlibDepTag: |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 840 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 841 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 842 | if !ok || !rlib.rlib() { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 843 | ctx.ModuleErrorf("mod %q not an rlib library", depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 844 | return |
| 845 | } |
| 846 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 847 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 848 | case procMacroDepTag: |
| 849 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
| 850 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 851 | case android.SourceDepTag: |
| 852 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 853 | // OS/Arch variant is used. |
| 854 | var helper string |
| 855 | if ctx.Host() { |
| 856 | helper = "missing 'host_supported'?" |
| 857 | } else { |
| 858 | helper = "device module defined?" |
| 859 | } |
| 860 | |
| 861 | if dep.Target().Os != ctx.Os() { |
| 862 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 863 | return |
| 864 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 865 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 866 | return |
| 867 | } |
| 868 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 871 | //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] | 872 | if depTag != procMacroDepTag { |
| 873 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 874 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 875 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 876 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 879 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 880 | linkFile := rustDep.outputFile |
| 881 | if !linkFile.Valid() { |
| 882 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", |
| 883 | depName, ctx.ModuleName()) |
| 884 | return |
| 885 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 886 | linkDir := linkPathFromFilePath(linkFile.Path()) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 887 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 888 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 892 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 893 | //Handle C dependencies |
| 894 | if _, ok := ccDep.(*Module); !ok { |
| 895 | if ccDep.Module().Target().Os != ctx.Os() { |
| 896 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 897 | return |
| 898 | } |
| 899 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 900 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 901 | return |
| 902 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 903 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 904 | linkObject := ccDep.OutputFile() |
| 905 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 906 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 907 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 908 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 909 | } |
| 910 | |
| 911 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 912 | switch { |
| 913 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 914 | // Only pass -lstatic for rlibs as it results in dylib bloat. |
| 915 | if lib, ok := ctx.Module().(*Module).compiler.(libraryInterface); ok && lib.rlib() { |
| 916 | // Link cc static libraries using "-lstatic" so rustc can reason about how to handle these |
| 917 | // (for example, bundling them into rlibs). |
| 918 | // |
| 919 | // rustc does not support linking libraries with the "-l" flag unless they are prefixed by "lib". |
| 920 | // If we need to link a library that isn't prefixed by "lib", we'll just link to it directly through |
| 921 | // linkObjects; such a library may need to be redeclared by static dependents. |
| 922 | if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
| 923 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
| 924 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 928 | // 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] | 929 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 930 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 931 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 932 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 933 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 934 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 935 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 936 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 937 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
| 938 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 939 | case cc.IsSharedDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 940 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 941 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 942 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 943 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 944 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 945 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 946 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 947 | directSharedLibDeps = append(directSharedLibDeps, ccDep) |
| 948 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) |
| 949 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 950 | case cc.IsHeaderDepTag(depTag): |
| 951 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 952 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 953 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 954 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 955 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 956 | depPaths.CrtBegin = linkObject |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 957 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 958 | depPaths.CrtEnd = linkObject |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 962 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 963 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 964 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 965 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 966 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 967 | |
| 968 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
| 969 | switch depTag { |
| 970 | case android.SourceDepTag: |
| 971 | // These are usually genrules which don't have per-target variants. |
| 972 | directSrcDeps = append(directSrcDeps, srcDep) |
| 973 | } |
| 974 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 975 | }) |
| 976 | |
| 977 | var rlibDepFiles RustLibraries |
| 978 | for _, dep := range directRlibDeps { |
| 979 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 980 | } |
| 981 | var dylibDepFiles RustLibraries |
| 982 | for _, dep := range directDylibDeps { |
| 983 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 984 | } |
| 985 | var procMacroDepFiles RustLibraries |
| 986 | for _, dep := range directProcMacroDeps { |
| 987 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 988 | } |
| 989 | |
| 990 | var staticLibDepFiles android.Paths |
| 991 | for _, dep := range directStaticLibDeps { |
| 992 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 993 | } |
| 994 | |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 995 | var sharedLibFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 996 | var sharedLibDepFiles android.Paths |
| 997 | for _, dep := range directSharedLibDeps { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 998 | sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path()) |
| 999 | if dep.Toc().Valid() { |
| 1000 | sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path()) |
| 1001 | } else { |
| 1002 | sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) |
| 1003 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1006 | var srcProviderDepFiles android.Paths |
| 1007 | for _, dep := range directSrcProvidersDeps { |
| 1008 | srcs, _ := dep.OutputFiles("") |
| 1009 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1010 | } |
| 1011 | for _, dep := range directSrcDeps { |
| 1012 | srcs := dep.Srcs() |
| 1013 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1014 | } |
| 1015 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1016 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1017 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 1018 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1019 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1020 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 1021 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1022 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1023 | |
| 1024 | // Dedup exported flags from dependencies |
| 1025 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1026 | depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1027 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1028 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1029 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1030 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1031 | |
| 1032 | return depPaths |
| 1033 | } |
| 1034 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1035 | func (mod *Module) InstallInData() bool { |
| 1036 | if mod.compiler == nil { |
| 1037 | return false |
| 1038 | } |
| 1039 | return mod.compiler.inData() |
| 1040 | } |
| 1041 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1042 | func linkPathFromFilePath(filepath android.Path) string { |
| 1043 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1044 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 1045 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1046 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1047 | ctx := &depsContext{ |
| 1048 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1049 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1050 | |
| 1051 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1052 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1053 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1054 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1055 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1056 | stdLinkage = "rlib-std" |
| 1057 | } |
| 1058 | |
| 1059 | rlibDepVariations := commonDepVariations |
| 1060 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1061 | rlibDepVariations = append(rlibDepVariations, |
| 1062 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1063 | } |
| 1064 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1065 | actx.AddVariationDependencies( |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1066 | append(rlibDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1067 | {Mutator: "rust_libraries", Variation: rlibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1068 | rlibDepTag, deps.Rlibs...) |
| 1069 | actx.AddVariationDependencies( |
| 1070 | append(commonDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1071 | {Mutator: "rust_libraries", Variation: dylibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1072 | dylibDepTag, deps.Dylibs...) |
| 1073 | |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1074 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1075 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1076 | if autoDep.depTag == rlibDepTag { |
| 1077 | actx.AddVariationDependencies( |
| 1078 | append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1079 | autoDep.depTag, deps.Rustlibs...) |
| 1080 | } else { |
| 1081 | actx.AddVariationDependencies( |
| 1082 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1083 | autoDep.depTag, deps.Rustlibs...) |
| 1084 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1085 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1086 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1087 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1088 | actx.AddVariationDependencies( |
| 1089 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}), |
| 1090 | rlibDepTag, deps.Stdlibs...) |
| 1091 | } else { |
| 1092 | actx.AddVariationDependencies( |
| 1093 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), |
| 1094 | dylibDepTag, deps.Stdlibs...) |
| 1095 | } |
| 1096 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1097 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1098 | blueprint.Variation{Mutator: "link", Variation: "shared"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1099 | cc.SharedDepTag(), deps.SharedLibs...) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1100 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1101 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1102 | cc.StaticDepTag(), deps.StaticLibs...) |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1103 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1104 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1105 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1106 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1107 | if deps.CrtBegin != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1108 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1109 | } |
| 1110 | if deps.CrtEnd != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1111 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1114 | if mod.sourceProvider != nil { |
| 1115 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1116 | bindgen.Properties.Custom_bindgen != "" { |
| 1117 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1118 | bindgen.Properties.Custom_bindgen) |
| 1119 | } |
| 1120 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1121 | // 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] | 1122 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1125 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1126 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1127 | mod.beginMutator(ctx) |
| 1128 | } |
| 1129 | } |
| 1130 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1131 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1132 | ctx := &baseModuleContext{ |
| 1133 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1134 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1135 | |
| 1136 | mod.begin(ctx) |
| 1137 | } |
| 1138 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1139 | func (mod *Module) Name() string { |
| 1140 | name := mod.ModuleBase.Name() |
| 1141 | if p, ok := mod.compiler.(interface { |
| 1142 | Name(string) string |
| 1143 | }); ok { |
| 1144 | name = p.Name(name) |
| 1145 | } |
| 1146 | return name |
| 1147 | } |
| 1148 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1149 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1150 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1151 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1155 | var _ android.HostToolProvider = (*Module)(nil) |
| 1156 | |
| 1157 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1158 | if !mod.Host() { |
| 1159 | return android.OptionalPath{} |
| 1160 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1161 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1162 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1163 | } |
| 1164 | return android.OptionalPath{} |
| 1165 | } |
| 1166 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1167 | var _ android.ApexModule = (*Module)(nil) |
| 1168 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1169 | func (mod *Module) minSdkVersion() string { |
| 1170 | return String(mod.Properties.Min_sdk_version) |
| 1171 | } |
| 1172 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1173 | var _ android.ApexModule = (*Module)(nil) |
| 1174 | |
| 1175 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1176 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1177 | minSdkVersion := mod.minSdkVersion() |
| 1178 | if minSdkVersion == "apex_inherit" { |
| 1179 | return nil |
| 1180 | } |
| 1181 | if minSdkVersion == "" { |
| 1182 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1183 | } |
| 1184 | |
| 1185 | // Not using nativeApiLevelFromUser because the context here is not |
| 1186 | // necessarily a native context. |
| 1187 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1188 | if err != nil { |
| 1189 | return err |
| 1190 | } |
| 1191 | |
| 1192 | if ver.GreaterThan(sdkVersion) { |
| 1193 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1194 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1195 | return nil |
| 1196 | } |
| 1197 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1198 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1199 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1200 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1201 | |
| 1202 | if ccm, ok := dep.(*cc.Module); ok { |
| 1203 | if ccm.HasStubsVariants() { |
| 1204 | if cc.IsSharedDepTag(depTag) { |
| 1205 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1206 | return false |
| 1207 | } |
| 1208 | if cc.IsRuntimeDepTag(depTag) { |
| 1209 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1210 | return false |
| 1211 | } |
| 1212 | |
| 1213 | if cc.IsHeaderDepTag(depTag) { |
| 1214 | return false |
| 1215 | } |
| 1216 | } |
| 1217 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1218 | // shared_lib dependency from a static lib is considered as crossing |
| 1219 | // the APEX boundary because the dependency doesn't actually is |
| 1220 | // linked; the dependency is used only during the compilation phase. |
| 1221 | return false |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | if depTag == procMacroDepTag { |
| 1226 | return false |
| 1227 | } |
| 1228 | |
| 1229 | return true |
| 1230 | } |
| 1231 | |
| 1232 | // Overrides ApexModule.IsInstallabeToApex() |
| 1233 | func (mod *Module) IsInstallableToApex() bool { |
| 1234 | if mod.compiler != nil { |
| 1235 | if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) { |
| 1236 | return true |
| 1237 | } |
| 1238 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1239 | return true |
| 1240 | } |
| 1241 | } |
| 1242 | return false |
| 1243 | } |
| 1244 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1245 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1246 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1247 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1248 | if strings.HasPrefix(libName, "lib") { |
| 1249 | libName = libName[3:] |
| 1250 | return libName, true |
| 1251 | } |
| 1252 | return "", false |
| 1253 | } |
| 1254 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1255 | var Bool = proptools.Bool |
| 1256 | var BoolDefault = proptools.BoolDefault |
| 1257 | var String = proptools.String |
| 1258 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1259 | |
| 1260 | var _ android.OutputFileProducer = (*Module)(nil) |