From 42003751844d783224a4a97d5577ed5fe9f1af20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Tue, 17 Sep 2024 16:06:04 -0400 Subject: [PATCH] prevent creating rust bindings if they're not needed --- cmd/substreams/build.go | 20 ++++++++++++++------ codegen/helpers.go | 12 +++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/substreams/build.go b/cmd/substreams/build.go index a96a5d6a..7ba5fb88 100644 --- a/cmd/substreams/build.go +++ b/cmd/substreams/build.go @@ -60,7 +60,9 @@ func runBuildE(cmd *cobra.Command, args []string) error { Manifest: manif, } - protoBuilder, err := newProtoBuilder(info) + binaryLabel := sflags.MustGetString(cmd, "binary") + + protoBuilder, err := newProtoBuilder(info, binaryLabel) if err != nil { return fmt.Errorf("error creating proto builder: %w", err) } @@ -69,8 +71,6 @@ func runBuildE(cmd *cobra.Command, args []string) error { return fmt.Errorf("error running protogen: %w", err) } - binaryLabel := sflags.MustGetString(cmd, "binary") - binaryBuilder, err := newBinaryBuilder(info, binaryLabel) if err != nil { return fmt.Errorf("error creating binary builder: %w", err) @@ -125,16 +125,24 @@ type manifestInfo struct { } type ProtoBuilder struct { - manifInfo *manifestInfo + manifInfo *manifestInfo + binaryLabel string } -func newProtoBuilder(manifInfo *manifestInfo) (*ProtoBuilder, error) { +func newProtoBuilder(manifInfo *manifestInfo, binaryLabel string) (*ProtoBuilder, error) { return &ProtoBuilder{ - manifInfo: manifInfo, + manifInfo: manifInfo, + binaryLabel: binaryLabel, }, nil } func (p *ProtoBuilder) Build(ctx context.Context) error { + + if len(p.manifInfo.Manifest.Binaries) == 0 || !strings.HasPrefix(p.manifInfo.Manifest.Binaries[p.binaryLabel].Type, "wasm/rust-v1") { + fmt.Println("Notice: No binaries found of type `wasm/rust-v1`, not generating rust bindings...") + return nil + } + excludes := strings.Join(p.manifInfo.Manifest.Protobuf.ExcludePaths, ",") if excludes == "" { fmt.Printf("Notice: No exclude paths found:\n") diff --git a/codegen/helpers.go b/codegen/helpers.go index e3058bbc..5e51af22 100644 --- a/codegen/helpers.go +++ b/codegen/helpers.go @@ -126,9 +126,15 @@ func buildGenerateCommandFromArgs(manifestPath string, outputType OutputType, wi moduleNames = append(moduleNames, module.Name) } - selectedModule, err := createSelectForm(moduleNames, "Please select a mapper module to build the subgraph from:") - if err != nil { - return fmt.Errorf("creating request module form: %w", err) + var selectedModule string + if len(moduleNames) == 1 { + selectedModule = moduleNames[0] + fmt.Printf("\nThe substreams module %q will be used as output.\n\n", selectedModule) + } else { + selectedModule, err = createSelectForm(moduleNames, "Please select a mapper module to build the subgraph from:") + if err != nil { + return fmt.Errorf("creating request module form: %w", err) + } } requestedModule, err := getModule(pkg, selectedModule)