diff --git a/CHANGELOG.md b/CHANGELOG.md index b197b40..8f61ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v0.4.3] - 2022-04-20 (Beta) + +## Fixes + +- Version [v0.4.2][v0.4.2] did not embed the templates for RPC generation into frisbee, leading to runtime panics when + generating RPC frameworks from outside the frisbee repository directory. This has now been fixed by embedding the + templates into the compiled plugin binary file. + ## [v0.4.2] - 2022-04-20 (Beta) ## Changes @@ -219,7 +227,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Initial Release of Frisbee -[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.4.2...HEAD +[unreleased]: https://github.com/loopholelabs/frisbee/compare/v0.4.3...HEAD +[v0.4.3]: https://github.com/loopholelabs/frisbee/compare/v0.4.2...v0.4.3 [v0.4.2]: https://github.com/loopholelabs/frisbee/compare/v0.4.1...v0.4.2 [v0.4.1]: https://github.com/loopholelabs/frisbee/compare/v0.4.0...v0.4.1 [v0.4.0]: https://github.com/loopholelabs/frisbee/compare/v0.3.2...v0.4.0 diff --git a/go.mod b/go.mod index 28a321d..7b37713 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/loopholelabs/frisbee -go 1.15 +go 1.16 require ( github.com/loopholelabs/testing v0.2.3 diff --git a/protoc-gen-frisbee/dockerfile b/protoc-gen-frisbee/dockerfile index cb2571f..df77a8b 100644 --- a/protoc-gen-frisbee/dockerfile +++ b/protoc-gen-frisbee/dockerfile @@ -2,7 +2,7 @@ FROM golang as builder ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=0 -RUN go install github.com/loopholelabs/frisbee/protoc-gen-frisbee@v0.4.1 +RUN go install github.com/loopholelabs/frisbee/protoc-gen-frisbee@v0.4.3 # Note, the Docker images must be built for amd64. If the host machine architecture is not amd64 # you need to cross-compile the binary and move it into /go/bin. @@ -12,7 +12,7 @@ FROM scratch # Runtime dependencies LABEL "build.buf.plugins.runtime_library_versions.0.name"="github.com/loopholelabs/frisbee" -LABEL "build.buf.plugins.runtime_library_versions.0.version"="v0.4.1" +LABEL "build.buf.plugins.runtime_library_versions.0.version"="v0.4.3" COPY --from=builder /go/bin / diff --git a/protoc-gen-frisbee/pkg/generator/generator.go b/protoc-gen-frisbee/pkg/generator/generator.go index f348698..4e07bf7 100644 --- a/protoc-gen-frisbee/pkg/generator/generator.go +++ b/protoc-gen-frisbee/pkg/generator/generator.go @@ -19,6 +19,7 @@ package generator import ( "github.com/loopholelabs/frisbee/protoc-gen-frisbee/internal/utils" "github.com/loopholelabs/frisbee/protoc-gen-frisbee/internal/version" + "github.com/loopholelabs/frisbee/protoc-gen-frisbee/templates" "google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/pluginpb" @@ -29,6 +30,27 @@ type Generator struct { options *protogen.Options } +var templ *template.Template + +func init() { + templ = template.Must(template.New("main").Funcs(template.FuncMap{ + "CamelCase": utils.CamelCaseFullName, + "CamelCaseName": utils.CamelCaseName, + "MakeIterable": utils.MakeIterable, + "Counter": utils.Counter, + "FirstLowerCase": utils.FirstLowerCase, + "FirstLowerCaseName": utils.FirstLowerCaseName, + "FindValue": findValue, + "GetKind": getKind, + "GetLUTEncoder": getLUTEncoder, + "GetLUTDecoder": getLUTDecoder, + "GetEncodingFields": getEncodingFields, + "GetDecodingFields": getDecodingFields, + "GetKindLUT": getKindLUT, + "GetServerFields": getServerFields, + }).ParseFS(templates.FS, "*")) +} + func New() *Generator { return &Generator{ options: &protogen.Options{ @@ -53,23 +75,6 @@ func (g *Generator) Generate(req *pluginpb.CodeGeneratorRequest) (res *pluginpb. return nil, err } - templ := template.Must(template.New("main").Funcs(template.FuncMap{ - "CamelCase": utils.CamelCaseFullName, - "CamelCaseName": utils.CamelCaseName, - "MakeIterable": utils.MakeIterable, - "Counter": utils.Counter, - "FirstLowerCase": utils.FirstLowerCase, - "FirstLowerCaseName": utils.FirstLowerCaseName, - "FindValue": findValue, - "GetKind": getKind, - "GetLUTEncoder": getLUTEncoder, - "GetLUTDecoder": getLUTDecoder, - "GetEncodingFields": getEncodingFields, - "GetDecodingFields": getDecodingFields, - "GetKindLUT": getKindLUT, - "GetServerFields": getServerFields, - }).ParseGlob("protoc-gen-frisbee/templates/*")) - for _, f := range plugin.Files { if !f.Generate { continue diff --git a/protoc-gen-frisbee/templates/templates.go b/protoc-gen-frisbee/templates/templates.go new file mode 100644 index 0000000..fa88068 --- /dev/null +++ b/protoc-gen-frisbee/templates/templates.go @@ -0,0 +1,22 @@ +/* + Copyright 2022 Loophole Labs + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package templates + +import "embed" + +//go:embed * +var FS embed.FS