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