blob: 97fe297fdb4fde162f2991e3eec1e5ed83a4f73a [file] [log] [blame]
Vinh Tran75159942023-10-17 16:28:04 -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
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/rust"
20 "testing"
21)
22
23func runRustFfiTestCase(t *testing.T, tc Bp2buildTestCase) {
24 t.Helper()
25 RunBp2BuildTestCase(t, registerRustFfiModuleTypes, tc)
26}
27
28func registerRustFfiModuleTypes(ctx android.RegistrationContext) {
29 ctx.RegisterModuleType("rust_ffi_static", rust.RustFFIStaticFactory)
30 ctx.RegisterModuleType("rust_library", rust.RustLibraryFactory)
31}
32
33func TestRustFfiStatic(t *testing.T) {
34 runRustFfiTestCase(t, Bp2buildTestCase{
35 Dir: "external/rust/crates/foo",
36 Blueprint: "",
37 Filesystem: map[string]string{
38 "external/rust/crates/foo/src/lib.rs": "",
39 "external/rust/crates/foo/src/helper.rs": "",
40 "external/rust/crates/foo/Android.bp": `
41rust_ffi_static {
42 name: "libfoo",
43 crate_name: "foo",
44 host_supported: true,
45 srcs: ["src/lib.rs"],
46 edition: "2015",
47 include_dirs: [
48 "include",
49 ],
50 rustlibs: ["libbar"],
51 bazel_module: { bp2build_available: true },
52}
53`,
54 "external/rust/crates/bar/Android.bp": `
55rust_library {
56 name: "libbar",
57 crate_name: "bar",
58 host_supported: true,
59 srcs: ["src/lib.rs"],
60 bazel_module: { bp2build_available: true },
61}
62`,
63 },
64 ExpectedBazelTargets: []string{
65 MakeBazelTargetNoRestrictions("rust_ffi_static", "libfoo", AttrNameToString{
66 "crate_name": `"foo"`,
67 "deps": `["//external/rust/crates/bar:libbar"]`,
68 "srcs": `[
69 "src/helper.rs",
70 "src/lib.rs",
71 ]`,
72 "edition": `"2015"`,
73 "export_includes": `["include"]`,
74 }),
75 },
76 },
77 )
78}