distributable:
  url: https://github.com/grpc/grpc-go/archive/refs/tags/{{version.tag}}.tar.gz
  strip-components: 1

versions:
  github: grpc/grpc-go

provides:
  - bin/protoc-gen-go-grpc

dependencies:
  google.com/protobuf-go: ^1

companions:
  protobuf.dev: '*'
  go.dev: '*'

build:
  dependencies:
    go.dev: ^1.19
  working-directory: cmd/protoc-gen-go-grpc
  script:
    - go mod download
    - go build -v -trimpath -ldflags="$GO_LDFLAGS" -o $BUILDLOC .
  env:
    BUILDLOC: '{{prefix}}/bin/protoc-gen-go-grpc'
    GO_LDFLAGS:
      - -s
      - -w
    linux:
      GO_LDFLAGS:
        - -buildmode=pie

test:
  - run: cp $FIXTURE test.proto
    fixture: |
      syntax = "proto3";

      option go_package = "./test";
      option java_multiple_files = true;
      option java_package = "io.grpc.examples.helloworld";
      option java_outer_classname = "HelloWorldProto";

      package helloworld;

      service Greeter {
        rpc SayHello (HelloRequest) returns (HelloReply) {}
      }

      message HelloRequest {
        string name = 1;
      }

      message HelloReply {
        string message = 1;
      }
  - protoc --go_out=. --go-grpc_out=. test.proto
  - grep 'package test' test/test_grpc.pb.go
