xref: /aosp_15_r20/build/soong/rust/testing.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2019 The Android Open Source Project
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage rust
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"android/soong/android"
19*333d2b36SAndroid Build Coastguard Worker	"android/soong/bloaty"
20*333d2b36SAndroid Build Coastguard Worker	"android/soong/cc"
21*333d2b36SAndroid Build Coastguard Worker)
22*333d2b36SAndroid Build Coastguard Worker
23*333d2b36SAndroid Build Coastguard Worker// Preparer that will define all cc module types and a limited set of mutators and singletons that
24*333d2b36SAndroid Build Coastguard Worker// make those module types usable.
25*333d2b36SAndroid Build Coastguard Workervar PrepareForTestWithRustBuildComponents = android.GroupFixturePreparers(
26*333d2b36SAndroid Build Coastguard Worker	android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
27*333d2b36SAndroid Build Coastguard Worker)
28*333d2b36SAndroid Build Coastguard Worker
29*333d2b36SAndroid Build Coastguard Worker// The directory in which rust test default modules will be defined.
30*333d2b36SAndroid Build Coastguard Worker//
31*333d2b36SAndroid Build Coastguard Worker// Placing them here ensures that their location does not conflict with default test modules
32*333d2b36SAndroid Build Coastguard Worker// defined by other packages.
33*333d2b36SAndroid Build Coastguard Workerconst rustDefaultsDir = "defaults/rust/"
34*333d2b36SAndroid Build Coastguard Worker
35*333d2b36SAndroid Build Coastguard Worker// Preparer that will define default rust modules, e.g. standard prebuilt modules.
36*333d2b36SAndroid Build Coastguard Workervar PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers(
37*333d2b36SAndroid Build Coastguard Worker	cc.PrepareForTestWithCcDefaultModules,
38*333d2b36SAndroid Build Coastguard Worker	bloaty.PrepareForTestWithBloatyDefaultModules,
39*333d2b36SAndroid Build Coastguard Worker	PrepareForTestWithRustBuildComponents,
40*333d2b36SAndroid Build Coastguard Worker	android.FixtureAddTextFile(rustDefaultsDir+"Android.bp", GatherRequiredDepsForTest()),
41*333d2b36SAndroid Build Coastguard Worker)
42*333d2b36SAndroid Build Coastguard Worker
43*333d2b36SAndroid Build Coastguard Worker// Preparer that will allow use of all rust modules fully.
44*333d2b36SAndroid Build Coastguard Workervar PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
45*333d2b36SAndroid Build Coastguard Worker	PrepareForTestWithRustDefaultModules,
46*333d2b36SAndroid Build Coastguard Worker	cc.PrepareForIntegrationTestWithCc,
47*333d2b36SAndroid Build Coastguard Worker)
48*333d2b36SAndroid Build Coastguard Worker
49*333d2b36SAndroid Build Coastguard Workerfunc GatherRequiredDepsForTest() string {
50*333d2b36SAndroid Build Coastguard Worker	bp := `
51*333d2b36SAndroid Build Coastguard Worker		rust_prebuilt_library {
52*333d2b36SAndroid Build Coastguard Worker			name: "libstd",
53*333d2b36SAndroid Build Coastguard Worker			crate_name: "std",
54*333d2b36SAndroid Build Coastguard Worker			rlib: {
55*333d2b36SAndroid Build Coastguard Worker				srcs: ["libstd/libstd.rlib"],
56*333d2b36SAndroid Build Coastguard Worker			},
57*333d2b36SAndroid Build Coastguard Worker			dylib: {
58*333d2b36SAndroid Build Coastguard Worker				srcs: ["libstd/libstd.so"],
59*333d2b36SAndroid Build Coastguard Worker			},
60*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
61*333d2b36SAndroid Build Coastguard Worker			sysroot: true,
62*333d2b36SAndroid Build Coastguard Worker		}
63*333d2b36SAndroid Build Coastguard Worker		rust_prebuilt_library {
64*333d2b36SAndroid Build Coastguard Worker			name: "libcore.sysroot",
65*333d2b36SAndroid Build Coastguard Worker			crate_name: "core",
66*333d2b36SAndroid Build Coastguard Worker			rlib: {
67*333d2b36SAndroid Build Coastguard Worker				srcs: ["libcore/libcore.rlib"],
68*333d2b36SAndroid Build Coastguard Worker			},
69*333d2b36SAndroid Build Coastguard Worker			dylib: {
70*333d2b36SAndroid Build Coastguard Worker				srcs: ["libcore/libcore.so"],
71*333d2b36SAndroid Build Coastguard Worker			},
72*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
73*333d2b36SAndroid Build Coastguard Worker			sysroot: true,
74*333d2b36SAndroid Build Coastguard Worker		}
75*333d2b36SAndroid Build Coastguard Worker		//////////////////////////////
76*333d2b36SAndroid Build Coastguard Worker		// Device module requirements
77*333d2b36SAndroid Build Coastguard Worker
78*333d2b36SAndroid Build Coastguard Worker		cc_library {
79*333d2b36SAndroid Build Coastguard Worker			name: "liblog",
80*333d2b36SAndroid Build Coastguard Worker			no_libcrt: true,
81*333d2b36SAndroid Build Coastguard Worker			nocrt: true,
82*333d2b36SAndroid Build Coastguard Worker			system_shared_libs: [],
83*333d2b36SAndroid Build Coastguard Worker			apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
84*333d2b36SAndroid Build Coastguard Worker			min_sdk_version: "29",
85*333d2b36SAndroid Build Coastguard Worker			vendor_available: true,
86*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
87*333d2b36SAndroid Build Coastguard Worker			recovery_available: true,
88*333d2b36SAndroid Build Coastguard Worker			llndk: {
89*333d2b36SAndroid Build Coastguard Worker				symbol_file: "liblog.map.txt",
90*333d2b36SAndroid Build Coastguard Worker			},
91*333d2b36SAndroid Build Coastguard Worker		}
92*333d2b36SAndroid Build Coastguard Worker		cc_library {
93*333d2b36SAndroid Build Coastguard Worker			name: "libprotobuf-cpp-full",
94*333d2b36SAndroid Build Coastguard Worker			no_libcrt: true,
95*333d2b36SAndroid Build Coastguard Worker			nocrt: true,
96*333d2b36SAndroid Build Coastguard Worker			system_shared_libs: [],
97*333d2b36SAndroid Build Coastguard Worker			export_include_dirs: ["libprotobuf-cpp-full-includes"],
98*333d2b36SAndroid Build Coastguard Worker		}
99*333d2b36SAndroid Build Coastguard Worker		cc_library {
100*333d2b36SAndroid Build Coastguard Worker			name: "libclang_rt.asan",
101*333d2b36SAndroid Build Coastguard Worker			no_libcrt: true,
102*333d2b36SAndroid Build Coastguard Worker			nocrt: true,
103*333d2b36SAndroid Build Coastguard Worker			system_shared_libs: [],
104*333d2b36SAndroid Build Coastguard Worker		}
105*333d2b36SAndroid Build Coastguard Worker		cc_library {
106*333d2b36SAndroid Build Coastguard Worker			name: "libclang_rt.hwasan_static",
107*333d2b36SAndroid Build Coastguard Worker			no_libcrt: true,
108*333d2b36SAndroid Build Coastguard Worker			nocrt: true,
109*333d2b36SAndroid Build Coastguard Worker			system_shared_libs: [],
110*333d2b36SAndroid Build Coastguard Worker		}
111*333d2b36SAndroid Build Coastguard Worker		rust_library {
112*333d2b36SAndroid Build Coastguard Worker			name: "libstd",
113*333d2b36SAndroid Build Coastguard Worker			crate_name: "std",
114*333d2b36SAndroid Build Coastguard Worker			srcs: ["foo.rs"],
115*333d2b36SAndroid Build Coastguard Worker			no_stdlibs: true,
116*333d2b36SAndroid Build Coastguard Worker			product_available: true,
117*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
118*333d2b36SAndroid Build Coastguard Worker			vendor_available: true,
119*333d2b36SAndroid Build Coastguard Worker			vendor_ramdisk_available: true,
120*333d2b36SAndroid Build Coastguard Worker			recovery_available: true,
121*333d2b36SAndroid Build Coastguard Worker			native_coverage: false,
122*333d2b36SAndroid Build Coastguard Worker			sysroot: true,
123*333d2b36SAndroid Build Coastguard Worker			apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
124*333d2b36SAndroid Build Coastguard Worker			min_sdk_version: "29",
125*333d2b36SAndroid Build Coastguard Worker		}
126*333d2b36SAndroid Build Coastguard Worker		rust_library {
127*333d2b36SAndroid Build Coastguard Worker			name: "libtest",
128*333d2b36SAndroid Build Coastguard Worker			crate_name: "test",
129*333d2b36SAndroid Build Coastguard Worker			srcs: ["foo.rs"],
130*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
131*333d2b36SAndroid Build Coastguard Worker			vendor_available: true,
132*333d2b36SAndroid Build Coastguard Worker			vendor_ramdisk_available: true,
133*333d2b36SAndroid Build Coastguard Worker			recovery_available: true,
134*333d2b36SAndroid Build Coastguard Worker			native_coverage: false,
135*333d2b36SAndroid Build Coastguard Worker			apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
136*333d2b36SAndroid Build Coastguard Worker			min_sdk_version: "29",
137*333d2b36SAndroid Build Coastguard Worker		}
138*333d2b36SAndroid Build Coastguard Worker		rust_library {
139*333d2b36SAndroid Build Coastguard Worker			name: "libprotobuf",
140*333d2b36SAndroid Build Coastguard Worker			crate_name: "protobuf",
141*333d2b36SAndroid Build Coastguard Worker			srcs: ["foo.rs"],
142*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
143*333d2b36SAndroid Build Coastguard Worker		}
144*333d2b36SAndroid Build Coastguard Worker		rust_library {
145*333d2b36SAndroid Build Coastguard Worker			name: "libgrpcio",
146*333d2b36SAndroid Build Coastguard Worker			crate_name: "grpcio",
147*333d2b36SAndroid Build Coastguard Worker			srcs: ["foo.rs"],
148*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
149*333d2b36SAndroid Build Coastguard Worker		}
150*333d2b36SAndroid Build Coastguard Worker		rust_library {
151*333d2b36SAndroid Build Coastguard Worker			name: "libfutures",
152*333d2b36SAndroid Build Coastguard Worker			crate_name: "futures",
153*333d2b36SAndroid Build Coastguard Worker			srcs: ["foo.rs"],
154*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
155*333d2b36SAndroid Build Coastguard Worker		}
156*333d2b36SAndroid Build Coastguard Worker		rust_library {
157*333d2b36SAndroid Build Coastguard Worker			name: "liblibfuzzer_sys",
158*333d2b36SAndroid Build Coastguard Worker			crate_name: "libfuzzer_sys",
159*333d2b36SAndroid Build Coastguard Worker			srcs:["foo.rs"],
160*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
161*333d2b36SAndroid Build Coastguard Worker		}
162*333d2b36SAndroid Build Coastguard Worker		rust_library {
163*333d2b36SAndroid Build Coastguard Worker			name: "libcriterion",
164*333d2b36SAndroid Build Coastguard Worker			crate_name: "criterion",
165*333d2b36SAndroid Build Coastguard Worker			srcs:["foo.rs"],
166*333d2b36SAndroid Build Coastguard Worker			host_supported: true,
167*333d2b36SAndroid Build Coastguard Worker		}
168*333d2b36SAndroid Build Coastguard Worker`
169*333d2b36SAndroid Build Coastguard Worker	return bp
170*333d2b36SAndroid Build Coastguard Worker}
171*333d2b36SAndroid Build Coastguard Worker
172*333d2b36SAndroid Build Coastguard Workerfunc registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
173*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
174*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
175*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
176*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
177*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
178*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
179*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_test", RustTestFactory)
180*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
181*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library", RustLibraryFactory)
182*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
183*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
184*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
185*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
186*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
187*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
188*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_fuzz_host", RustFuzzHostFactory)
189*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
190*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
191*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
192*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory)
193*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
194*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
195*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
196*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory)
197*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
198*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
199*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
200*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
201*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
202*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
203*333d2b36SAndroid Build Coastguard Worker	ctx.PreDepsMutators(registerPreDepsMutators)
204*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
205*333d2b36SAndroid Build Coastguard Worker	ctx.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
206*333d2b36SAndroid Build Coastguard Worker	ctx.PostDepsMutators(registerPostDepsMutators)
207*333d2b36SAndroid Build Coastguard Worker}
208