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

Go | Docker | Build static binary using musl C library #35

Open
atc0005 opened this issue Oct 7, 2020 · 2 comments
Open

Go | Docker | Build static binary using musl C library #35

atc0005 opened this issue Oct 7, 2020 · 2 comments

Comments

@atc0005
Copy link
Owner

atc0005 commented Oct 7, 2020

Modified Makefile build command (using spaces here vs required tabs in the actual Makefile):

BUILDCMD = go build -mod=vendor -tags 'osusergo,netgo,sqlite_omit_load_extension' -a -ldflags "-extldflags '-static' -s -w -X $(VERSION_VAR_PKG).version=$(VERSION)"

This is for a cgo-enabled project which uses the https://github.com/mattn/go-sqlite3 package.

$ docker run --rm -it -v $PWD:$PWD -w $PWD --rm i386/golang:alpine3.12 /bin/sh
# apk update
# apk add make bash util-linux nano git gcc musl-dev file
# make all && rm release_assets/*/*.sha256 && file release_assets/*/*

This allowed building both x86 and x64 binaries, whereas if I tried to use the standard golang:alpine3.12 container I was unable to cross-compile both x86 and x64 binaries.

This is all from an Ubuntu 18.04 LTS VM with Docker CE installed.

@atc0005
Copy link
Owner Author

atc0005 commented Oct 8, 2020

For building a project that uses the mattn/go-sqlite3 package, I found that I needed to use mingw-w64 to build the Windows binaries. This required installation of the mingw-w64-gcc package to obtain these binaries:

  • i686-w64-mingw32
  • x86_64-w64-mingw32-gcc

Worth noting:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant