Pārlūkot izejas kodu

Document the Linux cross-build

CGO_ENABLED=0 plus GOOS/GOARCH gives a static binary that needs no libc on
the target, so no toolchain is needed there. Verified on linux/amd64 under
Alpine: zone list, record list, dry-run and JSON output all work, and ldd
reports "not a valid dynamic program".

dist/ is ignored. The arm64 build is compiled and verified to be a valid
static ELF, but not executed — the arm64 Alpine image in the local Docker
store is broken, so it is untested at runtime.
Paul-Dieter Klumpp 1 nedēļu atpakaļ
vecāks
revīzija
a23146c8bf
2 mainītis faili ar 21 papildinājumiem un 1 dzēšanām
  1. 2 1
      .gitignore
  2. 19 0
      README.md

+ 2 - 1
.gitignore

@@ -9,8 +9,9 @@
 .opencode/package.json
 .opencode/package-lock.json
 
-# the compiled binary
+# compiled binaries
 /schlundtech-dns
+/dist/
 
 # holds the gateway password
 .env

+ 19 - 0
README.md

@@ -5,6 +5,8 @@ and set them — from the terminal, no web interface.
 
 ## Build and run
 
+On the machine you develop on:
+
 ```bash
 go build
 ./schlundtech-dns --help
@@ -19,6 +21,23 @@ go run . --help
 > Use `go build`, not `go build ./...`. With more than one package the `...`
 > form only compiles and writes nothing.
 
+### Build for a Linux server
+
+No toolchain on the target needed — the binary is pure Go and statically
+linked, so it runs on any Linux without a libc:
+
+```bash
+CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" \
+  -o dist/schlundtech-dns-linux-amd64 .
+```
+
+`GOARCH=arm64` gives you `dist/schlundtech-dns-linux-arm64`. Copy the file over
+and run it:
+
+```bash
+./schlundtech-dns-linux-amd64 --help
+```
+
 ## Configure
 
 Copy the example file and fill it in: