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 ( |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
| 20 | |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 21 | "android/soong/bazel" |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 22 | "android/soong/bloaty" |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 23 | "android/soong/ui/metrics/bp2build_metrics_proto" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | "github.com/google/blueprint/proptools" |
| 27 | |
| 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 30 | cc_config "android/soong/cc/config" |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 31 | "android/soong/fuzz" |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 32 | "android/soong/multitree" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | "android/soong/rust/config" |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 34 | "android/soong/snapshot" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | ) |
| 36 | |
| 37 | var pctx = android.NewPackageContext("android/soong/rust") |
| 38 | |
| 39 | func init() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 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 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 47 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 48 | }) |
Inseob Kim | 3b24406 | 2023-07-11 13:31:36 +0900 | [diff] [blame] | 49 | pctx.Import("android/soong/android") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 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") |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 52 | android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory) |
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 |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 65 | EmitXrefs bool // If true, emit rules to aid cross-referencing |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | type BaseProperties struct { |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 69 | AndroidMkRlibs []string `blueprint:"mutated"` |
| 70 | AndroidMkDylibs []string `blueprint:"mutated"` |
| 71 | AndroidMkProcMacroLibs []string `blueprint:"mutated"` |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 72 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
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"` |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 86 | RamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 87 | RecoveryVariantNeeded bool `blueprint:"mutated"` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 88 | ExtraVariants []string `blueprint:"mutated"` |
| 89 | |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 90 | // Allows this module to use non-APEX version of libraries. Useful |
| 91 | // for building binaries that are started before APEXes are activated. |
| 92 | Bootstrap *bool |
| 93 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 94 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 95 | SnapshotSharedLibs []string `blueprint:"mutated"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 96 | SnapshotStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 97 | SnapshotRlibs []string `blueprint:"mutated"` |
| 98 | SnapshotDylibs []string `blueprint:"mutated"` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 99 | |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 100 | // Make this module available when building for ramdisk. |
| 101 | // On device without a dedicated recovery partition, the module is only |
| 102 | // available after switching root into |
| 103 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 104 | // the recovery variant instead. |
| 105 | Ramdisk_available *bool |
| 106 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 107 | // Make this module available when building for vendor ramdisk. |
| 108 | // On device without a dedicated recovery partition, the module is only |
| 109 | // available after switching root into |
| 110 | // /first_stage_ramdisk. To expose the module before switching root, install |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 111 | // the recovery variant instead |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 112 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 113 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 114 | // Normally Soong uses the directory structure to decide which modules |
| 115 | // should be included (framework) or excluded (non-framework) from the |
| 116 | // different snapshots (vendor, recovery, etc.), but this property |
| 117 | // allows a partner to exclude a module normally thought of as a |
| 118 | // framework module from the vendor snapshot. |
| 119 | Exclude_from_vendor_snapshot *bool |
| 120 | |
| 121 | // Normally Soong uses the directory structure to decide which modules |
| 122 | // should be included (framework) or excluded (non-framework) from the |
| 123 | // different snapshots (vendor, recovery, etc.), but this property |
| 124 | // allows a partner to exclude a module normally thought of as a |
| 125 | // framework module from the recovery snapshot. |
| 126 | Exclude_from_recovery_snapshot *bool |
| 127 | |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 128 | // Make this module available when building for recovery |
| 129 | Recovery_available *bool |
| 130 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 131 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 132 | Min_sdk_version *string |
| 133 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 134 | HideFromMake bool `blueprint:"mutated"` |
| 135 | PreventInstall bool `blueprint:"mutated"` |
| 136 | |
| 137 | Installable *bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | type Module struct { |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 141 | fuzz.FuzzModule |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 142 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 143 | VendorProperties cc.VendorProperties |
| 144 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 145 | Properties BaseProperties |
| 146 | |
| 147 | hod android.HostOrDeviceSupported |
| 148 | multilib android.Multilib |
| 149 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 150 | makeLinkType string |
| 151 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 152 | afdo *afdo |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 153 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 154 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 155 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 156 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 157 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 158 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 159 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 160 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 161 | // Output file to be installed, may be stripped or unstripped. |
| 162 | outputFile android.OptionalPath |
| 163 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 164 | // Cross-reference input file |
| 165 | kytheFiles android.Paths |
| 166 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 167 | docTimestampFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 168 | |
| 169 | hideApexVariantFromMake bool |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 170 | |
| 171 | // For apex variants, this is set as apex.min_sdk_version |
| 172 | apexSdkVersion android.ApiLevel |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 173 | |
| 174 | transitiveAndroidMkSharedLibs *android.DepSet[string] |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 175 | |
| 176 | android.BazelModuleBase |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 179 | func (mod *Module) Header() bool { |
| 180 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 181 | return false |
| 182 | } |
| 183 | |
| 184 | func (mod *Module) SetPreventInstall() { |
| 185 | mod.Properties.PreventInstall = true |
| 186 | } |
| 187 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 188 | func (mod *Module) SetHideFromMake() { |
| 189 | mod.Properties.HideFromMake = true |
| 190 | } |
| 191 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 192 | func (mod *Module) HiddenFromMake() bool { |
| 193 | return mod.Properties.HideFromMake |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 196 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 197 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 198 | // nil since we need compiler to actually sanitize. |
| 199 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 202 | func (mod *Module) IsPrebuilt() bool { |
| 203 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 204 | return true |
| 205 | } |
| 206 | return false |
| 207 | } |
| 208 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 209 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 210 | switch tag { |
| 211 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 212 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 213 | return mod.sourceProvider.Srcs(), nil |
| 214 | } else { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 215 | if mod.OutputFile().Valid() { |
| 216 | return android.Paths{mod.OutputFile().Path()}, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 217 | } |
| 218 | return android.Paths{}, nil |
| 219 | } |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 220 | case "unstripped": |
| 221 | if mod.compiler != nil { |
| 222 | return android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), nil |
| 223 | } |
| 224 | return nil, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 225 | default: |
| 226 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 227 | } |
| 228 | } |
| 229 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 230 | func (mod *Module) SelectedStl() string { |
| 231 | return "" |
| 232 | } |
| 233 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 234 | func (mod *Module) NonCcVariants() bool { |
| 235 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 236 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 237 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 241 | } |
| 242 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 243 | func (mod *Module) Static() bool { |
| 244 | if mod.compiler != nil { |
| 245 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 246 | return library.static() |
| 247 | } |
| 248 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 249 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | func (mod *Module) Shared() bool { |
| 253 | if mod.compiler != nil { |
| 254 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 255 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 256 | } |
| 257 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 258 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 261 | func (mod *Module) Dylib() bool { |
| 262 | if mod.compiler != nil { |
| 263 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 264 | return library.dylib() |
| 265 | } |
| 266 | } |
| 267 | return false |
| 268 | } |
| 269 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 270 | func (mod *Module) RlibStd() bool { |
| 271 | if mod.compiler != nil { |
| 272 | if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() { |
| 273 | return library.rlibStd() |
| 274 | } |
| 275 | } |
| 276 | panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName())) |
| 277 | } |
| 278 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 279 | func (mod *Module) Rlib() bool { |
| 280 | if mod.compiler != nil { |
| 281 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 282 | return library.rlib() |
| 283 | } |
| 284 | } |
| 285 | return false |
| 286 | } |
| 287 | |
| 288 | func (mod *Module) Binary() bool { |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 289 | if binary, ok := mod.compiler.(binaryInterface); ok { |
| 290 | return binary.binary() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 291 | } |
| 292 | return false |
| 293 | } |
| 294 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 295 | func (mod *Module) StaticExecutable() bool { |
| 296 | if !mod.Binary() { |
| 297 | return false |
| 298 | } |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 299 | return mod.StaticallyLinked() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 300 | } |
| 301 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 302 | func (mod *Module) Object() bool { |
| 303 | // Rust has no modules which produce only object files. |
| 304 | return false |
| 305 | } |
| 306 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 307 | func (mod *Module) Toc() android.OptionalPath { |
| 308 | if mod.compiler != nil { |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 309 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 310 | return lib.toc() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 314 | } |
| 315 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 316 | func (mod *Module) UseSdk() bool { |
| 317 | return false |
| 318 | } |
| 319 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 320 | func (mod *Module) RelativeInstallPath() string { |
| 321 | if mod.compiler != nil { |
| 322 | return mod.compiler.relativeInstallPath() |
| 323 | } |
| 324 | return "" |
| 325 | } |
| 326 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 327 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 328 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 331 | func (mod *Module) Bootstrap() bool { |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 332 | return Bool(mod.Properties.Bootstrap) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 333 | } |
| 334 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 335 | func (mod *Module) MustUseVendorVariant() bool { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 336 | return true |
| 337 | } |
| 338 | |
| 339 | func (mod *Module) SubName() string { |
| 340 | return mod.Properties.SubName |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 344 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 345 | return false |
| 346 | } |
| 347 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 348 | func (mod *Module) IsVndkExt() bool { |
| 349 | return false |
| 350 | } |
| 351 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 352 | func (mod *Module) IsVndkSp() bool { |
| 353 | return false |
| 354 | } |
| 355 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 356 | func (mod *Module) IsVndkPrebuiltLibrary() bool { |
| 357 | // Rust modules do not provide VNDK prebuilts |
| 358 | return false |
| 359 | } |
| 360 | |
| 361 | func (mod *Module) IsVendorPublicLibrary() bool { |
| 362 | return mod.VendorProperties.IsVendorPublicLibrary |
| 363 | } |
| 364 | |
| 365 | func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool { |
| 366 | // Rust modules to not provide Sdk variants |
| 367 | return false |
| 368 | } |
| 369 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 370 | func (c *Module) IsVndkPrivate() bool { |
| 371 | return false |
| 372 | } |
| 373 | |
| 374 | func (c *Module) IsLlndk() bool { |
| 375 | return false |
| 376 | } |
| 377 | |
| 378 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 379 | return false |
| 380 | } |
| 381 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 382 | func (mod *Module) KernelHeadersDecorator() bool { |
| 383 | return false |
| 384 | } |
| 385 | |
Colin Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame] | 386 | func (m *Module) NeedsLlndkVariants() bool { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 387 | return false |
| 388 | } |
| 389 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 390 | func (m *Module) NeedsVendorPublicLibraryVariants() bool { |
| 391 | return false |
| 392 | } |
| 393 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 394 | func (mod *Module) HasLlndkStubs() bool { |
| 395 | return false |
| 396 | } |
| 397 | |
| 398 | func (mod *Module) StubsVersion() string { |
| 399 | panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName())) |
| 400 | } |
| 401 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 402 | func (mod *Module) SdkVersion() string { |
| 403 | return "" |
| 404 | } |
| 405 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 406 | func (mod *Module) AlwaysSdk() bool { |
| 407 | return false |
| 408 | } |
| 409 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 410 | func (mod *Module) IsSdkVariant() bool { |
| 411 | return false |
| 412 | } |
| 413 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 414 | func (mod *Module) SplitPerApiLevel() bool { |
| 415 | return false |
| 416 | } |
| 417 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 418 | func (mod *Module) XrefRustFiles() android.Paths { |
| 419 | return mod.kytheFiles |
| 420 | } |
| 421 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 422 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 423 | Dylibs []string |
| 424 | Rlibs []string |
| 425 | Rustlibs []string |
| 426 | Stdlibs []string |
| 427 | ProcMacros []string |
| 428 | SharedLibs []string |
| 429 | StaticLibs []string |
| 430 | WholeStaticLibs []string |
| 431 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 432 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 433 | // Used for data dependencies adjacent to tests |
| 434 | DataLibs []string |
| 435 | DataBins []string |
| 436 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 437 | CrtBegin, CrtEnd []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | type PathDeps struct { |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 441 | Dylibs *android.DepSet[RustLibrary] |
| 442 | Rlibs *android.DepSet[RustLibrary] |
| 443 | ProcMacros *android.DepSet[RustLibrary] |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 444 | LibDeps android.Paths |
| 445 | WholeStaticLibs android.Paths |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 446 | AfdoProfiles android.Paths |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 447 | // These paths are files needed to run the build tools and will be located under |
| 448 | // __SBOX_SANDBOX_DIR__/tools/... |
| 449 | BuildToolDeps android.Paths |
| 450 | // These paths are files needed to run the build tools and will be located under |
| 451 | // __SBOX_SANDBOX_DIR__/... |
| 452 | BuildToolSrcDeps android.Paths |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 453 | |
| 454 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 455 | depFlags []string |
| 456 | depLinkFlags []string |
| 457 | |
| 458 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. |
| 459 | // Both of these are exported and propagate to dependencies. |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 460 | linkDirs android.Paths |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 461 | linkObjects android.Paths |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 462 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 463 | // Used by bindgen modules which call clang |
| 464 | depClangFlags []string |
| 465 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 466 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 467 | depSystemIncludePaths android.Paths |
| 468 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 469 | CrtBegin android.Paths |
| 470 | CrtEnd android.Paths |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 471 | |
| 472 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 473 | SrcDeps android.Paths |
| 474 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | type RustLibraries []RustLibrary |
| 478 | |
| 479 | type RustLibrary struct { |
| 480 | Path android.Path |
| 481 | CrateName string |
| 482 | } |
| 483 | |
| 484 | type compiler interface { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 485 | initialize(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 486 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 487 | cfgFlags(ctx ModuleContext, flags Flags) Flags |
| 488 | featureFlags(ctx ModuleContext, flags Flags) Flags |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 489 | compilerProps() []interface{} |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 490 | compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 491 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 492 | crateName() string |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 493 | rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 494 | crateRoot(ctx ModuleContext) android.Path |
| 495 | compilationSourcesAndData(ctx ModuleContext) android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 496 | |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 497 | // Output directory in which source-generated code from dependencies is |
| 498 | // copied. This is equivalent to Cargo's OUT_DIR variable. |
| 499 | CargoOutDir() android.OptionalPath |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 500 | |
Ivan Lozano | a9a1fc0 | 2021-08-11 15:13:43 -0400 | [diff] [blame] | 501 | // CargoPkgVersion returns the value of the Cargo_pkg_version property. |
| 502 | CargoPkgVersion() string |
| 503 | |
| 504 | // CargoEnvCompat returns whether Cargo environment variables should be used. |
| 505 | CargoEnvCompat() bool |
| 506 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 507 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 508 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 509 | relativeInstallPath() string |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 510 | everInstallable() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 511 | |
| 512 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 513 | |
| 514 | Disabled() bool |
| 515 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 516 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 517 | stdLinkage(ctx *depsContext) RustLinkage |
Ivan Lozano | 9ef9cb8 | 2023-02-14 10:56:14 -0500 | [diff] [blame] | 518 | noStdlibs() bool |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 519 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 520 | unstrippedOutputFilePath() android.Path |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 521 | strippedOutputFilePath() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 522 | } |
| 523 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 524 | type exportedFlagsProducer interface { |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 525 | exportLinkDirs(...android.Path) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 526 | exportLinkObjects(...android.Path) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 529 | type xref interface { |
| 530 | XrefRustFiles() android.Paths |
| 531 | } |
| 532 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 533 | type flagExporter struct { |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 534 | linkDirs android.Paths |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 535 | linkObjects android.Paths |
| 536 | libDeps android.Paths |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 539 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...android.Path) { |
| 540 | flagExporter.linkDirs = android.FirstUniquePaths(append(flagExporter.linkDirs, dirs...)) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 543 | func (flagExporter *flagExporter) exportLinkObjects(flags ...android.Path) { |
| 544 | flagExporter.linkObjects = android.FirstUniquePaths(append(flagExporter.linkObjects, flags...)) |
| 545 | } |
| 546 | |
| 547 | func (flagExporter *flagExporter) exportLibDeps(paths ...android.Path) { |
| 548 | flagExporter.libDeps = android.FirstUniquePaths(append(flagExporter.libDeps, paths...)) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 549 | } |
| 550 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 551 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 552 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 553 | LinkDirs: flagExporter.linkDirs, |
| 554 | LinkObjects: flagExporter.linkObjects, |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 555 | LibDeps: flagExporter.libDeps, |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 556 | }) |
| 557 | } |
| 558 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 559 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 560 | |
| 561 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 562 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 565 | type FlagExporterInfo struct { |
| 566 | Flags []string |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 567 | LinkDirs android.Paths |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 568 | LinkObjects android.Paths |
| 569 | LibDeps android.Paths |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 573 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 574 | func (mod *Module) isCoverageVariant() bool { |
| 575 | return mod.coverage.Properties.IsCoverageVariant |
| 576 | } |
| 577 | |
| 578 | var _ cc.Coverage = (*Module)(nil) |
| 579 | |
| 580 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 581 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 582 | } |
| 583 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 584 | func (mod *Module) VndkVersion() string { |
| 585 | return mod.Properties.VndkVersion |
| 586 | } |
| 587 | |
| 588 | func (mod *Module) PreventInstall() bool { |
| 589 | return mod.Properties.PreventInstall |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 590 | } |
| 591 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 592 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 593 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 594 | } |
| 595 | |
| 596 | func (mod *Module) EnableCoverageIfNeeded() { |
| 597 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | func defaultsFactory() android.Module { |
| 601 | return DefaultsFactory() |
| 602 | } |
| 603 | |
| 604 | type Defaults struct { |
| 605 | android.ModuleBase |
| 606 | android.DefaultsModuleBase |
| 607 | } |
| 608 | |
| 609 | func DefaultsFactory(props ...interface{}) android.Module { |
| 610 | module := &Defaults{} |
| 611 | |
| 612 | module.AddProperties(props...) |
| 613 | module.AddProperties( |
| 614 | &BaseProperties{}, |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 615 | &cc.AfdoProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 616 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 617 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 618 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 619 | &BaseCompilerProperties{}, |
| 620 | &BinaryCompilerProperties{}, |
| 621 | &LibraryCompilerProperties{}, |
| 622 | &ProcMacroCompilerProperties{}, |
| 623 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 624 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 625 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 626 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 627 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 628 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 629 | &SanitizeProperties{}, |
Pawan Wagh | ccb7558 | 2023-08-16 23:58:25 +0000 | [diff] [blame] | 630 | &fuzz.FuzzProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 631 | ) |
| 632 | |
| 633 | android.InitDefaultsModule(module) |
| 634 | return module |
| 635 | } |
| 636 | |
| 637 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 638 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 641 | func (mod *Module) CcLibrary() bool { |
| 642 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 643 | if _, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 644 | return true |
| 645 | } |
| 646 | } |
| 647 | return false |
| 648 | } |
| 649 | |
| 650 | func (mod *Module) CcLibraryInterface() bool { |
| 651 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 652 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 653 | // VariantIs{Static,Shared} is set. |
| 654 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 655 | return true |
| 656 | } |
| 657 | } |
| 658 | return false |
| 659 | } |
| 660 | |
Ivan Lozano | 61c02cc | 2023-06-09 14:06:44 -0400 | [diff] [blame] | 661 | func (mod *Module) RustLibraryInterface() bool { |
| 662 | if mod.compiler != nil { |
| 663 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 664 | return true |
| 665 | } |
| 666 | } |
| 667 | return false |
| 668 | } |
| 669 | |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 670 | func (mod *Module) IsFuzzModule() bool { |
| 671 | if _, ok := mod.compiler.(*fuzzDecorator); ok { |
| 672 | return true |
| 673 | } |
| 674 | return false |
| 675 | } |
| 676 | |
| 677 | func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule { |
| 678 | return mod.FuzzModule |
| 679 | } |
| 680 | |
| 681 | func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { |
| 682 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 683 | return fuzzer.fuzzPackagedModule |
| 684 | } |
| 685 | panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName())) |
| 686 | } |
| 687 | |
Hamzeh Zawawy | 3891749 | 2023-04-05 22:08:46 +0000 | [diff] [blame] | 688 | func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 689 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 690 | return fuzzer.sharedLibraries |
| 691 | } |
| 692 | panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName())) |
| 693 | } |
| 694 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 695 | func (mod *Module) UnstrippedOutputFile() android.Path { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 696 | if mod.compiler != nil { |
| 697 | return mod.compiler.unstrippedOutputFilePath() |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 698 | } |
| 699 | return nil |
| 700 | } |
| 701 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 702 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 703 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 704 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 705 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 709 | } |
| 710 | |
| 711 | func (mod *Module) SetStatic() { |
| 712 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 713 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 714 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 715 | return |
| 716 | } |
| 717 | } |
| 718 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 719 | } |
| 720 | |
| 721 | func (mod *Module) SetShared() { |
| 722 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 723 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 724 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 725 | return |
| 726 | } |
| 727 | } |
| 728 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 729 | } |
| 730 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 731 | func (mod *Module) BuildStaticVariant() bool { |
| 732 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 733 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 734 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 738 | } |
| 739 | |
| 740 | func (mod *Module) BuildSharedVariant() bool { |
| 741 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 742 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 743 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 747 | } |
| 748 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 749 | func (mod *Module) Module() android.Module { |
| 750 | return mod |
| 751 | } |
| 752 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 753 | func (mod *Module) OutputFile() android.OptionalPath { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 754 | return mod.outputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 757 | func (mod *Module) CoverageFiles() android.Paths { |
| 758 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 759 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 760 | } |
| 761 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 762 | } |
| 763 | |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 764 | // Rust does not produce gcno files, and therefore does not produce a coverage archive. |
| 765 | func (mod *Module) CoverageOutputFile() android.OptionalPath { |
| 766 | return android.OptionalPath{} |
| 767 | } |
| 768 | |
| 769 | func (mod *Module) IsNdk(config android.Config) bool { |
| 770 | return false |
| 771 | } |
| 772 | |
| 773 | func (mod *Module) IsStubs() bool { |
| 774 | return false |
| 775 | } |
| 776 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 777 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
Jiyong Park | 2811e07 | 2021-09-30 17:25:21 +0900 | [diff] [blame] | 778 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) { |
Jiyong Park | bf8147a | 2021-05-17 13:19:33 +0900 | [diff] [blame] | 779 | return false |
| 780 | } |
| 781 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 782 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 783 | // in the system partition as a standalone file. |
| 784 | if !apexInfo.IsForPlatform() { |
| 785 | return false |
| 786 | } |
| 787 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 788 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 789 | } |
| 790 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 791 | func (ctx moduleContext) apexVariationName() string { |
| 792 | return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName |
| 793 | } |
| 794 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 795 | var _ cc.LinkableInterface = (*Module)(nil) |
| 796 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 797 | func (mod *Module) Init() android.Module { |
| 798 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 799 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 800 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 801 | if mod.afdo != nil { |
| 802 | mod.AddProperties(mod.afdo.props()...) |
| 803 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 804 | if mod.compiler != nil { |
| 805 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 806 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 807 | if mod.coverage != nil { |
| 808 | mod.AddProperties(mod.coverage.props()...) |
| 809 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 810 | if mod.clippy != nil { |
| 811 | mod.AddProperties(mod.clippy.props()...) |
| 812 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 813 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 814 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 815 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 816 | if mod.sanitize != nil { |
| 817 | mod.AddProperties(mod.sanitize.props()...) |
| 818 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 819 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 820 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 821 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 822 | |
| 823 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 824 | return mod |
| 825 | } |
| 826 | |
| 827 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 828 | return &Module{ |
| 829 | hod: hod, |
| 830 | multilib: multilib, |
| 831 | } |
| 832 | } |
| 833 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 834 | module := newBaseModule(hod, multilib) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 835 | module.afdo = &afdo{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 836 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 837 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 838 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 839 | return module |
| 840 | } |
| 841 | |
| 842 | type ModuleContext interface { |
| 843 | android.ModuleContext |
| 844 | ModuleContextIntf |
| 845 | } |
| 846 | |
| 847 | type BaseModuleContext interface { |
| 848 | android.BaseModuleContext |
| 849 | ModuleContextIntf |
| 850 | } |
| 851 | |
| 852 | type DepsContext interface { |
| 853 | android.BottomUpMutatorContext |
| 854 | ModuleContextIntf |
| 855 | } |
| 856 | |
| 857 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 858 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 859 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | type depsContext struct { |
| 863 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | type moduleContext struct { |
| 867 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 870 | type baseModuleContext struct { |
| 871 | android.BaseModuleContext |
| 872 | } |
| 873 | |
| 874 | func (ctx *moduleContext) RustModule() *Module { |
| 875 | return ctx.Module().(*Module) |
| 876 | } |
| 877 | |
| 878 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 879 | return ctx.RustModule().toolchain(ctx) |
| 880 | } |
| 881 | |
| 882 | func (ctx *depsContext) RustModule() *Module { |
| 883 | return ctx.Module().(*Module) |
| 884 | } |
| 885 | |
| 886 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 887 | return ctx.RustModule().toolchain(ctx) |
| 888 | } |
| 889 | |
| 890 | func (ctx *baseModuleContext) RustModule() *Module { |
| 891 | return ctx.Module().(*Module) |
| 892 | } |
| 893 | |
| 894 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 895 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | func (mod *Module) nativeCoverage() bool { |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 899 | // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage |
| 900 | if mod.Target().NativeBridge == android.NativeBridgeEnabled { |
| 901 | return false |
| 902 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 903 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 904 | } |
| 905 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 906 | func (mod *Module) EverInstallable() bool { |
| 907 | return mod.compiler != nil && |
| 908 | // Check to see whether the module is actually ever installable. |
| 909 | mod.compiler.everInstallable() |
| 910 | } |
| 911 | |
| 912 | func (mod *Module) Installable() *bool { |
| 913 | return mod.Properties.Installable |
| 914 | } |
| 915 | |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 916 | func (mod *Module) ProcMacro() bool { |
| 917 | if pm, ok := mod.compiler.(procMacroInterface); ok { |
| 918 | return pm.ProcMacro() |
| 919 | } |
| 920 | return false |
| 921 | } |
| 922 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 923 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 924 | if mod.cachedToolchain == nil { |
| 925 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 926 | } |
| 927 | return mod.cachedToolchain |
| 928 | } |
| 929 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 930 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 931 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 932 | } |
| 933 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 934 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 935 | } |
| 936 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 937 | type RustInfo struct { |
| 938 | TransitiveRlibs *android.DepSet[RustLibrary] |
| 939 | TransitiveDylibs *android.DepSet[RustLibrary] |
| 940 | TransitiveProcMacros *android.DepSet[RustLibrary] |
| 941 | } |
| 942 | |
| 943 | var RustInfoProvider = blueprint.NewProvider(RustInfo{}) |
| 944 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 945 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 946 | ctx := &moduleContext{ |
| 947 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 948 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 949 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 950 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 951 | if !apexInfo.IsForPlatform() { |
| 952 | mod.hideApexVariantFromMake = true |
| 953 | } |
| 954 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 955 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 956 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 957 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 958 | mod.Properties.SubName = cc.GetSubnameProperty(actx, mod) |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 959 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 960 | if !toolchain.Supported() { |
| 961 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 962 | return |
| 963 | } |
| 964 | |
| 965 | deps := mod.depsToPaths(ctx) |
| 966 | flags := Flags{ |
| 967 | Toolchain: toolchain, |
| 968 | } |
| 969 | |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 970 | // Calculate rustc flags |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 971 | if mod.afdo != nil { |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 972 | flags, deps = mod.afdo.flags(actx, flags, deps) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 973 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 974 | if mod.compiler != nil { |
| 975 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 976 | flags = mod.compiler.cfgFlags(ctx, flags) |
| 977 | flags = mod.compiler.featureFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 978 | } |
| 979 | if mod.coverage != nil { |
| 980 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 981 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 982 | if mod.clippy != nil { |
| 983 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 984 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 985 | if mod.sanitize != nil { |
| 986 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 987 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 988 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 989 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 990 | // compile() so it can provide the source. A SourceProvider has |
| 991 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 992 | // variant is responsible for effectively generating the source. The |
| 993 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 994 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 995 | if mod.compiler.(libraryInterface).source() { |
| 996 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 997 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 998 | } else { |
| 999 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 1000 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 1001 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1002 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 1006 | mod.compiler.initialize(ctx) |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1007 | buildOutput := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1008 | if ctx.Failed() { |
| 1009 | return |
| 1010 | } |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1011 | mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile) |
| 1012 | if buildOutput.kytheFile != nil { |
| 1013 | mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile) |
| 1014 | } |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1015 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath())) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 1016 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 1017 | mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps) |
Matthew Maurer | e380363 | 2021-12-10 21:57:21 +0000 | [diff] [blame] | 1018 | if mod.docTimestampFile.Valid() { |
| 1019 | ctx.CheckbuildFile(mod.docTimestampFile.Path()) |
| 1020 | } |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 1021 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1022 | // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or |
| 1023 | // RECOVERY_SNAPSHOT_VERSION is current. |
| 1024 | if lib, ok := mod.compiler.(snapshotLibraryInterface); ok { |
| 1025 | if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) { |
| 1026 | lib.collectHeadersForSnapshot(ctx, deps) |
| 1027 | } |
| 1028 | } |
| 1029 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 1030 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1031 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() { |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1032 | // If the module has been specifically configure to not be installed then |
| 1033 | // hide from make as otherwise it will break when running inside make as the |
| 1034 | // output path to install will not be specified. Not all uninstallable |
| 1035 | // modules can be hidden from make as some are needed for resolving make |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1036 | // side dependencies. In particular, proc-macros need to be captured in the |
| 1037 | // host snapshot. |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1038 | mod.HideFromMake() |
| 1039 | } else if !mod.installable(apexInfo) { |
| 1040 | mod.SkipInstall() |
| 1041 | } |
| 1042 | |
| 1043 | // Still call install though, the installs will be stored as PackageSpecs to allow |
| 1044 | // using the outputs in a genrule. |
| 1045 | if mod.OutputFile().Valid() { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 1046 | mod.compiler.install(ctx) |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1047 | if ctx.Failed() { |
| 1048 | return |
| 1049 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1050 | } |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 1051 | |
| 1052 | ctx.Phony("rust", ctx.RustModule().OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1053 | } |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1054 | |
| 1055 | ctx.SetProvider(RustInfoProvider, RustInfo{ |
| 1056 | TransitiveRlibs: deps.Rlibs, |
| 1057 | TransitiveDylibs: deps.Dylibs, |
| 1058 | TransitiveProcMacros: deps.ProcMacros, |
| 1059 | }) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 1063 | deps := Deps{} |
| 1064 | |
| 1065 | if mod.compiler != nil { |
| 1066 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1067 | } |
| 1068 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 1069 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1072 | if mod.coverage != nil { |
| 1073 | deps = mod.coverage.deps(ctx, deps) |
| 1074 | } |
| 1075 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1076 | if mod.sanitize != nil { |
| 1077 | deps = mod.sanitize.deps(ctx, deps) |
| 1078 | } |
| 1079 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1080 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 1081 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1082 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1083 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 1084 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1085 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Andrew Walbran | 797e4be | 2022-03-07 15:41:53 +0000 | [diff] [blame] | 1086 | deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1087 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1088 | return deps |
| 1089 | |
| 1090 | } |
| 1091 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1092 | type dependencyTag struct { |
| 1093 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1094 | name string |
| 1095 | library bool |
| 1096 | procMacro bool |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1097 | dynamic bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1100 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 1101 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 1102 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1103 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 1107 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1108 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 1109 | if d.library && d.dynamic { |
| 1110 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
| 1111 | } |
| 1112 | return nil |
| 1113 | } |
| 1114 | |
| 1115 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 1116 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1117 | var ( |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1118 | buildToolDepTag = dependencyTag{name: "buildToolTag"} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1119 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 1120 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1121 | dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1122 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1123 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1124 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1125 | dataLibDepTag = dependencyTag{name: "data lib"} |
| 1126 | dataBinDepTag = dependencyTag{name: "data bin"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1127 | ) |
| 1128 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1129 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 1130 | tag, ok := depTag.(dependencyTag) |
| 1131 | return ok && tag == dylibDepTag |
| 1132 | } |
| 1133 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 1134 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 1135 | tag, ok := depTag.(dependencyTag) |
| 1136 | return ok && tag == rlibDepTag |
| 1137 | } |
| 1138 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1139 | type autoDep struct { |
| 1140 | variation string |
| 1141 | depTag dependencyTag |
| 1142 | } |
| 1143 | |
| 1144 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1145 | rlibVariation = "rlib" |
| 1146 | dylibVariation = "dylib" |
| 1147 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 1148 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1149 | ) |
| 1150 | |
| 1151 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1152 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1155 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 1156 | if mod.coverage != nil { |
| 1157 | mod.coverage.begin(ctx) |
| 1158 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1159 | if mod.sanitize != nil { |
| 1160 | mod.sanitize.begin(ctx) |
| 1161 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1164 | func (mod *Module) Prebuilt() *android.Prebuilt { |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1165 | if p, ok := mod.compiler.(rustPrebuilt); ok { |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1166 | return p.prebuilt() |
| 1167 | } |
| 1168 | return nil |
| 1169 | } |
| 1170 | |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1171 | func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.LinkableInterface, depName string) string { |
| 1172 | if rustDep, ok := dep.(*Module); ok { |
| 1173 | // Use base module name for snapshots when exporting to Makefile. |
| 1174 | if snapshotPrebuilt, ok := rustDep.compiler.(cc.SnapshotInterface); ok { |
| 1175 | baseName := rustDep.BaseModuleName() |
| 1176 | return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix() + rustDep.AndroidMkSuffix() |
| 1177 | } |
| 1178 | } |
| 1179 | return cc.MakeLibName(ctx, c, dep, depName) |
| 1180 | } |
| 1181 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1182 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 1183 | var depPaths PathDeps |
| 1184 | |
| 1185 | directRlibDeps := []*Module{} |
| 1186 | directDylibDeps := []*Module{} |
| 1187 | directProcMacroDeps := []*Module{} |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1188 | directSharedLibDeps := []cc.SharedLibraryInfo{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1189 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1190 | directSrcProvidersDeps := []*Module{} |
| 1191 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1192 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 1193 | // For the dependency from platform to apex, use the latest stubs |
| 1194 | mod.apexSdkVersion = android.FutureApiLevel |
| 1195 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1196 | if !apexInfo.IsForPlatform() { |
| 1197 | mod.apexSdkVersion = apexInfo.MinSdkVersion |
| 1198 | } |
| 1199 | |
| 1200 | if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { |
| 1201 | // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) |
| 1202 | // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). |
| 1203 | // (b/144430859) |
| 1204 | mod.apexSdkVersion = android.FutureApiLevel |
| 1205 | } |
| 1206 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1207 | skipModuleList := map[string]bool{} |
| 1208 | |
| 1209 | var apiImportInfo multitree.ApiImportInfo |
| 1210 | hasApiImportInfo := false |
| 1211 | |
| 1212 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1213 | if dep.Name() == "api_imports" { |
| 1214 | apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo) |
| 1215 | hasApiImportInfo = true |
| 1216 | } |
| 1217 | }) |
| 1218 | |
| 1219 | if hasApiImportInfo { |
| 1220 | targetStubModuleList := map[string]string{} |
| 1221 | targetOrigModuleList := map[string]string{} |
| 1222 | |
| 1223 | // Search for dependency which both original module and API imported library with APEX stub exists |
| 1224 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1225 | depName := ctx.OtherModuleName(dep) |
| 1226 | if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok { |
| 1227 | targetStubModuleList[apiLibrary] = depName |
| 1228 | } |
| 1229 | }) |
| 1230 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1231 | depName := ctx.OtherModuleName(dep) |
| 1232 | if origLibrary, ok := targetStubModuleList[depName]; ok { |
| 1233 | targetOrigModuleList[origLibrary] = depName |
| 1234 | } |
| 1235 | }) |
| 1236 | |
| 1237 | // Decide which library should be used between original and API imported library |
| 1238 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1239 | depName := ctx.OtherModuleName(dep) |
| 1240 | if apiLibrary, ok := targetOrigModuleList[depName]; ok { |
| 1241 | if cc.ShouldUseStubForApex(ctx, dep) { |
| 1242 | skipModuleList[depName] = true |
| 1243 | } else { |
| 1244 | skipModuleList[apiLibrary] = true |
| 1245 | } |
| 1246 | } |
| 1247 | }) |
| 1248 | } |
| 1249 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1250 | var transitiveAndroidMkSharedLibs []*android.DepSet[string] |
| 1251 | var directAndroidMkSharedLibs []string |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1252 | transitiveRlibs := android.NewDepSetBuilder[RustLibrary](android.PREORDER) |
| 1253 | transitiveDylibs := android.NewDepSetBuilder[RustLibrary](android.PREORDER) |
| 1254 | transitiveProcMacros := android.NewDepSetBuilder[RustLibrary](android.PREORDER) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1255 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1256 | depName := ctx.OtherModuleName(dep) |
| 1257 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1258 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1259 | if _, exists := skipModuleList[depName]; exists { |
| 1260 | return |
| 1261 | } |
A. Cody Schuffelen | c183e3a | 2023-08-14 21:09:47 -0700 | [diff] [blame] | 1262 | |
| 1263 | if depTag == android.DarwinUniversalVariantTag { |
| 1264 | return |
| 1265 | } |
| 1266 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1267 | rustInfo := ctx.OtherModuleProvider(dep, RustInfoProvider).(RustInfo) |
| 1268 | if rustInfo.TransitiveDylibs != nil { |
| 1269 | transitiveDylibs.Transitive(rustInfo.TransitiveDylibs) |
| 1270 | } |
| 1271 | if rustInfo.TransitiveRlibs != nil { |
| 1272 | transitiveRlibs.Transitive(rustInfo.TransitiveRlibs) |
| 1273 | } |
| 1274 | if rustInfo.TransitiveProcMacros != nil { |
| 1275 | transitiveProcMacros.Transitive(rustInfo.TransitiveProcMacros) |
| 1276 | } |
| 1277 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1278 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1279 | //Handle Rust Modules |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1280 | makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName) |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1281 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1282 | switch depTag { |
| 1283 | case dylibDepTag: |
| 1284 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 1285 | if !ok || !dylib.dylib() { |
| 1286 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 1287 | return |
| 1288 | } |
| 1289 | directDylibDeps = append(directDylibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1290 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1291 | mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName)) |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1292 | transitiveDylibs.Direct(RustLibrary{ |
| 1293 | Path: rustDep.UnstrippedOutputFile(), |
| 1294 | CrateName: rustDep.CrateName(), |
| 1295 | }) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1296 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1297 | case rlibDepTag: |
| 1298 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 1299 | if !ok || !rlib.rlib() { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1300 | ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1301 | return |
| 1302 | } |
| 1303 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1304 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1305 | mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName)) |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1306 | transitiveRlibs.Direct(RustLibrary{ |
| 1307 | Path: rustDep.UnstrippedOutputFile(), |
| 1308 | CrateName: rustDep.CrateName(), |
| 1309 | }) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1310 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1311 | case procMacroDepTag: |
| 1312 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1313 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1314 | transitiveProcMacros.Direct(RustLibrary{ |
| 1315 | Path: rustDep.UnstrippedOutputFile(), |
| 1316 | CrateName: rustDep.CrateName(), |
| 1317 | }) |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1320 | transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs) |
| 1321 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1322 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1323 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 1324 | // OS/Arch variant is used. |
| 1325 | var helper string |
| 1326 | if ctx.Host() { |
| 1327 | helper = "missing 'host_supported'?" |
| 1328 | } else { |
| 1329 | helper = "device module defined?" |
| 1330 | } |
| 1331 | |
| 1332 | if dep.Target().Os != ctx.Os() { |
| 1333 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1334 | return |
| 1335 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1336 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1337 | return |
| 1338 | } |
| 1339 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 1342 | //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] | 1343 | if depTag != procMacroDepTag { |
| 1344 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 1345 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 1346 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 1347 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1348 | depPaths.LibDeps = append(depPaths.LibDeps, exportedInfo.LibDeps...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1351 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1352 | linkFile := rustDep.UnstrippedOutputFile() |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1353 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1354 | lib.exportLinkDirs(linkFile.Dir()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1358 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1359 | //Handle C dependencies |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1360 | makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1361 | if _, ok := ccDep.(*Module); !ok { |
| 1362 | if ccDep.Module().Target().Os != ctx.Os() { |
| 1363 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1364 | return |
| 1365 | } |
| 1366 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1367 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1368 | return |
| 1369 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1370 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1371 | linkObject := ccDep.OutputFile() |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1372 | if !linkObject.Valid() { |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1373 | if !ctx.Config().AllowMissingDependencies() { |
| 1374 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1375 | } else { |
| 1376 | ctx.AddMissingDependencies([]string{depName}) |
| 1377 | } |
| 1378 | return |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1381 | linkPath := linkObject.Path().Dir() |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1382 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1383 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1384 | switch { |
| 1385 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1386 | if cc.IsWholeStaticLib(depTag) { |
| 1387 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 1388 | // if the library is not prefixed by "lib". |
Ivan Lozano | fdadcd7 | 2021-11-01 09:04:23 -0400 | [diff] [blame] | 1389 | if mod.Binary() { |
| 1390 | // Binaries may sometimes need to link whole static libraries that don't start with 'lib'. |
| 1391 | // Since binaries don't need to 'rebundle' these like libraries and only use these for the |
| 1392 | // final linkage, pass the args directly to the linker to handle these cases. |
| 1393 | depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...) |
| 1394 | } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1395 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1396 | depPaths.WholeStaticLibs = append(depPaths.WholeStaticLibs, linkObject.Path()) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1397 | } else { |
| 1398 | 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] | 1399 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 1403 | // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant. |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1404 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1405 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 1406 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1407 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1408 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1409 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1410 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1411 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1412 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
Justin Yun | 2b3ed64 | 2022-02-16 08:15:07 +0900 | [diff] [blame] | 1413 | |
| 1414 | // Record baseLibName for snapshots. |
| 1415 | mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName)) |
| 1416 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1417 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1418 | case cc.IsSharedDepTag(depTag): |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1419 | // For the shared lib dependencies, we may link to the stub variant |
| 1420 | // of the dependency depending on the context (e.g. if this |
| 1421 | // dependency crosses the APEX boundaries). |
| 1422 | sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep) |
| 1423 | |
| 1424 | // Re-get linkObject as ChooseStubOrImpl actually tells us which |
| 1425 | // object (either from stub or non-stub) to use. |
| 1426 | linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary) |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1427 | if !linkObject.Valid() { |
| 1428 | if !ctx.Config().AllowMissingDependencies() { |
| 1429 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1430 | } else { |
| 1431 | ctx.AddMissingDependencies([]string{depName}) |
| 1432 | } |
| 1433 | return |
| 1434 | } |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1435 | linkPath = linkObject.Path().Dir() |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1436 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1437 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1438 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.AsPaths()...) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1439 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1440 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1441 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1442 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1443 | directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1444 | |
| 1445 | // Record baseLibName for snapshots. |
| 1446 | mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName)) |
| 1447 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1448 | directAndroidMkSharedLibs = append(directAndroidMkSharedLibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1449 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1450 | case cc.IsHeaderDepTag(depTag): |
| 1451 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1452 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1453 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1454 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1455 | case depTag == cc.CrtBeginDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1456 | depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path()) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1457 | case depTag == cc.CrtEndDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1458 | depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1462 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 1463 | lib.exportLinkDirs(linkPath) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1464 | if linkObject.Valid() { |
| 1465 | lib.exportLinkObjects(linkObject.Path()) |
| 1466 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1467 | } |
Colin Cross | 018cbeb | 2022-01-24 17:22:45 -0800 | [diff] [blame] | 1468 | } else { |
| 1469 | switch { |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1470 | case depTag == buildToolDepTag: |
| 1471 | buildTool := ctx.OtherModuleProvider(dep, android.PrebuiltBuildToolInfoProvider).(android.PrebuiltBuildToolInfo) |
| 1472 | depPaths.BuildToolDeps = append(depPaths.BuildToolDeps, buildTool.Src) |
| 1473 | depPaths.BuildToolDeps = append(depPaths.BuildToolDeps, buildTool.Deps...) |
| 1474 | switch android.RemoveOptionalPrebuiltPrefix(dep.Name()) { |
| 1475 | case "rustc": |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1476 | // rustc expects the standard cc toolchain libraries (libdl, libm, libc, etc.) |
| 1477 | // not to be under the __SBOX_SANDBOX_DIR__/ directory |
| 1478 | depPaths.BuildToolSrcDeps = append(depPaths.BuildToolSrcDeps, buildTool.Deps...) |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1479 | } |
Colin Cross | 018cbeb | 2022-01-24 17:22:45 -0800 | [diff] [blame] | 1480 | case depTag == cc.CrtBeginDepTag: |
| 1481 | depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, "")) |
| 1482 | case depTag == cc.CrtEndDepTag: |
| 1483 | depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, "")) |
| 1484 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1485 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1486 | |
| 1487 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1488 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1489 | // These are usually genrules which don't have per-target variants. |
| 1490 | directSrcDeps = append(directSrcDeps, srcDep) |
| 1491 | } |
| 1492 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1493 | }) |
| 1494 | |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1495 | var libDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1496 | for _, dep := range directStaticLibDeps { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1497 | libDepFiles = append(libDepFiles, dep.OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1500 | for _, dep := range directSharedLibDeps { |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1501 | if dep.TableOfContents.Valid() { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1502 | libDepFiles = append(libDepFiles, dep.TableOfContents.Path()) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1503 | } else { |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1504 | libDepFiles = append(libDepFiles, dep.SharedLibrary) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1505 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1508 | var srcProviderDepFiles android.Paths |
| 1509 | for _, dep := range directSrcProvidersDeps { |
| 1510 | srcs, _ := dep.OutputFiles("") |
| 1511 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1512 | } |
| 1513 | for _, dep := range directSrcDeps { |
| 1514 | srcs := dep.Srcs() |
| 1515 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1516 | } |
| 1517 | |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1518 | depPaths.LibDeps = append(depPaths.LibDeps, libDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1519 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1520 | |
| 1521 | // Dedup exported flags from dependencies |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1522 | depPaths.linkDirs = android.FirstUniquePaths(depPaths.linkDirs) |
Peter Collingbourne | e7c71c3 | 2023-03-31 20:21:19 -0700 | [diff] [blame] | 1523 | depPaths.linkObjects = android.FirstUniquePaths(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1524 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1525 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1526 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1527 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1528 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1529 | depPaths.Rlibs = transitiveRlibs.Build() |
| 1530 | depPaths.Dylibs = transitiveDylibs.Build() |
| 1531 | depPaths.ProcMacros = transitiveProcMacros.Build() |
| 1532 | mod.transitiveAndroidMkSharedLibs = android.NewDepSet[string](android.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs) |
| 1533 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1534 | return depPaths |
| 1535 | } |
| 1536 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1537 | func (mod *Module) InstallInData() bool { |
| 1538 | if mod.compiler == nil { |
| 1539 | return false |
| 1540 | } |
| 1541 | return mod.compiler.inData() |
| 1542 | } |
| 1543 | |
Matthew Maurer | 9f59e8d | 2021-08-19 13:10:05 -0700 | [diff] [blame] | 1544 | func (mod *Module) InstallInRamdisk() bool { |
| 1545 | return mod.InRamdisk() |
| 1546 | } |
| 1547 | |
| 1548 | func (mod *Module) InstallInVendorRamdisk() bool { |
| 1549 | return mod.InVendorRamdisk() |
| 1550 | } |
| 1551 | |
| 1552 | func (mod *Module) InstallInRecovery() bool { |
| 1553 | return mod.InRecovery() |
| 1554 | } |
| 1555 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1556 | // usePublicApi returns true if the rust variant should link against NDK (publicapi) |
| 1557 | func (r *Module) usePublicApi() bool { |
| 1558 | return r.Device() && r.UseSdk() |
| 1559 | } |
| 1560 | |
| 1561 | // useVendorApi returns true if the rust variant should link against LLNDK (vendorapi) |
| 1562 | func (r *Module) useVendorApi() bool { |
| 1563 | return r.Device() && (r.InVendor() || r.InProduct()) |
| 1564 | } |
| 1565 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1566 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1567 | ctx := &depsContext{ |
| 1568 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1569 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1570 | |
| 1571 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1572 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1573 | var snapshotInfo *cc.SnapshotInfo |
| 1574 | |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1575 | apiImportInfo := cc.GetApiImports(mod, actx) |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1576 | if mod.usePublicApi() || mod.useVendorApi() { |
| 1577 | for idx, lib := range deps.SharedLibs { |
| 1578 | deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs) |
| 1579 | } |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1580 | } |
| 1581 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1582 | if ctx.Os() == android.Android { |
| 1583 | deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs) |
| 1584 | } |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1585 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1586 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1587 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1588 | stdLinkage = "rlib-std" |
| 1589 | } |
| 1590 | |
| 1591 | rlibDepVariations := commonDepVariations |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1592 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1593 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1594 | rlibDepVariations = append(rlibDepVariations, |
| 1595 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1596 | } |
| 1597 | |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1598 | ctx.AddFarVariationDependencies([]blueprint.Variation{}, buildToolDepTag, "rustc") |
Sam Delmerico | a588d15 | 2023-06-16 10:28:04 -0400 | [diff] [blame] | 1599 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1600 | // rlibs |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1601 | rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation}) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1602 | for _, lib := range deps.Rlibs { |
| 1603 | depTag := rlibDepTag |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1604 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1605 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1606 | actx.AddVariationDependencies(rlibDepVariations, depTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1607 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1608 | |
| 1609 | // dylibs |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1610 | dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation}) |
| 1611 | for _, lib := range deps.Dylibs { |
| 1612 | addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag) |
| 1613 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1614 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1615 | // rustlibs |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1616 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1617 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1618 | for _, lib := range deps.Rustlibs { |
| 1619 | if autoDep.depTag == rlibDepTag { |
| 1620 | // Handle the rlib deptag case |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1621 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1622 | } else { |
| 1623 | // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. |
| 1624 | // Check for the existence of the dylib deptag variant. Select it if available, |
| 1625 | // otherwise select the rlib variant. |
| 1626 | autoDepVariations := append(commonDepVariations, |
| 1627 | blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1628 | |
| 1629 | replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs) |
| 1630 | |
| 1631 | if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) { |
| 1632 | addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1633 | } else { |
| 1634 | // If there's no dylib dependency available, try to add the rlib dependency instead. |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1635 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1636 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1637 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1638 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1639 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1640 | // stdlibs |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1641 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1642 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1643 | for _, lib := range deps.Stdlibs { |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1644 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1645 | actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1646 | rlibDepTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1647 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1648 | } else { |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1649 | for _, lib := range deps.Stdlibs { |
| 1650 | addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag) |
| 1651 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1652 | } |
| 1653 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1654 | |
| 1655 | for _, lib := range deps.SharedLibs { |
| 1656 | depTag := cc.SharedDepTag() |
| 1657 | name, version := cc.StubsLibNameAndVersion(lib) |
| 1658 | |
| 1659 | variations := []blueprint.Variation{ |
| 1660 | {Mutator: "link", Variation: "shared"}, |
| 1661 | } |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1662 | // For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists) |
| 1663 | // GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary |
| 1664 | if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) { |
| 1665 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) |
| 1666 | } |
| 1667 | |
| 1668 | if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok { |
| 1669 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false) |
| 1670 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | for _, lib := range deps.WholeStaticLibs { |
| 1674 | depTag := cc.StaticDepTag(true) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1675 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1676 | |
| 1677 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1678 | {Mutator: "link", Variation: "static"}, |
| 1679 | }, depTag, lib) |
| 1680 | } |
| 1681 | |
| 1682 | for _, lib := range deps.StaticLibs { |
| 1683 | depTag := cc.StaticDepTag(false) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1684 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1685 | |
| 1686 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1687 | {Mutator: "link", Variation: "static"}, |
| 1688 | }, depTag, lib) |
| 1689 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1690 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1691 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1692 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1693 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1694 | for _, crt := range deps.CrtBegin { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1695 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1696 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1697 | } |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1698 | for _, crt := range deps.CrtEnd { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1699 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1700 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1703 | if mod.sourceProvider != nil { |
| 1704 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1705 | bindgen.Properties.Custom_bindgen != "" { |
| 1706 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1707 | bindgen.Properties.Custom_bindgen) |
| 1708 | } |
| 1709 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1710 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1711 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1712 | {Mutator: "link", Variation: "shared"}, |
| 1713 | }, dataLibDepTag, deps.DataLibs...) |
| 1714 | |
| 1715 | actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...) |
| 1716 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1717 | // 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] | 1718 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1719 | |
| 1720 | mod.afdo.addDep(ctx, actx) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1723 | // addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available. |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1724 | func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation) { |
| 1725 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Rlibs) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1726 | actx.AddVariationDependencies(variations, rlibDepTag, lib) |
| 1727 | } |
| 1728 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1729 | func addDylibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation, depTag dependencyTag) { |
| 1730 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Dylibs) |
| 1731 | actx.AddVariationDependencies(variations, depTag, lib) |
| 1732 | } |
| 1733 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1734 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1735 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1736 | mod.beginMutator(ctx) |
| 1737 | } |
| 1738 | } |
| 1739 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1740 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1741 | ctx := &baseModuleContext{ |
| 1742 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1743 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1744 | |
| 1745 | mod.begin(ctx) |
| 1746 | } |
| 1747 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1748 | func (mod *Module) Name() string { |
| 1749 | name := mod.ModuleBase.Name() |
| 1750 | if p, ok := mod.compiler.(interface { |
| 1751 | Name(string) string |
| 1752 | }); ok { |
| 1753 | name = p.Name(name) |
| 1754 | } |
| 1755 | return name |
| 1756 | } |
| 1757 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1758 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1759 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1760 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1761 | } |
| 1762 | } |
| 1763 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1764 | var _ android.HostToolProvider = (*Module)(nil) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1765 | var _ snapshot.RelativeInstallPath = (*Module)(nil) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1766 | |
| 1767 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1768 | if !mod.Host() { |
| 1769 | return android.OptionalPath{} |
| 1770 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1771 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1772 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1773 | } else if pm, ok := mod.compiler.(*procMacroDecorator); ok { |
| 1774 | // Even though proc-macros aren't strictly "tools", since they target the compiler |
| 1775 | // and act as compiler plugins, we treat them similarly. |
| 1776 | return android.OptionalPathForPath(pm.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1777 | } |
| 1778 | return android.OptionalPath{} |
| 1779 | } |
| 1780 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1781 | var _ android.ApexModule = (*Module)(nil) |
| 1782 | |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1783 | func (mod *Module) MinSdkVersion() string { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1784 | return String(mod.Properties.Min_sdk_version) |
| 1785 | } |
| 1786 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1787 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1788 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1789 | minSdkVersion := mod.MinSdkVersion() |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1790 | if minSdkVersion == "apex_inherit" { |
| 1791 | return nil |
| 1792 | } |
| 1793 | if minSdkVersion == "" { |
| 1794 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1795 | } |
| 1796 | |
| 1797 | // Not using nativeApiLevelFromUser because the context here is not |
| 1798 | // necessarily a native context. |
| 1799 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1800 | if err != nil { |
| 1801 | return err |
| 1802 | } |
| 1803 | |
| 1804 | if ver.GreaterThan(sdkVersion) { |
| 1805 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1806 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1807 | return nil |
| 1808 | } |
| 1809 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1810 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1811 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1812 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1813 | |
| 1814 | if ccm, ok := dep.(*cc.Module); ok { |
| 1815 | if ccm.HasStubsVariants() { |
| 1816 | if cc.IsSharedDepTag(depTag) { |
| 1817 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1818 | return false |
| 1819 | } |
| 1820 | if cc.IsRuntimeDepTag(depTag) { |
| 1821 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1822 | return false |
| 1823 | } |
| 1824 | |
| 1825 | if cc.IsHeaderDepTag(depTag) { |
| 1826 | return false |
| 1827 | } |
| 1828 | } |
| 1829 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1830 | // shared_lib dependency from a static lib is considered as crossing |
| 1831 | // the APEX boundary because the dependency doesn't actually is |
| 1832 | // linked; the dependency is used only during the compilation phase. |
| 1833 | return false |
| 1834 | } |
| 1835 | } |
| 1836 | |
Matthew Maurer | 581b6d8 | 2022-09-29 16:46:25 -0700 | [diff] [blame] | 1837 | if depTag == procMacroDepTag || depTag == customBindgenDepTag { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1838 | return false |
| 1839 | } |
| 1840 | |
| 1841 | return true |
| 1842 | } |
| 1843 | |
| 1844 | // Overrides ApexModule.IsInstallabeToApex() |
| 1845 | func (mod *Module) IsInstallableToApex() bool { |
| 1846 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 1847 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1848 | return true |
| 1849 | } |
| 1850 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1851 | return true |
| 1852 | } |
| 1853 | } |
| 1854 | return false |
| 1855 | } |
| 1856 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1857 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1858 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1859 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1860 | if strings.HasPrefix(libName, "lib") { |
| 1861 | libName = libName[3:] |
| 1862 | return libName, true |
| 1863 | } |
| 1864 | return "", false |
| 1865 | } |
| 1866 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1867 | func kytheExtractRustFactory() android.Singleton { |
| 1868 | return &kytheExtractRustSingleton{} |
| 1869 | } |
| 1870 | |
| 1871 | type kytheExtractRustSingleton struct { |
| 1872 | } |
| 1873 | |
| 1874 | func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 1875 | var xrefTargets android.Paths |
| 1876 | ctx.VisitAllModules(func(module android.Module) { |
| 1877 | if rustModule, ok := module.(xref); ok { |
| 1878 | xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...) |
| 1879 | } |
| 1880 | }) |
| 1881 | if len(xrefTargets) > 0 { |
| 1882 | ctx.Phony("xref_rust", xrefTargets...) |
| 1883 | } |
| 1884 | } |
| 1885 | |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 1886 | func (c *Module) Partition() string { |
| 1887 | return "" |
| 1888 | } |
| 1889 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 1890 | func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1891 | if ctx.ModuleType() == "rust_library_host" || ctx.ModuleType() == "rust_library" { |
| 1892 | libraryBp2build(ctx, m) |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1893 | } else if ctx.ModuleType() == "rust_proc_macro" { |
| 1894 | procMacroBp2build(ctx, m) |
Vinh Tran | 093a57e | 2023-08-24 12:10:49 -0400 | [diff] [blame] | 1895 | } else if ctx.ModuleType() == "rust_binary_host" { |
| 1896 | binaryBp2build(ctx, m) |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1897 | } else if ctx.ModuleType() == "rust_protobuf_host" { |
| 1898 | protoLibraryBp2build(ctx, m) |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1899 | } else { |
| 1900 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") |
| 1901 | } |
| 1902 | } |
| 1903 | |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1904 | // This is a workaround by assuming the conventions that rust crate repos are structured |
Vinh Tran | c1a6cee | 2023-08-24 12:10:49 -0400 | [diff] [blame] | 1905 | // while waiting for the sandboxing work to complete. |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1906 | // TODO(b/297344471): When crate_root prop is set which enforces inputs sandboxing, |
| 1907 | // always use `srcs` and `compile_data` props to generate `srcs` and `compile_data` attributes |
| 1908 | // instead of using globs. |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 1909 | func srcsAndCompileDataAttrs(ctx android.Bp2buildMutatorContext, c baseCompiler) (bazel.LabelList, bazel.LabelList) { |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1910 | var srcs bazel.LabelList |
| 1911 | var compileData bazel.LabelList |
| 1912 | |
| 1913 | if c.Properties.Srcs[0] == "src/lib.rs" { |
| 1914 | srcs = android.BazelLabelForModuleSrc(ctx, []string{"src/**/*.rs"}) |
| 1915 | compileData = android.BazelLabelForModuleSrc( |
| 1916 | ctx, |
| 1917 | []string{ |
| 1918 | "src/**/*.proto", |
| 1919 | "examples/**/*.rs", |
| 1920 | "**/*.md", |
| 1921 | }, |
| 1922 | ) |
| 1923 | } else { |
| 1924 | srcs = android.BazelLabelForModuleSrc(ctx, c.Properties.Srcs) |
| 1925 | } |
| 1926 | |
| 1927 | return srcs, compileData |
| 1928 | } |
| 1929 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1930 | var Bool = proptools.Bool |
| 1931 | var BoolDefault = proptools.BoolDefault |
| 1932 | var String = proptools.String |
| 1933 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1934 | |
| 1935 | var _ android.OutputFileProducer = (*Module)(nil) |