feat: add static linking for Linux builds using musl

Enable static linking for Linux binaries by installing musl-tools and passing appropriate LDFLAGS during build. This ensures portable, self-contained executables for Linux targets.
This commit is contained in:
Eric Coissac
2026-03-13 14:26:17 +01:00
parent 30ec8b1b63
commit 74e6fcaf83
2 changed files with 14 additions and 2 deletions

View File

@@ -62,6 +62,12 @@ jobs:
TAG=${GITHUB_REF#refs/tags/Release_} TAG=${GITHUB_REF#refs/tags/Release_}
echo "version=$TAG" >> $GITHUB_OUTPUT echo "version=$TAG" >> $GITHUB_OUTPUT
- name: Install build tools (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update -q
sudo apt-get install -y musl-tools
- name: Install build tools (macOS) - name: Install build tools (macOS)
if: runner.os == 'macOS' if: runner.os == 'macOS'
run: | run: |
@@ -74,8 +80,13 @@ jobs:
GOOS: ${{ matrix.goos }} GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }} GOARCH: ${{ matrix.goarch }}
VERSION: ${{ steps.get_version.outputs.version }} VERSION: ${{ steps.get_version.outputs.version }}
CC: ${{ matrix.goos == 'linux' && 'musl-gcc' || '' }}
run: | run: |
if [ "$GOOS" = "linux" ]; then
make LDFLAGS='-linkmode=external -extldflags=-static' obitools
else
make obitools make obitools
fi
mkdir -p artifacts mkdir -p artifacts
# Create a single tar.gz with all binaries for this platform # Create a single tar.gz with all binaries for this platform
tar -czf artifacts/obitools4_${VERSION}_${{ matrix.output_name }}.tar.gz -C build . tar -czf artifacts/obitools4_${VERSION}_${{ matrix.output_name }}.tar.gz -C build .

View File

@@ -10,8 +10,9 @@ BLUE := \033[0;34m
NC := \033[0m NC := \033[0m
GOFLAGS= GOFLAGS=
LDFLAGS=
GOCMD=go GOCMD=go
GOBUILD=$(GOCMD) build $(GOFLAGS) GOBUILD=$(GOCMD) build $(GOFLAGS) $(if $(LDFLAGS),-ldflags='$(LDFLAGS)')
GOGENERATE=$(GOCMD) generate GOGENERATE=$(GOCMD) generate
GOCLEAN=$(GOCMD) clean GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test GOTEST=$(GOCMD) test