Skip to content

Commit fb5e67a

Browse files
committed
cagent: fix build since switch to CGo
Signed-off-by: CrazyMax <[email protected]>
1 parent 035153f commit fb5e67a

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

pkg/cagent/Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
ARG XX_VERSION="1.7.0"
17+
ARG XX_VERSION="1.9.0"
1818
ARG DEBIAN_FRONTEND="noninteractive"
1919

2020
ARG DISTRO_NAME="debian12"
@@ -32,13 +32,18 @@ ARG GO_IMAGE="golang"
3232
ARG GO_VERSION="1.25.5"
3333
ARG GO_IMAGE_VARIANT="bookworm"
3434

35+
ARG ZIG_VERSION="0.15.2"
36+
3537
# stage used as named context that mounts hack/scripts
3638
# see pkg target in docker-bake.hcl
3739
FROM scratch AS scripts
3840

3941
# cross compilation helper
4042
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
4143

44+
# osxcross contains the MacOSX cross toolchain for xx
45+
FROM crazymax/osxcross:15.5-debian AS osxcross
46+
4247
# go base image to retrieve /usr/local/go
4348
FROM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go
4449
FROM --platform=$BUILDPLATFORM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS gocross
@@ -90,7 +95,7 @@ ENV GOPATH="/go"
9095
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
9196
ENV GOTOOLCHAIN="local"
9297
ENV GO111MODULE="on"
93-
ENV CGO_ENABLED="0"
98+
ENV CGO_ENABLED="1"
9499
ARG DISTRO_NAME
95100
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils bash ca-certificates curl devscripts equivs git
96101
COPY deb /root/package/debian
@@ -124,7 +129,7 @@ ENV GOPATH="/go"
124129
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
125130
ENV GOTOOLCHAIN="local"
126131
ENV GO111MODULE="on"
127-
ENV CGO_ENABLED="0"
132+
ENV CGO_ENABLED="1"
128133
ARG DISTRO_NAME
129134
RUN --mount=type=bind,from=scripts,source=rpm-init.sh,target=/usr/local/bin/rpm-init \
130135
--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-
157162
FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static
158163
COPY --from=xx / /
159164
ARG DEBIAN_FRONTEND
160-
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar
165+
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates file git zip tar \
166+
dpkg-dev clang make pkg-config curl
167+
ARG ZIG_VERSION
168+
RUN <<EOT
169+
set -e
170+
ARCH=$(xx-info march)-$(xx-info os)
171+
set -x
172+
curl -LO https://ziglang.org/download/$ZIG_VERSION/zig-$ARCH-$ZIG_VERSION.tar.xz
173+
tar xf zig-$ARCH-$ZIG_VERSION.tar.xz
174+
mv zig-$ARCH-$ZIG_VERSION /opt/zig-$ZIG_VERSION
175+
ln -sf /opt/zig-$ZIG_VERSION/zig /usr/local/bin/zig
176+
zig version
177+
EOT
161178
ENV GOPROXY="https://proxy.golang.org|direct"
162179
ENV GOPATH="/go"
163180
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
164181
ENV GOTOOLCHAIN="local"
165182
ENV GO111MODULE="on"
166-
ENV CGO_ENABLED="0"
183+
ENV CGO_ENABLED="1"
167184
ARG NIGHTLY_BUILD
168185
ARG PKG_NAME
169186
ARG PKG_REF
@@ -180,6 +197,7 @@ RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/p
180197
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
181198
--mount=type=bind,from=src,source=/src,target=/usr/local/src/cagent \
182199
--mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw \
200+
--mount=type=bind,from=osxcross,src=/osxsdk,target=/xx-sdk \
183201
OUTDIR=/out BUILDDIR=/build SRCDIR=/usr/local/src/cagent pkg-static-build
184202

185203
FROM builder-${DISTRO_TYPE} AS build-pkg

pkg/cagent/deb/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Vcs-Browser: https://github.com/docker/cagent
77
Vcs-Git: git://github.com/docker/cagent.git
88
Standards-Version: 3.9.6
99
Build-Depends: bash,
10+
gcc,
1011
debhelper-compat (= 12)
1112

1213
Package: cagent

pkg/cagent/rpm/cagent.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Vendor: Docker
1313
Packager: Docker <[email protected]>
1414

1515
BuildRequires: bash
16+
BuildRequires: gcc
1617

1718
%description
1819
cagent is a powerful multi-agent AI runtime that enables you to create,

pkg/cagent/scripts/pkg-static-build.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ for l in $(gen-ver "${SRCDIR}"); do
4040
export "${l?}"
4141
done
4242

43+
if [ "$(xx-info os)" != "darwin" ]; then
44+
export XX_GO_PREFER_C_COMPILER=zig
45+
fi
46+
4347
xx-go --wrap
44-
fix-cc
48+
49+
if [ "$(xx-info os)" = "darwin" ]; then
50+
fix-cc
51+
fi
4552

4653
binext=$([ "$(xx-info os)" = "windows" ] && echo ".exe" || true)
4754
mkdir -p ${BUILDDIR}/${PKG_NAME}
@@ -51,7 +58,7 @@ mkdir -p ${BUILDDIR}/${PKG_NAME}
5158
pushd ${SRCDIR}
5259
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}" .
5360
popd
54-
xx-verify --static "${BUILDDIR}/${PKG_NAME}/cagent${binext}"
61+
xx-verify "${BUILDDIR}/${PKG_NAME}/cagent${binext}"
5562
)
5663

5764
pkgoutput="$OUTDIR/static/$(xx-info os)/$(xx-info arch)"

0 commit comments

Comments
 (0)