Skip to content

How to generate stub.go files with proper imports? #333

@vsivsi

Description

@vsivsi

The provided example project that shows how to use custom types in avo generated asm functions depends on using a handcrafted stub.go file that is not overwritten by using a -stubs parameter.

It would be a very handy minor change to be able to specify one or more import statements to insert in generated stubs so that large/complex stub files don't need to be hand maintained as the example requires.

I'm imagining something like:

//go:build ignore
// +build ignore

package main

import . "github.com/mmcloughlin/avo/build"

func main() {
	Package("github.com/mmcloughlin/avo/examples/ext")
	Import("github.com/mmcloughlin/avo/examples/ext/ext")  // <-- Specify where type(s) defined

	TEXT("StructFieldB", NOSPLIT, "func(e ext.Struct) byte")
	Doc("StructFieldB returns field B.")
	b := Load(Param("e").Field("B"), GP8())
	Store(b, ReturnIndex(0))
	RET()
	Generate()
}

Which could then generate with: //go:generate go run asm.go -out ext.s -stubs stub.go and generate a corresponding stub:

// Code generated by command: go run asm.go -out ext.s -stubs stub.go. DO NOT EDIT.

package ext

import "github.com/mmcloughlin/avo/examples/ext/ext"

// StructFieldB returns field B.
func StructFieldB(e ext.Struct) byte

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions