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

unable to build a csharp_proto_library due to a toolchain-related error #254

Open
ltcmelo opened this issue Apr 12, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@ltcmelo
Copy link

ltcmelo commented Apr 12, 2023

Issue Description

I'm unable to build a csharp_proto_library due to a toolchain-related error. I can reproduce this error with the csharp_proto_library example on the master branch.

csharp_proto_library git:(master) bazel build //:person_csharp_proto.dll
ERROR: /Users/ltcmelo/scm/rules_proto_grpc/example/csharp/csharp_proto_library/BUILD.bazel:3:21: While resolving toolchains for target //:person_csharp_proto.dll: no matching toolchains found for types @io_bazel_rules_dotnet//dotnet:toolchain_type_csharp_core
ERROR: Analysis of target '//:person_csharp_proto.dll' failed; build aborted:
INFO: Elapsed time: 0.092s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

Building a csharp_proto_compile works, though.

csharp_proto_compile git:(master) bazel build //:person_csharp_proto
INFO: Analyzed target //:person_csharp_proto (0 packages loaded, 1 target configured).
INFO: Found 1 target...
Target //:person_csharp_proto up-to-date:
  bazel-bin/person_csharp_proto/Person.cs
INFO: Elapsed time: 0.130s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

rules_proto_grpc Version

4.3.0 (and master)

Bazel Version

5.3.0

OS

macos (darwin arm64)

dotnet Version

6.0.101, 7.0.101, 7.0.202, and 7.0.203

@ltcmelo ltcmelo added the bug Something isn't working label Apr 12, 2023
@aaliddell
Copy link
Member

To use the C# rules you need to manually specify the toolchains and platforms, for example:

bazel build --platforms=@io_bazel_rules_dotnet//dotnet/toolchain:linux_amd64_5.0.201 --host_platform=@io_bazel_rules_dotnet//dotnet/toolchain:linux_amd64_5.0.201 //:person_csharp_proto.dll

This is a requirement of rules_dotnet and isn't specific to rules_proto_grpc. It appears that recent rules_dotnet updates remove this mandatory toolchain specification, but that version is not currently used here. You could try overriding your rules_dotnet version in your WORKSPACE prior to loading rules_proto_grpc, but you'd be in untested territory.

@ltcmelo
Copy link
Author

ltcmelo commented Apr 13, 2023

Thanks @aaliddell . Indeed, the current rules_dotnet allows you to register the desired dotnet toolchain in the WORKSPACE.

Yet, I tried --platforms and --host-platform as you suggest, and while works for a "pure C#" csharp_proto_library, it doesn't for a C# csharp_proto_library that depends on a proto_library.

proto_library(
    name = "lib",
    srcs = [a.proto],
    deps = ["@com_google_protobuf//..."],
    visibility = ["//visibility:public"],
)

csharp_proto_library(
    name = "other_lib.dll",
    protos = [b.proto],
    deps = ["//:lib"],
    visibility = ["//visibility:public"],
)
bazel build --platforms=@io_bazel_rules_dotnet//dotnet/toolchain:darwin_arm64_6.0.101 --host_platform=@io_bazel_rules_dotnet//dotnet/toolchain:darwin_arm64_6.0.101 //src/dotnet:other_lib.dll
ERROR: /src/dotnet/BUILD.bazel:55:21: in deps attribute of csharp_library rule //src/dotnet:other_lib.dll: '//:lib' does not have mandatory providers: 'DotnetLibraryInfo'. Since this rule was created by the macro 'csharp_proto_library', the error might have been caused by the macro implementation

But I'm not sure whether this error ☝🏽 is related to same issue; would you have an idea?

@ltcmelo
Copy link
Author

ltcmelo commented Apr 13, 2023

It appears that I'm supposed to add "//:lib" to protos rather than to deps. Still, the deps from lib don't seem to be picked up (automatically), and if I add them to other_lib.dll, I'm "back" to the missing provider problem.

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

2 participants