Skip to content

Commit

Permalink
Add cc toolchain files to rustc dependencies (for linker) (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
m3rcuriel authored and mfarrugi committed May 9, 2019
1 parent d28b121 commit 60a2654
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ rust_proto_library = rule(
toolchains = [
"@io_bazel_rules_rust//proto:toolchain",
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type",
],
doc = """
Builds a Rust library crate from a set of `proto_library`s.
Expand Down Expand Up @@ -275,6 +276,7 @@ rust_grpc_library = rule(
toolchains = [
"@io_bazel_rules_rust//proto:toolchain",
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type",
],
doc = """
Builds a Rust library crate from a set of `proto_library`s suitable for gRPC.
Expand Down
20 changes: 16 additions & 4 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ rust_library = rule(
_rust_library_attrs.items()),
fragments = ["cpp"],
host_fragments = ["cpp"],
toolchains = ["@io_bazel_rules_rust//rust:toolchain"],
toolchains = [
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type"
],
doc = """
Builds a Rust library crate.
Expand Down Expand Up @@ -417,7 +420,10 @@ rust_binary = rule(
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
toolchains = ["@io_bazel_rules_rust//rust:toolchain"],
toolchains = [
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type"
],
doc = """
Builds a Rust binary crate.
Expand Down Expand Up @@ -512,7 +518,10 @@ rust_test = rule(
fragments = ["cpp"],
host_fragments = ["cpp"],
test = True,
toolchains = ["@io_bazel_rules_rust//rust:toolchain"],
toolchains = [
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type"
],
doc = """
Builds a Rust test crate.
Expand Down Expand Up @@ -656,7 +665,10 @@ rust_benchmark = rule(
executable = True,
fragments = ["cpp"],
host_fragments = ["cpp"],
toolchains = ["@io_bazel_rules_rust//rust:toolchain"],
toolchains = [
"@io_bazel_rules_rust//rust:toolchain",
"@bazel_tools//tools/cpp:toolchain_type"
],
doc = """
Builds a Rust benchmark test.
Expand Down
9 changes: 9 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ def rustc_compile_action(

linker_script = getattr(ctx.file, "linker_script") if hasattr(ctx.file, "linker_script") else None

cc_toolchain = find_cpp_toolchain(ctx)

if (len(BAZEL_VERSION) == 0 or
versions.is_at_least("0.25.0", BAZEL_VERSION)):
linker_depset = find_cpp_toolchain(ctx).all_files
else:
linker_depset = depset(ctx.files._cc_toolchain)

compile_inputs = depset(
crate_info.srcs +
getattr(ctx.files, "data", []) +
Expand All @@ -198,6 +206,7 @@ def rustc_compile_action(
transitive = [
toolchain.rustc_lib.files,
toolchain.rust_lib.files,
linker_depset,
],
)

Expand Down

0 comments on commit 60a2654

Please sign in to comment.