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

A few changes needed to support go-libvirt #164

Merged
merged 3 commits into from Feb 26, 2024

Conversation

mpontillo
Copy link
Contributor

At DigitalOcean, we are using c-for-go for our go-libvirt project.

Two breaking changes have occurred recently, which are preventing us from using c-for-go to generate the necessary constants:

(1) In libvirt itself, header files were switched from using double-quotes (#include "foo.h") to using brackets (#include <foo.h>). Because these were self-referencing headers (intended for eventual placement on the system include path on the target system), this resulted in the inability of c-for-go to find libvirt's own headers. We resolved this by adding the ability to configure the system include path, such (in our case) by specifying SysIncludePaths: [./lv_source/include, ./lv_source/build/include] in the configuration.

(2) In c-for-go, an update of the cc dependency to v4 caused a change in the way enums were handled. For context, although c-for-go correctly treats C enumerations as being of type int, the libvirt code contains two enum usages where their values are used for bit fields, and explicitly declared as unsigned 32-bit values. This causes c-for-go to generate incorrect code (because the integer value 2147483648, which comes from 1u << 31, could not fit into a signed 32-bit field). This was resolved by adding the concept of enum type tips and unsigned type tips (TipTypeUnsigned), such as (in our case) by declaring the following in the configuration:

    TypeTips:
        enum:
            - { target: "ConnectGetAllDomainStatsFlags", tips: [ unsigned ] }
            - { target: "ConnectListAllNodeDeviceFlags", tips: [ unsigned ] }

We have been testing these changes successfully in our digitalocean-labs/c-for-go fork, and hope you will consider applying them to the official version.

@xlab
Copy link
Owner

xlab commented Feb 26, 2024

@mpontillo thank you very much for coming up with these battlefield tested changes and actually publishing this as a PR to upstream! I'm glad that c-for-go helps and community makes it better in return :)

I'll merge these changes, at some point when having time will update the Wiki to have those tips.

@xlab xlab merged commit 850240e into xlab:master Feb 26, 2024
@mpontillo mpontillo deleted the do--upstreamable-changes branch February 27, 2024 01:10
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.

None yet

2 participants