blob: a5abbdb89880f0722a32e998e5db9a5f3232bc07 [file] [log] [blame]
Liz Kammer267f1f72023-09-01 01:17:21 -04001// Copyright 2023 Google Inc. All rights reserved.
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
Vinh Tran093a57e2023-08-24 12:10:49 -040015package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/rust"
20 "testing"
21)
22
23func runRustBinaryTestCase(t *testing.T, tc Bp2buildTestCase) {
24 t.Helper()
25 RunBp2BuildTestCase(t, registerRustBinaryModuleTypes, tc)
26}
27
28func registerRustBinaryModuleTypes(ctx android.RegistrationContext) {
29 ctx.RegisterModuleType("rust_binary_host", rust.RustBinaryHostFactory)
30 ctx.RegisterModuleType("rust_library_host", rust.RustLibraryHostFactory)
31 ctx.RegisterModuleType("rust_proc_macro", rust.ProcMacroFactory)
32
33}
34
35func TestRustBinaryHost(t *testing.T) {
36 runRustBinaryTestCase(t, Bp2buildTestCase{
37 Dir: "external/rust/crates/foo",
38 Blueprint: "",
39 Filesystem: map[string]string{
40 "external/rust/crates/foo/src/lib.rs": "",
41 "external/rust/crates/foo/src/helper.rs": "",
42 "external/rust/crates/foo/Android.bp": `
43rust_binary_host {
44 name: "libfoo",
45 crate_name: "foo",
46 srcs: ["src/main.rs"],
47 edition: "2021",
48 features: ["bah-enabled"],
49 cfgs: ["baz"],
50 rustlibs: ["libbar"],
51 proc_macros: ["libbah"],
52 bazel_module: { bp2build_available: true },
53}
54`,
55 "external/rust/crates/bar/Android.bp": `
56rust_library_host {
57 name: "libbar",
58 crate_name: "bar",
59 srcs: ["src/lib.rs"],
60 bazel_module: { bp2build_available: true },
61}
62`,
63 "external/rust/crates/bah/Android.bp": `
64rust_proc_macro {
65 name: "libbah",
66 crate_name: "bah",
67 srcs: ["src/lib.rs"],
68 bazel_module: { bp2build_available: true },
69}
70`,
71 },
72 ExpectedBazelTargets: []string{
73 makeBazelTargetHostOrDevice("rust_binary", "libfoo", AttrNameToString{
74 "crate_name": `"foo"`,
75 "srcs": `[
76 "src/helper.rs",
77 "src/lib.rs",
78 ]`,
79 "deps": `["//external/rust/crates/bar:libbar"]`,
80 "proc_macro_deps": `["//external/rust/crates/bah:libbah"]`,
81 "edition": `"2021"`,
82 "crate_features": `["bah-enabled"]`,
83 "rustc_flags": `["--cfg=baz"]`,
84 }, android.HostSupported),
85 },
86 },
87 )
88}