From 4dbe8b1558e88dd4840f0ad67ab675c58df8fc8d Mon Sep 17 00:00:00 2001 From: Alessio Date: Sun, 9 Jun 2024 14:33:25 -0700 Subject: [PATCH] Make the CI actually not use static linking of libc --- build/build_dpkg.sh | 5 ++++- cmd/compile.sh | 16 ++++++++++++++-- cmd/windows-compile.sh | 5 ++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/build/build_dpkg.sh b/build/build_dpkg.sh index e82c7dd..e64a691 100755 --- a/build/build_dpkg.sh +++ b/build/build_dpkg.sh @@ -8,6 +8,9 @@ then >&2 echo "No version number provided! Exiting." exit 1 fi +version=$1 + +(cd ../cmd && ./compile.sh --static $version) # Prepare the output folder if [[ -e dpkg_tmp ]] @@ -32,7 +35,7 @@ cp Twitter.desktop dpkg_tmp/usr/share/applications/Twitter.desktop # Create the `DEBIAN/control` file mkdir dpkg_tmp/DEBIAN echo "Package: offline-twitter -Version: $1 +Version: $version Architecture: all Maintainer: alex@playfulpachyderm.com Installed-Size: `du -k dpkg_tmp | tail -n 1 | cut -f 1` diff --git a/cmd/compile.sh b/cmd/compile.sh index 4d948ad..ad6336e 100755 --- a/cmd/compile.sh +++ b/cmd/compile.sh @@ -6,13 +6,25 @@ set -e # General build flags FLAGS="-s -w -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" -if [[ -n "$1" ]]; then +# Check for the `--static` flag and consume it +USE_STATIC=false +if [[ "$1" == "--static" ]] || [[ "$1" == "-static" ]]; then + USE_STATIC=true + shift +fi + +if [[ -z "$1" ]]; then + # If no version string, it's a development build + go build -ldflags="$FLAGS" -o tw ./twitter +elif $USE_STATIC; then # Static build params export CGO_ENABLED=1 export CC=musl-gcc SPECIAL_FLAGS_FOR_STATIC_BUILD="-linkmode=external -extldflags=-static" go build -ldflags="$FLAGS $SPECIAL_FLAGS_FOR_STATIC_BUILD -X main.version_string=$1" -o tw ./twitter else - go build -ldflags="$FLAGS" -o tw ./twitter + # Version string, but not static + go build -ldflags="$FLAGS -X main.version_string=$1" -o tw ./twitter fi + chmod +x tw diff --git a/cmd/windows-compile.sh b/cmd/windows-compile.sh index 9622889..a250a46 100755 --- a/cmd/windows-compile.sh +++ b/cmd/windows-compile.sh @@ -13,4 +13,7 @@ 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" -o twitter.exe ./twitter +# Always use static build for windows +FLAGS="-s -w -X gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver.use_embedded=true" +SPECIAL_FLAGS_FOR_STATIC_BUILD="-linkmode=external -extldflags=-static" +go build -ldflags="$FLAGS $SPECIAL_FLAGS_FOR_STATIC_BUILD -X main.version_string=$1" -o twitter.exe ./twitter