Skip to content
Open
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
.DS_Store
*.wasm
dist/
.direnv/
11 changes: 9 additions & 2 deletions cmd/protoc-gen-go-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ import (
func main() {
var flags flag.FlagSet
disablePbGen := flags.Bool("disable_pb_gen", false, "disable .pb.go generation")
wasmPackage := flags.String("wasm_package", "github.com/knqyf263/go-plugin/wasm", "override package that provide wasm memory management")
useGoPluginKnownTypes := flags.Bool("goplugin_known_types", true, "use go-plugin known types")
protogen.Options{ParamFunc: flags.Set}.Run(func(plugin *protogen.Plugin) error {
g, err := gen.NewGenerator(plugin)
opts := gen.Options{
UseGoPluginKnownTypes: *useGoPluginKnownTypes,
DisablePBGen: *disablePbGen,
WasmPackage: *wasmPackage,
}
g, err := gen.NewGenerator(plugin, opts)
if err != nil {
return err
}
Expand All @@ -22,7 +29,7 @@ func main() {
if !f.Generate {
continue
}
g.GenerateFiles(f, gen.Options{DisablePBGen: *disablePbGen})
g.GenerateFiles(f, opts)
}

plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "bitmagnet dev shell";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
system = system;
};
in {
formatter = pkgs.alejandra;
devShells = {
default = pkgs.mkShell {
hardeningDisable = [ "fortify" ];
packages = with pkgs; [
go
golangci-lint
protobuf
protoc-gen-go
];
};
};
});
}
11 changes: 7 additions & 4 deletions gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
wazeroSysPackage goImportPath = protogen.GoImportPath("github.com/tetratelabs/wazero/sys")
wazeroWasiPackage goImportPath = protogen.GoImportPath("github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1")

pluginWasmPackage goImportPath = protogen.GoImportPath("github.com/knqyf263/go-plugin/wasm")
pluginWasmPackage goImportPath = protogen.GoImportPath("")
)

type goImportPath interface {
Expand All @@ -90,10 +90,12 @@ type Generator struct {
}

type Options struct {
DisablePBGen bool
UseGoPluginKnownTypes bool
DisablePBGen bool
WasmPackage string
}

func NewGenerator(plugin *protogen.Plugin) (*Generator, error) {
func NewGenerator(plugin *protogen.Plugin, opts Options) (*Generator, error) {
ext := &vtgenerator.Extensions{}
featureNames := []string{"marshal", "unmarshal", "size"}

Expand All @@ -103,7 +105,7 @@ func NewGenerator(plugin *protogen.Plugin) (*Generator, error) {
}

for _, f := range plugin.Files {
if !f.Generate {
if !f.Generate || !opts.UseGoPluginKnownTypes {
continue
}

Expand Down Expand Up @@ -144,6 +146,7 @@ func replaceImport(m *protogen.Message) {
// GenerateFiles generates the contents of a .pb.go file.
func (gg *Generator) GenerateFiles(file *protogen.File, opts Options) *protogen.GeneratedFile {
f := gg.newFileInfo(file)
pluginWasmPackage = protogen.GoImportPath(opts.WasmPackage)
gg.generatePBFile(f, opts.DisablePBGen)
gg.generateHostFile(f)
gg.generatePluginFile(f)
Expand Down