Skip to content

Commit

Permalink
Remove transition from binary/test/bench rules, add to grpc/proto (#309)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dfreese committed Apr 21, 2020
1 parent 3189246 commit e285f2b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
23 changes: 0 additions & 23 deletions examples/proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
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__"])

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",
],
)
25 changes: 25 additions & 0 deletions examples/proto/basic/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
File renamed without changes.
File renamed without changes.
15 changes: 12 additions & 3 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
9 changes: 3 additions & 6 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -336,6 +333,9 @@ _rust_library_attrs = {
"""),
default = "rlib",
),
"_whitelist_function_transition": attr.label(
default = "//tools/whitelists/function_transition_whitelist",
),
}

_rust_test_attrs = {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e285f2b

Please sign in to comment.