From 25c77c56642204828310f044ac6ffe5c970c4079 Mon Sep 17 00:00:00 2001 From: henrygd Date: Wed, 11 Feb 2026 13:49:29 -0500 Subject: [PATCH] make: auto-apply glibc tag for agent on linux/amd64 glibc --- Makefile | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4d55c5ba..f072fe30 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,40 @@ OS ?= $(shell go env GOOS) ARCH ?= $(shell go env GOARCH) # Skip building the web UI if true SKIP_WEB ?= false +# Controls NVML/glibc agent build tag behavior: +# - auto (default): enable on linux/amd64 glibc hosts +# - true: always enable +# - false: always disable +NVML ?= auto + +# Detect glibc host for local linux/amd64 builds. +HOST_GLIBC := $(shell \ + if [ "$(OS)" = "linux" ] && [ "$(ARCH)" = "amd64" ]; then \ + for p in /lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /lib/ld-linux-x86-64.so.2; do \ + [ -e "$$p" ] && { echo true; exit 0; }; \ + done; \ + if command -v ldd >/dev/null 2>&1; then \ + if ldd --version 2>&1 | tr '[:upper:]' '[:lower:]' | awk '/gnu libc|glibc/{found=1} END{exit !found}'; then \ + echo true; \ + else \ + echo false; \ + fi; \ + else \ + echo false; \ + fi; \ + else \ + echo false; \ + fi) + +# Enable glibc build tag for NVML on supported Linux builds. +AGENT_GO_TAGS := +ifeq ($(NVML),true) +AGENT_GO_TAGS := -tags glibc +else ifeq ($(NVML),auto) +ifeq ($(HOST_GLIBC),true) +AGENT_GO_TAGS := -tags glibc +endif +endif # Set executable extension based on target OS EXE_EXT := $(if $(filter windows,$(OS)),.exe,) @@ -54,7 +88,7 @@ fetch-smartctl-conditional: # Update build-agent to include conditional .NET build build-agent: tidy build-dotnet-conditional fetch-smartctl-conditional - GOOS=$(OS) GOARCH=$(ARCH) go build -o ./build/beszel-agent_$(OS)_$(ARCH)$(EXE_EXT) -ldflags "-w -s" ./internal/cmd/agent + GOOS=$(OS) GOARCH=$(ARCH) go build $(AGENT_GO_TAGS) -o ./build/beszel-agent_$(OS)_$(ARCH)$(EXE_EXT) -ldflags "-w -s" ./internal/cmd/agent build-hub: tidy $(if $(filter false,$(SKIP_WEB)),build-web-ui) GOOS=$(OS) GOARCH=$(ARCH) go build -o ./build/beszel_$(OS)_$(ARCH)$(EXE_EXT) -ldflags "-w -s" ./internal/cmd/hub @@ -90,9 +124,9 @@ dev-hub: dev-agent: @if command -v entr >/dev/null 2>&1; then \ - find ./internal/cmd/agent/*.go ./agent/*.go | entr -r go run github.com/henrygd/beszel/internal/cmd/agent; \ + find ./internal/cmd/agent/*.go ./agent/*.go | entr -r go run $(AGENT_GO_TAGS) github.com/henrygd/beszel/internal/cmd/agent; \ else \ - go run github.com/henrygd/beszel/internal/cmd/agent; \ + go run $(AGENT_GO_TAGS) github.com/henrygd/beszel/internal/cmd/agent; \ fi build-dotnet: