testing.go 8.1 KB

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