blob: 1afe27ef028fcd623955b6cafc8ddefe3d5ffd05 [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
22func GatherRequiredDepsForTest() string {
23 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070024 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070025 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070026 crate_name: "std",
27 rlib: {
28 srcs: ["libstd.rlib"],
29 },
30 dylib: {
31 srcs: ["libstd.so"],
32 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070033 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040034 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070035 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070036 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070037 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070038 crate_name: "test",
39 rlib: {
40 srcs: ["libtest.rlib"],
41 },
42 dylib: {
43 srcs: ["libtest.so"],
44 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070045 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040046 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070047 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020048 rust_prebuilt_library {
Ivan Lozanoc5d34ec2021-02-09 14:22:00 -050049 name: "libstd_i686-unknown-linux-gnu",
50 crate_name: "std",
51 rlib: {
52 srcs: ["libstd.rlib"],
53 },
54 dylib: {
55 srcs: ["libstd.so"],
56 },
57 host_supported: true,
58 sysroot: true,
59 }
60 rust_prebuilt_library {
61 name: "libtest_i686-unknown-linux-gnu",
62 crate_name: "test",
63 rlib: {
64 srcs: ["libtest.rlib"],
65 },
66 dylib: {
67 srcs: ["libtest.so"],
68 },
69 host_supported: true,
70 sysroot: true,
71 }
72 rust_prebuilt_library {
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020073 name: "libstd_x86_64-apple-darwin",
74 crate_name: "std",
75 rlib: {
76 srcs: ["libstd.rlib"],
77 },
78 dylib: {
79 srcs: ["libstd.so"],
80 },
81 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040082 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020083 }
84 rust_prebuilt_library {
85 name: "libtest_x86_64-apple-darwin",
86 crate_name: "test",
87 rlib: {
88 srcs: ["libtest.rlib"],
89 },
90 dylib: {
91 srcs: ["libtest.so"],
92 },
93 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040094 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020095 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070096 //////////////////////////////
97 // Device module requirements
98
Ivan Lozanob9040d62019-09-24 13:23:50 -070099 cc_library {
100 name: "liblog",
101 no_libcrt: true,
102 nocrt: true,
103 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +0900104 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500105 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -0700106 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800107 cc_library {
108 name: "libprotobuf-cpp-full",
109 no_libcrt: true,
110 nocrt: true,
111 system_shared_libs: [],
112 export_include_dirs: ["libprotobuf-cpp-full-includes"],
113 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500114 cc_library {
115 name: "libclang_rt.asan-aarch64-android",
116 no_libcrt: true,
117 nocrt: true,
118 system_shared_libs: [],
119 export_include_dirs: ["libprotobuf-cpp-full-includes"],
120 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700121 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400122 name: "libstd",
123 crate_name: "std",
124 srcs: ["foo.rs"],
125 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400126 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500127 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500128 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700129 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400130 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900131 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500132 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400133 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700134 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400135 name: "libtest",
136 crate_name: "test",
137 srcs: ["foo.rs"],
138 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400139 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500140 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500141 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700142 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400143 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900144 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500145 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400146 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000147 rust_library {
148 name: "libprotobuf",
149 crate_name: "protobuf",
150 srcs: ["foo.rs"],
151 host_supported: true,
152 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800153 rust_library {
154 name: "libgrpcio",
155 crate_name: "grpcio",
156 srcs: ["foo.rs"],
157 host_supported: true,
158 }
159 rust_library {
160 name: "libfutures",
161 crate_name: "futures",
162 srcs: ["foo.rs"],
163 host_supported: true,
164 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500165 rust_library {
166 name: "liblibfuzzer_sys",
167 crate_name: "libfuzzer_sys",
168 srcs:["foo.rs"],
169 host_supported: true,
170 }
Jiyong Park99644e92020-11-17 22:21:02 +0900171`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700172 return bp
173}
174
Jiyong Park99644e92020-11-17 22:21:02 +0900175func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Colin Cross4b49b762019-11-22 15:25:03 -0800176 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
177 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400178 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200179 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800180 ctx.RegisterModuleType("rust_test", RustTestFactory)
181 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
182 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800183 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700184 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
185 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
186 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
187 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500188 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700189 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
190 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
191 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
192 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
193 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
194 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800195 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000196 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
197 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700198 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800199 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700200 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700201 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700202 // rust mutators
203 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400204 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400205 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700206 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200207 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900208}
209
210func CreateTestContext(config android.Config) *android.TestContext {
211 ctx := android.NewTestArchContext(config)
212 android.RegisterPrebuiltMutators(ctx)
213 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
214 cc.RegisterRequiredBuildComponentsForTest(ctx)
215 RegisterRequiredBuildComponentsForTest(ctx)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700216
217 return ctx
218}