veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.22k stars 222 forks source link

Using as a Go module breaks static linkage #391

Closed jclc closed 5 years ago

jclc commented 5 years ago

I'm trying out the static build tag and I'm getting this:

# github.com/veandco/go-sdl2/sdl
/usr/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lSDL2_windows_amd64
/usr/lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lSDL2main_windows_amd64

Contents of the module directory:

[go-sdl2@v0.3.1-0.20190223112835-174578a60025]$ ls
BREAKING.md  CONTRIBUTING.md  gfx          img      make.bat  raster     sdl
BSDmakefile  CONTRIBUTORS.md  GNUmakefile  LICENSE  mix       README.md  ttf

So the git submodule with SDL2 binaries isn't being downloaded. This seems logical to me, since it is in a different repository (I don't think Go fetches git submodules as part of Go modules?). Moving the binaries into a subdirectory in this repository might fix this.

veeableful commented 5 years ago

Hi @jclc, I'm not familiar with the Go modules yet but could you see if the sub-module directory is there via ls -a? If it's there but not initialized, you could try running git submodule update --init in the go-sdl2 directory and try again.

I'm not sure if we should put the static libraries into the main repository though. I fear that the size will increase too much. It is already at 36M and each version update may double the size.

jclc commented 5 years ago

I'm an idiot, forgot the -a flag. But still no submodules. Also, the module directory isn't a git repository so I can't download the submodules either (tried that earlier).

I'm not sure if we should put the static libraries into the main repository though. I fear that the size will increase too much.

This seems pretty common with cgo packages. They could be split into their respective packages, eg. libSDL2_image_*.a in go-sdl2/img/ and so on. I don't consider the extra space requirement to be a huge issue, you'd be downloading the binaries anyway. Doesn't really matter if they're in the same repository or not.

Another option could be to make both this and go-sdl2-libs Go modules (definitely a good idea to do that anyway; just run go mod init <module name> and commit go.mod and go.sum). Then, add go-sdl2-libs as a dependency for go-sdl2 and import the package containing the libs whenever static is enabled. This might get really convoluted, though, and I'm not even sure if it would work.

It is already at 36M and each version update may double the size.

Why would updating double the size?

veeableful commented 5 years ago

Also, the module directory isn't a git repository so I can't download the sub-modules either (tried that earlier).

Ahh that's too bad. I guess since it's not a git repository, it should be fine to include the static libraries here then.

This seems pretty common with cgo packages. They could be split into their respective packages, eg. libSDL2_image_*.a in go-sdl2/img/ and so on. I don't consider the extra space requirement to be a huge issue, you'd be downloading the binaries anyway. Doesn't really matter if they're in the same repository or not.

Hmm I suppose you're right.. If you're not in a hurry, I'll get it done later this week (probably this Saturday when I have my morning breakfast in the cafe 😌). But let me know if you need it ASAP. I'll make time for it!

I'll create a PR and ask @gen2brain for his comments when it's done as he's a lot more experienced than me..

Why would updating double the size?

This only applies to the git repository. I believe compression doesn't work as well on binaries. I've seen some repository that has binaries updated once in a while and it grew to a very large size. If I'm not mistaken, the repository size usually increases by a large portion of the size of all binaries for every update.

jclc commented 5 years ago

No rush :)

veeableful commented 5 years ago

Hi @jclc, I have merged the static libraries into the repository so you should have no problem building with the Module system now using the master branch like this:

go get -v github.com/veandco/go-sdl2/sdl@master

Let me know if this solves your problem!

jclc commented 5 years ago

Yep, works like a charm now!