testing.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. package rust
  15. import (
  16. "android/soong/android"
  17. "android/soong/bloaty"
  18. "android/soong/cc"
  19. )
  20. // Preparer that will define all cc module types and a limited set of mutators and singletons that
  21. // make those module types usable.
  22. var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
  23. android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
  24. )
  25. // The directory in which rust test default modules will be defined.
  26. //
  27. // Placing them here ensures that their location does not conflict with default test modules
  28. // defined by other packages.
  29. const rustDefaultsDir = "defaults/rust/"
  30. // Preparer that will define default rust modules, e.g. standard prebuilt modules.
  31. var PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers(
  32. cc.PrepareForTestWithCcDefaultModules,
  33. bloaty.PrepareForTestWithBloatyDefaultModules,
  34. PrepareForTestWithRustBuildComponents,
  35. android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()),
  36. )
  37. // Preparer that will allow use of all rust modules fully.
  38. var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
  39. PrepareForTestWithRustDefaultModules,
  40. )
  41. var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers(
  42. PrepareForIntegrationTestWithRust,
  43. cc.PrepareForTestWithCcIncludeVndk,
  44. )
  45. func GatherRequiredDepsForTest() string {
  46. bp := `
  47. rust_prebuilt_library {
  48. name: "libstd",
  49. crate_name: "std",
  50. rlib: {
  51. srcs: ["libstd.rlib"],
  52. },
  53. dylib: {
  54. srcs: ["libstd.so"],
  55. },
  56. host_supported: true,
  57. sysroot: true,
  58. }
  59. //////////////////////////////
  60. // Device module requirements
  61. cc_library {
  62. name: "liblog",
  63. no_libcrt: true,
  64. nocrt: true,
  65. system_shared_libs: [],
  66. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  67. min_sdk_version: "29",
  68. vendor_available: true,
  69. recovery_available: true,
  70. llndk: {
  71. symbol_file: "liblog.map.txt",
  72. },
  73. }
  74. cc_library {
  75. name: "libprotobuf-cpp-full",
  76. no_libcrt: true,
  77. nocrt: true,
  78. system_shared_libs: [],
  79. export_include_dirs: ["libprotobuf-cpp-full-includes"],
  80. }
  81. cc_library {
  82. name: "libclang_rt.asan",
  83. no_libcrt: true,
  84. nocrt: true,
  85. system_shared_libs: [],
  86. }
  87. cc_library {
  88. name: "libclang_rt.hwasan_static",
  89. no_libcrt: true,
  90. nocrt: true,
  91. system_shared_libs: [],
  92. }
  93. rust_library {
  94. name: "libstd",
  95. crate_name: "std",
  96. srcs: ["foo.rs"],
  97. no_stdlibs: true,
  98. product_available: true,
  99. host_supported: true,
  100. vendor_available: true,
  101. vendor_ramdisk_available: true,
  102. recovery_available: true,
  103. native_coverage: false,
  104. sysroot: true,
  105. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  106. min_sdk_version: "29",
  107. }
  108. rust_library {
  109. name: "libtest",
  110. crate_name: "test",
  111. srcs: ["foo.rs"],
  112. host_supported: true,
  113. vendor_available: true,
  114. vendor_ramdisk_available: true,
  115. recovery_available: true,
  116. native_coverage: false,
  117. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  118. min_sdk_version: "29",
  119. }
  120. rust_library {
  121. name: "libprotobuf",
  122. crate_name: "protobuf",
  123. srcs: ["foo.rs"],
  124. host_supported: true,
  125. }
  126. rust_library {
  127. name: "libprotobuf_deprecated",
  128. crate_name: "protobuf",
  129. srcs: ["foo.rs"],
  130. host_supported: true,
  131. }
  132. rust_library {
  133. name: "libgrpcio",
  134. crate_name: "grpcio",
  135. srcs: ["foo.rs"],
  136. host_supported: true,
  137. }
  138. rust_library {
  139. name: "libfutures",
  140. crate_name: "futures",
  141. srcs: ["foo.rs"],
  142. host_supported: true,
  143. }
  144. rust_library {
  145. name: "liblibfuzzer_sys",
  146. crate_name: "libfuzzer_sys",
  147. srcs:["foo.rs"],
  148. host_supported: true,
  149. }
  150. rust_library {
  151. name: "libcriterion",
  152. crate_name: "criterion",
  153. srcs:["foo.rs"],
  154. host_supported: true,
  155. }
  156. `
  157. return bp
  158. }
  159. func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
  160. ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
  161. ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
  162. ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
  163. ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
  164. ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
  165. ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
  166. ctx.RegisterModuleType("rust_test", RustTestFactory)
  167. ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
  168. ctx.RegisterModuleType("rust_library", RustLibraryFactory)
  169. ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
  170. ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
  171. ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
  172. ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
  173. ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
  174. ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
  175. ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
  176. ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
  177. ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
  178. ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
  179. ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
  180. ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
  181. ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
  182. ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
  183. ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
  184. ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
  185. ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
  186. ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
  187. ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
  188. // rust mutators
  189. ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
  190. ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
  191. ctx.BottomUp("rust_begin", BeginMutator).Parallel()
  192. })
  193. ctx.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
  194. ctx.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
  195. ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
  196. ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
  197. })
  198. registerRustSnapshotModules(ctx)
  199. }