xref: /aosp_15_r20/external/bazelbuild-rules_rust/test/linker_inputs_propagation/BUILD.bazel (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library", "cc_test")
2load(
3    "@rules_rust//rust:defs.bzl",
4    "rust_library",
5    "rust_shared_library",
6    "rust_static_library",
7)
8
9package(default_visibility = ["//test/unit/linker_inputs_propagation:__pkg__"])
10
11rust_library(
12    name = "foo",
13    srcs = ["foo.rs"],
14    edition = "2018",
15)
16
17cc_library(
18    name = "foo_shared",
19    srcs = [
20        "foo_shared.cc",
21    ],
22    hdrs = ["foo_shared.h"],
23    target_compatible_with = [
24        "@platforms//os:linux",
25    ],
26)
27
28cc_binary(
29    name = "foo_shared.dll",
30    srcs = [
31        "foo_shared.cc",
32        "foo_shared.h",
33    ],
34    features = ["windows_export_all_symbols"],
35    linkshared = True,
36    target_compatible_with = [
37        "@platforms//os:windows",
38    ],
39)
40
41filegroup(
42    name = "shared_library_file",
43    srcs = [":foo_shared"],
44    output_group = "dynamic_library",
45)
46
47filegroup(
48    name = "interface_library_file",
49    srcs = [":foo_shared.dll"],
50    output_group = "interface_library",
51)
52
53filegroup(
54    name = "empty",
55    srcs = ["empty.so"],
56)
57
58cc_import(
59    name = "import_foo_shared",
60    hdrs = ["foo_shared.h"],
61    interface_library = select({
62        "@platforms//os:linux": "shared_library_file",
63        "@platforms//os:windows": "interface_library_file",
64        "//conditions:default": ":empty",
65    }),
66    shared_library = select({
67        "@platforms//os:linux": "shared_library_file",
68        "@platforms//os:windows": "foo_shared.dll",
69        "//conditions:default": ":empty",
70    }),
71)
72
73rust_static_library(
74    name = "staticlib_uses_foo",
75    srcs = ["bar_uses_foo.rs"],
76    edition = "2018",
77    target_compatible_with = [
78        "@platforms//os:linux",
79        "@platforms//os:windows",
80    ],
81    deps = [":foo"],
82)
83
84rust_shared_library(
85    name = "sharedlib_uses_foo",
86    srcs = ["bar_uses_foo.rs"],
87    edition = "2018",
88    target_compatible_with = [
89        "@platforms//os:linux",
90        "@platforms//os:windows",
91    ],
92    deps = [":foo"],
93)
94
95rust_static_library(
96    name = "staticlib_uses_shared_foo",
97    srcs = ["bar_uses_shared_foo.rs"],
98    edition = "2018",
99    target_compatible_with = [
100        "@platforms//os:linux",
101        "@platforms//os:windows",
102    ],
103    deps = [":import_foo_shared"],
104)
105
106rust_static_library(
107    name = "sharedlib_uses_shared_foo",
108    srcs = ["bar_uses_shared_foo.rs"],
109    edition = "2018",
110    target_compatible_with = [
111        "@platforms//os:linux",
112        "@platforms//os:windows",
113    ],
114    deps = [":import_foo_shared"],
115)
116
117cc_test(
118    name = "depends_on_foo_via_staticlib",
119    srcs = ["baz.cc"],
120    target_compatible_with = [
121        "@platforms//os:linux",
122        "@platforms//os:windows",
123    ],
124    deps = [":staticlib_uses_foo"],
125)
126
127cc_test(
128    name = "depends_on_foo_via_sharedlib",
129    srcs = ["baz.cc"],
130    target_compatible_with = [
131        "@platforms//os:linux",
132        "@platforms//os:windows",
133    ],
134    deps = [":sharedlib_uses_foo"],
135)
136
137cc_test(
138    name = "depends_on_shared_foo_via_sharedlib",
139    srcs = ["baz.cc"],
140    target_compatible_with = [
141        "@platforms//os:linux",
142        "@platforms//os:windows",
143    ],
144    deps = [":sharedlib_uses_shared_foo"],
145)
146
147cc_test(
148    name = "depends_on_shared_foo_via_staticlib",
149    srcs = ["baz.cc"],
150    target_compatible_with = [
151        "@platforms//os:linux",
152        "@platforms//os:windows",
153    ],
154    deps = [":staticlib_uses_shared_foo"],
155)
156