@@ -23,6 +23,7 @@ import (
2323 "github.com/bufbuild/buf/private/bufpkg/bufconfig"
2424 "github.com/bufbuild/buf/private/bufpkg/bufimage"
2525 "github.com/bufbuild/buf/private/bufpkg/bufplugin"
26+ "github.com/bufbuild/buf/private/pkg/pluginrpcutil"
2627 "github.com/bufbuild/buf/private/pkg/slicesext"
2728 "github.com/bufbuild/buf/private/pkg/syserror"
2829 "github.com/bufbuild/buf/private/pkg/wasm"
@@ -176,55 +177,41 @@ func WithPluginConfigs(pluginConfigs ...bufconfig.PluginConfig) ClientFunctionOp
176177
177178// RunnerProvider provides pluginrpc.Runners for a given plugin config.
178179type RunnerProvider interface {
179- NewRunner (pluginConfig bufconfig. PluginConfig ) (pluginrpc.Runner , error )
180+ NewRunner (plugin bufplugin. Plugin ) (pluginrpc.Runner , error )
180181}
181182
182183// RunnerProviderFunc is a function that implements RunnerProvider.
183- type RunnerProviderFunc func (pluginConfig bufconfig. PluginConfig ) (pluginrpc.Runner , error )
184+ type RunnerProviderFunc func (plugin bufplugin. Plugin ) (pluginrpc.Runner , error )
184185
185186// NewRunner implements RunnerProvider.
186187//
187188// RunnerProvider selects the correct Runner based on the type of pluginConfig.
188- func (r RunnerProviderFunc ) NewRunner (pluginConfig bufconfig. PluginConfig ) (pluginrpc.Runner , error ) {
189- return r (pluginConfig )
189+ func (r RunnerProviderFunc ) NewRunner (plugin bufplugin. Plugin ) (pluginrpc.Runner , error ) {
190+ return r (plugin )
190191}
191192
192- // NewLocalRunnerProvider returns a new RunnerProvider for the wasm.Runtime and
193- // the given plugin providers.
193+ // NewLocalRunnerProvider returns a new RunnerProvider to invoke plugins locally.
194194//
195195// This implementation should only be used for local applications. It is safe to
196196// use concurrently.
197197//
198- // The RunnerProvider selects the correct Runner based on the PluginConfigType.
199- // The supported types are:
200- // - bufconfig.PluginConfigTypeLocal
201- // - bufconfig.PluginConfigTypeLocalWasm
202- // - bufconfig.PluginConfigTypeRemoteWasm
198+ // The RunnerProvider selects the correct Runner based on the Plugin:
199+ // - Local plugins will be run with pluginrpcutil.NewLocalRunner.
200+ // - Local Wasm plugins will be run with pluginrpcutil.NewWasmRunner.
201+ // - Remote Wasm plugins will be run with pluginrpcutil.NewWasmRunner.
203202//
204- // If the PluginConfigType is not supported, an error is returned.
203+ // If the plugin type is not supported, an error is returned.
205204// To disable support for Wasm plugins, set wasmRuntime to wasm.UnimplementedRuntime.
206- // To disable support for bufconfig.PluginConfigTypeRemoteWasm Plugins, set
207- // pluginKeyProvider and pluginDataProvider to bufplugin.NopPluginKeyProvider
208- // and bufplugin.NopPluginDataProvider.
209- func NewLocalRunnerProvider (
210- wasmRuntime wasm.Runtime ,
211- pluginKeyProvider bufplugin.PluginKeyProvider ,
212- pluginDataProvider bufplugin.PluginDataProvider ,
213- ) RunnerProvider {
214- return newRunnerProvider (
215- wasmRuntime ,
216- pluginKeyProvider ,
217- pluginDataProvider ,
218- )
205+ func NewLocalRunnerProvider (wasmRuntime wasm.Runtime ) RunnerProvider {
206+ return newLocalRunnerProvider (wasmRuntime )
219207}
220208
221209// NewClient returns a new Client.
222210func NewClient (
223211 logger * slog.Logger ,
224- runnerProvider RunnerProvider ,
225212 options ... ClientOption ,
226213) (Client , error ) {
227- return newClient (logger , runnerProvider , options ... )
214+ return newClient (logger , options ... )
228215}
229216
230217// ClientOption is an option for a new Client.
@@ -239,6 +226,47 @@ func ClientWithStderr(stderr io.Writer) ClientOption {
239226 }
240227}
241228
229+ // ClientWithRunnerProvider returns a new ClientOption that specifies a RunnerProvider.
230+ //
231+ // The runnerProvider is used to create pluginrpc.Runners for the plugins.
232+ // By default, only builtin plugins are used.
233+ func ClientWithRunnerProvider (runnerProvider RunnerProvider ) ClientOption {
234+ return func (clientOptions * clientOptions ) {
235+ clientOptions .runnerProvider = runnerProvider
236+ }
237+ }
238+
239+ // ClientWithLocalWasmPlugins returns a new ClientOption that specifies reading Wasm plugins.
240+ //
241+ // The readBucket is used to read the Wasm plugin data from the filesystem.
242+ func ClientWithLocalWasmPlugins (readFile func (string ) ([]byte , error )) ClientOption {
243+ return func (clientOptions * clientOptions ) {
244+ clientOptions .pluginReadFile = readFile
245+ }
246+ }
247+
248+ // ClientWithLocalWasmPluginsFromOS returns a new ClientOption that specifies reading Wasm plugins
249+ // from the OS.
250+ //
251+ // This is only used for local applications.
252+ func ClientWithLocalWasmPluginsFromOS () ClientOption {
253+ return func (clientOptions * clientOptions ) {
254+ clientOptions .pluginReadFile = pluginrpcutil .ReadWasmFileFromOS
255+ }
256+ }
257+
258+ // ClientWithRemoteWasmPlugins returns a new ClientOption that specifies the remote plugin key
259+ // and data providers.
260+ func ClientWithRemoteWasmPlugins (
261+ pluginKeyProvider bufplugin.PluginKeyProvider ,
262+ pluginDataProvider bufplugin.PluginDataProvider ,
263+ ) ClientOption {
264+ return func (clientOptions * clientOptions ) {
265+ clientOptions .pluginKeyProvider = pluginKeyProvider
266+ clientOptions .pluginDataProvider = pluginDataProvider
267+ }
268+ }
269+
242270// PrintRules prints the rules to the Writer.
243271func PrintRules (writer io.Writer , rules []Rule , options ... PrintRulesOption ) (retErr error ) {
244272 return printRules (writer , rules , options ... )
0 commit comments