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

RegisterSchema once per golang package #490 #544

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

davidhubbard
Copy link
Collaborator

Fixes #490 by only generating one RegisterSchema() function per $Go.package().

For example, the unit tests persistent-simple.capnp and persistent-samepkg.capnp now both have the annotation:

$Go.package("persistent_simple");

Their generated go code thus starts with:

package persistent_simple

but only one of them will include a RegisterSchema().

capnpc-go/capnpc-go.go Outdated Show resolved Hide resolved
capnpc-go/capnpc-go.go Outdated Show resolved Hide resolved
Fixes capnproto#490
by only generating one `RegisterSchema()` function per `$Go.package()`.

For example, the unit tests persistent-simple.capnp and
persistent-samepkg.capnp now both have the annotation:

`$Go.package("persistent_simple");`

Their generated go code thus starts with:

`package persistent_simple`

but only one of them will include a `RegisterSchema()`.

Note: if `capnp` is invoked with only one .capnp file at a time on its command
line, `capnpc-go` will not detect any *other* .capnp files that might have the
same $Go.package. For that use case, the user might be able to cope by running
`capnpc -o - persistent-simple.capnp | capnpc-go --forceschemasalways` and
editing the generated code to rename all but one `RegisterSchema()` and
add calls to the renamed code inside the one remainig `RegisterSchema()`...
though that is not a supported solution.

e.g. Use this:

`capnpc -o go persistent-simple.capnp persistent-samepkg.capnp`

Because the following will fail to compile due to duplicate `RegisterSchema()`
definitions:

```
capnpc -o go persistent-simple.capnp
capnpc -o go persistent-samepkg.capnp
```
@davidhubbard davidhubbard merged commit 2a85fea into capnproto:main Sep 11, 2023
0 of 4 checks passed
@davidhubbard davidhubbard deleted the issue-490 branch September 11, 2023 13:34
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

Successfully merging this pull request may close these issues.

Generator can create duplicate RegisterSchema functions
2 participants