-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Root capnp import not added to generated file unless struct or interface keyword is present #305
Comments
Confirming this bug
import (
schemas "capnproto.org/go/capnp/v3/schemas"
) Compared to my proto files which have structs: import (
capnp "capnproto.org/go/capnp/v3"
text "capnproto.org/go/capnp/v3/encoding/text" // not expected in my simple enum file
schemas "capnproto.org/go/capnp/v3/schemas"
) However the compiled Go code will utilize type MyEnumType_List = capnp.EnumList[MyEnumType]
func NewMyEnumType_List(s *capnp.Segment, sz int32) (MyEnumType_List, error) {
return capnp.NewEnumList[MyEnumType](s, sz)
} |
I think we should simplify this and just have the imports be inserted unconditionally; rather than try to detect whether they're needed, we should just add some dummy assignments to silence unused import warnings in case they aren't:
iirc this is what protobuf does. |
The v1.0 serializer always adds the capnp import, I thought about doing the same here in a fork, but wasn't sure if there were cases where the Code from the 1.0 Serializer fprintf(file, "import (\n")
fprintf(file, "C \"%s\"\n", go_capnproto_import) https://github.com/glycerine/go-capnproto/blob/master/capnpc-go/capnpc-go.go#L1038-L1042 The logic of generating the |
For anyone in need of a workaround, I've added this to my @sd "import \(" "import (\\n\\tcapnp \"capnproto.org/go/capnp/v3\"" $(find . -type f -iname "*.go" -exec grep -L "capnp \"capnproto.org/go/capnp/v3\"" {} \+) |
@jared-bounti Could I convince you to open a PR for this? 🙂 |
I've spent some time looking at it and unfortunately it isn't so simple. Adding the As for where the
Thus my local workaround above would need another pipe to |
Quoting Jared (2022-10-17 14:17:01)
a file with only const declarations has no use for the
capnp import. Which would then cause non-compiling Go code.
Yeah, this is why I suggested adding dummy uses of the module to silence
these errors. This avoids the need to worry about whether or not the
import is otherwise used.
|
The following schema file is compiled without the
"capnproto.org/go/capnp/v3"
import statementAdding
struct Foo{}
anywhere in the file triggers the inclusion of the missing import.The text was updated successfully, but these errors were encountered: