fix: auto-detect native deps, skip nix-shell in Docker
Some checks failed
check / check (push) Failing after 43s

Check for pkg-config at make-time; if present (Docker, existing
nix-shell) run commands directly, otherwise wrap with nix-shell.
This commit is contained in:
Jeffrey Paul 2026-02-25 20:11:02 +07:00
parent 429926fb71
commit a1c0ae0a44

View File

@ -3,8 +3,16 @@
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) # Use nix-shell to provide CGO dependencies unless they are already available
NIX_SHELL := nix-shell -p pkg-config vips libheif golangci-lint git --run # (e.g. inside a Docker build or an existing nix-shell).
HAS_PKGCONFIG := $(shell command -v pkg-config 2>/dev/null)
ifdef HAS_PKGCONFIG
NIX_RUN_PREFIX =
NIX_RUN_SUFFIX =
else
NIX_RUN_PREFIX = nix-shell -p pkg-config vips libheif golangci-lint git --run '
NIX_RUN_SUFFIX = '
endif
# Default target: run all checks # Default target: run all checks
check: fmt-check lint test check: fmt-check lint test
@ -22,17 +30,17 @@ fmt:
# Run linter # Run linter
lint: lint:
@echo "Running linter..." @echo "Running linter..."
$(NIX_SHELL) "golangci-lint run" $(NIX_RUN_PREFIX)golangci-lint run$(NIX_RUN_SUFFIX)
# Run tests (30-second timeout) # Run tests (30-second timeout)
test: test:
@echo "Running tests..." @echo "Running tests..."
$(NIX_SHELL) "CGO_ENABLED=1 go test -timeout 30s -v ./..." $(NIX_RUN_PREFIX)CGO_ENABLED=1 go test -timeout 30s -v ./...$(NIX_RUN_SUFFIX)
# Build the binary # Build the binary
build: build:
@echo "Building pixad..." @echo "Building pixad..."
$(NIX_SHELL) "CGO_ENABLED=1 go build -ldflags '$(LDFLAGS)' -o ./bin/pixad ./cmd/pixad" $(NIX_RUN_PREFIX)CGO_ENABLED=1 go build -ldflags "$(LDFLAGS)" -o ./bin/pixad ./cmd/pixad$(NIX_RUN_SUFFIX)
# Clean build artifacts # Clean build artifacts
clean: clean: