Skip to content

Commit

Permalink
Add new cmake registry type (#3156)
Browse files Browse the repository at this point in the history
This adds a new registry type and config for cmake to the protobuf
definitions. It also adds the plumbing for using this config for remote
plugins.

Note that the registry config struct is intentionally empty since Cmake
does not necessitate any sort of registry config (at least currently).
  • Loading branch information
smaye81 authored Jul 16, 2024
1 parent b13657b commit afb50e1
Show file tree
Hide file tree
Showing 12 changed files with 1,280 additions and 876 deletions.
14 changes: 14 additions & 0 deletions private/buf/cmd/buf/command/registry/sdk/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ func run(
return err
}
version = nugetVersionResponse.Msg.Version
case registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_CMAKE:
cmakeVersionResponse, err := resolveServiceClient.GetCmakeVersion(
ctx,
connect.NewRequest(
&registryv1alpha1.GetCmakeVersionRequest{
ModuleReference: moduleReference,
PluginReference: pluginReference,
},
),
)
if err != nil {
return err
}
version = cmakeVersionResponse.Msg.Version
default:
return syserror.Newf("unknown PluginRegistryType: %v", pluginRegistryType)
}
Expand Down
24 changes: 24 additions & 0 deletions private/bufpkg/bufremoteplugin/bufremoteplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func PluginToProtoPluginRegistryType(plugin Plugin) registryv1alpha1.PluginRegis
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_CARGO
case registry.Nuget != nil:
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_NUGET
case registry.Cmake != nil:
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_CMAKE
}
}
return registryType
Expand Down Expand Up @@ -214,6 +216,12 @@ func PluginRegistryToProtoRegistryConfig(pluginRegistry *bufremotepluginconfig.R
return nil, err
}
registryConfig.RegistryConfig = &registryv1alpha1.RegistryConfig_NugetConfig{NugetConfig: nugetConfig}
case pluginRegistry.Cmake != nil:
cmakeConfig, err := CmakeRegistryConfigToProtoCmakeConfig(pluginRegistry.Cmake)
if err != nil {
return nil, err
}
registryConfig.RegistryConfig = &registryv1alpha1.RegistryConfig_CmakeConfig{CmakeConfig: cmakeConfig}
}
return registryConfig, nil
}
Expand Down Expand Up @@ -296,6 +304,12 @@ func ProtoRegistryConfigToPluginRegistry(config *registryv1alpha1.RegistryConfig
return nil, err
}
registryConfig.Nuget = nugetConfig
case config.GetCmakeConfig() != nil:
cmakeConfig, err := ProtoCmakeConfigToCmakeRegistryConfig(config.GetCmakeConfig())
if err != nil {
return nil, err
}
registryConfig.Cmake = cmakeConfig
}
return registryConfig, nil
}
Expand Down Expand Up @@ -342,6 +356,11 @@ func ProtoNugetConfigToNugetRegistryConfig(protoConfig *registryv1alpha1.NugetCo
return config, err
}

// ProtoCmakeConfigToCmakeRegistryConfig converts protoCmakeConfig to an equivalent [*bufremotepluginconfig.CmakeRegistryConfig].
func ProtoCmakeConfigToCmakeRegistryConfig(protoCmakeConfig *registryv1alpha1.CmakeConfig) (*bufremotepluginconfig.CmakeRegistryConfig, error) {
return &bufremotepluginconfig.CmakeRegistryConfig{}, nil
}

// CargoRegistryConfigToProtoCargoConfig converts cargoConfig to an equivalent [*registryv1alpha1.CargoConfig].
func CargoRegistryConfigToProtoCargoConfig(cargoConfig *bufremotepluginconfig.CargoRegistryConfig) (*registryv1alpha1.CargoConfig, error) {
protoCargoConfig := &registryv1alpha1.CargoConfig{
Expand Down Expand Up @@ -384,6 +403,11 @@ func NugetRegistryConfigToProtoNugetConfig(nugetConfig *bufremotepluginconfig.Nu
return protoNugetConfig, nil
}

// CmakeRegistryConfigToProtoCmakeConfig converts cmakeConfig to an equivalent [*registryv1alpha1.CmakeConfig].
func CmakeRegistryConfigToProtoCmakeConfig(cmakeConfig *bufremotepluginconfig.CmakeRegistryConfig) (*registryv1alpha1.CmakeConfig, error) {
return &registryv1alpha1.CmakeConfig{}, nil
}

// ProtoPythonConfigToPythonRegistryConfig converts protoPythonConfig to an equivalent [*bufremotepluginconfig.PythonRegistryConfig].
func ProtoPythonConfigToPythonRegistryConfig(protoPythonConfig *registryv1alpha1.PythonConfig) (*bufremotepluginconfig.PythonRegistryConfig, error) {
pythonConfig := &bufremotepluginconfig.PythonRegistryConfig{
Expand Down
4 changes: 4 additions & 0 deletions private/bufpkg/bufremoteplugin/bufremoteplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestPluginToProtoPluginRegistryType(t *testing.T) {
assertPluginToPluginRegistryType(t, &bufremotepluginconfig.RegistryConfig{Python: &bufremotepluginconfig.PythonRegistryConfig{}}, registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_PYTHON)
assertPluginToPluginRegistryType(t, &bufremotepluginconfig.RegistryConfig{Cargo: &bufremotepluginconfig.CargoRegistryConfig{}}, registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_CARGO)
assertPluginToPluginRegistryType(t, &bufremotepluginconfig.RegistryConfig{Nuget: &bufremotepluginconfig.NugetRegistryConfig{}}, registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_NUGET)
assertPluginToPluginRegistryType(t, &bufremotepluginconfig.RegistryConfig{Cmake: &bufremotepluginconfig.CmakeRegistryConfig{}}, registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_CMAKE)
}

func assertPluginToPluginRegistryType(t testing.TB, config *bufremotepluginconfig.RegistryConfig, registryType registryv1alpha1.PluginRegistryType) {
Expand Down Expand Up @@ -206,6 +207,9 @@ func TestPluginRegistryRoundTrip(t *testing.T) {
},
},
})
assertPluginRegistryRoundTrip(t, &bufremotepluginconfig.RegistryConfig{
Cmake: &bufremotepluginconfig.CmakeRegistryConfig{},
})
}

func assertPluginRegistryRoundTrip(t testing.TB, config *bufremotepluginconfig.RegistryConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type RegistryConfig struct {
Python *PythonRegistryConfig
Cargo *CargoRegistryConfig
Nuget *NugetRegistryConfig
Cmake *CmakeRegistryConfig
// Options is the set of options passed into the plugin for the
// remote registry.
//
Expand Down Expand Up @@ -289,6 +290,9 @@ type NugetRegistryConfig struct {
Deps []NugetDependencyConfig
}

// CmakeRegistryConfig defines the configuration for a cmake registry.
type CmakeRegistryConfig struct{}

// ConfigOption is an optional option used when loading a Config.
type ConfigOption func(*configOptions)

Expand Down Expand Up @@ -421,6 +425,7 @@ type ExternalRegistryConfig struct {
Python *ExternalPythonRegistryConfig `json:"python,omitempty" yaml:"python,omitempty"`
Cargo *ExternalCargoRegistryConfig `json:"cargo,omitempty" yaml:"cargo,omitempty"`
Nuget *ExternalNugetRegistryConfig `json:"nuget,omitempty" yaml:"nuget,omitempty"`
Cmake *ExternalCmakeRegistryConfig `json:"cmake,omitempty" yaml:"cmake,omitempty"`
Opts []string `json:"opts,omitempty" yaml:"opts,omitempty"`
}

Expand Down Expand Up @@ -580,6 +585,9 @@ type ExternalNugetRegistryConfig struct {
Deps []ExternalNugetDependency `json:"deps,omitempty" yaml:"deps,omitempty"`
}

// ExternalCmakeRegistryConfig defines the configuration for a cmake registry.
type ExternalCmakeRegistryConfig struct{}

type externalConfigVersion struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,34 @@ func TestParsePluginConfigNugetYAML(t *testing.T) {
)
}

func TestParsePluginConfigCmakeYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "cmake", "buf.plugin.yaml"))
require.NoError(t, err)
pluginIdentity, err := bufremotepluginref.PluginIdentityForString("buf.build/grpc/cpp")
require.NoError(t, err)
depPluginRef, err := bufremotepluginref.PluginReferenceForString("buf.build/protocolbuffers/cpp:v26.1", 0)
require.NoError(t, err)
require.Equal(
t,
&Config{
Name: pluginIdentity,
PluginVersion: "v1.65.0",
Dependencies: []bufremotepluginref.PluginReference{depPluginRef},
SourceURL: "https://github.com/grpc/grpc",
Description: "Generates C++ client and server stubs for the gRPC framework.",
SPDXLicenseID: "Apache-2.0",
LicenseURL: "https://github.com/grpc/grpc/blob/v1.65.0/LICENSE",
OutputLanguages: []string{"cpp"},
Registry: &RegistryConfig{
Cmake: &CmakeRegistryConfig{},
Options: nil,
},
},
pluginConfig,
)
}

func TestParsePluginConfigOptionsYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "options", "buf.plugin.yaml"))
Expand Down
18 changes: 18 additions & 0 deletions private/bufpkg/bufremoteplugin/bufremotepluginconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
isPythonEmpty = externalRegistryConfig.Python == nil
isCargoEmpty = externalRegistryConfig.Cargo == nil
isNugetEmpty = externalRegistryConfig.Nuget == nil
isCmakeEmpty = externalRegistryConfig.Cmake == nil
)
var registryCount int
for _, isEmpty := range []bool{
Expand All @@ -105,6 +106,7 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
isPythonEmpty,
isCargoEmpty,
isNugetEmpty,
isCmakeEmpty,
} {
if !isEmpty {
registryCount++
Expand Down Expand Up @@ -184,6 +186,15 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
Nuget: nugetRegistryConfig,
Options: options,
}, nil
case !isCmakeEmpty:
cmakeRegistryConfig, err := newCmakeRegistryConfig(externalRegistryConfig.Cmake)
if err != nil {
return nil, err
}
return &RegistryConfig{
Cmake: cmakeRegistryConfig,
Options: options,
}, nil
default:
return nil, errors.New("unknown registry configuration")
}
Expand Down Expand Up @@ -470,6 +481,13 @@ func validateNugetTargetFramework(targetFramework string) error {
return nil
}

func newCmakeRegistryConfig(externalCmakeRegistryConfig *ExternalCmakeRegistryConfig) (*CmakeRegistryConfig, error) {
if externalCmakeRegistryConfig == nil {
return nil, nil
}
return &CmakeRegistryConfig{}, nil
}

func pluginIdentityForStringWithOverrideRemote(identityStr string, overrideRemote string) (bufremotepluginref.PluginIdentity, error) {
identity, err := bufremotepluginref.PluginIdentityForString(identityStr)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v1
name: buf.build/grpc/cpp
plugin_version: v1.65.0
source_url: https://github.com/grpc/grpc
description: Generates C++ client and server stubs for the gRPC framework.
deps:
- plugin: buf.build/protocolbuffers/cpp:v26.1
output_languages:
- cpp
spdx_license_id: Apache-2.0
license_url: https://github.com/grpc/grpc/blob/v1.65.0/LICENSE
registry:
cmake: {}

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

Loading

0 comments on commit afb50e1

Please sign in to comment.