From 429926fb7172fa9245c74551c667e527e2cb6ea1 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 25 Feb 2026 20:08:04 +0700 Subject: [PATCH] chore: use nix-shell for CGO-dependent Makefile targets Wrap test, lint, and build targets with nix-shell to provide pkg-config, vips, libheif, and golangci-lint automatically. --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e09733d..ce2f756 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") LDFLAGS := -X main.Version=$(VERSION) +# nix-shell wrapper for targets that need CGO dependencies (libvips, pkg-config) +NIX_SHELL := nix-shell -p pkg-config vips libheif golangci-lint git --run + # Default target: run all checks check: fmt-check lint test @@ -19,19 +22,17 @@ fmt: # Run linter lint: @echo "Running linter..." - golangci-lint run + $(NIX_SHELL) "golangci-lint run" # Run tests (30-second timeout) test: @echo "Running tests..." - go test -timeout 30s -v ./... + $(NIX_SHELL) "CGO_ENABLED=1 go test -timeout 30s -v ./..." # Build the binary -build: ./bin/pixad - -./bin/pixad: ./internal/*/*.go ./cmd/pixad/*.go ./internal/static/* ./internal/templates/* +build: @echo "Building pixad..." - go build -ldflags "$(LDFLAGS)" -o $@ ./cmd/pixad + $(NIX_SHELL) "CGO_ENABLED=1 go build -ldflags '$(LDFLAGS)' -o ./bin/pixad ./cmd/pixad" # Clean build artifacts clean: @@ -62,6 +63,5 @@ devserver-stop: # Install pre-commit hook hooks: @printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit - @printf 'go mod tidy\ngo fmt ./...\ngit diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit @printf 'make check\n' >> .git/hooks/pre-commit @chmod +x .git/hooks/pre-commit