13
13
# limitations under the License.
14
14
15
15
load ("@io_bazel_rules_rust//rust:rust.bzl" , "rust_library" )
16
+ load ("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl" , "get_libs_for_static_executable" )
16
17
17
18
def rust_bindgen_library (
18
19
name ,
@@ -44,7 +45,7 @@ def _rust_bindgen_impl(ctx):
44
45
# nb. We can't grab the cc_library`s direct headers, so a header must be provided.
45
46
cc_lib = ctx .attr .cc_lib
46
47
header = ctx .file .header
47
- if header not in cc_lib . cc . transitive_headers :
48
+ if header not in cc_lib [ CcInfo ]. compilation_context . headers :
48
49
fail ("Header {} is not in {}'s transitive headers." .format (ctx .attr .header , cc_lib ), "header" )
49
50
50
51
toolchain = ctx .toolchains ["@io_bazel_rules_rust//bindgen:bindgen_toolchain" ]
@@ -68,10 +69,10 @@ def _rust_bindgen_impl(ctx):
68
69
output = ctx .outputs .out
69
70
70
71
# libclang should only have 1 output file
71
- libclang_dir = libclang . cc . libs .to_list ()[0 ].dirname
72
- include_directories = cc_lib . cc . include_directories
73
- quote_include_directories = cc_lib . cc . quote_include_directories
74
- system_include_directories = cc_lib . cc . system_include_directories
72
+ libclang_dir = get_libs_for_static_executable ( libclang ) .to_list ()[0 ].dirname
73
+ include_directories = cc_lib [ CcInfo ]. compilation_context . includes . to_list ()
74
+ quote_include_directories = cc_lib [ CcInfo ]. compilation_context . quote_includes . to_list ()
75
+ system_include_directories = cc_lib [ CcInfo ]. compilation_context . system_includes . to_list ()
75
76
76
77
# Vanilla usage of bindgen produces formatted output, here we do the same if we have `rustfmt` in our toolchain.
77
78
if rustfmt_bin :
@@ -92,7 +93,11 @@ def _rust_bindgen_impl(ctx):
92
93
executable = bindgen_bin ,
93
94
inputs = depset (
94
95
[header ],
95
- transitive = [cc_lib .cc .transitive_headers , libclang .cc .libs , libstdcxx .cc .libs ],
96
+ transitive = [
97
+ cc_lib [CcInfo ].compilation_context .headers ,
98
+ get_libs_for_static_executable (libclang ),
99
+ get_libs_for_static_executable (libstdcxx ),
100
+ ],
96
101
),
97
102
outputs = [unformatted_output ],
98
103
mnemonic = "RustBindgen" ,
@@ -102,7 +107,7 @@ def _rust_bindgen_impl(ctx):
102
107
"CLANG_PATH" : clang_bin .path ,
103
108
# Bindgen loads libclang at runtime, which also needs libstdc++, so we setup LD_LIBRARY_PATH
104
109
"LIBCLANG_PATH" : libclang_dir ,
105
- "LD_LIBRARY_PATH" : ":" .join ([f .dirname for f in libstdcxx . cc . libs ]),
110
+ "LD_LIBRARY_PATH" : ":" .join ([f .dirname for f in get_libs_for_static_executable ( libstdcxx ) ]),
106
111
},
107
112
arguments = [args ],
108
113
tools = [clang_bin ],
@@ -126,7 +131,7 @@ rust_bindgen = rule(
126
131
),
127
132
"cc_lib" : attr .label (
128
133
doc = "The cc_library that contains the .h file. This is used to find the transitive includes." ,
129
- providers = ["cc" ],
134
+ providers = [CcInfo ],
130
135
),
131
136
"bindgen_flags" : attr .string_list (
132
137
doc = "Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details." ,
@@ -173,12 +178,12 @@ rust_bindgen_toolchain = rule(
173
178
"libclang" : attr .label (
174
179
doc = "A cc_library that provides bindgen's runtime dependency on libclang." ,
175
180
cfg = "host" ,
176
- providers = ["cc" ],
181
+ providers = [CcInfo ],
177
182
),
178
183
"libstdcxx" : attr .label (
179
184
doc = "A cc_library that satisfies libclang's libstdc++ dependency." ,
180
185
cfg = "host" ,
181
- providers = ["cc" ],
186
+ providers = [CcInfo ],
182
187
),
183
188
},
184
189
)
0 commit comments