Skip to content

Commit 84e8cc5

Browse files
committed
refactor: Enable true dynamic SQLite linking and strip debug symbols
- Add -tags libsqlite3 build flag to use system SQLite - Add -w -s linker flags to strip debug symbols and reduce binary size - Update all build tasks (build, install, test, release) - Update CI/CD workflows (artifacts.yml, ci.yml) Benefits: - Binary size reduced by ~33% (39MB → 26MB on macOS) - Uses system SQLite library instead of bundled code - Better compatibility with system SQLite tools - Faster builds (no need to compile SQLite source) - Security: system SQLite gets OS security updates Requirements: - libsqlite3 must be installed at runtime - Already added to Dockerfile (sqlite-libs package) Signed-off-by: Eden Reich <[email protected]>
1 parent 13890bb commit 84e8cc5

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

.github/workflows/artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
GOARCH: ${{ matrix.goarch }}
7676
CC: ${{ matrix.goarch == 'arm64' && matrix.goos == 'linux' && 'aarch64-linux-gnu-gcc' || '' }}
7777
run: |
78-
go build -ldflags "-X github.com/inference-gateway/cli/cmd.version=${{ steps.version.outputs.version }} -X github.com/inference-gateway/cli/cmd.commit=${{ steps.version.outputs.commit }} -X github.com/inference-gateway/cli/cmd.date=${{ steps.version.outputs.date }}" -o infer-${{ matrix.goos }}-${{ matrix.goarch }} .
78+
go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version=${{ steps.version.outputs.version }} -X github.com/inference-gateway/cli/cmd.commit=${{ steps.version.outputs.commit }} -X github.com/inference-gateway/cli/cmd.date=${{ steps.version.outputs.date }}" -o infer-${{ matrix.goos }}-${{ matrix.goarch }} .
7979
8080
- name: Upload artifact
8181
uses: actions/upload-artifact@v5

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ jobs:
107107
CGO_ENABLED: 1
108108
run: |
109109
go build \
110+
-tags libsqlite3 \
110111
-ldflags "\
112+
-w -s \
111113
-X github.com/inference-gateway/cli/cmd.version=${{ github.ref_name }} \
112114
-X github.com/inference-gateway/cli/cmd.commit=${{ github.sha }} \
113115
-X github.com/inference-gateway/cli/cmd.date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
@@ -135,4 +137,4 @@ jobs:
135137
- name: Run tests
136138
env:
137139
CGO_ENABLED: 1
138-
run: go test ./...
140+
run: go test -tags libsqlite3 ./...

Taskfile.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tasks:
2525
echo "Install: build-essential (Linux) or Xcode CLI Tools (macOS)"
2626
exit 1
2727
fi
28-
- CGO_ENABLED=1 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o {{.BINARY_NAME}} {{.MAIN_PACKAGE}}
28+
- CGO_ENABLED=1 go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o {{.BINARY_NAME}} {{.MAIN_PACKAGE}}
2929
sources:
3030
- "**/*.go"
3131
- go.mod
@@ -36,7 +36,7 @@ tasks:
3636
install:
3737
desc: Install the CLI from source
3838
cmds:
39-
- CGO_ENABLED=1 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o $(go env GOPATH)/bin/{{.BINARY_NAME}} {{.MAIN_PACKAGE}}
39+
- CGO_ENABLED=1 go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o $(go env GOPATH)/bin/{{.BINARY_NAME}} {{.MAIN_PACKAGE}}
4040

4141
clean:
4242
desc: Clean build artifacts
@@ -47,17 +47,17 @@ tasks:
4747
test:
4848
desc: Run all tests
4949
cmds:
50-
- CGO_ENABLED=1 go test ./...
50+
- CGO_ENABLED=1 go test -tags libsqlite3 ./...
5151

5252
test:verbose:
5353
desc: Run tests with verbose output
5454
cmds:
55-
- CGO_ENABLED=1 go test -v ./...
55+
- CGO_ENABLED=1 go test -tags libsqlite3 -v ./...
5656

5757
test:coverage:
5858
desc: Run tests with coverage report
5959
cmds:
60-
- CGO_ENABLED=1 go test -cover ./...
60+
- CGO_ENABLED=1 go test -tags libsqlite3 -cover ./...
6161

6262
lint:
6363
desc: Run linter (requires golangci-lint)
@@ -154,10 +154,10 @@ tasks:
154154
desc: Build release binaries for multiple platforms (Linux only - macOS builds require native runners)
155155
cmds:
156156
- mkdir -p dist
157-
- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-amd64 {{.MAIN_PACKAGE}}
157+
- CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-amd64 {{.MAIN_PACKAGE}}
158158
- |
159159
if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
160-
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PACKAGE}}
160+
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PACKAGE}}
161161
else
162162
echo "⚠ ARM64 cross-compiler not found, skipping linux-arm64 build"
163163
echo " Install: gcc-aarch64-linux-gnu (or build on ARM64 machine)"
@@ -178,7 +178,7 @@ tasks:
178178
sh: go env GOARCH
179179
cmds:
180180
- mkdir -p dist
181-
- CGO_ENABLED=1 GOOS=darwin GOARCH={{.GOARCH}} go build -ldflags "-X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-darwin-{{.GOARCH}} {{.MAIN_PACKAGE}}
181+
- CGO_ENABLED=1 GOOS=darwin GOARCH={{.GOARCH}} go build -tags libsqlite3 -ldflags "-w -s -X github.com/inference-gateway/cli/cmd.version={{.VERSION}} -X github.com/inference-gateway/cli/cmd.commit={{.COMMIT}} -X github.com/inference-gateway/cli/cmd.date={{.DATE}}" -o dist/{{.BINARY_NAME}}-darwin-{{.GOARCH}} {{.MAIN_PACKAGE}}
182182

183183
container:build:
184184
desc: Build container image locally for testing

0 commit comments

Comments
 (0)