xgo is a great Go CGO cross compiler that can help users to build the application written in Golang to multi-platforms at the same time.
For more information in details, please check out these URLs:
https://github.com/karalabe/xgo
https://www.jianshu.com/p/a6047d3f976e
But, without any further study, we probably cannot understand how it works well. So here I just give some information about it. I will use my Github repository as the example:
Then, we finish the cross-compilation for my application
And actually, xgo, this tool, is based on its prebuilt docker image: "karalabe/xgo-latest" to complete the cross-compilation task. We can check the dockerhub for it as well: https://hub.docker.com/r/karalabe/xgo-latest/builds
So, we can directly run this Docker Image to cross-compile my application based on my case as follows:
Furthermore, we can directly run xgo's build.sh to cross-compile my application in the host instead of in in the container:
Reference:
Golang 交叉编译
Golang交叉编译各个平台的二进制文件
Fyne Cross Compile