Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright (C) 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 ( |
| 18 | "android/soong/android" |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame] | 19 | "android/soong/bloaty" |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 20 | "android/soong/cc" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 21 | ) |
| 22 | |
Paul Duffin | db48889 | 2021-03-11 11:48:35 +0000 | [diff] [blame] | 23 | // Preparer that will define all cc module types and a limited set of mutators and singletons that |
| 24 | // make those module types usable. |
| 25 | var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers( |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 26 | android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest), |
Paul Duffin | db48889 | 2021-03-11 11:48:35 +0000 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | // The directory in which rust test default modules will be defined. |
| 30 | // |
| 31 | // Placing them here ensures that their location does not conflict with default test modules |
| 32 | // defined by other packages. |
| 33 | const rustDefaultsDir = "defaults/rust/" |
| 34 | |
| 35 | // Preparer that will define default rust modules, e.g. standard prebuilt modules. |
| 36 | var PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers( |
| 37 | cc.PrepareForTestWithCcDefaultModules, |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame] | 38 | bloaty.PrepareForTestWithBloatyDefaultModules, |
Paul Duffin | db48889 | 2021-03-11 11:48:35 +0000 | [diff] [blame] | 39 | PrepareForTestWithRustBuildComponents, |
| 40 | android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()), |
| 41 | ) |
| 42 | |
| 43 | // Preparer that will allow use of all rust modules fully. |
| 44 | var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers( |
| 45 | PrepareForTestWithRustDefaultModules, |
| 46 | ) |
| 47 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 48 | var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers( |
| 49 | PrepareForIntegrationTestWithRust, |
| 50 | cc.PrepareForTestWithCcIncludeVndk, |
| 51 | ) |
| 52 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 53 | func GatherRequiredDepsForTest() string { |
| 54 | bp := ` |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 55 | rust_prebuilt_library { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 56 | name: "libstd_x86_64-unknown-linux-gnu", |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 57 | crate_name: "std", |
| 58 | rlib: { |
| 59 | srcs: ["libstd.rlib"], |
| 60 | }, |
| 61 | dylib: { |
| 62 | srcs: ["libstd.so"], |
| 63 | }, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 64 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 65 | sysroot: true, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 66 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 67 | rust_prebuilt_library { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 68 | name: "libtest_x86_64-unknown-linux-gnu", |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 69 | crate_name: "test", |
| 70 | rlib: { |
| 71 | srcs: ["libtest.rlib"], |
| 72 | }, |
| 73 | dylib: { |
| 74 | srcs: ["libtest.so"], |
| 75 | }, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 76 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 77 | sysroot: true, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 78 | } |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 79 | rust_prebuilt_library { |
Ivan Lozano | c5d34ec | 2021-02-09 14:22:00 -0500 | [diff] [blame] | 80 | name: "libstd_i686-unknown-linux-gnu", |
| 81 | crate_name: "std", |
| 82 | rlib: { |
| 83 | srcs: ["libstd.rlib"], |
| 84 | }, |
| 85 | dylib: { |
| 86 | srcs: ["libstd.so"], |
| 87 | }, |
| 88 | host_supported: true, |
| 89 | sysroot: true, |
| 90 | } |
| 91 | rust_prebuilt_library { |
| 92 | name: "libtest_i686-unknown-linux-gnu", |
| 93 | crate_name: "test", |
| 94 | rlib: { |
| 95 | srcs: ["libtest.rlib"], |
| 96 | }, |
| 97 | dylib: { |
| 98 | srcs: ["libtest.so"], |
| 99 | }, |
| 100 | host_supported: true, |
| 101 | sysroot: true, |
| 102 | } |
| 103 | rust_prebuilt_library { |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 104 | name: "libstd_x86_64-apple-darwin", |
| 105 | crate_name: "std", |
| 106 | rlib: { |
| 107 | srcs: ["libstd.rlib"], |
| 108 | }, |
| 109 | dylib: { |
| 110 | srcs: ["libstd.so"], |
| 111 | }, |
| 112 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 113 | sysroot: true, |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 114 | } |
| 115 | rust_prebuilt_library { |
| 116 | name: "libtest_x86_64-apple-darwin", |
| 117 | crate_name: "test", |
| 118 | rlib: { |
| 119 | srcs: ["libtest.rlib"], |
| 120 | }, |
| 121 | dylib: { |
| 122 | srcs: ["libtest.so"], |
| 123 | }, |
| 124 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 125 | sysroot: true, |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 126 | } |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 127 | ////////////////////////////// |
| 128 | // Device module requirements |
| 129 | |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 130 | cc_library { |
| 131 | name: "liblog", |
| 132 | no_libcrt: true, |
| 133 | nocrt: true, |
| 134 | system_shared_libs: [], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 135 | apex_available: ["//apex_available:platform", "//apex_available:anyapex"], |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 136 | min_sdk_version: "29", |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 137 | vendor_available: true, |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 138 | llndk: { |
| 139 | symbol_file: "liblog.map.txt", |
| 140 | }, |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 141 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 142 | cc_library { |
| 143 | name: "libprotobuf-cpp-full", |
| 144 | no_libcrt: true, |
| 145 | nocrt: true, |
| 146 | system_shared_libs: [], |
| 147 | export_include_dirs: ["libprotobuf-cpp-full-includes"], |
| 148 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 149 | cc_library { |
| 150 | name: "libclang_rt.asan-aarch64-android", |
| 151 | no_libcrt: true, |
| 152 | nocrt: true, |
| 153 | system_shared_libs: [], |
Ivan Lozano | 5482d6a | 2021-11-01 10:13:25 -0400 | [diff] [blame^] | 154 | } |
| 155 | cc_library { |
| 156 | name: "libclang_rt.hwasan_static-aarch64-android", |
| 157 | no_libcrt: true, |
| 158 | nocrt: true, |
| 159 | system_shared_libs: [], |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 160 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 161 | rust_library { |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 162 | name: "libstd", |
| 163 | crate_name: "std", |
| 164 | srcs: ["foo.rs"], |
| 165 | no_stdlibs: true, |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 166 | host_supported: true, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 167 | vendor_available: true, |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 168 | vendor_ramdisk_available: true, |
Ivan Lozano | 699e218 | 2021-03-22 14:29:47 -0400 | [diff] [blame] | 169 | native_coverage: false, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 170 | sysroot: true, |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 171 | apex_available: ["//apex_available:platform", "//apex_available:anyapex"], |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 172 | min_sdk_version: "29", |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 173 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 174 | rust_library { |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 175 | name: "libtest", |
| 176 | crate_name: "test", |
| 177 | srcs: ["foo.rs"], |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 178 | host_supported: true, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 179 | vendor_available: true, |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 180 | vendor_ramdisk_available: true, |
Ivan Lozano | 699e218 | 2021-03-22 14:29:47 -0400 | [diff] [blame] | 181 | native_coverage: false, |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 182 | apex_available: ["//apex_available:platform", "//apex_available:anyapex"], |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 183 | min_sdk_version: "29", |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 184 | } |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 185 | rust_library { |
| 186 | name: "libprotobuf", |
| 187 | crate_name: "protobuf", |
| 188 | srcs: ["foo.rs"], |
| 189 | host_supported: true, |
| 190 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 191 | rust_library { |
| 192 | name: "libgrpcio", |
| 193 | crate_name: "grpcio", |
| 194 | srcs: ["foo.rs"], |
| 195 | host_supported: true, |
| 196 | } |
| 197 | rust_library { |
| 198 | name: "libfutures", |
| 199 | crate_name: "futures", |
| 200 | srcs: ["foo.rs"], |
| 201 | host_supported: true, |
| 202 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 203 | rust_library { |
| 204 | name: "liblibfuzzer_sys", |
| 205 | crate_name: "libfuzzer_sys", |
| 206 | srcs:["foo.rs"], |
| 207 | host_supported: true, |
| 208 | } |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 209 | rust_library { |
| 210 | name: "libcriterion", |
| 211 | crate_name: "criterion", |
| 212 | srcs:["foo.rs"], |
| 213 | host_supported: true, |
| 214 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 215 | ` |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 216 | return bp |
| 217 | } |
| 218 | |
Paul Duffin | 9e0c3f9 | 2021-03-30 22:45:21 +0100 | [diff] [blame] | 219 | func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) { |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 220 | ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory) |
| 221 | ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 222 | ctx.RegisterModuleType("rust_binary", RustBinaryFactory) |
| 223 | ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 224 | ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory) |
Thiébaud Weksteen | a6351ca | 2020-09-29 09:53:21 +0200 | [diff] [blame] | 225 | ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 226 | ctx.RegisterModuleType("rust_test", RustTestFactory) |
| 227 | ctx.RegisterModuleType("rust_test_host", RustTestHostFactory) |
| 228 | ctx.RegisterModuleType("rust_library", RustLibraryFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 229 | ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 230 | ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory) |
| 231 | ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory) |
| 232 | ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) |
| 233 | ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 234 | ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory) |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 235 | ctx.RegisterModuleType("rust_ffi", RustFFIFactory) |
| 236 | ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory) |
| 237 | ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory) |
| 238 | ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory) |
| 239 | ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory) |
| 240 | ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 241 | ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 242 | ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory) |
| 243 | ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory) |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 244 | ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 245 | ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 246 | ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 247 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 248 | // rust mutators |
| 249 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 250 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 251 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 252 | }) |
Thiébaud Weksteen | e4d12a0 | 2020-06-05 11:09:27 +0200 | [diff] [blame] | 253 | ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton) |
Ivan Lozano | 5482d6a | 2021-11-01 10:13:25 -0400 | [diff] [blame^] | 254 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 255 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel() |
| 256 | }) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 257 | registerRustSnapshotModules(ctx) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 258 | } |