blob: 6ee49a971b4bc7c6bb17b3876cb00994a9cd2347 [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,
Kiyoung Kim0d1c1e62024-03-26 16:33:58 +090046 cc.PrepareForIntegrationTestWithCc,
Ivan Lozano1921e802021-05-20 13:39:16 -040047)
48
Ivan Lozanoffee3342019-08-27 12:03:00 -070049func GatherRequiredDepsForTest() string {
50 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070051 rust_prebuilt_library {
Ivan Lozano0a468a42024-05-13 21:03:34 -040052 name: "libstd",
53 crate_name: "std",
54 rlib: {
55 srcs: ["libstd/libstd.rlib"],
56 },
57 dylib: {
58 srcs: ["libstd/libstd.so"],
59 },
60 host_supported: true,
61 sysroot: true,
62 }
63 rust_prebuilt_library {
64 name: "libcore.sysroot",
65 crate_name: "core",
66 rlib: {
67 srcs: ["libcore/libcore.rlib"],
68 },
69 dylib: {
70 srcs: ["libcore/libcore.so"],
71 },
72 host_supported: true,
73 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020074 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070075 //////////////////////////////
76 // Device module requirements
77
Ivan Lozanob9040d62019-09-24 13:23:50 -070078 cc_library {
79 name: "liblog",
80 no_libcrt: true,
81 nocrt: true,
82 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +090083 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050084 min_sdk_version: "29",
Ivan Lozanoc08897c2021-04-02 12:41:32 -040085 vendor_available: true,
Andrew Walbrana5deb732024-02-15 13:39:46 +000086 host_supported: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -050087 recovery_available: true,
Ivan Lozano3149e6e2021-06-01 15:09:53 -040088 llndk: {
89 symbol_file: "liblog.map.txt",
90 },
Ivan Lozanob9040d62019-09-24 13:23:50 -070091 }
Zach Johnson3df4e632020-11-06 11:56:27 -080092 cc_library {
93 name: "libprotobuf-cpp-full",
94 no_libcrt: true,
95 nocrt: true,
96 system_shared_libs: [],
97 export_include_dirs: ["libprotobuf-cpp-full-includes"],
98 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -050099 cc_library {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800100 name: "libclang_rt.asan",
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500101 no_libcrt: true,
102 nocrt: true,
103 system_shared_libs: [],
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400104 }
105 cc_library {
Colin Cross4c4c1be2022-02-10 11:41:18 -0800106 name: "libclang_rt.hwasan_static",
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400107 no_libcrt: true,
108 nocrt: true,
109 system_shared_libs: [],
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500110 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700111 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400112 name: "libstd",
113 crate_name: "std",
114 srcs: ["foo.rs"],
115 no_stdlibs: true,
Matthew Maurer993db7a2023-01-24 16:36:02 -0800116 product_available: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400117 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500118 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500119 vendor_ramdisk_available: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500120 recovery_available: true,
Ivan Lozano699e2182021-03-22 14:29:47 -0400121 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400122 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900123 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500124 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400125 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700126 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400127 name: "libtest",
128 crate_name: "test",
129 srcs: ["foo.rs"],
Ivan Lozano9d1df102020-04-28 10:10:23 -0400130 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500131 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500132 vendor_ramdisk_available: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500133 recovery_available: true,
Ivan Lozano699e2182021-03-22 14:29:47 -0400134 native_coverage: false,
Jiyong Park99644e92020-11-17 22:21:02 +0900135 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500136 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400137 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000138 rust_library {
Jeff Vander Stoepc1490ec2023-04-24 11:28:25 +0200139 name: "libprotobuf",
140 crate_name: "protobuf",
141 srcs: ["foo.rs"],
142 host_supported: true,
143 }
144 rust_library {
Zach Johnson3df4e632020-11-06 11:56:27 -0800145 name: "libgrpcio",
146 crate_name: "grpcio",
147 srcs: ["foo.rs"],
148 host_supported: true,
149 }
150 rust_library {
151 name: "libfutures",
152 crate_name: "futures",
153 srcs: ["foo.rs"],
154 host_supported: true,
155 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500156 rust_library {
157 name: "liblibfuzzer_sys",
158 crate_name: "libfuzzer_sys",
159 srcs:["foo.rs"],
160 host_supported: true,
161 }
Jakub Kotur1d640d02021-01-06 12:40:43 +0100162 rust_library {
163 name: "libcriterion",
164 crate_name: "criterion",
165 srcs:["foo.rs"],
166 host_supported: true,
167 }
Jiyong Park99644e92020-11-17 22:21:02 +0900168`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700169 return bp
170}
171
Paul Duffin9e0c3f92021-03-30 22:45:21 +0100172func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Jakub Kotur1d640d02021-01-06 12:40:43 +0100173 ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
174 ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800175 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
176 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400177 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200178 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800179 ctx.RegisterModuleType("rust_test", RustTestFactory)
180 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
181 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800182 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700183 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
184 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
185 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
186 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500187 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Ivan Lozano2fcbffa2023-07-27 10:40:52 -0400188 ctx.RegisterModuleType("rust_fuzz_host", RustFuzzHostFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700189 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
190 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
Ivan Lozano0a468a42024-05-13 21:03:34 -0400191 ctx.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400192 ctx.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700193 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
194 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
Ivan Lozano0a468a42024-05-13 21:03:34 -0400195 ctx.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400196 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800197 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000198 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
199 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700200 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800201 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700202 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700203 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700204 // rust mutators
205 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400206 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400207 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700208 })
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000209 ctx.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
210 ctx.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400211 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
212 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
213 })
Jiyong Park99644e92020-11-17 22:21:02 +0900214}