Skip to content

Commit

Permalink
add support for multiple plugins
Browse files Browse the repository at this point in the history
Instead of requiring a 'lang' option to be specified, create separate
binaries configured to output code for a given language.
  • Loading branch information
pkwarren committed Nov 4, 2022
1 parent 353096c commit e6f0693
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 149 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git/
.idea/
.bin/
dist/
2 changes: 2 additions & 0 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: goreleaser

on:
Expand All @@ -19,6 +20,7 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
use-latest: true
cache: true
- uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
java-version: "17"
distribution: "temurin"

cache: "maven"
- name: Verify with Maven
working-directory: ${{ github.workspace }}/java
run: mvn -B verify
1 change: 1 addition & 0 deletions .github/workflows/maven-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: sonatype-nexus-snapshots
server-username: ${ env.SONATYPE_USER }
server-password: ${ env.SONATYPE_PASSWORD }
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ bazel-*
!vendor/*

/bin
/cmd/protoc-gen-cpp/protoc-gen-validate-cpp
/cmd/protoc-gen-go/protoc-gen-validate-go
/cmd/protoc-gen-java/protoc-gen-validate-java
/dist/
/protoc-gen-validate

/python/LICENSE
Expand Down
14 changes: 14 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
builds:
- main: .
id: "protoc-gen-validate"
binary: "protoc-gen-validate"
- main: ./cmd/protoc-gen-validate-cpp
id: "protoc-gen-validate-cpp"
binary: "protoc-gen-validate-cpp"
- main: ./cmd/protoc-gen-validate-go
id: "protoc-gen-validate-go"
binary: "protoc-gen-validate-go"
- main: ./cmd/protoc-gen-validate-java
id: "protoc-gen-validate-java"
binary: "protoc-gen-validate-java"

release:
# If set to true, will not auto-publish the release.
# Available only for GitHub and Gitea.
Expand Down
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@ RUN apt update \
&& apt clean

# bazel
ENV BAZEL_VER=5.3.1
RUN wget -O bazel https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VER}/bazel-${BAZEL_VER}-linux-$([ $(uname -m) = "aarch64" ] && echo "arm64" || echo "x86_64") \
ENV BAZEL_VER=5.3.2
RUN wget -q -O bazel https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VER}/bazel-${BAZEL_VER}-linux-$([ $(uname -m) = "aarch64" ] && echo "arm64" || echo "x86_64") \
&& chmod +x bazel \
&& mv bazel usr/local/bin/bazel

# protoc
ENV PROTOC_VER=21.5
ENV PROTOC_VER=21.9
RUN export PROTOC_REL=protoc-${PROTOC_VER}-linux-$([ $(uname -m) = "aarch64" ] && echo "aarch" || echo "x86")_64.zip \
&& wget https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/${PROTOC_REL} \
&& wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/${PROTOC_REL} \
&& unzip ${PROTOC_REL} -d protoc \
&& mv protoc /usr/local \
&& ln -s /usr/local/protoc/bin/protoc /usr/local/bin
&& ln -s /usr/local/protoc/bin/protoc /usr/local/bin \
&& rm ${PROTOC_REL}

# go
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH
RUN export GORELEASE=go1.19.1.linux-$([ $(uname -m) = "aarch64" ] && echo "arm64" || echo "amd64").tar.gz \
RUN export GORELEASE=go1.19.3.linux-$([ $(uname -m) = "aarch64" ] && echo "arm64" || echo "amd64").tar.gz \
&& wget -q https://dl.google.com/go/$GORELEASE \
&& tar -C $(dirname $GOROOT) -xzf $GORELEASE \
&& rm $GORELEASE \
&& mkdir -p $GOPATH/{src,bin,pkg}

# protoc-gen-go
ENV PGG_VER=v1.27.1
ENV PGG_VER=v1.28.1
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@${PGG_VER} \
&& rm -rf $(go env GOCACHE) \
&& rm -rf $(go env GOMODCACHE)
Expand All @@ -60,17 +61,19 @@ RUN go install github.com/bazelbuild/buildtools/buildozer@${BDR_VER} \
&& rm -rf $(go env GOCACHE) \
&& rm -rf $(go env GOMODCACHE)

WORKDIR ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate
COPY . .

# python must be on PATH for the execution of py_binary bazel targets, but
# the distribution we installed doesn't provide this alias
RUN ln -s /usr/bin/python3.8 /usr/bin/python

WORKDIR ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate

# python tooling for linting and uploading to PyPI
COPY requirements.txt .
RUN python3.8 -m easy_install pip \
&& python3.8 -m pip install -r requirements.txt

COPY . .

RUN make build

ENTRYPOINT ["make"]
Expand Down
107 changes: 0 additions & 107 deletions Gopkg.lock

This file was deleted.

15 changes: 0 additions & 15 deletions Gopkg.toml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build: validate/validate.pb.go ## generates the PGV binary and installs it into

.PHONY: bazel
bazel: ## generate the PGV plugin with Bazel
bazel build //tests/...
bazel build //cmd/... //tests/...

.PHONY: build_generation_tests
build_generation_tests:
Expand Down Expand Up @@ -53,7 +53,7 @@ bin/golint:
GOBIN=$(shell pwd)/bin go install golang.org/x/lint/golint

bin/protoc-gen-go:
GOBIN=$(shell pwd)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
GOBIN=$(shell pwd)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1

bin/harness:
cd tests && go build -o ../bin/harness ./harness/executor
Expand Down
2 changes: 1 addition & 1 deletion bazel/dependency_imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _pgv_pip_dependencies():
def _pgv_go_dependencies():
go_rules_dependencies()
go_register_toolchains(
version = "1.19.1",
version = "1.19.3",
)
gazelle_dependencies()

Expand Down
29 changes: 29 additions & 0 deletions cmd/protoc-gen-validate-cpp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:prefix github.com/envoyproxy/protoc-gen-validate
# gazelle:exclude tests
# gazelle:exclude example-workspace
# gazelle:exclude validate/validate.h
# gazelle:go_naming_convention import_alias
gazelle(name = "gazelle")

go_binary(
name = "protoc-gen-validate-cpp",
embed = [":protoc-gen-validate-cpp_lib"],
importpath = "github.com/envoyproxy/protoc-gen-validate/cmd/protoc-gen-validate-cpp",
visibility = ["//visibility:public"],
)

go_library(
name = "protoc-gen-validate-cpp_lib",
srcs = ["main.go"],
importpath = "github.com/envoyproxy/protoc-gen-validate/cmd/protoc-gen-validate-cpp",
visibility = ["//visibility:private"],
deps = [
"//module",
"@com_github_lyft_protoc_gen_star//:protoc-gen-star",
"@com_github_lyft_protoc_gen_star//lang/go",
"@org_golang_google_protobuf//types/pluginpb",
],
)
15 changes: 15 additions & 0 deletions cmd/protoc-gen-validate-cpp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"github.com/envoyproxy/protoc-gen-validate/module"
pgs "github.com/lyft/protoc-gen-star"
"google.golang.org/protobuf/types/pluginpb"
)

func main() {
optional := uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
pgs.
Init(pgs.DebugEnv("DEBUG_PGV"), pgs.SupportedFeatures(&optional)).
RegisterModule(module.ValidatorForLanguage("cc")).
Render()
}
29 changes: 29 additions & 0 deletions cmd/protoc-gen-validate-go/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

# gazelle:prefix github.com/envoyproxy/protoc-gen-validate
# gazelle:exclude tests
# gazelle:exclude example-workspace
# gazelle:exclude validate/validate.h
# gazelle:go_naming_convention import_alias
gazelle(name = "gazelle")

go_binary(
name = "protoc-gen-validate-go",
embed = [":protoc-gen-validate-go_lib"],
importpath = "github.com/envoyproxy/protoc-gen-validate/cmd/protoc-gen-validate-go",
visibility = ["//visibility:public"],
)

go_library(
name = "protoc-gen-validate-go_lib",
srcs = ["main.go"],
importpath = "github.com/envoyproxy/protoc-gen-validate/cmd/protoc-gen-validate-go",
visibility = ["//visibility:private"],
deps = [
"//module",
"@com_github_lyft_protoc_gen_star//:protoc-gen-star",
"@com_github_lyft_protoc_gen_star//lang/go",
"@org_golang_google_protobuf//types/pluginpb",
],
)
17 changes: 17 additions & 0 deletions cmd/protoc-gen-validate-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"github.com/envoyproxy/protoc-gen-validate/module"
pgs "github.com/lyft/protoc-gen-star"
pgsgo "github.com/lyft/protoc-gen-star/lang/go"
"google.golang.org/protobuf/types/pluginpb"
)

func main() {
optional := uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
pgs.
Init(pgs.DebugEnv("DEBUG_PGV"), pgs.SupportedFeatures(&optional)).
RegisterModule(module.ValidatorForLanguage("go")).
RegisterPostProcessor(pgsgo.GoFmt()).
Render()
}

0 comments on commit e6f0693

Please sign in to comment.