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 local Wasm plugins #3349

Merged
merged 50 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6cd7178
Init support for WASM plugins
emcfarlane Sep 23, 2024
a17f1c1
Remove custom look path
emcfarlane Sep 30, 2024
58c9e6f
Fix test
emcfarlane Sep 30, 2024
ccdb801
Fix test
emcfarlane Sep 30, 2024
1fb09fe
Fix test
emcfarlane Sep 30, 2024
4084811
Use Wasm abbr
emcfarlane Sep 30, 2024
cc42495
Fix description
emcfarlane Oct 1, 2024
5cd84ca
Move RunnerProvider to bufpluginrunner pkg
emcfarlane Oct 1, 2024
0b4321b
Rename Plugin to CompiledModule
emcfarlane Oct 1, 2024
ce2c42a
Use tracer
emcfarlane Oct 2, 2024
8ef1070
Unimplemented as var
emcfarlane Oct 2, 2024
fa26987
Move wasm pkg
emcfarlane Oct 2, 2024
9429c87
move to bufpluginrpcutil
emcfarlane Oct 2, 2024
9634e9d
Fixes
emcfarlane Oct 2, 2024
3498241
use wasmruntime cache dir
emcfarlane Oct 2, 2024
767897e
doc RunnerProvider config
emcfarlane Oct 2, 2024
a69da63
fix wasm args
emcfarlane Oct 2, 2024
87676c0
cleanup wasm module docs
emcfarlane Oct 2, 2024
e42f48d
fix bufconfig
emcfarlane Oct 2, 2024
88ffcb7
fix naming
emcfarlane Oct 2, 2024
85c7fbc
fix banimports
emcfarlane Oct 2, 2024
6a45022
Merge branch 'main' into ed/pluginWASM
emcfarlane Oct 2, 2024
41f8127
fix pluginrpcutil
emcfarlane Oct 2, 2024
2be37aa
fix doc
emcfarlane Oct 2, 2024
0aacd54
fix once
emcfarlane Oct 2, 2024
a073aed
add changelog
emcfarlane Oct 2, 2024
e3c329d
fix docs
emcfarlane Oct 2, 2024
e1c589b
doc wasm cache
emcfarlane Oct 2, 2024
f035402
Fix runtime options
emcfarlane Oct 2, 2024
4e161a6
fix naming to Close
emcfarlane Oct 2, 2024
cec3d6d
fix var names
emcfarlane Oct 2, 2024
64764cc
fix unimplemented
emcfarlane Oct 2, 2024
75fe87e
fix changelog
emcfarlane Oct 2, 2024
a5e1c43
fix commandRunner naming
emcfarlane Oct 2, 2024
799658a
fix delegate
emcfarlane Oct 2, 2024
41705f9
clarify args
emcfarlane Oct 2, 2024
4bfc10c
use filepath.Ext
emcfarlane Oct 2, 2024
d09ddbf
expand doc on limits
emcfarlane Oct 2, 2024
2fc5bf6
doc instantiation
emcfarlane Oct 2, 2024
1415eea
fix see docs
emcfarlane Oct 2, 2024
dc11fe5
doc memory page limits
emcfarlane Oct 2, 2024
086a6ce
note about size restriction
emcfarlane Oct 2, 2024
6ab5dcb
fix
emcfarlane Oct 2, 2024
5e8e9d9
doc limits
emcfarlane Oct 2, 2024
1866ce1
fix Runtime
emcfarlane Oct 2, 2024
ef0d8a8
fix closed
emcfarlane Oct 2, 2024
6c4030a
fix doc
emcfarlane Oct 2, 2024
bf634a5
move unimplemented runtime
emcfarlane Oct 3, 2024
423e044
fix global var position
emcfarlane Oct 3, 2024
ef1a275
Merge branch 'main' into ed/pluginWASM
emcfarlane Oct 3, 2024
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/tetratelabs/wazero v1.8.0
go.lsp.dev/jsonrpc2 v0.10.0
go.lsp.dev/protocol v0.12.0
go.opentelemetry.io/otel v1.30.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
2 changes: 2 additions & 0 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ GO_TEST_BINS := $(GO_TEST_BINS) \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-rpc-ext \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-category \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-duplicate-rule
GO_TEST_WASM_BINS := $(GO_TEST_WASM_BINS) \
private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix
GO_MOD_VERSION := 1.22
DOCKER_BINS := $(DOCKER_BINS) buf
FILE_IGNORES := $(FILE_IGNORES) \
Expand Down
18 changes: 17 additions & 1 deletion make/go/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GO_BINS ?=
# Settable
GO_TEST_BINS ?=
# Settable
GO_TEST_WASM_BINS ?=
# Settable
GO_GET_PKGS ?=
# Settable
GO_MOD_VERSION ?= 1.21
Expand Down Expand Up @@ -142,7 +144,7 @@ build: prebuild ## Run go build.
pretest::

.PHONY: test
test: pretest installtest ## Run all go tests.
test: pretest installtest installtestwasm ## Run all go tests.
go test $(GO_TEST_FLAGS) $(GOPKGS)

.PHONY: testrace
Expand Down Expand Up @@ -203,3 +205,17 @@ endef

$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval $(call gotestbinfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))

.PHONY: installtestwasm
installtestwasm::

define gotestwasmfunc
.PHONY: installtestwasm$(notdir $(1))
installtestwasm$(notdir $(1)):
GOOS=wasip1 GOARCH=wasm go build -o $(GOBIN)/$(notdir $(1)).wasm ./$(1)

installtestwasm:: installtestwasm$(notdir $(1))
endef

$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval $(call gotestwasmfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))
15 changes: 15 additions & 0 deletions private/buf/bufcli/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ var (
//
// Normalized.
v3CacheModuleLockRelDirPath = normalpath.Join("v3", "modulelocks")
// v3CachePluginsRelDirPath is the relative path to the plugins cache directory in its newest iteration.
Copy link
Member

Choose a reason for hiding this comment

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

This documentation isn't really accurate. If you dive down into the code, it appears you are passing this to the bufwasm.Runtime, which then happens to use this as a cache for some WASM compilation that is happening. Given the naming, and the documentation here, I would expect this to be a cache of downloaded plugins from the BSR, which it is not. This is effectively an implementation-specific cache.

This should be v3/wasmruntime or the like, whatever makes sense, and the documentation should reflect what this is specifically used for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed and updated the docs to the v3/wasmruntime dir.

//
// Normalized.
v3CachePluginsRelDirPath = normalpath.Join("v3", "plugins")
)

// NewModuleDataProvider returns a new ModuleDataProvider while creating the
Expand Down Expand Up @@ -135,6 +139,17 @@ func NewCommitProvider(container appext.Container) (bufmodule.CommitProvider, er
)
}

// CreatePluginCacheDir creates the cache directory for plugins.
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem correct. See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to CreateWasmRuntimeCacheDir.

//
// This is used by the [bufwasm.WithLocalCacheDir] option.
Copy link
Member

Choose a reason for hiding this comment

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

Is the [] something that Godoc picks up? If not, we don't use it anywhere else. If so, good to know!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed [] use. It is supported in Godoc as a link but must be imported, so here it didn't link correctly.

func CreatePluginCacheDir(container appext.Container) (string, error) {
if err := createCacheDir(container.CacheDirPath(), v3CachePluginsRelDirPath); err != nil {
return "", err
}
fullCacheDirPath := normalpath.Join(container.CacheDirPath(), v3CachePluginsRelDirPath)
return fullCacheDirPath, nil
}

// newWKTStore returns a new bufwktstore.Store while creating the required cache directories.
func newWKTStore(container appext.Container) (bufwktstore.Store, error) {
if err := createCacheDir(container.CacheDirPath(), v3CacheWKTRelDirPath); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion private/buf/buflsp/buflsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufctl"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/storage"
Expand Down Expand Up @@ -58,7 +59,12 @@ func Serve(
}

tracer := tracing.NewTracer(container.Tracer())
checkClient, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(container.Stderr()))
checkClient, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(command.NewRunner()),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion private/buf/bufmigrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/slicesext"
Expand Down Expand Up @@ -712,7 +713,7 @@ func equivalentCheckConfigInV2(
) (bufconfig.CheckConfig, error) {
// No need for custom lint/breaking plugins since there's no plugins to migrate from <=v1.
// TODO: If we ever need v3, then we will have to deal with this.
client, err := bufcheck.NewClient(logger, tracer, bufcheck.NewRunnerProvider(runner))
client, err := bufcheck.NewClient(logger, tracer, bufpluginrunner.NewRunnerProvider(runner))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion private/buf/cmd/buf/buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
imagev1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/image/v1"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appcmd/appcmdtesting"
Expand Down Expand Up @@ -1349,7 +1350,7 @@ func TestCheckLsBreakingRulesFromConfigExceptDeprecated(t *testing.T) {
t.Run(version.String(), func(t *testing.T) {
t.Parallel()
// Do not need any custom lint/breaking plugins here.
client, err := bufcheck.NewClient(zap.NewNop(), tracing.NopTracer, bufcheck.NewRunnerProvider(command.NewRunner()))
client, err := bufcheck.NewClient(zap.NewNop(), tracing.NopTracer, bufpluginrunner.NewRunnerProvider(command.NewRunner()))
require.NoError(t, err)
allRules, err := client.AllRules(context.Background(), check.RuleTypeBreaking, version)
require.NoError(t, err)
Expand Down
24 changes: 22 additions & 2 deletions private/buf/cmd/buf/command/breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/bufpkg/bufwasm"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/stringutil"
"github.com/bufbuild/buf/private/pkg/tracing"
"github.com/spf13/pflag"
"go.uber.org/multierr"
)

const (
Expand Down Expand Up @@ -145,7 +148,7 @@ func run(
ctx context.Context,
container appext.Container,
flags *flags,
) error {
) (retErr error) {
if err := bufcli.ValidateRequiredFlag(againstFlagName, flags.Against); err != nil {
return err
}
Expand Down Expand Up @@ -206,10 +209,27 @@ func run(
len(againstImageWithConfigs),
)
}
pluginCacheDir, err := bufcli.CreatePluginCacheDir(container)
if err != nil {
return err
}
wasmRuntime, err := bufwasm.NewRuntime(ctx, bufwasm.WithLocalCacheDir(pluginCacheDir))
if err != nil {
return err
}
defer func() { retErr = multierr.Append(retErr, wasmRuntime.Release(ctx)) }()
tracer := tracing.NewTracer(container.Tracer())
var allFileAnnotations []bufanalysis.FileAnnotation
for i, imageWithConfig := range imageWithConfigs {
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(container.Stderr()))
client, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(
command.NewRunner(),
bufpluginrunner.RunnerProviderWithWasmRuntime(wasmRuntime),
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion private/buf/cmd/buf/command/config/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
Expand Down Expand Up @@ -185,7 +186,12 @@ func lsRun(
}
}
tracer := tracing.NewTracer(container.Tracer())
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(container.Stderr()))
client, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(command.NewRunner()),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
return err
}
Expand Down
25 changes: 24 additions & 1 deletion private/buf/cmd/buf/command/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"github.com/bufbuild/buf/private/buf/bufctl"
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/bufpkg/bufwasm"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/stringutil"
"github.com/bufbuild/buf/private/pkg/tracing"
"github.com/spf13/pflag"
"go.uber.org/multierr"
)

const (
Expand Down Expand Up @@ -131,10 +134,30 @@ func run(
if err != nil {
return err
}
pluginCacheDir, err := bufcli.CreatePluginCacheDir(container)
if err != nil {
return err
}
wasmRuntime, err := bufwasm.NewRuntime(
ctx,
bufwasm.WithLocalCacheDir(pluginCacheDir),
)
if err != nil {
return err
}
defer func() { retErr = multierr.Append(retErr, wasmRuntime.Release(ctx)) }()
tracer := tracing.NewTracer(container.Tracer())
var allFileAnnotations []bufanalysis.FileAnnotation
for _, imageWithConfig := range imageWithConfigs {
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(container.Stderr()))
client, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(
command.NewRunner(),
bufpluginrunner.RunnerProviderWithWasmRuntime(wasmRuntime),
),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion private/buf/cmd/buf/command/mod/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
Expand Down Expand Up @@ -175,7 +176,11 @@ func lsRun(
}
// BufYAMLFiles <=v1 never had plugins.
tracer := tracing.NewTracer(container.Tracer())
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(container.Stderr()))
client, err := bufcheck.NewClient(
container.Logger(), tracer,
bufpluginrunner.NewRunnerProvider(command.NewRunner()),
bufcheck.ClientWithStderr(container.Stderr()),
)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion private/buf/cmd/protoc-gen-buf-breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/protodescriptor"
Expand Down Expand Up @@ -125,7 +126,12 @@ func handle(
}
// The protoc plugins do not support custom lint/breaking change plugins for now.
tracer := tracing.NewTracer(container.Tracer())
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(pluginEnv.Stderr))
client, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(command.NewRunner()),
bufcheck.ClientWithStderr(pluginEnv.Stderr),
)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion private/buf/cmd/protoc-gen-buf-lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufanalysis"
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/encoding"
"github.com/bufbuild/buf/private/pkg/protodescriptor"
Expand Down Expand Up @@ -100,7 +101,12 @@ func handle(
}
// The protoc plugins do not support custom lint/breaking change plugins for now.
tracer := tracing.NewTracer(container.Tracer())
client, err := bufcheck.NewClient(container.Logger(), tracer, bufcheck.NewRunnerProvider(command.NewRunner()), bufcheck.ClientWithStderr(pluginEnv.Stderr))
client, err := bufcheck.NewClient(
container.Logger(),
tracer,
bufpluginrunner.NewRunnerProvider(command.NewRunner()),
bufcheck.ClientWithStderr(pluginEnv.Stderr),
)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion private/bufpkg/bufcheck/breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufcheck"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufpluginrunner"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/bufbuild/buf/private/pkg/tracing"
Expand Down Expand Up @@ -1347,7 +1348,7 @@ func testBreaking(
require.NoError(t, err)
breakingConfig := workspace.GetBreakingConfigForOpaqueID(opaqueID)
require.NotNil(t, breakingConfig)
client, err := bufcheck.NewClient(zap.NewNop(), tracing.NopTracer, bufcheck.NewRunnerProvider(command.NewRunner()))
client, err := bufcheck.NewClient(zap.NewNop(), tracing.NopTracer, bufpluginrunner.NewRunnerProvider(command.NewRunner()))
require.NoError(t, err)
err = client.Breaking(
ctx,
Expand Down
20 changes: 0 additions & 20 deletions private/bufpkg/bufcheck/bufcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"buf.build/go/bufplugin/check"
"github.com/bufbuild/buf/private/bufpkg/bufconfig"
"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/pluginrpcutil"
"github.com/bufbuild/buf/private/pkg/slicesext"
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/bufbuild/buf/private/pkg/tracing"
Expand Down Expand Up @@ -169,24 +167,6 @@ func (r RunnerProviderFunc) NewRunner(pluginConfig bufconfig.PluginConfig) (plug
return r(pluginConfig)
}

// NewRunnerProvider returns a new RunnerProvider for the command.Runner.
func NewRunnerProvider(delegate command.Runner) RunnerProvider {
return RunnerProviderFunc(
func(pluginConfig bufconfig.PluginConfig) (pluginrpc.Runner, error) {
if pluginConfig.Type() != bufconfig.PluginConfigTypeLocal {
return nil, syserror.New("only local plugins are supported")
}
path := pluginConfig.Path()
return pluginrpcutil.NewRunner(
delegate,
// We know that Path is of at least length 1.
path[0],
path[1:]...,
), nil
},
)
}

// NewClient returns a new Client.
func NewClient(
logger *zap.Logger,
Expand Down
Loading