blob: 3d583e1977ae6a0af5cabf2abeb22b7888ae7011 [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 := `
Matthew Maurerc761eec2020-06-25 00:47:46 -070024 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070025 name: "libstd_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070026 crate_name: "std",
27 rlib: {
28 srcs: ["libstd.rlib"],
29 },
30 dylib: {
31 srcs: ["libstd.so"],
32 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070033 host_supported: true,
34 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070035 rust_prebuilt_library {
Ivan Lozanoffee3342019-08-27 12:03:00 -070036 name: "libtest_x86_64-unknown-linux-gnu",
Matthew Maurerc761eec2020-06-25 00:47:46 -070037 crate_name: "test",
38 rlib: {
39 srcs: ["libtest.rlib"],
40 },
41 dylib: {
42 srcs: ["libtest.so"],
43 },
Ivan Lozanoffee3342019-08-27 12:03:00 -070044 host_supported: true,
45 }
Ivan Lozanob9040d62019-09-24 13:23:50 -070046
47 //////////////////////////////
48 // Device module requirements
49
Ivan Lozanob9040d62019-09-24 13:23:50 -070050 cc_library {
51 name: "liblog",
52 no_libcrt: true,
53 nocrt: true,
54 system_shared_libs: [],
55 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070056 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040057 name: "libstd",
58 crate_name: "std",
59 srcs: ["foo.rs"],
60 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -040061 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -070062 native_coverage: false,
Ivan Lozano2f15bae2020-04-09 09:32:15 -040063 }
Matthew Maurerc761eec2020-06-25 00:47:46 -070064 rust_library {
Ivan Lozano2f15bae2020-04-09 09:32:15 -040065 name: "libtest",
66 crate_name: "test",
67 srcs: ["foo.rs"],
68 no_stdlibs: true,
Ivan Lozano9d1df102020-04-28 10:10:23 -040069 host_supported: true,
Matthew Maurerc761eec2020-06-25 00:47:46 -070070 native_coverage: false,
Ivan Lozano2f15bae2020-04-09 09:32:15 -040071 }
72
Paul Duffin77980a82019-12-19 16:01:36 +000073` + cc.GatherRequiredDepsForTest(android.NoOsType)
Ivan Lozanoffee3342019-08-27 12:03:00 -070074 return bp
75}
76
Colin Cross98be1bb2019-12-13 20:41:13 -080077func CreateTestContext() *android.TestContext {
Ivan Lozanoffee3342019-08-27 12:03:00 -070078 ctx := android.NewTestArchContext()
Paul Duffin77980a82019-12-19 16:01:36 +000079 cc.RegisterRequiredBuildComponentsForTest(ctx)
Colin Cross4b49b762019-11-22 15:25:03 -080080 ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
81 ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
82 ctx.RegisterModuleType("rust_test", RustTestFactory)
83 ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
84 ctx.RegisterModuleType("rust_library", RustLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -080085 ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -070086 ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
87 ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
88 ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
89 ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
90 ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
91 ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
92 ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
93 ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
94 ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
95 ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
Colin Cross4b49b762019-11-22 15:25:03 -080096 ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -070097 ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Colin Cross4b49b762019-11-22 15:25:03 -080098 ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -070099 ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700100 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Ivan Lozano52767be2019-10-18 14:49:46 -0700101 // rust mutators
102 ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400103 ctx.BottomUp("rust_begin", BeginMutator).Parallel()
Ivan Lozano52767be2019-10-18 14:49:46 -0700104 })
ThiƩbaud Weksteene4d12a02020-06-05 11:09:27 +0200105 ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700106
107 return ctx
108}