blob: 1e01cc0c5773801be6070131e5c46f9689fb0d78 [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"
Ivan Lozanoffee3342019-08-27 12:03:00 -070020)
21
Paul Duffindb488892021-03-11 11:48:35 +000022// Preparer that will define all cc module types and a limited set of mutators and singletons that
23// make those module types usable.
24var PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
Paul Duffin9e0c3f92021-03-30 22:45:21 +010025 android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
Paul Duffindb488892021-03-11 11:48:35 +000026)
27
28// The directory in which rust test default modules will be defined.
29//
30// Placing them here ensures that their location does not conflict with default test modules
31// defined by other packages.
32const rustDefaultsDir = "defaults/rust/"
33
34// Preparer that will define default rust modules, e.g. standard prebuilt modules.
35var PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers(
36 cc.PrepareForTestWithCcDefaultModules,
37 PrepareForTestWithRustBuildComponents,
38 android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()),
39)
40
41// Preparer that will allow use of all rust modules fully.
42var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
43 PrepareForTestWithRustDefaultModules,
44)
45
Ivan Lozanoffee3342019-08-27 12:03:00 -070046func GatherRequiredDepsForTest() string {
47 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070048 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070049 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070050 crate_name: "std",
51 rlib: {
52 srcs: ["libstd.rlib"],
53 },
54 dylib: {
55 srcs: ["libstd.so"],
56 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070057 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040058 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070059 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070060 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070061 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070062 crate_name: "test",
63 rlib: {
64 srcs: ["libtest.rlib"],
65 },
66 dylib: {
67 srcs: ["libtest.so"],
68 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070069 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040070 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070071 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020072 rust_prebuilt_library {
Ivan Lozanoc5d34ec2021-02-09 14:22:00 -050073 name: "libstd_i686-unknown-linux-gnu",
74 crate_name: "std",
75 rlib: {
76 srcs: ["libstd.rlib"],
77 },
78 dylib: {
79 srcs: ["libstd.so"],
80 },
81 host_supported: true,
82 sysroot: true,
83 }
84 rust_prebuilt_library {
85 name: "libtest_i686-unknown-linux-gnu",
86 crate_name: "test",
87 rlib: {
88 srcs: ["libtest.rlib"],
89 },
90 dylib: {
91 srcs: ["libtest.so"],
92 },
93 host_supported: true,
94 sysroot: true,
95 }
96 rust_prebuilt_library {
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020097 name: "libstd_x86_64-apple-darwin",
98 crate_name: "std",
99 rlib: {
100 srcs: ["libstd.rlib"],
101 },
102 dylib: {
103 srcs: ["libstd.so"],
104 },
105 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -0400106 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200107 }
108 rust_prebuilt_library {
109 name: "libtest_x86_64-apple-darwin",
110 crate_name: "test",
111 rlib: {
112 srcs: ["libtest.rlib"],
113 },
114 dylib: {
115 srcs: ["libtest.so"],
116 },
117 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -0400118 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200119 }
Ivan Lozanob9040d62019-09-24 13:23:50 -0700120 //////////////////////////////
121 // Device module requirements
122
Ivan Lozanob9040d62019-09-24 13:23:50 -0700123 cc_library {
124 name: "liblog",
125 no_libcrt: true,
126 nocrt: true,
127 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +0900128 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500129 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700130 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800131 cc_library {
132 name: "libprotobuf-cpp-full",
133 no_libcrt: true,
134 nocrt: true,
135 system_shared_libs: [],
136 export_include_dirs: ["libprotobuf-cpp-full-includes"],
137 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500138 cc_library {
139 name: "libclang_rt.asan-aarch64-android",
140 no_libcrt: true,
141 nocrt: true,
142 system_shared_libs: [],
143 export_include_dirs: ["libprotobuf-cpp-full-includes"],
144 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700145 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400146 name: "libstd",
147 crate_name: "std",
148 srcs: ["foo.rs"],
149 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400150 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500151 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500152 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700153 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400154 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900155 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500156 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400157 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700158 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400159 name: "libtest",
160 crate_name: "test",
161 srcs: ["foo.rs"],
162 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400163 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500164 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500165 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700166 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400167 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900168 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500169 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400170 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000171 rust_library {
172 name: "libprotobuf",
173 crate_name: "protobuf",
174 srcs: ["foo.rs"],
175 host_supported: true,
176 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800177 rust_library {
178 name: "libgrpcio",
179 crate_name: "grpcio",
180 srcs: ["foo.rs"],
181 host_supported: true,
182 }
183 rust_library {
184 name: "libfutures",
185 crate_name: "futures",
186 srcs: ["foo.rs"],
187 host_supported: true,
188 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500189 rust_library {
190 name: "liblibfuzzer_sys",
191 crate_name: "libfuzzer_sys",
192 srcs:["foo.rs"],
193 host_supported: true,
194 }
Jakub Kotur1d640d02021-01-06 12:40:43 +0100195 rust_library {
196 name: "libcriterion",
197 crate_name: "criterion",
198 srcs:["foo.rs"],
199 host_supported: true,
200 }
Jiyong Park99644e92020-11-17 22:21:02 +0900201`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700202 return bp
203}
204
Paul Duffin9e0c3f92021-03-30 22:45:21 +0100205func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Jakub Kotur1d640d02021-01-06 12:40:43 +0100206 ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
207 ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800208 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
209 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400210 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200211 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800212 ctx.RegisterModuleType("rust_test", RustTestFactory)
213 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
214 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800215 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700216 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
217 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
218 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
219 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500220 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700221 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
222 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
223 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
224 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
225 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
226 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800227 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000228 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
229 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700230 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800231 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700232 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700233 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700234 // rust mutators
235 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400236 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400237 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700238 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200239 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900240}