Skip to content

Commit

Permalink
Fix build issues?
Browse files Browse the repository at this point in the history
  • Loading branch information
anders617 committed Nov 9, 2019
1 parent cce4942 commit e62c68c
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 11 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ go_dependencies()

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

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

Expand Down
2 changes: 1 addition & 1 deletion examples/client/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")

cc_binary(
name = "client_cpp",
Expand Down
21 changes: 20 additions & 1 deletion examples/server/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary")

cc_binary(
name = "cc_server",
name = "server_cpp",
srcs = ["main.cpp"],
deps = [
"//proto:mdining_cc_grpc",
Expand All @@ -8,4 +10,21 @@ cc_binary(
data = [
"//proto/sample:proto_sample_data",
]
)


go_binary(
name = "server_go",
visibility = ["//visibility:public"],
srcs = ["main.go"],
deps = [
"//proto:mdining_go_proto",
"@com_github_golang_protobuf//proto:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
],
data = [
"//proto/sample:proto_sample_data",
]
)
113 changes: 113 additions & 0 deletions examples/server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package main

import (
"context"
"flag"
"fmt"
"io/ioutil"
"net"
"os"

pb "github.com/anders617/mdining-proto/proto/mdining"
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

//
// ReadProtoFromFile - Reads a proto from the given file path
//
func ReadProtoFromFileOrDie(path string, p proto.Message) {
data, err := ioutil.ReadFile(path)
if err != nil {
fmt.Printf("Failed to read in text proto, %v\n", err)
os.Exit(1)
}
if proto.UnmarshalText(string(data), p) != nil {
fmt.Printf("Failed to read in text proto, %v\n", err)
os.Exit(1)
}
}

type server struct {
diningHallsReply pb.DiningHallsReply
itemsReply pb.ItemsReply
filterableEntriesReply pb.FilterableEntriesReply
allReply pb.AllReply
}

func newserver() *server {
s := new(server)
ReadProtoFromFileOrDie("proto/sample/dininghalls.proto.txt", &s.diningHallsReply)
ReadProtoFromFileOrDie("proto/sample/items.proto.txt", &s.itemsReply)
ReadProtoFromFileOrDie("proto/sample/filterableentries.proto.txt", &s.filterableEntriesReply)
s.allReply = pb.AllReply{
DiningHalls: s.diningHallsReply.DiningHalls,
Items: s.itemsReply.Items,
FilterableEntries: s.filterableEntriesReply.FilterableEntries}
return s
}

func (s *server) GetDiningHalls(ctx context.Context, req *pb.DiningHallsRequest) (*pb.DiningHallsReply, error) {
fmt.Printf("GetDiningHalls req{%v}\n", req)
return &s.diningHallsReply, nil
}

func (s *server) GetItems(ctx context.Context, req *pb.ItemsRequest) (*pb.ItemsReply, error) {
fmt.Printf("GetItems req{%v}\n", req)
return &s.itemsReply, nil
}

func (s *server) GetFilterableEntries(ctx context.Context, req *pb.FilterableEntriesRequest) (*pb.FilterableEntriesReply, error) {
fmt.Printf("GetFilterableEntries req{%v}\n", req)
return &s.filterableEntriesReply, nil
}

func (s *server) GetAll(ctx context.Context, req *pb.AllRequest) (*pb.AllReply, error) {
fmt.Printf("GetAll req{%v}\n", req)
return &s.allReply, nil
}

func (s *server) GetMenu(ctx context.Context, req *pb.MenuRequest) (*pb.MenuReply, error) {
fmt.Printf("GetMenu req{%v}\n", req)
return nil, status.New(codes.Unimplemented, "Unimplemented").Err()
}

func (s *server) GetFood(ctx context.Context, req *pb.FoodRequest) (*pb.FoodReply, error) {
fmt.Printf("GetFood req{%v}\n", req)
return nil, status.New(codes.Unimplemented, "Unimplemented").Err()
}

func (s *server) GetFoodStats(ctx context.Context, req *pb.FoodStatsRequest) (*pb.FoodStatsReply, error) {
fmt.Printf("GetFoodStats req{%v}\n", req)
return nil, status.New(codes.Unimplemented, "Unimplemented").Err()
}

//
// Serves GRPC requests
//
func serveGRPC(port string, server *server) {
lis, err := net.Listen("tcp", ":"+port)
if err != nil {
fmt.Printf("Failed to listen: %v\n", err)
os.Exit(1)
}
s := grpc.NewServer()

// Register server
pb.RegisterMDiningServer(s, server)

fmt.Printf("Serving GRPC Requests on %s\n", port)
if err := s.Serve(lis); err != nil {
fmt.Printf("failed to server: %v", err)
os.Exit(1)
}
}

func main() {
port := flag.String("port", "50051", "The port to serve on")
flag.Parse()
s := newserver()
serveGRPC(*port, s)
}
2 changes: 1 addition & 1 deletion proto/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
# load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("//rules:defs.bzl", "node_grpc_web_proto_library", "node_proto_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
Expand Down
19 changes: 13 additions & 6 deletions rules/proto_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@ def proto_dependencies():
)

maybe(
http_archive,
git_repository,
name = "com_github_grpc_grpc",
urls = [
"https://github.com/grpc/grpc/archive/v1.22.0.tar.gz",
],
strip_prefix = "grpc-1.22.0",
)
commit = "bd0aa9a600a13cc988c6ebfd12deab8d1abcf171",
remote = "https://github.com/grpc/grpc",
)

# maybe(
# http_archive,
# name = "com_github_grpc_grpc",
# urls = [
# "https://github.com/grpc/grpc/archive/v1.22.0.tar.gz",
# ],
# strip_prefix = "grpc-1.22.0",
# )

0 comments on commit e62c68c

Please sign in to comment.