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 := ` |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 24 | rust_prebuilt_library { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 25 | name: "libstd_x86_64-unknown-linux-gnu", |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 26 | crate_name: "std", |
| 27 | rlib: { |
| 28 | srcs: ["libstd.rlib"], |
| 29 | }, |
| 30 | dylib: { |
| 31 | srcs: ["libstd.so"], |
| 32 | }, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 34 | sysroot: true, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 36 | rust_prebuilt_library { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | name: "libtest_x86_64-unknown-linux-gnu", |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 38 | crate_name: "test", |
| 39 | rlib: { |
| 40 | srcs: ["libtest.rlib"], |
| 41 | }, |
| 42 | dylib: { |
| 43 | srcs: ["libtest.so"], |
| 44 | }, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 45 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 46 | sysroot: true, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 47 | } |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 48 | rust_prebuilt_library { |
| 49 | name: "libstd_x86_64-apple-darwin", |
| 50 | crate_name: "std", |
| 51 | rlib: { |
| 52 | srcs: ["libstd.rlib"], |
| 53 | }, |
| 54 | dylib: { |
| 55 | srcs: ["libstd.so"], |
| 56 | }, |
| 57 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 58 | sysroot: true, |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 59 | } |
| 60 | rust_prebuilt_library { |
| 61 | name: "libtest_x86_64-apple-darwin", |
| 62 | crate_name: "test", |
| 63 | rlib: { |
| 64 | srcs: ["libtest.rlib"], |
| 65 | }, |
| 66 | dylib: { |
| 67 | srcs: ["libtest.so"], |
| 68 | }, |
| 69 | host_supported: true, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 70 | sysroot: true, |
Thiébaud Weksteen | 83ee52f | 2020-08-05 09:29:23 +0200 | [diff] [blame] | 71 | } |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 72 | ////////////////////////////// |
| 73 | // Device module requirements |
| 74 | |
Ivan Lozano | b9040d6 | 2019-09-24 13:23:50 -0700 | [diff] [blame] | 75 | cc_library { |
| 76 | name: "liblog", |
| 77 | no_libcrt: true, |
| 78 | nocrt: true, |
| 79 | system_shared_libs: [], |
| 80 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 81 | cc_library { |
| 82 | name: "libprotobuf-cpp-full", |
| 83 | no_libcrt: true, |
| 84 | nocrt: true, |
| 85 | system_shared_libs: [], |
| 86 | export_include_dirs: ["libprotobuf-cpp-full-includes"], |
| 87 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 88 | rust_library { |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 89 | name: "libstd", |
| 90 | crate_name: "std", |
| 91 | srcs: ["foo.rs"], |
| 92 | no_stdlibs: true, |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 93 | host_supported: true, |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 94 | native_coverage: false, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 95 | sysroot: true, |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 96 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 97 | rust_library { |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 98 | name: "libtest", |
| 99 | crate_name: "test", |
| 100 | srcs: ["foo.rs"], |
| 101 | no_stdlibs: true, |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 102 | host_supported: true, |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 103 | native_coverage: false, |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 104 | sysroot: true, |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 105 | } |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 106 | rust_library { |
| 107 | name: "libprotobuf", |
| 108 | crate_name: "protobuf", |
| 109 | srcs: ["foo.rs"], |
| 110 | host_supported: true, |
| 111 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 112 | rust_library { |
| 113 | name: "libgrpcio", |
| 114 | crate_name: "grpcio", |
| 115 | srcs: ["foo.rs"], |
| 116 | host_supported: true, |
| 117 | } |
| 118 | rust_library { |
| 119 | name: "libfutures", |
| 120 | crate_name: "futures", |
| 121 | srcs: ["foo.rs"], |
| 122 | host_supported: true, |
| 123 | } |
Ivan Lozano | 2f15bae | 2020-04-09 09:32:15 -0400 | [diff] [blame] | 124 | |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 125 | ` + cc.GatherRequiredDepsForTest(android.NoOsType) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 126 | return bp |
| 127 | } |
| 128 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 129 | func CreateTestContext(config android.Config) *android.TestContext { |
| 130 | ctx := android.NewTestArchContext(config) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 131 | android.RegisterPrebuiltMutators(ctx) |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 132 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 133 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 134 | ctx.RegisterModuleType("rust_binary", RustBinaryFactory) |
| 135 | ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 136 | ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory) |
Thiébaud Weksteen | a6351ca | 2020-09-29 09:53:21 +0200 | [diff] [blame] | 137 | ctx.RegisterModuleType("rust_bindgen_host", RustBindgenHostFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 138 | ctx.RegisterModuleType("rust_test", RustTestFactory) |
| 139 | ctx.RegisterModuleType("rust_test_host", RustTestHostFactory) |
| 140 | ctx.RegisterModuleType("rust_library", RustLibraryFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 141 | ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) |
Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 142 | ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory) |
| 143 | ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory) |
| 144 | ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) |
| 145 | ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) |
| 146 | ctx.RegisterModuleType("rust_ffi", RustFFIFactory) |
| 147 | ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory) |
| 148 | ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory) |
| 149 | ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory) |
| 150 | ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory) |
| 151 | ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory) |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 152 | ctx.RegisterModuleType("rust_grpcio", RustGrpcioFactory) |
| 153 | ctx.RegisterModuleType("rust_grpcio_host", RustGrpcioHostFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 154 | ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory) |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 155 | ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory) |
| 156 | ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory) |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 157 | ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 158 | ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 159 | ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 160 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 161 | // rust mutators |
| 162 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 163 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 164 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 165 | }) |
Thiébaud Weksteen | e4d12a0 | 2020-06-05 11:09:27 +0200 | [diff] [blame] | 166 | ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 167 | |
| 168 | return ctx |
| 169 | } |