From 87e7bb9e8c1e90e422f0685f2aadd16532b75129 Mon Sep 17 00:00:00 2001 From: RS Date: Sun, 29 Aug 2021 09:19:58 -0700 Subject: [PATCH 1/4] Adjust env for bindgen compilation. --- bindgen/bindgen.bzl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bindgen/bindgen.bzl b/bindgen/bindgen.bzl index cf28023f8f..38d622aec0 100644 --- a/bindgen/bindgen.bzl +++ b/bindgen/bindgen.bzl @@ -16,7 +16,8 @@ load("//rust:rust.bzl", "rust_library") # buildifier: disable=bzl-visibility -load("//rust/private:utils.bzl", "find_toolchain", "get_preferred_artifact") +load("//rust/private:utils.bzl", "find_toolchain", "find_cc_toolchain", "get_preferred_artifact") +load("//rust/private:rustc.bzl", "get_linker_and_args") # TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API. def _get_libs_for_static_executable(dep): @@ -111,6 +112,8 @@ def _rust_bindgen_impl(ctx): else: unformatted_output = output + cc_toolchain, feature_configuration = find_cc_toolchain(ctx) + args = ctx.actions.args() args.add_all(bindgen_args) args.add(header.path) @@ -126,6 +129,8 @@ def _rust_bindgen_impl(ctx): "LIBCLANG_PATH": libclang_dir, "RUST_BACKTRACE": "1", } + _, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None) + env.update(**linker_env) # Set the dynamic linker search path so that clang uses the libstdcxx from the toolchain. # DYLD_LIBRARY_PATH is LD_LIBRARY_PATH on macOS. @@ -194,11 +199,16 @@ rust_bindgen = rule( allow_single_file = True, cfg = "exec", ), + "_cc_toolchain": attr.label( + default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), + ), }, outputs = {"out": "%{name}.rs"}, + fragments = ["cpp"], toolchains = [ str(Label("//bindgen:bindgen_toolchain")), str(Label("//rust:toolchain")), + "@bazel_tools//tools/cpp:toolchain_type", ], incompatible_use_toolchain_transition = True, ) From ecc65a8ef70566c5044f796e57c860f1c14e6803 Mon Sep 17 00:00:00 2001 From: RS Date: Sun, 29 Aug 2021 09:28:46 -0700 Subject: [PATCH 2/4] Buildifier. --- bindgen/bindgen.bzl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bindgen/bindgen.bzl b/bindgen/bindgen.bzl index 38d622aec0..519ef776d8 100644 --- a/bindgen/bindgen.bzl +++ b/bindgen/bindgen.bzl @@ -16,7 +16,7 @@ load("//rust:rust.bzl", "rust_library") # buildifier: disable=bzl-visibility -load("//rust/private:utils.bzl", "find_toolchain", "find_cc_toolchain", "get_preferred_artifact") +load("//rust/private:utils.bzl", "find_cc_toolchain", "find_toolchain", "get_preferred_artifact") load("//rust/private:rustc.bzl", "get_linker_and_args") # TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API. @@ -112,8 +112,6 @@ def _rust_bindgen_impl(ctx): else: unformatted_output = output - cc_toolchain, feature_configuration = find_cc_toolchain(ctx) - args = ctx.actions.args() args.add_all(bindgen_args) args.add(header.path) @@ -129,6 +127,7 @@ def _rust_bindgen_impl(ctx): "LIBCLANG_PATH": libclang_dir, "RUST_BACKTRACE": "1", } + cc_toolchain, feature_configuration = find_cc_toolchain(ctx) _, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None) env.update(**linker_env) From c43edc76ff20745722ff77f734f3ecbb9b30e8bb Mon Sep 17 00:00:00 2001 From: RS Date: Sun, 29 Aug 2021 11:19:41 -0700 Subject: [PATCH 3/4] Fix visibility warning. --- bindgen/bindgen.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindgen/bindgen.bzl b/bindgen/bindgen.bzl index 519ef776d8..6d7efe7faa 100644 --- a/bindgen/bindgen.bzl +++ b/bindgen/bindgen.bzl @@ -17,6 +17,8 @@ load("//rust:rust.bzl", "rust_library") # buildifier: disable=bzl-visibility load("//rust/private:utils.bzl", "find_cc_toolchain", "find_toolchain", "get_preferred_artifact") + +# buildifier: disable=bzl-visibility load("//rust/private:rustc.bzl", "get_linker_and_args") # TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API. From 869f96b1983b35306031e8234c67b1ef57a1ea53 Mon Sep 17 00:00:00 2001 From: RS Date: Sun, 29 Aug 2021 11:26:27 -0700 Subject: [PATCH 4/4] More buildifier. --- bindgen/bindgen.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen/bindgen.bzl b/bindgen/bindgen.bzl index 6d7efe7faa..f35ea6ca45 100644 --- a/bindgen/bindgen.bzl +++ b/bindgen/bindgen.bzl @@ -16,10 +16,10 @@ load("//rust:rust.bzl", "rust_library") # buildifier: disable=bzl-visibility -load("//rust/private:utils.bzl", "find_cc_toolchain", "find_toolchain", "get_preferred_artifact") +load("//rust/private:rustc.bzl", "get_linker_and_args") # buildifier: disable=bzl-visibility -load("//rust/private:rustc.bzl", "get_linker_and_args") +load("//rust/private:utils.bzl", "find_cc_toolchain", "find_toolchain", "get_preferred_artifact") # TODO(hlopko): use the more robust logic from rustc.bzl also here, through a reasonable API. def _get_libs_for_static_executable(dep): @@ -194,15 +194,15 @@ rust_bindgen = rule( doc = "The .h file to generate bindings for.", allow_single_file = True, ), + "_cc_toolchain": attr.label( + default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), + ), "_process_wrapper": attr.label( default = Label("//util/process_wrapper"), executable = True, allow_single_file = True, cfg = "exec", ), - "_cc_toolchain": attr.label( - default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), - ), }, outputs = {"out": "%{name}.rs"}, fragments = ["cpp"],