From dc433f8dc9cfb4bd1ea7a1f5fd802ecc2b5a62ff Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 13 Feb 2025 22:15:27 +0700 Subject: [PATCH] cmd/cli: support nocgo version for upgrade command linux/amd64 have the nocgo binary to support system where standard libc missing. If the current binary is a nocgo version, "ctrld upgrade" command must honor the nocgo setting and download the right binary. --- cmd/cli/cgo.go | 5 +++++ cmd/cli/cli.go | 5 +++++ cmd/cli/nocgo.go | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 cmd/cli/cgo.go create mode 100644 cmd/cli/nocgo.go diff --git a/cmd/cli/cgo.go b/cmd/cli/cgo.go new file mode 100644 index 0000000..9979523 --- /dev/null +++ b/cmd/cli/cgo.go @@ -0,0 +1,5 @@ +//go:build cgo + +package cli + +const cgoEnabled = true diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index 9d01206..016f4ac 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -1739,9 +1739,14 @@ func goArm() string { // upgradeUrl returns the url for downloading new ctrld binary. func upgradeUrl(baseUrl string) string { dlPath := fmt.Sprintf("%s-%s/ctrld", runtime.GOOS, runtime.GOARCH) + // Use arm version set during build time, v5 binary can be run on higher arm version system. if armVersion := goArm(); armVersion != "" { dlPath = fmt.Sprintf("%s-%sv%s/ctrld", runtime.GOOS, runtime.GOARCH, armVersion) } + // linux/amd64 has nocgo version, to support systems that missing some libc (like openwrt). + if !cgoEnabled && runtime.GOOS == "linux" && runtime.GOARCH == "amd64" { + dlPath = fmt.Sprintf("%s-%s-nocgo/ctrld", runtime.GOOS, runtime.GOARCH) + } dlUrl := fmt.Sprintf("%s/%s", baseUrl, dlPath) if runtime.GOOS == "windows" { dlUrl += ".exe" diff --git a/cmd/cli/nocgo.go b/cmd/cli/nocgo.go new file mode 100644 index 0000000..2596d09 --- /dev/null +++ b/cmd/cli/nocgo.go @@ -0,0 +1,5 @@ +//go:build !cgo + +package cli + +const cgoEnabled = false