• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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"
19	"android/soong/bloaty"
20	"android/soong/cc"
21)
22
23// 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(
26	android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
27)
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,
38	bloaty.PrepareForTestWithBloatyDefaultModules,
39	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	cc.PrepareForIntegrationTestWithCc,
47)
48
49func GatherRequiredDepsForTest() string {
50	bp := `
51		rust_prebuilt_library {
52			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,
74		}
75		//////////////////////////////
76		// Device module requirements
77
78		cc_library {
79			name: "liblog",
80			no_libcrt: true,
81			nocrt: true,
82			system_shared_libs: [],
83			min_sdk_version: "29",
84			vendor_available: true,
85			host_supported: true,
86			recovery_available: true,
87			llndk: {
88				symbol_file: "liblog.map.txt",
89			},
90			stubs: {
91				symbol_file: "liblog.map.txt",
92				versions: [
93					"29",
94					"30",
95				],
96			},
97		}
98		cc_library {
99			name: "libprotobuf-cpp-full",
100			no_libcrt: true,
101			nocrt: true,
102			system_shared_libs: [],
103			export_include_dirs: ["libprotobuf-cpp-full-includes"],
104		}
105		cc_library {
106			name: "libclang_rt.asan",
107			no_libcrt: true,
108			nocrt: true,
109			system_shared_libs: [],
110		}
111		cc_library {
112			name: "libclang_rt.hwasan_static",
113			no_libcrt: true,
114			nocrt: true,
115			system_shared_libs: [],
116		}
117		rust_library {
118			name: "libstd",
119			crate_name: "std",
120			srcs: ["foo.rs"],
121			no_stdlibs: true,
122			product_available: true,
123			host_supported: true,
124			vendor_available: true,
125			vendor_ramdisk_available: true,
126			recovery_available: true,
127			native_coverage: false,
128			sysroot: true,
129			apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
130			min_sdk_version: "29",
131		}
132		rust_library {
133			name: "libtest",
134			crate_name: "test",
135			srcs: ["foo.rs"],
136			host_supported: true,
137			vendor_available: true,
138			vendor_ramdisk_available: true,
139			recovery_available: true,
140			native_coverage: false,
141			apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
142			min_sdk_version: "29",
143		}
144		rust_library {
145			name: "libprotobuf",
146			crate_name: "protobuf",
147			srcs: ["foo.rs"],
148			host_supported: true,
149		}
150		rust_library {
151			name: "libgrpcio",
152			crate_name: "grpcio",
153			srcs: ["foo.rs"],
154			host_supported: true,
155		}
156		rust_library {
157			name: "libfutures",
158			crate_name: "futures",
159			srcs: ["foo.rs"],
160			host_supported: true,
161		}
162		rust_library {
163			name: "liblibfuzzer_sys",
164			crate_name: "libfuzzer_sys",
165			srcs:["foo.rs"],
166			host_supported: true,
167		}
168		rust_library {
169			name: "libcriterion",
170			crate_name: "criterion",
171			srcs:["foo.rs"],
172			host_supported: true,
173		}
174`
175	return bp
176}
177
178func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
179	ctx.RegisterModuleType("rust_benchmark", RustBenchmarkFactory)
180	ctx.RegisterModuleType("rust_benchmark_host", RustBenchmarkHostFactory)
181	ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
182	ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
183	ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
184	ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
185	ctx.RegisterModuleType("rust_test", RustTestFactory)
186	ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
187	ctx.RegisterModuleType("rust_library", RustLibraryFactory)
188	ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
189	ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
190	ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
191	ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
192	ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
193	ctx.RegisterModuleType("rust_fuzz", RustFuzzFactory)
194	ctx.RegisterModuleType("rust_fuzz_host", RustFuzzHostFactory)
195	ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
196	ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
197	ctx.RegisterModuleType("rust_ffi_static", RustLibraryRlibFactory)
198	ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
199	ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
200	ctx.RegisterModuleType("rust_ffi_host_static", RustLibraryRlibHostFactory)
201	ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
202	ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
203	ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
204	ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
205	ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
206	ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
207	ctx.PreDepsMutators(registerPreDepsMutators)
208	ctx.RegisterParallelSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
209	ctx.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory)
210	ctx.PostDepsMutators(registerPostDepsMutators)
211}
212