Skip to content

Commit 96e2d5b

Browse files
authored
Adjust env for bindgen compilation. (#916)
This fixes #899 by putting `XCODE_VERSION_OVERRIDE`, `APPLE_SDK_VERSION_OVERRIDE`, `APPLE_SDK_PLATFORM` in the env.
1 parent 7456276 commit 96e2d5b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

bindgen/bindgen.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
load("//rust:rust.bzl", "rust_library")
1717

1818
# 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")
2023

2124
# TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API.
2225
def _get_libs_for_static_executable(dep):
@@ -126,6 +129,9 @@ def _rust_bindgen_impl(ctx):
126129
"LIBCLANG_PATH": libclang_dir,
127130
"RUST_BACKTRACE": "1",
128131
}
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)
129135

130136
# Set the dynamic linker search path so that clang uses the libstdcxx from the toolchain.
131137
# DYLD_LIBRARY_PATH is LD_LIBRARY_PATH on macOS.
@@ -188,6 +194,9 @@ rust_bindgen = rule(
188194
doc = "The .h file to generate bindings for.",
189195
allow_single_file = True,
190196
),
197+
"_cc_toolchain": attr.label(
198+
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
199+
),
191200
"_process_wrapper": attr.label(
192201
default = Label("//util/process_wrapper"),
193202
executable = True,
@@ -196,9 +205,11 @@ rust_bindgen = rule(
196205
),
197206
},
198207
outputs = {"out": "%{name}.rs"},
208+
fragments = ["cpp"],
199209
toolchains = [
200210
str(Label("//bindgen:bindgen_toolchain")),
201211
str(Label("//rust:toolchain")),
212+
"@bazel_tools//tools/cpp:toolchain_type",
202213
],
203214
incompatible_use_toolchain_transition = True,
204215
)

0 commit comments

Comments
 (0)