From fb5e67ae1588d97339b43a814509af107414a3f0 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:57:10 +0100 Subject: [PATCH] cagent: fix build since switch to CGo Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- pkg/cagent/Dockerfile | 28 +++++++++++++++++++++----- pkg/cagent/deb/control | 1 + pkg/cagent/rpm/cagent.spec | 1 + pkg/cagent/scripts/pkg-static-build.sh | 11 ++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/pkg/cagent/Dockerfile b/pkg/cagent/Dockerfile index 9d1ffa67..677fccb7 100644 --- a/pkg/cagent/Dockerfile +++ b/pkg/cagent/Dockerfile @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG XX_VERSION="1.7.0" +ARG XX_VERSION="1.9.0" ARG DEBIAN_FRONTEND="noninteractive" ARG DISTRO_NAME="debian12" @@ -32,6 +32,8 @@ ARG GO_IMAGE="golang" ARG GO_VERSION="1.25.5" ARG GO_IMAGE_VARIANT="bookworm" +ARG ZIG_VERSION="0.15.2" + # stage used as named context that mounts hack/scripts # see pkg target in docker-bake.hcl FROM scratch AS scripts @@ -39,6 +41,9 @@ FROM scratch AS scripts # cross compilation helper FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx +# osxcross contains the MacOSX cross toolchain for xx +FROM crazymax/osxcross:15.5-debian AS osxcross + # go base image to retrieve /usr/local/go FROM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go FROM --platform=$BUILDPLATFORM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS gocross @@ -90,7 +95,7 @@ ENV GOPATH="/go" ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin" ENV GOTOOLCHAIN="local" ENV GO111MODULE="on" -ENV CGO_ENABLED="0" +ENV CGO_ENABLED="1" ARG DISTRO_NAME RUN apt-get update && apt-get install -y --no-install-recommends apt-utils bash ca-certificates curl devscripts equivs git COPY deb /root/package/debian @@ -124,7 +129,7 @@ ENV GOPATH="/go" ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin" ENV GOTOOLCHAIN="local" ENV GO111MODULE="on" -ENV CGO_ENABLED="0" +ENV CGO_ENABLED="1" ARG DISTRO_NAME RUN --mount=type=bind,from=scripts,source=rpm-init.sh,target=/usr/local/bin/rpm-init \ --mount=type=secret,id=RH_USER,env=RH_USER \ @@ -157,13 +162,25 @@ RUN --mount=type=bind,source=scripts/pkg-rpm-build.sh,target=/usr/local/bin/pkg- FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static COPY --from=xx / / ARG DEBIAN_FRONTEND -RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar +RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar \ + dpkg-dev clang make pkg-config curl +ARG ZIG_VERSION +RUN < BuildRequires: bash +BuildRequires: gcc %description cagent is a powerful multi-agent AI runtime that enables you to create, diff --git a/pkg/cagent/scripts/pkg-static-build.sh b/pkg/cagent/scripts/pkg-static-build.sh index 74cefa8c..6394e75b 100755 --- a/pkg/cagent/scripts/pkg-static-build.sh +++ b/pkg/cagent/scripts/pkg-static-build.sh @@ -40,8 +40,15 @@ for l in $(gen-ver "${SRCDIR}"); do export "${l?}" done +if [ "$(xx-info os)" != "darwin" ]; then + export XX_GO_PREFER_C_COMPILER=zig +fi + xx-go --wrap -fix-cc + +if [ "$(xx-info os)" = "darwin" ]; then + fix-cc +fi binext=$([ "$(xx-info os)" = "windows" ] && echo ".exe" || true) mkdir -p ${BUILDDIR}/${PKG_NAME} @@ -51,7 +58,7 @@ mkdir -p ${BUILDDIR}/${PKG_NAME} pushd ${SRCDIR} go build -trimpath -ldflags "-w -X 'github.com/docker/cagent/pkg/version.Version=${GENVER_VERSION}' -X 'github.com/docker/cagent/pkg/version.Commit=${GENVER_COMMIT}'" -o "${BUILDDIR}/${PKG_NAME}/cagent${binext}" . popd - xx-verify --static "${BUILDDIR}/${PKG_NAME}/cagent${binext}" + xx-verify "${BUILDDIR}/${PKG_NAME}/cagent${binext}" ) pkgoutput="$OUTDIR/static/$(xx-info os)/$(xx-info arch)"