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