blob: 10b768ca9f007d44f98a48582a4b89e37d7486b0 [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"
Thiébaud Weksteene4dd14b2021-04-14 11:18:47 +020019 "android/soong/bloaty"
Ivan Lozanob9040d62019-09-24 13:23:50 -070020 "android/soong/cc"
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(
Paul Duffin9e0c3f92021-03-30 22:45:21 +010026 android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
Paul Duffindb488892021-03-11 11:48:35 +000027)
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,
Thiébaud Weksteene4dd14b2021-04-14 11:18:47 +020038 bloaty.PrepareForTestWithBloatyDefaultModules,
Paul Duffindb488892021-03-11 11:48:35 +000039 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
Ivan Lozanoffee3342019-08-27 12:03:00 -070048func GatherRequiredDepsForTest() string {
49 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070050 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070051 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070052 crate_name: "std",
53 rlib: {
54 srcs: ["libstd.rlib"],
55 },
56 dylib: {
57 srcs: ["libstd.so"],
58 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070059 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040060 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070061 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070062 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070063 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070064 crate_name: "test",
65 rlib: {
66 srcs: ["libtest.rlib"],
67 },
68 dylib: {
69 srcs: ["libtest.so"],
70 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070071 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040072 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070073 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020074 rust_prebuilt_library {
Ivan Lozanoc5d34ec2021-02-09 14:22:00 -050075 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 {
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020099 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,
Ivan Lozano2b081132020-09-08 12:46:52 -0400108 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200109 }
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,
Ivan Lozano2b081132020-09-08 12:46:52 -0400120 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +0200121 }
Ivan Lozanob9040d62019-09-24 13:23:50 -0700122 //////////////////////////////
123 // Device module requirements
124
Ivan Lozanob9040d62019-09-24 13:23:50 -0700125 cc_library {
126 name: "liblog",
127 no_libcrt: true,
128 nocrt: true,
129 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +0900130 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500131 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700132 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800133 cc_library {
134 name: "libprotobuf-cpp-full",
135 no_libcrt: true,
136 nocrt: true,
137 system_shared_libs: [],
138 export_include_dirs: ["libprotobuf-cpp-full-includes"],
139 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500140 cc_library {
141 name: "libclang_rt.asan-aarch64-android",
142 no_libcrt: true,
143 nocrt: true,
144 system_shared_libs: [],
145 export_include_dirs: ["libprotobuf-cpp-full-includes"],
146 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700147 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400148 name: "libstd",
149 crate_name: "std",
150 srcs: ["foo.rs"],
151 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400152 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500153 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500154 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700155 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400156 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900157 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500158 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400159 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700160 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400161 name: "libtest",
162 crate_name: "test",
163 srcs: ["foo.rs"],
164 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400165 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500166 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500167 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700168 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400169 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900170 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500171 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400172 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000173 rust_library {
174 name: "libprotobuf",
175 crate_name: "protobuf",
176 srcs: ["foo.rs"],
177 host_supported: true,
178 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800179 rust_library {
180 name: "libgrpcio",
181 crate_name: "grpcio",
182 srcs: ["foo.rs"],
183 host_supported: true,
184 }
185 rust_library {
186 name: "libfutures",
187 crate_name: "futures",
188 srcs: ["foo.rs"],
189 host_supported: true,
190 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500191 rust_library {
192 name: "liblibfuzzer_sys",
193 crate_name: "libfuzzer_sys",
194 srcs:["foo.rs"],
195 host_supported: true,
196 }
Jakub Kotur1d640d02021-01-06 12:40:43 +0100197 rust_library {
198 name: "libcriterion",
199 crate_name: "criterion",
200 srcs:["foo.rs"],
201 host_supported: true,
202 }
Jiyong Park99644e92020-11-17 22:21:02 +0900203`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700204 return bp
205}
206
Paul Duffin9e0c3f92021-03-30 22:45:21 +0100207func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Jakub Kotur1d640d02021-01-06 12:40:43 +0100208 ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
209 ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800210 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
211 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400212 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200213 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800214 ctx.RegisterModuleType("rust_test", RustTestFactory)
215 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
216 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800217 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700218 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
219 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
220 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
221 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500222 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700223 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
224 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
225 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
226 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
227 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
228 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800229 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000230 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
231 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700232 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800233 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700234 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700235 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700236 // rust mutators
237 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400238 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400239 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700240 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200241 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900242}