Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 19 | "android/soong/cc" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 20 | ) |
| 21 | |
| 22 | func 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 Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 74 | |
| 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 Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 161 | ` |
| 162 | return bp |
| 163 | } |
| 164 | |
| 165 | func CreateTestContext(bp string) *android.TestContext { |
| 166 | ctx := android.NewTestArchContext() |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame^] | 167 | ctx.RegisterModuleType("cc_library", cc.LibraryFactory) |
| 168 | ctx.RegisterModuleType("cc_object", cc.ObjectFactory) |
| 169 | ctx.RegisterModuleType("rust_binary", RustBinaryFactory) |
| 170 | ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory) |
| 171 | ctx.RegisterModuleType("rust_test", RustTestFactory) |
| 172 | ctx.RegisterModuleType("rust_test_host", RustTestHostFactory) |
| 173 | ctx.RegisterModuleType("rust_library", RustLibraryFactory) |
| 174 | ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory) |
| 175 | ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) |
| 176 | ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) |
| 177 | ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory) |
| 178 | ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) |
| 179 | ctx.RegisterModuleType("rust_library_shared", RustLibrarySharedFactory) |
| 180 | ctx.RegisterModuleType("rust_library_static", RustLibraryStaticFactory) |
| 181 | ctx.RegisterModuleType("rust_library_host_shared", RustLibrarySharedHostFactory) |
| 182 | ctx.RegisterModuleType("rust_library_host_static", RustLibraryStaticHostFactory) |
| 183 | ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) |
| 184 | ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) |
| 185 | ctx.RegisterModuleType("toolchain_library", cc.ToolchainLibraryFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 186 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 187 | // cc mutators |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 188 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
| 189 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
| 190 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 191 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 192 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 193 | // rust mutators |
| 194 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Chih-Hung Hsieh | a5f22ed | 2019-10-24 20:47:54 -0700 | [diff] [blame] | 195 | ctx.BottomUp("rust_unit_tests", TestPerSrcMutator).Parallel() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 196 | }) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 197 | bp = bp + GatherRequiredDepsForTest() |
| 198 | |
| 199 | mockFS := map[string][]byte{ |
| 200 | "Android.bp": []byte(bp), |
| 201 | "foo.rs": nil, |
| 202 | "src/bar.rs": nil, |
| 203 | "liby.so": nil, |
| 204 | "libz.so": nil, |
| 205 | } |
| 206 | |
| 207 | ctx.MockFileSystem(mockFS) |
| 208 | |
| 209 | return ctx |
| 210 | } |