Statically link libc (musl) so the binaries are fully portable

This commit is contained in:
Alessio 2024-05-27 14:50:57 -07:00
parent 8c9fb06e52
commit fc08fb0be4
3 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,6 @@
from ubuntu:jammy
run apt update && apt install -y sudo curl wget build-essential sqlite3 jq git
run apt update && apt install -y sudo curl wget build-essential sqlite3 jq git musl-dev musl-tools
# Install go and golangci-lint
run wget https://go.dev/dl/go1.20.4.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz

View File

@ -3,9 +3,14 @@
set -x
set -e
export CGO_ENABLED=1
export CC=musl-gcc
FLAGS="-s -w -linkmode=external -extldflags=-static -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true"
if [[ -n "$1" ]]; then
go build -ldflags="-s -w -X main.version_string=$1 -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" -o tw ./twitter
go build -ldflags="$FLAGS -X main.version_string=$1" -o tw ./twitter
else
go build -ldflags="-s -w -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" -o tw ./twitter
go build -ldflags="$FLAGS" -o tw ./twitter
fi
chmod +x tw

View File

@ -13,4 +13,4 @@ if [[ -z "$1" ]]; then
exit 1
fi
go build -ldflags="-linkmode external -extldflags -static -s -w -X main.version_string=$1 -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" -buildvcs=false -o twitter.exe ./twitter
go build -ldflags="-linkmode external -extldflags -static -s -w -X main.version_string=$1 -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" -o twitter.exe ./twitter