Skip to content

Commit cb3ecb9

Browse files
committed
Update how cross-compiling works to speed things up
Currently only works on ubuntu20.04 Signed-off-by: Kevin Klues <[email protected]>
1 parent 0e74a41 commit cb3ecb9

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

.github/workflows/image.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
GENERATE_ARTIFACTS="false"
5050
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
5151
GENERATE_ARTIFACTS="false"
52+
elif [[ "${{ matrix.dist }}" == "ubuntu20.04" ]]; then
53+
GENERATE_ARTIFACTS="true"
5254
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
5355
GENERATE_ARTIFACTS="true"
5456
elif [[ "${{ github.event_name }}" == "push" ]]; then

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
DOCKER ?= docker
1616
MKDIR ?= mkdir
1717
TR ?= tr
18+
CC ?= cc
1819
DIST_DIR ?= $(CURDIR)/dist
1920

2021
include $(CURDIR)/common.mk
@@ -40,6 +41,7 @@ DOCKERFILE_DEVEL ?= "images/devel/Dockerfile"
4041
DOCKERFILE_CONTEXT ?= "https://github.com/NVIDIA/k8s-test-infra.git"
4142

4243
GOOS ?= linux
44+
GOARCH ?= $(shell uname -m | sed -e 's,aarch64,arm64,' -e 's,x86_64,amd64,')
4345
ifeq ($(VERSION),)
4446
CLI_VERSION = $(LIB_VERSION)$(if $(LIB_TAG),-$(LIB_TAG))
4547
else
@@ -53,15 +55,16 @@ cmd-%: COMMAND_BUILD_OPTIONS = -o $(PREFIX)/$(*)
5355
endif
5456
cmds: $(CMD_TARGETS)
5557
$(CMD_TARGETS): cmd-%:
56-
CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' GOOS=$(GOOS) \
58+
CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' \
59+
CC=$(CC) CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) \
5760
go build -ldflags "-s -w -X $(CLI_VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) -X $(CLI_VERSION_PACKAGE).version=$(CLI_VERSION)" $(COMMAND_BUILD_OPTIONS) $(MODULE)/cmd/$(*)
5861

5962
build:
60-
GOOS=$(GOOS) go build ./...
63+
CC=$(CC) GOOS=$(GOOS) GOARCH=$(GOARCH) go build ./...
6164

6265
examples: $(EXAMPLE_TARGETS)
6366
$(EXAMPLE_TARGETS): example-%:
64-
GOOS=$(GOOS) go build ./examples/$(*)
67+
CC=$(CC) GOOS=$(GOOS) GOARCH=$(GOARCH) go build ./examples/$(*)
6568

6669
all: check test build binaries
6770
check: $(CHECK_TARGETS)

deployments/container/Dockerfile.ubi8

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@ RUN yum install -y \
2424
rm -rf /var/cache/yum/*
2525

2626
ARG GOLANG_VERSION=x.x.x
27-
RUN set -eux; \
28-
\
29-
arch="$(uname -m)"; \
30-
case "${arch##*-}" in \
31-
x86_64 | amd64) ARCH='amd64' ;; \
32-
ppc64el | ppc64le) ARCH='ppc64le' ;; \
33-
aarch64 | arm64) ARCH='arm64' ;; \
34-
*) echo "unsupported architecture" ; exit 1 ;; \
35-
esac; \
36-
wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \
27+
RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${BUILDARCH}.tar.gz \
3728
| tar -C /usr/local -xz
3829

3930
ENV GOPATH /go

deployments/container/Dockerfile.ubuntu

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,16 @@ ARG GOLANG_VERSION=1.23.1
1616
ARG CUDA_IMAGE=cuda
1717
ARG CUDA_VERSION=11.8.0
1818
ARG BASE_DIST=ubuntu20.04
19-
FROM nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST} as build
19+
FROM --platform=${BUILDOS}/amd64 nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST} as build
2020

2121
RUN apt-get update && \
22-
apt-get install -y wget make git gcc \
22+
apt-get install -y wget make git gcc-aarch64-linux-gnu gcc \
2323
&& \
2424
rm -rf /var/lib/apt/lists/*
2525

26+
ARG BUILDARCH
2627
ARG GOLANG_VERSION=x.x.x
27-
RUN set -eux; \
28-
\
29-
arch="$(uname -m)"; \
30-
case "${arch##*-}" in \
31-
x86_64 | amd64) ARCH='amd64' ;; \
32-
ppc64el | ppc64le) ARCH='ppc64le' ;; \
33-
aarch64 | arm64) ARCH='arm64' ;; \
34-
*) echo "unsupported architecture" ; exit 1 ;; \
35-
esac; \
36-
wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \
28+
RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz \
3729
| tar -C /usr/local -xz
3830

3931
ENV GOPATH /go
@@ -42,10 +34,16 @@ ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
4234
WORKDIR /build
4335
COPY . .
4436

37+
ARG TARGETARCH
4538
RUN mkdir /artifacts
4639
ARG VERSION="N/A"
4740
ARG GIT_COMMIT="unknown"
48-
RUN make PREFIX=/artifacts cmds
41+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
42+
cc=gcc; \
43+
elif [ "$TARGETARCH" = "arm64" ]; then \
44+
cc=aarch64-linux-gnu-gcc; \
45+
fi && \
46+
make CC=${cc} GOARCH=${TARGETARCH} PREFIX=/artifacts cmds
4947

5048
FROM nvidia/${CUDA_IMAGE}:${CUDA_VERSION}-base-${BASE_DIST}
5149

deployments/container/native-only.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515
PUSH_ON_BUILD ?= false
16-
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64
16+
ARCH ?= $(shell uname -m | sed -e 's,aarch64,arm64,' -e 's,x86_64,amd64,')
17+
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/$(ARCH)
1718

1819
ifeq ($(PUSH_ON_BUILD),true)
1920
$(BUILD_TARGETS): build-%: image-%

0 commit comments

Comments
 (0)