From 702a89617dc4de5514a23db285981d17938f1079 Mon Sep 17 00:00:00 2001 From: David Freese Date: Mon, 20 Apr 2020 10:40:42 -0700 Subject: [PATCH] Remove transition from binary/test/bench rules, add to grpc/proto This mostly reverts commit a1d8936, removing the proc_macro_host_transition from most rules. This fixes #305, by no longer having a transition on rust_binary. It still solves #300 by adding this transition to rust_proto_library and rust_grpc_library. Those rules are meant to mirror rust_library, so they should share the same cfg values. Sharing the same configuration means that rust_proto_library or rust_grpc_library can be dependencies to rust_library or rust_binary and not cause another configuration of the library to be generated. The example introduced by #301 is moved in this commit into a subfolder to provide a more clear directory structure. --- examples/proto/BUILD | 23 ----------------------- examples/proto/basic/BUILD | 25 +++++++++++++++++++++++++ examples/proto/{ => basic}/lib.rs | 0 examples/proto/{ => basic}/main.rs | 0 proto/proto.bzl | 15 ++++++++++++--- rust/private/rust.bzl | 9 +++------ 6 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 examples/proto/basic/BUILD rename examples/proto/{ => basic}/lib.rs (100%) rename examples/proto/{ => basic}/main.rs (100%) diff --git a/examples/proto/BUILD b/examples/proto/BUILD index d3e31bc57a..9ddf0e33f2 100644 --- a/examples/proto/BUILD +++ b/examples/proto/BUILD @@ -1,7 +1,4 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("@io_bazel_rules_rust//proto:proto.bzl", "rust_proto_library") -load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library") -load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary") package(default_visibility = ["//proto:__subpackages__"]) @@ -9,23 +6,3 @@ proto_library( name = "common", srcs = ["common.proto"], ) - -rust_proto_library( - name = "common_proto_rust", - deps = [":common"], -) - -rust_library( - name = "common_lib", - srcs = ["lib.rs"], - deps = [":common_proto_rust"], -) - -rust_binary( - name = "common_bin", - srcs = ["main.rs"], - deps = [ - ":common_lib", - ":common_proto_rust", - ], -) diff --git a/examples/proto/basic/BUILD b/examples/proto/basic/BUILD new file mode 100644 index 0000000000..cf2b3ef78b --- /dev/null +++ b/examples/proto/basic/BUILD @@ -0,0 +1,25 @@ +load("@io_bazel_rules_rust//proto:proto.bzl", "rust_proto_library") +load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library") +load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary") + +package(default_visibility = ["//proto:__subpackages__"]) + +rust_proto_library( + name = "common_proto_rust", + deps = ["//proto:common"], +) + +rust_library( + name = "common_lib", + srcs = ["lib.rs"], + deps = [":common_proto_rust"], +) + +rust_binary( + name = "common_bin", + srcs = ["main.rs"], + deps = [ + ":common_lib", + ":common_proto_rust", + ], +) diff --git a/examples/proto/lib.rs b/examples/proto/basic/lib.rs similarity index 100% rename from examples/proto/lib.rs rename to examples/proto/basic/lib.rs diff --git a/examples/proto/main.rs b/examples/proto/basic/main.rs similarity index 100% rename from examples/proto/main.rs rename to examples/proto/basic/main.rs diff --git a/proto/proto.bzl b/proto/proto.bzl index bd60a150a9..f4174e2a03 100644 --- a/proto/proto.bzl +++ b/proto/proto.bzl @@ -35,14 +35,15 @@ rust_proto_repositories() """ load( - "//proto:toolchain.bzl", + "@io_bazel_rules_rust//proto:toolchain.bzl", "GRPC_COMPILE_DEPS", "PROTO_COMPILE_DEPS", _generate_proto = "rust_generate_proto", _generated_file_stem = "generated_file_stem", ) -load("//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action") -load("//rust:private/utils.bzl", "find_toolchain") +load("@io_bazel_rules_rust//rust:private/rustc.bzl", "CrateInfo", "rustc_compile_action") +load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain") +load("@io_bazel_rules_rust//rust:private/transitions.bzl", "proc_macro_host_transition") RustProtoProvider = provider( fields = { @@ -225,7 +226,11 @@ rust_proto_library = rule( "@io_bazel_rules_rust//proto:optional_output_wrapper", ), ), + "_whitelist_function_transition": attr.label( + default = "//tools/whitelists/function_transition_whitelist", + ), }, + cfg = proc_macro_host_transition, fragments = ["cpp"], host_fragments = ["cpp"], toolchains = [ @@ -285,7 +290,11 @@ rust_grpc_library = rule( "@io_bazel_rules_rust//proto:optional_output_wrapper", ), ), + "_whitelist_function_transition": attr.label( + default = "//tools/whitelists/function_transition_whitelist", + ), }, + cfg = proc_macro_host_transition, fragments = ["cpp"], host_fragments = ["cpp"], toolchains = [ diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index ceabbdbbc9..971514a0c0 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -321,9 +321,6 @@ _rust_common_attrs = { ], ), "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), - "_whitelist_function_transition": attr.label( - default = "//tools/whitelists/function_transition_whitelist", - ), } _rust_library_attrs = { @@ -336,6 +333,9 @@ _rust_library_attrs = { """), default = "rlib", ), + "_whitelist_function_transition": attr.label( + default = "//tools/whitelists/function_transition_whitelist", + ), } _rust_test_attrs = { @@ -443,7 +443,6 @@ rust_binary = rule( executable = True, fragments = ["cpp"], host_fragments = ["cpp"], - cfg = proc_macro_host_transition, toolchains = [ "@io_bazel_rules_rust//rust:toolchain", "@bazel_tools//tools/cpp:toolchain_type", @@ -541,7 +540,6 @@ rust_test = rule( executable = True, fragments = ["cpp"], host_fragments = ["cpp"], - cfg = proc_macro_host_transition, test = True, toolchains = [ "@io_bazel_rules_rust//rust:toolchain", @@ -690,7 +688,6 @@ rust_benchmark = rule( executable = True, fragments = ["cpp"], host_fragments = ["cpp"], - cfg = proc_macro_host_transition, toolchains = [ "@io_bazel_rules_rust//rust:toolchain", "@bazel_tools//tools/cpp:toolchain_type",