Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vsivsi opened this issue Nov 4, 2022 · 0 comments
Open

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

vsivsi opened this issue Nov 4, 2022 · 0 comments

Comments

@vsivsi
Copy link
Contributor

vsivsi commented Nov 4, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant