blob: 5be71c90e099755931e67a8436b55be7b89ff7d5 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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"
Ivan Lozanob9040d62019-09-24 13:23:50 -070019 "android/soong/cc"
Paul Duffind6ceb862021-03-04 23:02:31 +000020 "android/soong/genrule"
Ivan Lozanoffee3342019-08-27 12:03:00 -070021)
22
Paul Duffindb488892021-03-11 11:48:35 +000023// 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 PrepareForTestWithRustBuildComponents,
39 android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()),
40)
41
42// Preparer that will allow use of all rust modules fully.
43var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
44 PrepareForTestWithRustDefaultModules,
45)
46
Ivan Lozanoffee3342019-08-27 12:03:00 -070047func GatherRequiredDepsForTest() string {
48 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070049 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070050 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070051 crate_name: "std",
52 rlib: {
53 srcs: ["libstd.rlib"],
54 },
55 dylib: {
56 srcs: ["libstd.so"],
57 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070058 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040059 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070060 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070061 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070062 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070063 crate_name: "test",
64 rlib: {
65 srcs: ["libtest.rlib"],
66 },
67 dylib: {
68 srcs: ["libtest.so"],
69 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070070 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040071 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070072 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020073 rust_prebuilt_library {
Ivan Lozanoc5d34ec2021-02-09 14:22:00 -050074 name: "libstd_i686-unknown-linux-gnu",
75 crate_name: "std",
76 rlib: {
77 srcs: ["libstd.rlib"],
78 },
79 dylib: {
80 srcs: ["libstd.so"],
81 },
82 host_supported: true,
83 sysroot: true,
84 }
85 rust_prebuilt_library {
86 name: "libtest_i686-unknown-linux-gnu",
87 crate_name: "test",
88 rlib: {
89 srcs: ["libtest.rlib"],
90 },
91 dylib: {
92 srcs: ["libtest.so"],
93 },
94 host_supported: true,
95 sysroot: true,
96 }
97 rust_prebuilt_library {
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020098 name: "libstd_x86_64-apple-darwin",
99 crate_name: "std",
100 rlib: {
101 srcs: ["libstd.rlib"],
102 },
103 dylib: {
104 srcs: ["libstd.so"],
105 },
106 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -0400107 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200108 }
109 rust_prebuilt_library {
110 name: "libtest_x86_64-apple-darwin",
111 crate_name: "test",
112 rlib: {
113 srcs: ["libtest.rlib"],
114 },
115 dylib: {
116 srcs: ["libtest.so"],
117 },
118 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -0400119 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200120 }
Ivan Lozanob9040d62019-09-24 13:23:50 -0700121 //////////////////////////////
122 // Device module requirements
123
Ivan Lozanob9040d62019-09-24 13:23:50 -0700124 cc_library {
125 name: "liblog",
126 no_libcrt: true,
127 nocrt: true,
128 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +0900129 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500130 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700131 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800132 cc_library {
133 name: "libprotobuf-cpp-full",
134 no_libcrt: true,
135 nocrt: true,
136 system_shared_libs: [],
137 export_include_dirs: ["libprotobuf-cpp-full-includes"],
138 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500139 cc_library {
140 name: "libclang_rt.asan-aarch64-android",
141 no_libcrt: true,
142 nocrt: true,
143 system_shared_libs: [],
144 export_include_dirs: ["libprotobuf-cpp-full-includes"],
145 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700146 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400147 name: "libstd",
148 crate_name: "std",
149 srcs: ["foo.rs"],
150 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400151 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500152 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500153 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700154 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400155 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900156 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500157 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400158 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700159 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400160 name: "libtest",
161 crate_name: "test",
162 srcs: ["foo.rs"],
163 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400164 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500165 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500166 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700167 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400168 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900169 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500170 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400171 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000172 rust_library {
173 name: "libprotobuf",
174 crate_name: "protobuf",
175 srcs: ["foo.rs"],
176 host_supported: true,
177 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800178 rust_library {
179 name: "libgrpcio",
180 crate_name: "grpcio",
181 srcs: ["foo.rs"],
182 host_supported: true,
183 }
184 rust_library {
185 name: "libfutures",
186 crate_name: "futures",
187 srcs: ["foo.rs"],
188 host_supported: true,
189 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500190 rust_library {
191 name: "liblibfuzzer_sys",
192 crate_name: "libfuzzer_sys",
193 srcs:["foo.rs"],
194 host_supported: true,
195 }
Jiyong Park99644e92020-11-17 22:21:02 +0900196`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700197 return bp
198}
199
Jiyong Park99644e92020-11-17 22:21:02 +0900200func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Colin Cross4b49b762019-11-22 15:25:03 -0800201 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
202 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400203 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200204 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800205 ctx.RegisterModuleType("rust_test", RustTestFactory)
206 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
207 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800208 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700209 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)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500213 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700214 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)
Colin Cross4b49b762019-11-22 15:25:03 -0800220 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000221 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
222 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700223 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800224 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700225 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700226 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700227 // rust mutators
228 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400229 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400230 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700231 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200232 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900233}
234
235func CreateTestContext(config android.Config) *android.TestContext {
236 ctx := android.NewTestArchContext(config)
237 android.RegisterPrebuiltMutators(ctx)
238 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffind6ceb862021-03-04 23:02:31 +0000239 genrule.RegisterGenruleBuildComponents(ctx)
Jiyong Park99644e92020-11-17 22:21:02 +0900240 cc.RegisterRequiredBuildComponentsForTest(ctx)
241 RegisterRequiredBuildComponentsForTest(ctx)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700242
243 return ctx
244}