16
16
load ("//rust:rust.bzl" , "rust_library" )
17
17
18
18
# buildifier: disable=bzl-visibility
19
- load ("//rust/private:utils.bzl" , "find_toolchain" , "get_preferred_artifact" )
19
+ load ("//rust/private:rustc.bzl" , "get_linker_and_args" )
20
+
21
+ # buildifier: disable=bzl-visibility
22
+ load ("//rust/private:utils.bzl" , "find_cc_toolchain" , "find_toolchain" , "get_preferred_artifact" )
20
23
21
24
# TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API.
22
25
def _get_libs_for_static_executable (dep ):
@@ -126,6 +129,9 @@ def _rust_bindgen_impl(ctx):
126
129
"LIBCLANG_PATH" : libclang_dir ,
127
130
"RUST_BACKTRACE" : "1" ,
128
131
}
132
+ cc_toolchain , feature_configuration = find_cc_toolchain (ctx )
133
+ _ , _ , linker_env = get_linker_and_args (ctx , ctx .attr , cc_toolchain , feature_configuration , None )
134
+ env .update (** linker_env )
129
135
130
136
# Set the dynamic linker search path so that clang uses the libstdcxx from the toolchain.
131
137
# DYLD_LIBRARY_PATH is LD_LIBRARY_PATH on macOS.
@@ -188,6 +194,9 @@ rust_bindgen = rule(
188
194
doc = "The .h file to generate bindings for." ,
189
195
allow_single_file = True ,
190
196
),
197
+ "_cc_toolchain" : attr .label (
198
+ default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" ),
199
+ ),
191
200
"_process_wrapper" : attr .label (
192
201
default = Label ("//util/process_wrapper" ),
193
202
executable = True ,
@@ -196,9 +205,11 @@ rust_bindgen = rule(
196
205
),
197
206
},
198
207
outputs = {"out" : "%{name}.rs" },
208
+ fragments = ["cpp" ],
199
209
toolchains = [
200
210
str (Label ("//bindgen:bindgen_toolchain" )),
201
211
str (Label ("//rust:toolchain" )),
212
+ "@bazel_tools//tools/cpp:toolchain_type" ,
202
213
],
203
214
incompatible_use_toolchain_transition = True ,
204
215
)
0 commit comments