Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on arm64 architecture #1173

Open
4 tasks
Jeremy-boo opened this issue Apr 12, 2024 · 1 comment
Open
4 tasks

Build fails on arm64 architecture #1173

Jeremy-boo opened this issue Apr 12, 2024 · 1 comment
Labels

Comments

@Jeremy-boo
Copy link

Description

Build fails on arm64 architecture

kafka client version is: github.com/confluentinc/confluent-kafka-go/v2/kafka@v2.0.2

error message is:

25.17 # runtime/cgo
25.17 gcc_arm64.S: Assembler messages:
25.17 gcc_arm64.S:30: Error: no such instruction: stp x29,x30,[sp,' 25.17 gcc_arm64.S:34: Error: operand size mismatch for mov'
25.17 gcc_arm64.S:36: Error: no such instruction: stp x19,x20,[sp,' 25.17 gcc_arm64.S:39: Error: no such instruction: stp x21,x22,[sp,'
25.17 gcc_arm64.S:42: Error: no such instruction: stp x23,x24,[sp,' 25.17 gcc_arm64.S:45: Error: no such instruction: stp x25,x26,[sp,'
25.17 gcc_arm64.S:48: Error: no such instruction: stp x27,x28,[sp,' 25.17 gcc_arm64.S:52: Error: operand size mismatch for mov'
25.17 gcc_arm64.S:53: Error: operand size mismatch for mov' 25.17 gcc_arm64.S:54: Error: operand size mismatch for mov'
25.17 gcc_arm64.S:56: Error: no such instruction: blr x20' 25.17 gcc_arm64.S:57: Error: no such instruction: blr x19'
25.17 gcc_arm64.S:59: Error: no such instruction: ldp x27,x28,[sp,' 25.17 gcc_arm64.S:62: Error: no such instruction: ldp x25,x26,[sp,'
25.17 gcc_arm64.S:65: Error: no such instruction: ldp x23,x24,[sp,' 25.17 gcc_arm64.S:68: Error: no such instruction: ldp x21,x22,[sp,'
25.17 gcc_arm64.S:71: Error: no such instruction: ldp x19,x20,[sp,' 25.17 gcc_arm64.S:74: Error: no such instruction: ldp x29,x30,[sp],'

Dockerfile:19

17 | go env -w GOPROXY=https://goproxy.cn,direct
18 |
19 | >>> RUN GOARCH=${TARGETARCH} CGO_ENABLED=1 GOOS=linux go build -tags musl -ldflags="-extldflags -static" -o cmd/bin/main cmd/analyzer/main.go
20 |
21 |

ERROR: failed to solve: process "/bin/sh -c GOARCH=${TARGETARCH} CGO_ENABLED=1 GOOS=linux go build -tags musl -ldflags="-extldflags -static" -o cmd/bin/main cmd/analyzer/main.go" did not complete successfully: exit code: 1

How to reproduce

FROM --platform=linux/amd64 golang:1.21.8-alpine3.18 AS builder
ARG GO_MODULES_USER
ARG GO_MODULES_PERSONAL_ACCESS_TOKEN
ARG TARGETARCH

WORKDIR /build

COPY . .

RUN echo -e "machine gitlab.bingex.com\nlogin ${GO_MODULES_USER} \npassword ${GO_MODULES_PERSONAL_ACCESS_TOKEN}" > ~/.netrc

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories &&
apk --no-cache update &&
apk --no-cache add git gcc libc-dev

RUN go env -w GO111MODULE=on &&
go env -w GOPROXY=https://goproxy.cn,direct

RUN GOARCH=${TARGETARCH} CGO_ENABLED=1 GOOS=linux go build -tags musl -ldflags="-extldflags -static" -o cmd/bin/main cmd/analyzer/main.go

FROM alpine:3.13.5-iss

RUN mkdir /tmp/coupon-log-analyzer && touch /tmp/coupon-log-analyzer/coupon-log-analyzer.log && ln -sf /dev/stdout /tmp/coupon-log-analyzer/coupon-log-analyzer.log

COPY --from=builder /build/resources /resources

COPY --from=builder /build/cmd/bin/main ./main

CMD ./main

Checklist

Please provide the following information:

  • [ x] confluent-kafka-go and librdkafka version (LibraryVersion()):
  • [ x] Apache Kafka broker version:
  • Client configuration: ConfigMap{...}
  • Operating system:
  • [x ] Provide client logs (with "debug": ".." as necessary)
  • Provide broker log excerpts
  • Critical issue
@milindl
Copy link
Contributor

milindl commented Apr 23, 2024

@Jeremy-boo I understand that what you're trying to do is cross compile from an alpine linux amd64 builder, to an arm64 architecture. in this case, during the compilation step, the CC needs to be set to a cross compiler which can cross compile from your builder to your target architecture. This is required for the cgo bits of the library to be compiled.

For example, from glibc amd64 -> glibc arm64, I use CC=aarch64-linux-gnu-gcc GOOS=linux GOARCH=arm64 go build

Please try a cross compiler. I believe you will need aarch64-linux-musl-gcc from aarch64-linux-musl-cross available on the musl website. Similar to this answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants