blob: 40015663a65e6f45a53b58ec78d134167a1b872b [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"
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -070020 "android/soong/genrule"
Ivan Lozanoffee3342019-08-27 12:03:00 -070021)
22
23func GatherRequiredDepsForTest() string {
24 bp := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070025 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070026 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070027 crate_name: "std",
28 rlib: {
29 srcs: ["libstd.rlib"],
30 },
31 dylib: {
32 srcs: ["libstd.so"],
33 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070034 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040035 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070037 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070038 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070039 crate_name: "test",
40 rlib: {
41 srcs: ["libtest.rlib"],
42 },
43 dylib: {
44 srcs: ["libtest.so"],
45 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070046 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040047 sysroot: true,
Ivan Lozanoffee3342019-08-27 12:03:00 -070048 }
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020049 rust_prebuilt_library {
50 name: "libstd_x86_64-apple-darwin",
51 crate_name: "std",
52 rlib: {
53 srcs: ["libstd.rlib"],
54 },
55 dylib: {
56 srcs: ["libstd.so"],
57 },
58 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040059 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020060 }
61 rust_prebuilt_library {
62 name: "libtest_x86_64-apple-darwin",
63 crate_name: "test",
64 rlib: {
65 srcs: ["libtest.rlib"],
66 },
67 dylib: {
68 srcs: ["libtest.so"],
69 },
70 host_supported: true,
Ivan Lozano2b081132020-09-08 12:46:52 -040071 sysroot: true,
Thiébaud Weksteen83ee52f2020-08-05 09:29:23 +020072 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070073 //////////////////////////////
74 // Device module requirements
75
Ivan Lozanob9040d62019-09-24 13:23:50 -070076 cc_library {
77 name: "liblog",
78 no_libcrt: true,
79 nocrt: true,
80 system_shared_libs: [],
81 }
Zach Johnson3df4e632020-11-06 11:56:27 -080082 cc_library {
83 name: "libprotobuf-cpp-full",
84 no_libcrt: true,
85 nocrt: true,
86 system_shared_libs: [],
87 export_include_dirs: ["libprotobuf-cpp-full-includes"],
88 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070089 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040090 name: "libstd",
91 crate_name: "std",
92 srcs: ["foo.rs"],
93 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -040094 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -070095 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -040096 sysroot: true,
Ivan Lozano2f15bae2020-04-09 09:32:15 -040097 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070098 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040099 name: "libtest",
100 crate_name: "test",
101 srcs: ["foo.rs"],
102 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -0400103 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -0700104 native_coverage: false,
Ivan Lozano2b081132020-09-08 12:46:52 -0400105 sysroot: true,
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400106 }
Treehugger Robot588aae72020-08-21 10:01:58 +0000107 rust_library {
108 name: "libprotobuf",
109 crate_name: "protobuf",
110 srcs: ["foo.rs"],
111 host_supported: true,
112 }
Zach Johnson3df4e632020-11-06 11:56:27 -0800113 rust_library {
114 name: "libgrpcio",
115 crate_name: "grpcio",
116 srcs: ["foo.rs"],
117 host_supported: true,
118 }
119 rust_library {
120 name: "libfutures",
121 crate_name: "futures",
122 srcs: ["foo.rs"],
123 host_supported: true,
124 }
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400125
Paul Duffin77980a82019-12-19 16:01:36 +0000126` + cc.GatherRequiredDepsForTest(android.NoOsType)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700127 return bp
128}
129
Colin Cross98be1bb2019-12-13 20:41:13 -0800130func CreateTestContext() *android.TestContext {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700131 ctx := android.NewTestArchContext()
Paul Duffin021f4e52020-07-30 16:04:17 +0100132 android.RegisterPrebuiltMutators(ctx)
Dan Albert92fe7402020-07-15 13:33:30 -0700133 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin77980a82019-12-19 16:01:36 +0000134 cc.RegisterRequiredBuildComponentsForTest(ctx)
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700135 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800136 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
137 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400138 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Thiébaud Weksteena6351ca2020-09-29 09:53:21 +0200139 ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800140 ctx.RegisterModuleType("rust_test", RustTestFactory)
141 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
142 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800143 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700144 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
145 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
146 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
147 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
148 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
149 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
150 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
151 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
152 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
153 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Ivan Lozano6a3d1e92020-11-02 15:06:26 -0500154 ctx.RegisterModuleType("rust_grpcio", RustGrpcioFactory)
155 ctx.RegisterModuleType("rust_grpcio_host", RustGrpcioHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800156 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000157 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
158 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700159 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800160 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700161 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700162 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700163 // rust mutators
164 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozano2b081132020-09-08 12:46:52 -0400165 ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400166 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700167 })
Thiébaud Weksteene4d12a02020-06-05 11:09:27 +0200168 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700169
170 return ctx
171}