blob: 0144c8218fce5c9ec9ad7c382c580d3ed1676749 [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,
35 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070036 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070037 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070038 crate_name: "test",
39 rlib: {
40 srcs: ["libtest.rlib"],
41 },
42 dylib: {
43 srcs: ["libtest.so"],
44 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070045 host_supported: true,
46 }
ThiƩbaud Weksteen83ee52f2020-08-05 09:29:23 +020047 rust_prebuilt_library {
48 name: "libstd_x86_64-apple-darwin",
49 crate_name: "std",
50 rlib: {
51 srcs: ["libstd.rlib"],
52 },
53 dylib: {
54 srcs: ["libstd.so"],
55 },
56 host_supported: true,
57 }
58 rust_prebuilt_library {
59 name: "libtest_x86_64-apple-darwin",
60 crate_name: "test",
61 rlib: {
62 srcs: ["libtest.rlib"],
63 },
64 dylib: {
65 srcs: ["libtest.so"],
66 },
67 host_supported: true,
68 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070069 //////////////////////////////
70 // Device module requirements
71
Ivan Lozanob9040d62019-09-24 13:23:50 -070072 cc_library {
73 name: "liblog",
74 no_libcrt: true,
75 nocrt: true,
76 system_shared_libs: [],
77 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070078 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040079 name: "libstd",
80 crate_name: "std",
81 srcs: ["foo.rs"],
82 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -040083 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -070084 native_coverage: false,
Ivan Lozano2f15bae2020-04-09 09:32:15 -040085 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070086 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040087 name: "libtest",
88 crate_name: "test",
89 srcs: ["foo.rs"],
90 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -040091 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -070092 native_coverage: false,
Ivan Lozano2f15bae2020-04-09 09:32:15 -040093 }
Treehugger Robot588aae72020-08-21 10:01:58 +000094 rust_library {
95 name: "libprotobuf",
96 crate_name: "protobuf",
97 srcs: ["foo.rs"],
98 host_supported: true,
99 }
Ivan Lozano2f15bae2020-04-09 09:32:15 -0400100
Paul Duffin77980a82019-12-19 16:01:36 +0000101` + cc.GatherRequiredDepsForTest(android.NoOsType)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700102 return bp
103}
104
Colin Cross98be1bb2019-12-13 20:41:13 -0800105func CreateTestContext() *android.TestContext {
Ivan Lozanoffee3342019-08-27 12:03:00 -0700106 ctx := android.NewTestArchContext()
Paul Duffin021f4e52020-07-30 16:04:17 +0100107 android.RegisterPrebuiltMutators(ctx)
Dan Albert92fe7402020-07-15 13:33:30 -0700108 ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
Paul Duffin77980a82019-12-19 16:01:36 +0000109 cc.RegisterRequiredBuildComponentsForTest(ctx)
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -0700110 ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800111 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
112 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
Ivan Lozano4fef93c2020-07-08 08:39:44 -0400113 ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800114 ctx.RegisterModuleType("rust_test", RustTestFactory)
115 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
116 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800117 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -0700118 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
119 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
120 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
121 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
122 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
123 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
124 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
125 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
126 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
127 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800128 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Treehugger Robot588aae72020-08-21 10:01:58 +0000129 ctx.RegisterModuleType("rust_protobuf", RustProtobufFactory)
130 ctx.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700131 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -0800132 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -0700133 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700134 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700135 // rust mutators
136 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400137 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700138 })
ThiƩbaud Weksteene4d12a02020-06-05 11:09:27 +0200139 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700140
141 return ctx
142}