blob: 296f57e06e1c93446e0b3474e6c8c44cc53ee67a [file] [log] [blame]
Vinh Tranbcb5f572023-08-24 11:10:01 -04001package bp2build
2
3import (
4 "android/soong/android"
5 "android/soong/rust"
6 "testing"
7)
8
9func runRustLibraryTestCase(t *testing.T, tc Bp2buildTestCase) {
10 t.Helper()
11 RunBp2BuildTestCase(t, registerRustLibraryModuleTypes, tc)
12}
13
14func registerRustLibraryModuleTypes(ctx android.RegistrationContext) {
15 ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
16 ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
17}
18
19func TestRustLibrary(t *testing.T) {
20 expectedAttrs := AttrNameToString{
21 "crate_name": `"foo"`,
22 "srcs": `[
23 "src/helper.rs",
24 "src/lib.rs",
25 ]`,
26 "crate_features": `["bah-enabled"]`,
27 "edition": `"2021"`,
28 "rustc_flags": `["--cfg=baz"]`,
29 }
30
31 runRustLibraryTestCase(t, Bp2buildTestCase{
32 Dir: "external/rust/crates/foo",
33 Blueprint: "",
34 Filesystem: map[string]string{
35 "external/rust/crates/foo/src/lib.rs": "",
36 "external/rust/crates/foo/src/helper.rs": "",
37 "external/rust/crates/foo/Android.bp": `
38rust_library {
39 name: "libfoo",
40 crate_name: "foo",
41 host_supported: true,
42 srcs: ["src/lib.rs"],
43 edition: "2021",
44 features: ["bah-enabled"],
45 cfgs: ["baz"],
46 bazel_module: { bp2build_available: true },
47}
48rust_library_host {
49 name: "libfoo_host",
50 crate_name: "foo",
51 srcs: ["src/lib.rs"],
52 edition: "2021",
53 features: ["bah-enabled"],
54 cfgs: ["baz"],
55 bazel_module: { bp2build_available: true },
56}
57`,
58 },
59 ExpectedBazelTargets: []string{
60 // TODO(b/290790800): Remove the restriction when rust toolchain for android is implemented
61 makeBazelTargetHostOrDevice("rust_library", "libfoo", expectedAttrs, android.HostSupported),
62 makeBazelTargetHostOrDevice("rust_library", "libfoo_host", expectedAttrs, android.HostSupported),
63 },
64 },
65 )
66}