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
15package rust
16
17import (
18	"android/soong/android"
19	"android/soong/cc"
20	"android/soong/genrule"
21)
22
23func GatherRequiredDepsForTest() string {
24	bp := `
25		rust_prebuilt_library {
26				name: "libstd_x86_64-unknown-linux-gnu",
27                                crate_name: "std",
28                                rlib: {
29                                    srcs: ["libstd.rlib"],
30                                },
31                                dylib: {
32                                    srcs: ["libstd.so"],
33                                },
34				host_supported: true,
35		}
36		rust_prebuilt_library {
37				name: "libtest_x86_64-unknown-linux-gnu",
38                                crate_name: "test",
39                                rlib: {
40                                    srcs: ["libtest.rlib"],
41                                },
42                                dylib: {
43                                    srcs: ["libtest.so"],
44                                },
45				host_supported: true,
46		}
47
48		//////////////////////////////
49		// Device module requirements
50
51		cc_library {
52			name: "liblog",
53			no_libcrt: true,
54			nocrt: true,
55			system_shared_libs: [],
56		}
57		rust_library {
58			name: "libstd",
59			crate_name: "std",
60			srcs: ["foo.rs"],
61			no_stdlibs: true,
62			host_supported: true,
63                        native_coverage: false,
64		}
65		rust_library {
66			name: "libtest",
67			crate_name: "test",
68			srcs: ["foo.rs"],
69			no_stdlibs: true,
70			host_supported: true,
71                        native_coverage: false,
72		}
73
74` + cc.GatherRequiredDepsForTest(android.NoOsType)
75	return bp
76}
77
78func CreateTestContext() *android.TestContext {
79	ctx := android.NewTestArchContext()
80	android.RegisterPrebuiltMutators(ctx)
81	cc.RegisterRequiredBuildComponentsForTest(ctx)
82	ctx.RegisterModuleType("genrule", genrule.GenRuleFactory)
83	ctx.RegisterModuleType("rust_binary", RustBinaryFactory)
84	ctx.RegisterModuleType("rust_binary_host", RustBinaryHostFactory)
85	ctx.RegisterModuleType("rust_bindgen", RustBindgenFactory)
86	ctx.RegisterModuleType("rust_test", RustTestFactory)
87	ctx.RegisterModuleType("rust_test_host", RustTestHostFactory)
88	ctx.RegisterModuleType("rust_library", RustLibraryFactory)
89	ctx.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
90	ctx.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
91	ctx.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
92	ctx.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
93	ctx.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
94	ctx.RegisterModuleType("rust_ffi", RustFFIFactory)
95	ctx.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
96	ctx.RegisterModuleType("rust_ffi_static", RustFFIStaticFactory)
97	ctx.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
98	ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
99	ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
100	ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
101	ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
102	ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
103	ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
104	ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
105		// rust mutators
106		ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
107		ctx.BottomUp("rust_begin", BeginMutator).Parallel()
108	})
109	ctx.RegisterSingletonType("rust_project_generator", rustProjectGeneratorSingleton)
110
111	return ctx
112}
113