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

WIP C# Module #393

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/csharp/csharp_proto_compile/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_proto_grpc_csharp//:defs.bzl", "csharp_proto_compile")

csharp_proto_compile(
name = "person_csharp_proto",
protos = ["@rules_proto_grpc_example_protos//:person_proto"],
)

csharp_proto_compile(
name = "place_csharp_proto",
protos = ["@rules_proto_grpc_example_protos//:place_proto"],
)

csharp_proto_compile(
name = "thing_csharp_proto",
protos = ["@rules_proto_grpc_example_protos//:thing_proto"],
)
20 changes: 20 additions & 0 deletions examples/csharp/csharp_proto_compile/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_csharp", version = "0.0.0.rpg.version.placeholder")

local_path_override(
module_name = "rules_proto_grpc",
path = "../../../modules/core",
)

local_path_override(
module_name = "rules_proto_grpc_example_protos",
path = "../../../modules/example_protos",
)

local_path_override(
module_name = "rules_proto_grpc_csharp",
path = "../../../modules/csharp",
)

bazel_dep(name = "protobuf", version = "27.1")
Empty file.
21 changes: 21 additions & 0 deletions modules/csharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_proto_grpc//:defs.bzl", "proto_plugin")

proto_plugin(
name = "proto_plugin",
exclusions = [
"google/protobuf",
],
outputs = ["{basename|pascal}.cs"],
protoc_plugin_name = "chsarp",
visibility = ["//visibility:public"],
)

proto_plugin(
name = "grpc_plugin",
exclusions = [
"google/protobuf",
],
output_directory = True,
tool = "@grpc//src/compiler:grpc_csharp_plugin",
visibility = ["//visibility:public"],
)
26 changes: 26 additions & 0 deletions modules/csharp/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module(
name = "rules_proto_grpc_csharp",
version = "0.0.0.rpg.version.placeholder",
compatibility_level = 1,
)

bazel_dep(name = "grpc", version = "1.65.0")
bazel_dep(name = "protobuf", version = "27.1")
bazel_dep(name = "rules_dotnet", version = "0.17.5")
bazel_dep(name = "rules_proto_grpc", version = "0.0.0.rpg.version.placeholder")
bazel_dep(name = "rules_proto_grpc_example_protos", version = "0.0.0.rpg.version.placeholder")

register_toolchains("@dotnet_toolchains//:all")
local_path_override(
module_name = "rules_proto_grpc",
path = "../../modules/core",
)

local_path_override(
module_name = "rules_proto_grpc_example_protos",
path = "../../modules/example_protos",
)

dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
dotnet.toolchain(dotnet_version = "8.0.200")
use_repo(dotnet, "dotnet_toolchains")
27 changes: 27 additions & 0 deletions modules/csharp/csharp_grpc_compile.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Generated definition of csharp_grpc_compile."""

load(
"@rules_proto_grpc//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
"proto_compile_toolchains",
)

# Create compile rule
csharp_grpc_compile = rule(
implementation = proto_compile_impl,
attrs = dict(
proto_compile_attrs,
_plugins = attr.label_list(
providers = [ProtoPluginInfo],
default = [
Label("//:proto_plugin"),
Label("//:grpc_plugin"),
],
cfg = "exec",
doc = "List of protoc plugins to apply",
),
),
toolchains = proto_compile_toolchains,
)
38 changes: 38 additions & 0 deletions modules/csharp/csharp_grpc_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Generated definition of csharp_grpc_library."""

load("//:csharp_grpc_compile.bzl", "csharp_grpc_compile")
load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "filter_files", "proto_compile_attrs")
load("@rules_dotnet//dotnet:defs.bzl", "csharp_library")

def csharp_grpc_library(name, **kwargs):
# Compile protos
name_pb = name + "_pb"
csharp_grpc_compile(
name = name_pb,
**{
k: v
for (k, v) in kwargs.items()
if k in proto_compile_attrs.keys() or
k in bazel_build_rule_common_attrs
} # Forward args
)

# Create csharp library
csharp_library(
name = name,
srcs = [name_pb],
deps = GRPC_DEPS + kwargs.get("deps", []),
**{
k: v
for (k, v) in kwargs.items()
if k in bazel_build_rule_common_attrs
} # Forward Bazel common args
)

GRPC_DEPS = [
Label("@protobuf//:protobuf"),
# Label("@grpc//:grpc++"),
# "@grpc.net.client//:lib",
# "@grpc.aspnetcore//:lib",
# "@core_sdk_stdlib//:libraryset",
]
26 changes: 26 additions & 0 deletions modules/csharp/csharp_proto_compile.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Generated definition of csharp_proto_compile."""

load(
"@rules_proto_grpc//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
"proto_compile_toolchains",
)

# Create compile rule
csharp_proto_compile = rule(
implementation = proto_compile_impl,
attrs = dict(
proto_compile_attrs,
_plugins = attr.label_list(
providers = [ProtoPluginInfo],
default = [
Label("//:proto_plugin"),
],
cfg = "exec",
doc = "List of protoc plugins to apply",
),
),
toolchains = proto_compile_toolchains,
)
36 changes: 36 additions & 0 deletions modules/csharp/csharp_proto_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Generated definition of csharp_proto_library."""

load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "filter_files", "proto_compile_attrs")
load("//:csharp_proto_compile.bzl", "csharp_proto_compile")
load("@rules_dotnet//dotnet:defs.bzl", "csharp_library")


def csharp_proto_library(name, **kwargs): # buildifier: disable=function-docstring
# Compile protos
name_pb = name + "_pb"
csharp_proto_compile(
name = name_pb,
**{
k: v
for (k, v) in kwargs.items()
if k in proto_compile_attrs.keys() or
k in bazel_build_rule_common_attrs
} # Forward args
)

# Create csharp library
csharp_library(
name = name,
srcs = [name_pb],
deps = PROTO_DEPS + kwargs.get("deps", []),
**{
k: v
for (k, v) in kwargs.items()
if k in bazel_build_rule_common_attrs
} # Forward Bazel common args
)

PROTO_DEPS = [
Label("@protobuf//:protobuf"),
# Label("@core_sdk_stdlib//:libraryset"), # TODO needed?
]
12 changes: 12 additions & 0 deletions modules/csharp/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""csharp protobuf and grpc rules."""

load(":csharp_proto_compile.bzl", _csharp_proto_compile = "csharp_proto_compile")
load(":csharp_grpc_compile.bzl", _csharp_grpc_compile = "csharp_grpc_compile")
load(":csharp_proto_library.bzl", _csharp_proto_library = "csharp_proto_library")
load(":csharp_grpc_library.bzl", _csharp_grpc_library = "csharp_grpc_library")

# Export csharp rules
csharp_proto_compile = _csharp_proto_compile
csharp_grpc_compile = _csharp_grpc_compile
csharp_proto_library = _csharp_proto_library
csharp_grpc_library = _csharp_grpc_library
Loading