digitalocean / go-libvirt

Package libvirt provides a pure Go interface for interacting with Libvirt. Apache 2.0 Licensed.
Apache License 2.0
947 stars 131 forks source link

cannot use 2147483648 (untyped int constant) as * value in constant declaration (overflows) #186

Closed maybe32 closed 1 year ago

maybe32 commented 1 year ago

My environment:

ubuntu:20.04
go version go1.20.1 linux/amd64
c-for-go@v0.0.0-20221118134302-231d72d2aa87
goyacc@c6776771dde7a49828feb54fd8be11695a32b558

After running "go generate ./...", libvirt.yaml is processed successfully but failing for processing protocol file. 2147483648 is larger than MAX_INT32 which is 2147483647. I have following questions:

  1. Is const.gen.go generated automatically?
  2. Could you please tell me the versions of OS/GO/c-for-go/goyacc/libvirt on your environment?

The log is below:

go generate ./...
go: downloading golang.org/x/tools v0.6.0
go: downloading golang.org/x/sys v0.5.0
  processing libvirt.yml done.
protocol file processing
  processing src/remote/remote_protocol.x
../../const.gen.go:1161:72: cannot use 2147483648 (untyped int constant) as ConnectGetAllDomainStatsFlags value in constant declaration (overflows)
../../const.gen.go:2128:72: cannot use 2147483648 (untyped int constant) as ConnectListAllNodeDeviceFlags value in constant declaration (overflows)
panic: failed to load package:  couldn't load packages due to errors: const

goroutine 1 [running]:
github.com/digitalocean/go-libvirt/internal/lvgen.mapFlagTypes()
    /root/go-libvirt/internal/lvgen/generate.go:459 +0x3fb
github.com/digitalocean/go-libvirt/internal/lvgen.procLink()
    /root/go-libvirt/internal/lvgen/generate.go:420 +0x2e
github.com/digitalocean/go-libvirt/internal/lvgen.Generate({0xc0000b0109, 0xf}, {0x6ea908, 0xc00009a050})
    /root/go-libvirt/internal/lvgen/generate.go:257 +0x17e
main.processProto({0xc0000b00f0, 0x2a})
    /root/go-libvirt/internal/lvgen/gen/main.go:60 +0x248
main.main()
    /root/go-libvirt/internal/lvgen/gen/main.go:41 +0x217
exit status 2
internal/lvgen/lv-gen.go:29: running "go": exit status 1
connorkuehl commented 1 year ago

What version/git SHA of libvirt are you generating against?

I'm not experiencing your specific error, but a different error after upgrading my version of c-for-go.

c-for-go cef5ec7833f3274488b3edd519f46ddfb57d5735 is the last version of c-for-go that works for me:

$ LIBVIRT_SOURCE=/home/ckuehl/src/libvirt go generate ./...
  processing libvirt.yml done.
protocol file processing
  processing src/remote/remote_protocol.x
  processing src/remote/qemu_protocol.x
$ echo $?
0

Starting at c-for-go c95ebd03aba931e7248a6011f86d822ab878d00c, this is the error I get:

$ LIBVIRT_SOURCE=/home/ckuehl/src/libvirt go generate ./...
  processing libvirt.yml ⠋[ERR] lv_source/include/libvirt/libvirt.h:34:11: include file not found: <libvirt/libvirt-common.h>
lv_source/include/libvirt/libvirt.h:35:11: include file not found: <libvirt/libvirt-host.h>
lv_source/include/libvirt/libvirt.h:36:11: include file not found: <libvirt/libvirt-domain.h>
lv_source/include/libvirt/libvirt.h:37:11: include file not found: <libvirt/libvirt-domain-checkpoint.h>
lv_source/include/libvirt/libvirt.h:38:11: include file not found: <libvirt/libvirt-domain-snapshot.h>
lv_source/include/libvirt/libvirt.h:39:11: include file not found: <libvirt/libvirt-event.h>
lv_source/include/libvirt/libvirt.h:40:11: include file not found: <libvirt/libvirt-interface.h>
lv_source/include/libvirt/libvirt.h:41:11: include file not found: <libvirt/libvirt-network.h>
lv_source/include/libvirt/libvirt.h:42:11: include file not found: <libvirt/libvirt-nodedev.h>
lv_source/include/libvirt/libvirt.h:43:11: include file not found: <libvirt/libvirt-nwfilter.h>
lv_source/include/libvirt/libvirt.h:44:11: include file not found: <libvirt/libvirt-secret.h>
lv_source/include/libvirt/libvirt.h:45:11: include file not found: <libvirt/libvirt-storage.h>
lv_source/include/libvirt/libvirt.h:46:11: include file not found: <libvirt/libvirt-stream.h>
c-for-go failed
libvirt.go:19: running "scripts/gen-consts.sh": exit status 1
protocol file processing
  processing src/remote/remote_protocol.x
  processing src/remote/qemu_protocol.x
$ echo $?
1
maybe32 commented 1 year ago

Hi connorkuehl, Thank you so much for your reply! c-for-go cef5ec7833f3274488b3edd519f46ddfb57d5735 works for me and version/git SHA of libvirt on my environment is d427102fbd690cb2f43dbf33751cc5194a5b16ce.

My working environment is below:

ubuntu:20.04
go version go1.20.1 linux/amd64
c-for-go@cef5ec7833f3274488b3edd519f46ddfb57d5735
goyacc@c6776771dde7a49828feb54fd8be11695a32b558
libvirt d427102fbd690cb2f43dbf33751cc5194a5b16ce
maybe32 commented 1 year ago
$ LIBVIRT_SOURCE=/home/ckuehl/src/libvirt go generate ./...
  processing libvirt.yml ⠋[ERR] lv_source/include/libvirt/libvirt.h:34:11: include file not found: <libvirt/libvirt-common.h>
lv_source/include/libvirt/libvirt.h:35:11: include file not found: <libvirt/libvirt-host.h>
lv_source/include/libvirt/libvirt.h:36:11: include file not found: <libvirt/libvirt-domain.h>
lv_source/include/libvirt/libvirt.h:37:11: include file not found: <libvirt/libvirt-domain-checkpoint.h>
lv_source/include/libvirt/libvirt.h:38:11: include file not found: <libvirt/libvirt-domain-snapshot.h>
lv_source/include/libvirt/libvirt.h:39:11: include file not found: <libvirt/libvirt-event.h>
lv_source/include/libvirt/libvirt.h:40:11: include file not found: <libvirt/libvirt-interface.h>
lv_source/include/libvirt/libvirt.h:41:11: include file not found: <libvirt/libvirt-network.h>
lv_source/include/libvirt/libvirt.h:42:11: include file not found: <libvirt/libvirt-nodedev.h>
lv_source/include/libvirt/libvirt.h:43:11: include file not found: <libvirt/libvirt-nwfilter.h>
lv_source/include/libvirt/libvirt.h:44:11: include file not found: <libvirt/libvirt-secret.h>
lv_source/include/libvirt/libvirt.h:45:11: include file not found: <libvirt/libvirt-storage.h>
lv_source/include/libvirt/libvirt.h:46:11: include file not found: <libvirt/libvirt-stream.h>
c-for-go failed
libvirt.go:19: running "scripts/gen-consts.sh": exit status 1
protocol file processing
  processing src/remote/remote_protocol.x
  processing src/remote/qemu_protocol.x
$ echo $?
1

I also meet this error and resolve this by building libvirt and install as following:

meson setup build
ninja -C build install
maybe32 commented 1 year ago

I run code generators through docker and my steps are below. Hope this can be helpful for others.

sudo docker run -it ubuntu:20.04 bash
apt-get update
apt-get install git python3 python3-pip python3-setuptools python3-wheel ninja-build libxml2-utils xsltproc libglib2.0 libgnutls28-dev libxml2-dev wget -y
pip3 install meson docutils

cd /root
git clone https://github.com/libvirt/libvirt.git
cd /root/libvirt
meson setup build
ninja -C build install

wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz
export GOPATH=/root/go
export PATH=$PATH:/root/go/bin:/usr/local/go/bin
export LIBVIRT_SOURCE=/root/libvirt/

cd /root
git clone https://github.com/digitalocean/go-libvirt.git
cd /root/go-libvirt
go install github.com/xlab/c-for-go@cef5ec7833f3274488b3edd519f46ddfb57d5735 
go install golang.org/x/tools/cmd/goyacc@c6776771dde7a49828feb54fd8be11695a32b558
go generate ./...