probonopd / go-appimage

Go implementation of AppImage tools
MIT License
680 stars 69 forks source link

Allow to statically link Go programs, even with cgo #203

Closed probonopd closed 2 years ago

probonopd commented 2 years ago

Statically compile Go programs, even with cgo, using musl libc, like this:

wget -c -q http://www.musl-libc.org/releases/musl-1.1.10.tar.gz
tar -xvf musl-*.tar.gz
cd musl-*/
./configure
make -j4
sudo make install
CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' hello.go

Credits: https://honnef.co/posts/2015/06/statically_compiled_go_programs__always__even_with_cgo__using_musl/

We can probably get around compiling musl libc by using an Alpine Linux container rather than an Ubuntu one in the first place.

probonopd commented 2 years ago

Tradeoff: Using musl libc may result in us being unable to use mDNS/Zeroconf. So possibly we may not want to use it for appimaged.

mDNS and alternate hostname database backends The inability to use mDNS (a multicast-DNS-based zero config system) with musl has been raised as an issue by users in the past. On glibc, using mDNS is accomplished with NSS; obviously musl does not have (or want) NSS.

In principle, however, musl is fully extensible to use alternate hostname database backends in place of normal DNS. All that’s needed is a daemon that runs on localhost, speaks DNS, and translates the requests to whatever backend is needed. However it’s unclear whether there are any existing tools of this form. Developing one, adapting an existing DNS proxy program, or documenting how to setup an existing program that’s already capable could be a nice future project.

probonopd commented 2 years ago

Continued in https://github.com/probonopd/go-appimage/pull/207