From 6e800558760cfd80025fc8ba9883ba4eccd5d7cf Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Thu, 1 Oct 2026 22:50:10 +0000 Subject: [PATCH] Remove Buildarch: read the architecture at run time (closes #83) The architecture is no longer passed in at build time. The Buildarch variable and field are gone from main and globals, script/build no longer stamps it in with -X, and the startup and listen log lines report runtime.GOARCH under the key "arch". The Dockerfile comment and backend/README.md no longer describe an architecture being stamped in. Model: opus-5-5 --- Dockerfile | 2 +- backend/README.md | 2 +- backend/cmd/netwatch-server/main.go | 6 ++---- backend/internal/globals/globals.go | 12 ++++-------- backend/internal/logger/logger.go | 3 ++- backend/internal/server/http.go | 3 ++- backend/script/build | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index d13e53e..1504805 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ RUN make test # make build is a shim around backend/script/build, the one definition # of the build command: -# CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.Version=... -X main.Buildarch=..." +# CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.Version=..." # That script reads VERSION from the environment, so it is handed over # there rather than as a make variable. ARG VERSION=dev diff --git a/backend/README.md b/backend/README.md index 9914eb0..82ca05e 100644 --- a/backend/README.md +++ b/backend/README.md @@ -32,7 +32,7 @@ pattern as the repo root: the targets in `backend/Makefile` are thin shims over `test`, `fmt` and `fmt-check`: - `script/build` — compile the static `netwatch-server` binary with its version - and architecture stamped in. The version is `VERSION` from the environment; + stamped in. The version is `VERSION` from the environment; when that is unset or empty, it falls back to `git describe` inside a git checkout, then to `dev` - `script/test` — run the Go tests under a 30-second timeout diff --git a/backend/cmd/netwatch-server/main.go b/backend/cmd/netwatch-server/main.go index 01c77a4..7410367 100644 --- a/backend/cmd/netwatch-server/main.go +++ b/backend/cmd/netwatch-server/main.go @@ -19,9 +19,8 @@ import ( //nolint:gochecknoglobals // set via ldflags at build time var ( - Appname = "netwatch-server" - Version string - Buildarch string + Appname = "netwatch-server" + Version string ) func main() { @@ -40,7 +39,6 @@ func main() { globals.Appname = Appname globals.Version = Version - globals.Buildarch = Buildarch fx.New( fx.Provide( diff --git a/backend/internal/globals/globals.go b/backend/internal/globals/globals.go index 0e3807b..c6a48a2 100644 --- a/backend/internal/globals/globals.go +++ b/backend/internal/globals/globals.go @@ -10,22 +10,18 @@ var ( Appname string // Version is the git version tag. Version string - // Buildarch is the build architecture. - Buildarch string ) // Globals holds build-time metadata for the application. type Globals struct { - Appname string - Version string - Buildarch string + Appname string + Version string } // New creates a Globals instance from package-level variables. func New(_ fx.Lifecycle) (*Globals, error) { return &Globals{ - Appname: Appname, - Buildarch: Buildarch, - Version: Version, + Appname: Appname, + Version: Version, }, nil } diff --git a/backend/internal/logger/logger.go b/backend/internal/logger/logger.go index de6c884..fb31eeb 100644 --- a/backend/internal/logger/logger.go +++ b/backend/internal/logger/logger.go @@ -5,6 +5,7 @@ package logger import ( "log/slog" "os" + "runtime" "sneak.berlin/go/netwatch/internal/globals" @@ -95,6 +96,6 @@ func (l *Logger) Identify() { l.log.Info("starting", "appname", l.params.Globals.Appname, "version", l.params.Globals.Version, - "buildarch", l.params.Globals.Buildarch, + "arch", runtime.GOARCH, ) } diff --git a/backend/internal/server/http.go b/backend/internal/server/http.go index 46f4a67..df66092 100644 --- a/backend/internal/server/http.go +++ b/backend/internal/server/http.go @@ -4,6 +4,7 @@ import ( "errors" "net" "net/http" + "runtime" "strconv" "time" @@ -53,7 +54,7 @@ func (s *Server) listenAndServe() { s.log.Info("http begin listen", "listenaddr", s.httpServer.Addr, "version", s.params.Globals.Version, - "buildarch", s.params.Globals.Buildarch, + "arch", runtime.GOARCH, ) err := s.httpServer.ListenAndServe() diff --git a/backend/script/build b/backend/script/build index 40d4d01..4f30155 100755 --- a/backend/script/build +++ b/backend/script/build @@ -1,6 +1,6 @@ #!/bin/sh # script/build: compile the static netwatch-server binary into the -# backend project root, with its version and architecture stamped in. +# backend project root, with its version stamped in. set -eu ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" @@ -14,7 +14,7 @@ main() { version="${VERSION:-$(git describe --always --dirty 2>/dev/null || echo dev)}" CGO_ENABLED=0 go build -trimpath \ - -ldflags "-s -w -X main.Version=$version -X main.Buildarch=$(uname -m)" \ + -ldflags "-s -w -X main.Version=$version" \ -o netwatch-server ./cmd/netwatch-server/ }