-
Notifications
You must be signed in to change notification settings - Fork 648
Expand file tree
/
Copy pathbindgen_test.bzl
More file actions
152 lines (135 loc) · 4.59 KB
/
Copy pathbindgen_test.bzl
File metadata and controls
152 lines (135 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""Analysis test for for rust_bindgen_library rule."""
load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library")
load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library")
load("@rules_rust//rust:defs.bzl", "rust_binary")
load("@rules_rust_bindgen//:defs.bzl", "rust_bindgen_library")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
def _test_cc_linkopt_impl(env, target):
# Assert
env.expect.that_action(target.actions[0]) \
.contains_at_least_args(["--codegen=link-arg=-shared"])
def _test_cc_linkopt(name):
# Arrange
cc_library(
name = name + "_cc",
srcs = ["simple.cc"],
hdrs = ["simple.h"],
linkopts = ["-shared"],
tags = ["manual"],
)
rust_bindgen_library(
name = name + "_rust_bindgen",
cc_lib = name + "_cc",
header = "simple.h",
tags = ["manual"],
edition = "2021",
)
rust_binary(
name = name + "_rust_binary",
srcs = ["main.rs"],
deps = [name + "_rust_bindgen"],
tags = ["manual"],
edition = "2021",
)
# Act
# TODO: Use targets attr to also verify `rust_bindgen_library` not having
# the linkopt after https://github.com/bazelbuild/rules_testing/issues/67
# is released
analysis_test(
name = name,
target = name + "_rust_binary",
impl = _test_cc_linkopt_impl,
)
def _test_cc_lib_object_merging_impl(env, target):
env.expect.that_int(len(target.actions)).is_greater_than(2)
env.expect.that_action(target.actions[0]).mnemonic().contains("RustBindgen")
env.expect.that_action(target.actions[1]).mnemonic().contains("FileWrite")
env.expect.that_action(target.actions[1]).content().contains("-lstatic=test_cc_lib_object_merging_cc")
env.expect.that_action(target.actions[2]).mnemonic().contains("FileWrite")
env.expect.that_action(target.actions[2]).content().contains("-Lnative=")
def _test_cc_lib_object_merging_disabled_impl(env, target):
# no FileWrite actions writing arg files registered
env.expect.that_int(len(target.actions)).is_greater_than(0)
env.expect.that_action(target.actions[0]).mnemonic().contains("RustBindgen")
def _test_cc_lib_object_merging(name):
cc_library(
name = name + "_cc",
hdrs = ["simple.h"],
srcs = ["simple.cc"],
)
rust_bindgen_library(
name = name + "_rust_bindgen",
cc_lib = name + "_cc",
header = "simple.h",
tags = ["manual"],
edition = "2021",
)
analysis_test(
name = name,
target = name + "_rust_bindgen__bindgen",
impl = _test_cc_lib_object_merging_impl,
)
def _test_cc_lib_object_merging_disabled(name):
cc_library(
name = name + "_cc",
hdrs = ["simple.h"],
srcs = ["simple.cc"],
)
rust_bindgen_library(
name = name + "_rust_bindgen",
cc_lib = name + "_cc",
header = "simple.h",
tags = ["manual"],
merge_cc_lib_objects_into_rlib = False,
edition = "2021",
)
analysis_test(
name = name,
target = name + "_rust_bindgen__bindgen",
impl = _test_cc_lib_object_merging_disabled_impl,
)
def _test_cc_lib_dynamic_only_impl(env, target):
env.expect.that_int(len(target.actions)).is_greater_than(2)
env.expect.that_action(target.actions[0]).mnemonic().contains("RustBindgen")
env.expect.that_action(target.actions[1]).mnemonic().contains("FileWrite")
env.expect.that_action(target.actions[1]).content().contains("-ldylib=test_cc_lib_dynamic_only_cc_shared")
def _test_cc_lib_dynamic_only(name):
cc_library(
name = name + "_cc_objects",
srcs = ["simple.cc"],
hdrs = ["simple.h"],
tags = ["manual"],
)
cc_shared_library(
name = name + "_cc_shared",
deps = [name + "_cc_objects"],
tags = ["manual"],
)
cc_import(
name = name + "_cc",
shared_library = name + "_cc_shared",
hdrs = ["simple.h"],
tags = ["manual"],
)
rust_bindgen_library(
name = name + "_rust_bindgen",
cc_lib = name + "_cc",
header = "simple.h",
tags = ["manual"],
edition = "2021",
)
analysis_test(
name = name,
target = name + "_rust_bindgen__bindgen",
impl = _test_cc_lib_dynamic_only_impl,
)
def bindgen_test_suite(name):
test_suite(
name = name,
tests = [
_test_cc_linkopt,
_test_cc_lib_object_merging,
_test_cc_lib_object_merging_disabled,
_test_cc_lib_dynamic_only,
],
)