Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add reference (dep) to C# proto library target #293

Open
mayerber opened this issue Nov 19, 2023 · 0 comments
Open

Cannot add reference (dep) to C# proto library target #293

mayerber opened this issue Nov 19, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@mayerber
Copy link

mayerber commented Nov 19, 2023

Issue Description

I have the following two targets:

Target 1. C# proto library [full contents in BUILD section below]

csharp_proto_library(
    name = "thing_csharp_proto.dll",
    protos = [":thing_proto"],
    visibility = ["//example/csharp/console:__pkg__"],
)

Target 2. C# console app

csharp_binary(
    name = "console.exe",
    deps = [
        "//example/proto:thing_csharp_proto.dll",
    ]
)

First target thing_csharp_proto.dll builds fine. However, when I add a reference to it (deps) from the console target, build fails with error:

ERROR: /home/neto/repos/github.com/mayerber/bazel-learning/example/csharp/console/BUILD.bazel:6:14: in deps attribute of csharp_binary rule //example/csharp/console:console.exe: '//example/proto:thing_csharp_proto.dll' does not have mandatory providers: ['DotnetAssemblyCompileInfo', 'DotnetAssemblyRuntimeInfo']. Since this rule was created by the macro 'csharp_binary', the error might have been caused by the macro implementation

Looks like csharp_proto_library doesn't implement a couple mandatory providers.

Log Output

ERROR: /home/neto/repos/github.com/mayerber/bazel-learning/example/csharp/console/BUILD.bazel:6:14: in deps attribute of csharp_binary rule //example/csharp/console:console.exe: '//example/proto:thing_csharp_proto.dll' does not have mandatory providers: ['DotnetAssemblyCompileInfo', 'DotnetAssemblyRuntimeInfo']. Since this rule was created by the macro 'csharp_binary', the error might have been caused by the macro implementation
ERROR: /home/neto/repos/github.com/mayerber/bazel-learning/example/csharp/console/BUILD.bazel:6:14: Analysis of target '//example/csharp/console:console.exe' failed
ERROR: Analysis of target '//example/csharp/console:console.exe' failed; build aborted:
INFO: Elapsed time: 0.144s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 1 target configured)

rules_proto_grpc Version

4.5.0

Bazel Version

6.4.0

OS

Ubuntu (WSL2)

Link to Demo Repo

https://github.com/mayerber/bazel-learning/tree/ref_thing_proto

WORKSPACE Content

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "bazel_skylib",
    sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
    ],
)

http_archive(
    name = "rules_dotnet",
    sha256 = "718cb2c3431523aaf3df7feed0e997e4ded002abbf56ac37d9c0536a812d6276",
    strip_prefix = "rules_dotnet-0.12.0",
    url = "https://github.com/bazelbuild/rules_dotnet/releases/download/v0.12.0/rules_dotnet-v0.12.0.tar.gz",
)


load(
    "@rules_dotnet//dotnet:repositories.bzl",
    "dotnet_register_toolchains",
    "rules_dotnet_dependencies",
)

rules_dotnet_dependencies()

dotnet_register_toolchains("dotnet", "6.0.101")

load("@rules_dotnet//dotnet:rules_dotnet_nuget_packages.bzl", "rules_dotnet_nuget_packages")

rules_dotnet_nuget_packages()

load("@rules_dotnet//dotnet:paket2bazel_dependencies.bzl", "paket2bazel_dependencies")

paket2bazel_dependencies()

load("//:example_deps.bzl", "example_deps")

example_deps()

# Proto and gRPC

http_archive(
    name = "rules_proto_grpc",
    sha256 = "9ba7299c5eb6ec45b6b9a0ceb9916d0ab96789ac8218269322f0124c0c0d24e2",
    strip_prefix = "rules_proto_grpc-4.5.0",
    urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/releases/download/4.5.0/rules_proto_grpc-4.5.0.tar.gz"],
)

load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains", "rules_proto_grpc_repos")

rules_proto_grpc_toolchains()

rules_proto_grpc_repos()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

load("@rules_proto_grpc//cpp:repositories.bzl", "cpp_repos")

cpp_repos()

load("@rules_proto_grpc//csharp:repositories.bzl", rules_proto_grpc_csharp_repos = "csharp_repos")

rules_proto_grpc_csharp_repos()

load("@io_bazel_rules_dotnet//dotnet:deps.bzl", "dotnet_repositories")

dotnet_repositories()

load(
    "@io_bazel_rules_dotnet//dotnet:defs.bzl",
    "dotnet_register_toolchains",
    "dotnet_repositories_nugets",
)

dotnet_register_toolchains()

dotnet_repositories_nugets()

load("@rules_proto_grpc//csharp/nuget:nuget.bzl", "nuget_rules_proto_grpc_packages")

nuget_rules_proto_grpc_packages()

BUILD Content

FILE: console/BUILD.bazel

load(
    "@rules_dotnet//dotnet:defs.bzl",
    "csharp_binary",
)

csharp_binary(
    target_frameworks = ["net6.0"],
    targeting_packs = [
        "@example_deps//microsoft.netcore.app.ref",
    ],
    name = "console.exe",
    srcs = [
        "Program.cs",
    ],
    deps = [
        "//example/proto:thing_csharp_proto.dll",
    ]
)

FILE: proto/BUILD.bazel

load("@rules_proto_grpc//cpp:defs.bzl", "cpp_proto_library")
load("@rules_proto_grpc//csharp:defs.bzl", "csharp_proto_library")

proto_library(
    name = "thing_proto",
    srcs = ["thing.proto"],
    deps = ["@com_google_protobuf//:any_proto"],
)

cpp_proto_library(
    name = "cpp_thing_proto",
    protos = [":thing_proto"],
)

csharp_proto_library(
    name = "thing_csharp_proto.dll",
    protos = [":thing_proto"],
    visibility = ["//example/csharp/console:__pkg__"],
)

Proto Content

syntax = "proto3";

package example;

import "google/protobuf/any.proto";

message Thing {
    string name = 1;
    google.protobuf.Any payload = 2;
}

Any Other Content

No response

@mayerber mayerber added the bug Something isn't working label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant