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

add support for multiple plugins #717

Merged
merged 9 commits into from
Nov 7, 2022
Merged
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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.1
5.3.2
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/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used by goreleaser (tested it locally to ensure it built all binaries).

6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ on:
env:
# Keep these versions in sync with the Dockerfile
BDR_VER: '5.1.0'
GO_VER: '1.19.1'
PGG_VER: 'v1.27.1'
PROTOC_VER: '21.5'
GO_VER: '1.19.3'
PGG_VER: 'v1.28.1'
PROTOC_VER: '21.9'
PYTHON_VER: '3.8'
TEST_TAG: protoc-gen-validate:${{ github.sha }}

Expand Down
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was being identified as both a github workflow and a goreleaser config file in vscode - this will remove invalid flagged errors when editing this file.

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-validate-cpp/protoc-gen-validate-cpp
/cmd/protoc-gen-validate-go/protoc-gen-validate-go
/cmd/protoc-gen-validate-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 .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimized the docker build to benefit from layer caching so we don't re-download the Python dependencies if any other files change.

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/...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifies that the new commands can build w/ bazel.


.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")).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change (along with removing RegisterPostProcessor(pgsgo.GoFmt()). for non-Go generators).

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()
}
Loading