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