Skip to content

Commit

Permalink
prevent creating rust bindings if they're not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Sep 17, 2024
1 parent 67093d4 commit 4200375
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 14 additions & 6 deletions cmd/substreams/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 9 additions & 3 deletions codegen/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4200375

Please sign in to comment.