tree: 65dea2546d437173399f87f5e9b89d6274ab1374
  1. example/
  2. nuget/
  3. BUILD.bazel
  4. csharp_grpc_compile.bzl
  5. csharp_grpc_library.bzl
  6. csharp_proto_compile.bzl
  7. csharp_proto_library.bzl
  8. deps.bzl
  9. README.md
csharp/README.md

csharp

NOTE 1: the csharp_* rules currently don't play nicely with sandboxing. You may see errors like:

The user's home directory could not be determined. Set the 'DOTNET_CLI_HOME' environment variable to specify the directory to use.

or

System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2)
   at Microsoft.DotNet.Configurer.CliFallbackFolderPathCalculator.get_DotnetUserProfileFolderPath()
   at Microsoft.DotNet.Configurer.FirstTimeUseNoticeSentinel..ctor(CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

To remedy this, use --strategy=CoreCompile=standalone for the csharp rules (put it in your .bazelrc file).

NOTE 2: the csharp nuget dependency sha256 values do not appear stable.

RuleDescription
csharp_proto_compileGenerates csharp protobuf artifacts
csharp_grpc_compileGenerates csharp protobuf+gRPC artifacts
csharp_proto_libraryGenerates csharp protobuf library
csharp_grpc_libraryGenerates csharp protobuf+gRPC library

csharp_proto_compile

Generates csharp protobuf artifacts

WORKSPACE

load("@build_stack_rules_proto//csharp:deps.bzl", "csharp_proto_compile")

csharp_proto_compile()

BUILD.bazel

load("@build_stack_rules_proto//csharp:csharp_proto_compile.bzl", "csharp_proto_compile")

csharp_proto_compile(
    name = "person_csharp_proto",
    deps = ["@build_stack_rules_proto//example/proto:person_proto"],
)

Mandatory Attributes

NameTypeDefaultDescription
depslist<ProtoInfo>[]List of labels that provide a ProtoInfo (such as native.proto_library)

Optional Attributes

NameTypeDefaultDescription
pluginslist<ProtoPluginInfo>[]List of labels that provide a ProtoPluginInfo
plugin_optionslist<string>[]List of additional ‘global’ plugin options (applies to all plugins). To apply plugin specific options, use the options attribute on proto_plugin
outputslist<generated file>[]List of additional expected generated file outputs
verboseint0The verbosity level. Supported values and results are 1: show command, 2: show command and sandbox after running protoc, 3: show command and sandbox before and after running protoc, 4. show env, command, expected outputs and sandbox before and after running protoc
include_importsboolTruePass the --include_imports argument to the protoc_plugin
include_source_infoboolTruePass the --include_source_info argument to the protoc_plugin
transitiveboolTrueGenerate outputs for both *.proto directly named in deps AND all their transitive proto_library dependencies
transitivitystring_dict{}Transitive filters to apply when the ‘transitive’ property is enabled. This string_dict can be used to exclude or explicitly include protos from the compilation list by using exclude or include respectively as the dict value

csharp_grpc_compile

Generates csharp protobuf+gRPC artifacts

WORKSPACE

load("@build_stack_rules_proto//csharp:deps.bzl", "csharp_grpc_compile")

csharp_grpc_compile()

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

BUILD.bazel

load("@build_stack_rules_proto//csharp:csharp_grpc_compile.bzl", "csharp_grpc_compile")

csharp_grpc_compile(
    name = "greeter_csharp_grpc",
    deps = ["@build_stack_rules_proto//example/proto:greeter_grpc"],
)

Mandatory Attributes

NameTypeDefaultDescription
depslist<ProtoInfo>[]List of labels that provide a ProtoInfo (such as native.proto_library)

Optional Attributes

NameTypeDefaultDescription
pluginslist<ProtoPluginInfo>[]List of labels that provide a ProtoPluginInfo
plugin_optionslist<string>[]List of additional ‘global’ plugin options (applies to all plugins). To apply plugin specific options, use the options attribute on proto_plugin
outputslist<generated file>[]List of additional expected generated file outputs
verboseint0The verbosity level. Supported values and results are 1: show command, 2: show command and sandbox after running protoc, 3: show command and sandbox before and after running protoc, 4. show env, command, expected outputs and sandbox before and after running protoc
include_importsboolTruePass the --include_imports argument to the protoc_plugin
include_source_infoboolTruePass the --include_source_info argument to the protoc_plugin
transitiveboolTrueGenerate outputs for both *.proto directly named in deps AND all their transitive proto_library dependencies
transitivitystring_dict{}Transitive filters to apply when the ‘transitive’ property is enabled. This string_dict can be used to exclude or explicitly include protos from the compilation list by using exclude or include respectively as the dict value

csharp_proto_library

Generates csharp protobuf library

WORKSPACE

load("@build_stack_rules_proto//csharp:deps.bzl", "csharp_proto_library")

csharp_proto_library()

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

core_version = "v2.1.503"

dotnet_register_toolchains(
    core_version = core_version,
)

dotnet_register_toolchains(
    core_version = core_version,
)

core_register_sdk(
    name = "core_sdk",
    core_version = core_version,
)

dotnet_repositories()

load("@build_stack_rules_proto//csharp/nuget:packages.bzl", nuget_packages = "packages")

nuget_packages()

load("@build_stack_rules_proto//csharp/nuget:nuget.bzl", "nuget_protobuf_packages")

nuget_protobuf_packages()

BUILD.bazel

load("@build_stack_rules_proto//csharp:csharp_proto_library.bzl", "csharp_proto_library")

csharp_proto_library(
    name = "person_csharp_library",
    deps = ["@build_stack_rules_proto//example/proto:person_proto"],
)

Flags

CategoryFlagValueDescription
buildstrategyCoreCompile=standalonedotnet SDK desperately wants to find the HOME directory

Mandatory Attributes

NameTypeDefaultDescription
depslist<ProtoInfo>[]List of labels that provide a ProtoInfo (such as native.proto_library)

Optional Attributes

NameTypeDefaultDescription
pluginslist<ProtoPluginInfo>[]List of labels that provide a ProtoPluginInfo
plugin_optionslist<string>[]List of additional ‘global’ plugin options (applies to all plugins). To apply plugin specific options, use the options attribute on proto_plugin
outputslist<generated file>[]List of additional expected generated file outputs
verboseint0The verbosity level. Supported values and results are 1: show command, 2: show command and sandbox after running protoc, 3: show command and sandbox before and after running protoc, 4. show env, command, expected outputs and sandbox before and after running protoc
include_importsboolTruePass the --include_imports argument to the protoc_plugin
include_source_infoboolTruePass the --include_source_info argument to the protoc_plugin
transitiveboolTrueGenerate outputs for both *.proto directly named in deps AND all their transitive proto_library dependencies
transitivitystring_dict{}Transitive filters to apply when the ‘transitive’ property is enabled. This string_dict can be used to exclude or explicitly include protos from the compilation list by using exclude or include respectively as the dict value

csharp_grpc_library

Generates csharp protobuf+gRPC library

WORKSPACE

load("@build_stack_rules_proto//csharp:deps.bzl", "csharp_grpc_library")

csharp_grpc_library()

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

core_version = "v2.1.503"

dotnet_register_toolchains(
    core_version = core_version,
)

dotnet_register_toolchains(
    core_version = core_version,
)

core_register_sdk(
    name = "core_sdk",
    core_version = core_version,
)

dotnet_repositories()

load("@build_stack_rules_proto//csharp/nuget:packages.bzl", nuget_packages = "packages")

nuget_packages()

load("@build_stack_rules_proto//csharp/nuget:nuget.bzl", "nuget_protobuf_packages")

nuget_protobuf_packages()

load("@build_stack_rules_proto//csharp/nuget:nuget.bzl", "nuget_grpc_packages")

nuget_grpc_packages()

BUILD.bazel

load("@build_stack_rules_proto//csharp:csharp_grpc_library.bzl", "csharp_grpc_library")

csharp_grpc_library(
    name = "greeter_csharp_library",
    deps = ["@build_stack_rules_proto//example/proto:greeter_grpc"],
)

Flags

CategoryFlagValueDescription
buildstrategyCoreCompile=standalonedotnet SDK desperately wants to find the HOME directory

Mandatory Attributes

NameTypeDefaultDescription
depslist<ProtoInfo>[]List of labels that provide a ProtoInfo (such as native.proto_library)

Optional Attributes

NameTypeDefaultDescription
pluginslist<ProtoPluginInfo>[]List of labels that provide a ProtoPluginInfo
plugin_optionslist<string>[]List of additional ‘global’ plugin options (applies to all plugins). To apply plugin specific options, use the options attribute on proto_plugin
outputslist<generated file>[]List of additional expected generated file outputs
verboseint0The verbosity level. Supported values and results are 1: show command, 2: show command and sandbox after running protoc, 3: show command and sandbox before and after running protoc, 4. show env, command, expected outputs and sandbox before and after running protoc
include_importsboolTruePass the --include_imports argument to the protoc_plugin
include_source_infoboolTruePass the --include_source_info argument to the protoc_plugin
transitiveboolTrueGenerate outputs for both *.proto directly named in deps AND all their transitive proto_library dependencies
transitivitystring_dict{}Transitive filters to apply when the ‘transitive’ property is enabled. This string_dict can be used to exclude or explicitly include protos from the compilation list by using exclude or include respectively as the dict value