blob: cd630843451af498d3f4721f52e59ee8779e9312 [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"
Ivan Lozanoffee3342019-08-27 12:03:00 -070020)
21
22func GatherRequiredDepsForTest() string {
23 bp := `
24 rust_prebuilt_dylib {
25 name: "libarena_x86_64-unknown-linux-gnu",
26 srcs: [""],
27 host_supported: true,
28 }
29 rust_prebuilt_dylib {
30 name: "libfmt_macros_x86_64-unknown-linux-gnu",
31 srcs: [""],
32 host_supported: true,
33 }
34 rust_prebuilt_dylib {
35 name: "libgraphviz_x86_64-unknown-linux-gnu",
36 srcs: [""],
37 host_supported: true,
38 }
39 rust_prebuilt_dylib {
40 name: "libserialize_x86_64-unknown-linux-gnu",
41 srcs: [""],
42 host_supported: true,
43 }
44 rust_prebuilt_dylib {
45 name: "libstd_x86_64-unknown-linux-gnu",
46 srcs: [""],
47 host_supported: true,
48 }
49 rust_prebuilt_dylib {
50 name: "libsyntax_x86_64-unknown-linux-gnu",
51 srcs: [""],
52 host_supported: true,
53 }
54 rust_prebuilt_dylib {
55 name: "libsyntax_ext_x86_64-unknown-linux-gnu",
56 srcs: [""],
57 host_supported: true,
58 }
59 rust_prebuilt_dylib {
60 name: "libsyntax_pos_x86_64-unknown-linux-gnu",
61 srcs: [""],
62 host_supported: true,
63 }
64 rust_prebuilt_dylib {
65 name: "libterm_x86_64-unknown-linux-gnu",
66 srcs: [""],
67 host_supported: true,
68 }
69 rust_prebuilt_dylib {
70 name: "libtest_x86_64-unknown-linux-gnu",
71 srcs: [""],
72 host_supported: true,
73 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070074
75 //////////////////////////////
76 // Device module requirements
77
78 toolchain_library {
79 name: "libgcc",
80 no_libcrt: true,
81 nocrt: true,
82 src: "",
83 system_shared_libs: [],
84 }
85 cc_library {
86 name: "libc",
87 no_libcrt: true,
88 nocrt: true,
89 system_shared_libs: [],
90 }
91 cc_library {
92 name: "libm",
93 no_libcrt: true,
94 nocrt: true,
95 system_shared_libs: [],
96 }
97 cc_library {
98 name: "libdl",
99 no_libcrt: true,
100 nocrt: true,
101 system_shared_libs: [],
102 }
103 cc_object {
104 name: "crtbegin_dynamic",
105 }
106
107 cc_object {
108 name: "crtend_android",
109 }
110 cc_library {
111 name: "liblog",
112 no_libcrt: true,
113 nocrt: true,
114 system_shared_libs: [],
115 }
116
117 //////////////////////////////
118 // cc module requirements
119
120 toolchain_library {
121 name: "libatomic",
122 src: "",
123 }
124 toolchain_library {
125 name: "libclang_rt.builtins-aarch64-android",
126 src: "",
127 }
128 toolchain_library {
129 name: "libgcc_stripped",
130 src: "",
131 }
132 cc_library {
133 name: "libc++_static",
134 no_libcrt: true,
135 nocrt: true,
136 system_shared_libs: [],
137 stl: "none",
138 }
139 cc_library {
140 name: "libc++demangle",
141 no_libcrt: true,
142 nocrt: true,
143 system_shared_libs: [],
144 stl: "none",
145 host_supported: false,
146 }
147 cc_library {
148 name: "libc++",
149 no_libcrt: true,
150 nocrt: true,
151 system_shared_libs: [],
152 stl: "none",
153 }
154 cc_library {
155 name: "libunwind_llvm",
156 no_libcrt: true,
157 nocrt: true,
158 system_shared_libs: [],
159 stl: "none",
160 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700161 `
162 return bp
163}
164
165func CreateTestContext(bp string) *android.TestContext {
166 ctx := android.NewTestArchContext()
Ivan Lozanob9040d62019-09-24 13:23:50 -0700167 ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory))
168 ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
Ivan Lozanoffee3342019-08-27 12:03:00 -0700169 ctx.RegisterModuleType("rust_binary", android.ModuleFactoryAdaptor(RustBinaryFactory))
170 ctx.RegisterModuleType("rust_binary_host", android.ModuleFactoryAdaptor(RustBinaryHostFactory))
171 ctx.RegisterModuleType("rust_library", android.ModuleFactoryAdaptor(RustLibraryFactory))
172 ctx.RegisterModuleType("rust_library_host", android.ModuleFactoryAdaptor(RustLibraryHostFactory))
173 ctx.RegisterModuleType("rust_library_host_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibHostFactory))
174 ctx.RegisterModuleType("rust_library_host_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibHostFactory))
175 ctx.RegisterModuleType("rust_library_rlib", android.ModuleFactoryAdaptor(RustLibraryRlibFactory))
176 ctx.RegisterModuleType("rust_library_dylib", android.ModuleFactoryAdaptor(RustLibraryDylibFactory))
Ivan Lozano52767be2019-10-18 14:49:46 -0700177 ctx.RegisterModuleType("rust_library_shared", android.ModuleFactoryAdaptor(RustLibrarySharedFactory))
178 ctx.RegisterModuleType("rust_library_static", android.ModuleFactoryAdaptor(RustLibraryStaticFactory))
179 ctx.RegisterModuleType("rust_library_host_shared", android.ModuleFactoryAdaptor(RustLibrarySharedHostFactory))
180 ctx.RegisterModuleType("rust_library_host_static", android.ModuleFactoryAdaptor(RustLibraryStaticHostFactory))
Ivan Lozanoffee3342019-08-27 12:03:00 -0700181 ctx.RegisterModuleType("rust_proc_macro", android.ModuleFactoryAdaptor(ProcMacroFactory))
182 ctx.RegisterModuleType("rust_prebuilt_dylib", android.ModuleFactoryAdaptor(PrebuiltDylibFactory))
Ivan Lozanob9040d62019-09-24 13:23:50 -0700183 ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory))
Ivan Lozanoffee3342019-08-27 12:03:00 -0700184 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700185 // cc mutators
Ivan Lozanob9040d62019-09-24 13:23:50 -0700186 ctx.BottomUp("image", cc.ImageMutator).Parallel()
187 ctx.BottomUp("link", cc.LinkageMutator).Parallel()
188 ctx.BottomUp("version", cc.VersionMutator).Parallel()
189 ctx.BottomUp("begin", cc.BeginMutator).Parallel()
Ivan Lozanob9040d62019-09-24 13:23:50 -0700190
Ivan Lozano52767be2019-10-18 14:49:46 -0700191 // rust mutators
192 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
193 })
Ivan Lozanoffee3342019-08-27 12:03:00 -0700194 bp = bp + GatherRequiredDepsForTest()
195
196 mockFS := map[string][]byte{
197 "Android.bp": []byte(bp),
198 "foo.rs": nil,
199 "src/bar.rs": nil,
200 "liby.so": nil,
201 "libz.so": nil,
202 }
203
204 ctx.MockFileSystem(mockFS)
205
206 return ctx
207}