blob: 4c4df4a6dea384d2b4ff34a3cbcdcea1aaf2567c [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 {
49 name: "libstd_x86_64-apple-darwin",
50 crate_name: "std",
51 rlib: {
52 srcs: ["libstd.rlib"],
53 },
54 dylib: {
55 srcs: ["libstd.so"],
56 },
57 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040058 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020059 }
60 rust_prebuilt_library {
61 name: "libtest_x86_64-apple-darwin",
62 crate_name: "test",
63 rlib: {
64 srcs: ["libtest.rlib"],
65 },
66 dylib: {
67 srcs: ["libtest.so"],
68 },
69 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040070 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020071 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070072 //////////////////////////////
73 // Device module requirements
74
Ivan Lozanob9040d62019-09-24 13:23:50 -070075 cc_library {
76 name: "liblog",
77 no_libcrt: true,
78 nocrt: true,
79 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +090080 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050081 min_sdk_version: "29",
Ivan Lozanob9040d62019-09-24 13:23:50 -070082 }
Zach Johnson3df4e632020-11-06 11:56:27 -080083 cc_library {
84 name: "libprotobuf-cpp-full",
85 no_libcrt: true,
86 nocrt: true,
87 system_shared_libs: [],
88 export_include_dirs: ["libprotobuf-cpp-full-includes"],
89 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -050090 cc_library {
91 name: "libclang_rt.asan-aarch64-android",
92 no_libcrt: true,
93 nocrt: true,
94 system_shared_libs: [],
95 export_include_dirs: ["libprotobuf-cpp-full-includes"],
96 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070097 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040098 name: "libstd",
99 crate_name: "std",
100 srcs: ["foo.rs"],
101 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400102 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500103 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500104 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700105 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400106 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900107 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500108 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400109 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700110 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400111 name: "libtest",
112 crate_name: "test",
113 srcs: ["foo.rs"],
114 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400115 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500116 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500117 vendor_ramdisk_available: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700118 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400119 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900120 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500121 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400122 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000123 rust_library {
124 name: "libprotobuf",
125 crate_name: "protobuf",
126 srcs: ["foo.rs"],
127 host_supported: true,
128 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800129 rust_library {
130 name: "libgrpcio",
131 crate_name: "grpcio",
132 srcs: ["foo.rs"],
133 host_supported: true,
134 }
135 rust_library {
136 name: "libfutures",
137 crate_name: "futures",
138 srcs: ["foo.rs"],
139 host_supported: true,
140 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500141 rust_library {
142 name: "liblibfuzzer_sys",
143 crate_name: "libfuzzer_sys",
144 srcs:["foo.rs"],
145 host_supported: true,
146 }
Jiyong Park99644e92020-11-17 22:21:02 +0900147`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700148 return bp
149}
150
Jiyong Park99644e92020-11-17 22:21:02 +0900151func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Colin Cross4b49b762019-11-22 15:25:03 -0800152 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
153 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400154 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200155 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800156 ctx.RegisterModuleType("rust_test", RustTestFactory)
157 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
158 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800159 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700160 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
161 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
162 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
163 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500164 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700165 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
166 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
167 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
168 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
169 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
170 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800171 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000172 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
173 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700174 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800175 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700176 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700177 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700178 // rust mutators
179 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400180 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400181 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700182 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200183 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Jiyong Park99644e92020-11-17 22:21:02 +0900184}
185
186func CreateTestContext(config android.Config) *android.TestContext {
187 ctx := android.NewTestArchContext(config)
188 android.RegisterPrebuiltMutators(ctx)
189 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
190 cc.RegisterRequiredBuildComponentsForTest(ctx)
191 RegisterRequiredBuildComponentsForTest(ctx)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700192
193 return ctx
194}