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.
This commit is contained in:
14
Makefile
14
Makefile
@@ -3,6 +3,9 @@
|
|||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
LDFLAGS := -X main.Version=$(VERSION)
|
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
|
# Default target: run all checks
|
||||||
check: fmt-check lint test
|
check: fmt-check lint test
|
||||||
|
|
||||||
@@ -19,19 +22,17 @@ fmt:
|
|||||||
# Run linter
|
# Run linter
|
||||||
lint:
|
lint:
|
||||||
@echo "Running linter..."
|
@echo "Running linter..."
|
||||||
golangci-lint run
|
$(NIX_SHELL) "golangci-lint run"
|
||||||
|
|
||||||
# Run tests (30-second timeout)
|
# Run tests (30-second timeout)
|
||||||
test:
|
test:
|
||||||
@echo "Running tests..."
|
@echo "Running tests..."
|
||||||
go test -timeout 30s -v ./...
|
$(NIX_SHELL) "CGO_ENABLED=1 go test -timeout 30s -v ./..."
|
||||||
|
|
||||||
# Build the binary
|
# Build the binary
|
||||||
build: ./bin/pixad
|
build:
|
||||||
|
|
||||||
./bin/pixad: ./internal/*/*.go ./cmd/pixad/*.go ./internal/static/* ./internal/templates/*
|
|
||||||
@echo "Building pixad..."
|
@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 build artifacts
|
||||||
clean:
|
clean:
|
||||||
@@ -62,6 +63,5 @@ devserver-stop:
|
|||||||
# Install pre-commit hook
|
# Install pre-commit hook
|
||||||
hooks:
|
hooks:
|
||||||
@printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit
|
@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
|
@printf 'make check\n' >> .git/hooks/pre-commit
|
||||||
@chmod +x .git/hooks/pre-commit
|
@chmod +x .git/hooks/pre-commit
|
||||||
|
|||||||
Reference in New Issue
Block a user