blob: 33644017eb26164dfca7ce07c03917478b497f07 [file] [log] [blame]
Vinh Tran093a57e2023-08-24 12:10:49 -04001package bp2build
2
3import (
4 "android/soong/android"
5 "android/soong/rust"
6 "testing"
7)
8
9func runRustBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
10 t.Helper()
11 RunBp2BuildTestCase(t, registerRustBinaryModuleTypes, tc)
12}
13
14func registerRustBinaryModuleTypes(ctx android.RegistrationContext) {
15 ctx.RegisterModuleType("rust_binary_host", rust.RustBinaryHostFactory)
16 ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
17 ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
18
19}
20
21func TestRustBinaryHost(t *testing.T) {
22 runRustBinaryTestCase(t, Bp2buildTestCase{
23 Dir: "external/rust/crates/foo",
24 Blueprint: "",
25 Filesystem: map[string]string{
26 "external/rust/crates/foo/src/lib.rs": "",
27 "external/rust/crates/foo/src/helper.rs": "",
28 "external/rust/crates/foo/Android.bp": `
29rust_binary_host {
30 name: "libfoo",
31 crate_name: "foo",
32 srcs: ["src/main.rs"],
33 edition: "2021",
34 features: ["bah-enabled"],
35 cfgs: ["baz"],
36 rustlibs: ["libbar"],
37 proc_macros: ["libbah"],
38 bazel_module: { bp2build_available: true },
39}
40`,
41 "external/rust/crates/bar/Android.bp": `
42rust_library_host {
43 name: "libbar",
44 crate_name: "bar",
45 srcs: ["src/lib.rs"],
46 bazel_module: { bp2build_available: true },
47}
48`,
49 "external/rust/crates/bah/Android.bp": `
50rust_proc_macro {
51 name: "libbah",
52 crate_name: "bah",
53 srcs: ["src/lib.rs"],
54 bazel_module: { bp2build_available: true },
55}
56`,
57 },
58 ExpectedBazelTargets: []string{
59 makeBazelTargetHostOrDevice("rust_binary", "libfoo", AttrNameToString{
60 "crate_name": `"foo"`,
61 "srcs": `[
62 "src/helper.rs",
63 "src/lib.rs",
64 ]`,
65 "deps": `["//external/rust/crates/bar:libbar"]`,
66 "proc_macro_deps": `["//external/rust/crates/bah:libbah"]`,
67 "edition": `"2021"`,
68 "crate_features": `["bah-enabled"]`,
69 "rustc_flags": `["--cfg=baz"]`,
70 }, android.HostSupported),
71 },
72 },
73 )
74}