blob: 9534ab58007dcd31bd995657536c1f0376bdc8fc [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
23func GatherRequiredDepsForTest() string {
24 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070025 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070026 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070027 crate_name: "std",
28 rlib: {
29 srcs: ["libstd.rlib"],
30 },
31 dylib: {
32 srcs: ["libstd.so"],
33 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070034 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040035 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070037 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070038 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070039 crate_name: "test",
40 rlib: {
41 srcs: ["libtest.rlib"],
42 },
43 dylib: {
44 srcs: ["libtest.so"],
45 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070046 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040047 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070048 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020049 rust_prebuilt_library {
Ivan Lozanoc5d34ec2021-02-09 14:22:00 -050050 name: "libstd_i686-unknown-linux-gnu",
51 crate_name: "std",
52 rlib: {
53 srcs: ["libstd.rlib"],
54 },
55 dylib: {
56 srcs: ["libstd.so"],
57 },
58 host_supported: true,
59 sysroot: true,
60 }
61 rust_prebuilt_library {
62 name: "libtest_i686-unknown-linux-gnu",
63 crate_name: "test",
64 rlib: {
65 srcs: ["libtest.rlib"],
66 },
67 dylib: {
68 srcs: ["libtest.so"],
69 },
70 host_supported: true,
71 sysroot: true,
72 }
73 rust_prebuilt_library {
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020074 name: "libstd_x86_64-apple-darwin",
75 crate_name: "std",
76 rlib: {
77 srcs: ["libstd.rlib"],
78 },
79 dylib: {
80 srcs: ["libstd.so"],
81 },
82 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040083 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020084 }
85 rust_prebuilt_library {
86 name: "libtest_x86_64-apple-darwin",
87 crate_name: "test",
88 rlib: {
89 srcs: ["libtest.rlib"],
90 },
91 dylib: {
92 srcs: ["libtest.so"],
93 },
94 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040095 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020096 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070097 //////////////////////////////
98 // Device module requirements
99
Ivan Lozanob9040d62019-09-24 13:23:50 -0700100 cc_library {
101 name: "liblog",
102 no_libcrt: true,
103 nocrt: true,
104 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +0900105 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500106 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700107 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800108 cc_library {
109 name: "libprotobuf-cpp-full",
110 no_libcrt: true,
111 nocrt: true,
112 system_shared_libs: [],
113 export_include_dirs: ["libprotobuf-cpp-full-includes"],
114 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500115 cc_library {
116 name: "libclang_rt.asan-aarch64-android",
117 no_libcrt: true,
118 nocrt: true,
119 system_shared_libs: [],
120 export_include_dirs: ["libprotobuf-cpp-full-includes"],
121 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700122 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400123 name: "libstd",
124 crate_name: "std",
125 srcs: ["foo.rs"],
126 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400127 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500128 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500129 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700130 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400131 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900132 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500133 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400134 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700135 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400136 name: "libtest",
137 crate_name: "test",
138 srcs: ["foo.rs"],
139 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400140 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500141 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500142 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700143 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400144 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900145 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500146 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400147 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000148 rust_library {
149 name: "libprotobuf",
150 crate_name: "protobuf",
151 srcs: ["foo.rs"],
152 host_supported: true,
153 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800154 rust_library {
155 name: "libgrpcio",
156 crate_name: "grpcio",
157 srcs: ["foo.rs"],
158 host_supported: true,
159 }
160 rust_library {
161 name: "libfutures",
162 crate_name: "futures",
163 srcs: ["foo.rs"],
164 host_supported: true,
165 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500166 rust_library {
167 name: "liblibfuzzer_sys",
168 crate_name: "libfuzzer_sys",
169 srcs:["foo.rs"],
170 host_supported: true,
171 }
Jiyong Park99644e92020-11-17 22:21:02 +0900172`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700173 return bp
174}
175
Jiyong Park99644e92020-11-17 22:21:02 +0900176func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Colin Cross4b49b762019-11-22 15:25:03 -0800177 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
178 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400179 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200180 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800181 ctx.RegisterModuleType("rust_test", RustTestFactory)
182 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
183 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800184 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700185 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
186 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
187 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
188 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500189 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700190 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
191 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
192 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
193 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
194 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
195 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800196 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000197 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
198 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700199 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800200 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700201 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700202 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700203 // rust mutators
204 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400205 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400206 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700207 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200208 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900209}
210
211func CreateTestContext(config android.Config) *android.TestContext {
212 ctx := android.NewTestArchContext(config)
213 android.RegisterPrebuiltMutators(ctx)
214 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffind6ceb862021-03-04 23:02:31 +0000215 genrule.RegisterGenruleBuildComponents(ctx)
Jiyong Park99644e92020-11-17 22:21:02 +0900216 cc.RegisterRequiredBuildComponentsForTest(ctx)
217 RegisterRequiredBuildComponentsForTest(ctx)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700218
219 return ctx
220}