testing.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. func GatherRequiredDepsForTest() string {
  42. bp := `
  43. rust_prebuilt_library {
  44. name: "libstd_x86_64-unknown-linux-gnu",
  45. crate_name: "std",
  46. rlib: {
  47. srcs: ["libstd.rlib"],
  48. },
  49. dylib: {
  50. srcs: ["libstd.so"],
  51. },
  52. host_supported: true,
  53. sysroot: true,
  54. }
  55. rust_prebuilt_library {
  56. name: "libtest_x86_64-unknown-linux-gnu",
  57. crate_name: "test",
  58. rlib: {
  59. srcs: ["libtest.rlib"],
  60. },
  61. dylib: {
  62. srcs: ["libtest.so"],
  63. },
  64. host_supported: true,
  65. sysroot: true,
  66. }
  67. rust_prebuilt_library {
  68. name: "libstd_i686-unknown-linux-gnu",
  69. crate_name: "std",
  70. rlib: {
  71. srcs: ["libstd.rlib"],
  72. },
  73. dylib: {
  74. srcs: ["libstd.so"],
  75. },
  76. host_supported: true,
  77. sysroot: true,
  78. }
  79. rust_prebuilt_library {
  80. name: "libtest_i686-unknown-linux-gnu",
  81. crate_name: "test",
  82. rlib: {
  83. srcs: ["libtest.rlib"],
  84. },
  85. dylib: {
  86. srcs: ["libtest.so"],
  87. },
  88. host_supported: true,
  89. sysroot: true,
  90. }
  91. rust_prebuilt_library {
  92. name: "libstd_x86_64-apple-darwin",
  93. crate_name: "std",
  94. rlib: {
  95. srcs: ["libstd.rlib"],
  96. },
  97. dylib: {
  98. srcs: ["libstd.so"],
  99. },
  100. host_supported: true,
  101. sysroot: true,
  102. }
  103. rust_prebuilt_library {
  104. name: "libtest_x86_64-apple-darwin",
  105. crate_name: "test",
  106. rlib: {
  107. srcs: ["libtest.rlib"],
  108. },
  109. dylib: {
  110. srcs: ["libtest.so"],
  111. },
  112. host_supported: true,
  113. sysroot: true,
  114. }
  115. //////////////////////////////
  116. // Device module requirements
  117. cc_library {
  118. name: "liblog",
  119. no_libcrt: true,
  120. nocrt: true,
  121. system_shared_libs: [],
  122. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  123. min_sdk_version: "29",
  124. }
  125. cc_library {
  126. name: "libprotobuf-cpp-full",
  127. no_libcrt: true,
  128. nocrt: true,
  129. system_shared_libs: [],
  130. export_include_dirs: ["libprotobuf-cpp-full-includes"],
  131. }
  132. cc_library {
  133. name: "libclang_rt.asan-aarch64-android",
  134. no_libcrt: true,
  135. nocrt: true,
  136. system_shared_libs: [],
  137. export_include_dirs: ["libprotobuf-cpp-full-includes"],
  138. }
  139. rust_library {
  140. name: "libstd",
  141. crate_name: "std",
  142. srcs: ["foo.rs"],
  143. no_stdlibs: true,
  144. host_supported: true,
  145. vendor_available: true,
  146. vendor_ramdisk_available: true,
  147. native_coverage: false,
  148. sysroot: true,
  149. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  150. min_sdk_version: "29",
  151. }
  152. rust_library {
  153. name: "libtest",
  154. crate_name: "test",
  155. srcs: ["foo.rs"],
  156. no_stdlibs: true,
  157. host_supported: true,
  158. vendor_available: true,
  159. vendor_ramdisk_available: true,
  160. native_coverage: false,
  161. sysroot: true,
  162. apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
  163. min_sdk_version: "29",
  164. }
  165. rust_library {
  166. name: "libprotobuf",
  167. crate_name: "protobuf",
  168. srcs: ["foo.rs"],
  169. host_supported: true,
  170. }
  171. rust_library {
  172. name: "libgrpcio",
  173. crate_name: "grpcio",
  174. srcs: ["foo.rs"],
  175. host_supported: true,
  176. }
  177. rust_library {
  178. name: "libfutures",
  179. crate_name: "futures",
  180. srcs: ["foo.rs"],
  181. host_supported: true,
  182. }
  183. rust_library {
  184. name: "liblibfuzzer_sys",
  185. crate_name: "libfuzzer_sys",
  186. srcs:["foo.rs"],
  187. host_supported: true,
  188. }
  189. rust_library {
  190. name: "libcriterion",
  191. crate_name: "criterion",
  192. srcs:["foo.rs"],
  193. host_supported: true,
  194. }
  195. `
  196. return bp
  197. }
  198. func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
  199. ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
  200. ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
  201. ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
  202. ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
  203. ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
  204. ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
  205. ctx.RegisterModuleType("rust_test", RustTestFactory)
  206. ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
  207. ctx.RegisterModuleType("rust_library", RustLibraryFactory)
  208. ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
  209. ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
  210. ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
  211. ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
  212. ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
  213. ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
  214. ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
  215. ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
  216. ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
  217. ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
  218. ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
  219. ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
  220. ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
  221. ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
  222. ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
  223. ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
  224. ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
  225. ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
  226. ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
  227. // rust mutators
  228. ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
  229. ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
  230. ctx.BottomUp("rust_begin", BeginMutator).Parallel()
  231. })
  232. ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
  233. }