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