blob: cb98bed65e905d724046b532f00a2155dfdb35b2 [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 Lozano1921e802021-05-20 13:39:16 -040048var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers(
49 PrepareForIntegrationTestWithRust,
50 cc.PrepareForTestWithCcIncludeVndk,
51)
52
Ivan Lozanoffee3342019-08-27 12:03:00 -070053func GatherRequiredDepsForTest() string {
54 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070055 rust_prebuilt_library {
Ivan Lozanofba2aa22021-11-11 09:29:07 -050056 name: "libstd",
57 crate_name: "std",
58 rlib: {
59 srcs: ["libstd.rlib"],
60 },
61 dylib: {
62 srcs: ["libstd.so"],
63 },
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020064 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040065 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020066 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070067 //////////////////////////////
68 // Device module requirements
69
Ivan Lozanob9040d62019-09-24 13:23:50 -070070 cc_library {
71 name: "liblog",
72 no_libcrt: true,
73 nocrt: true,
74 system_shared_libs: [],
Jiyong Park99644e92020-11-17 22:21:02 +090075 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -050076 min_sdk_version: "29",
Ivan Lozanoc08897c2021-04-02 12:41:32 -040077 vendor_available: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -050078 recovery_available: true,
Ivan Lozano3149e6e2021-06-01 15:09:53 -040079 llndk: {
80 symbol_file: "liblog.map.txt",
81 },
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 {
Colin Crossfc0df952022-02-10 11:41:18 -080091 name: "libclang_rt.asan",
Ivan Lozano6cd99e62020-02-11 08:24:25 -050092 no_libcrt: true,
93 nocrt: true,
94 system_shared_libs: [],
Ivan Lozano5482d6a2021-11-01 10:13:25 -040095 }
96 cc_library {
Colin Crossfc0df952022-02-10 11:41:18 -080097 name: "libclang_rt.hwasan_static",
Ivan Lozano5482d6a2021-11-01 10:13:25 -040098 no_libcrt: true,
99 nocrt: true,
100 system_shared_libs: [],
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500101 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700102 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400103 name: "libstd",
104 crate_name: "std",
105 srcs: ["foo.rs"],
106 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400107 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500108 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500109 vendor_ramdisk_available: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500110 recovery_available: true,
Ivan Lozano699e2182021-03-22 14:29:47 -0400111 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400112 sysroot: true,
Jiyong Park99644e92020-11-17 22:21:02 +0900113 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500114 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400115 }
Matthew Maurerc761eec2020-06-25 00:47:46 -0700116 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400117 name: "libtest",
118 crate_name: "test",
119 srcs: ["foo.rs"],
Ivan Lozano9d1df102020-04-28 10:10:23 -0400120 host_supported: true,
Ivan Lozano6a884432020-12-02 09:15:16 -0500121 vendor_available: true,
Ivan Lozanoe6d30982021-02-05 10:57:43 -0500122 vendor_ramdisk_available: true,
Ivan Lozanoc2ca1ee2021-11-09 16:23:40 -0500123 recovery_available: true,
Ivan Lozano699e2182021-03-22 14:29:47 -0400124 native_coverage: false,
Jiyong Park99644e92020-11-17 22:21:02 +0900125 apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
Ivan Lozano3e9f9e42020-12-04 15:05:43 -0500126 min_sdk_version: "29",
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400127 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000128 rust_library {
129 name: "libprotobuf",
130 crate_name: "protobuf",
131 srcs: ["foo.rs"],
132 host_supported: true,
133 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800134 rust_library {
135 name: "libgrpcio",
136 crate_name: "grpcio",
137 srcs: ["foo.rs"],
138 host_supported: true,
139 }
140 rust_library {
141 name: "libfutures",
142 crate_name: "futures",
143 srcs: ["foo.rs"],
144 host_supported: true,
145 }
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500146 rust_library {
147 name: "liblibfuzzer_sys",
148 crate_name: "libfuzzer_sys",
149 srcs:["foo.rs"],
150 host_supported: true,
151 }
Jakub Kotur1d640d02021-01-06 12:40:43 +0100152 rust_library {
153 name: "libcriterion",
154 crate_name: "criterion",
155 srcs:["foo.rs"],
156 host_supported: true,
157 }
Jiyong Park99644e92020-11-17 22:21:02 +0900158`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700159 return bp
160}
161
Paul Duffin9e0c3f92021-03-30 22:45:21 +0100162func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
Jakub Kotur1d640d02021-01-06 12:40:43 +0100163 ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
164 ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800165 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
166 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400167 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200168 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800169 ctx.RegisterModuleType("rust_test", RustTestFactory)
170 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
171 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800172 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700173 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
174 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
175 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
176 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Ivan Lozano6cd99e62020-02-11 08:24:25 -0500177 ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700178 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
179 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
180 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
181 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
182 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
183 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800184 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000185 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
186 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700187 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800188 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700189 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700190 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700191 // rust mutators
192 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400193 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400194 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700195 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200196 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Ivan Lozano5482d6a2021-11-01 10:13:25 -0400197 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
198 ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
199 })
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400200 registerRustSnapshotModules(ctx)
Jiyong Park99644e92020-11-17 22:21:02 +0900201}