Skip to content

Can't cross-build linux/amd64 image on Mac M1 #762

@trekawek

Description

@trekawek

An attempt to build the recent source-controller (9e33041) on Mac M1, targeting the linux/amd64 platform, fails with the error cannot find -lcrypto.

Other architectures: linux/arm64 and linux/arm/v7 work correctly.

Reproduction steps:

$ make docker-build BUILD_PLATFORMS=linux/amd64

Output:

------
 > [linux/arm64->amd64 build  9/10] RUN export $(cat build/musl/$(xx-info alpine-arch).env | xargs) &&     export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" &&     export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" &&     export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2) -static" &&     GOARCH=amd64 go build          -ldflags "-s -w"         -tags 'netgo,osusergo,static_build'         -o /source-controller -trimpath main.go;:
#0 42.37 # runtime/cgo
#0 42.37 /workspace/build/musl/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: cannot find -lcrypto
#0 42.37 /workspace/build/musl/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: cannot find -lssl
#0 42.37 /workspace/build/musl/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: cannot find -lcrypto
#0 42.37 /workspace/build/musl/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: cannot find -lssl
#0 42.37 /workspace/build/musl/x86_64-linux-musl-cross/bin/../lib/gcc/x86_64-linux-musl/11.2.1/../../../../x86_64-linux-musl/bin/ld: cannot find -lcrypto
#0 42.37 collect2: error: ld returned 1 exit status
------
Dockerfile:84
--------------------
  83 |     # Instead of using xx-go, (cross) compile with vanilla go leveraging musl tool chain.
  84 | >>> RUN export $(cat build/musl/$(xx-info alpine-arch).env | xargs) && \
  85 | >>>     export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
  86 | >>>     export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
  87 | >>>     export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2) -static" && \
  88 | >>>     GOARCH=$TARGETARCH go build  \
  89 | >>>         -ldflags "-s -w" \
  90 | >>>         -tags 'netgo,osusergo,static_build' \
  91 | >>>         -o /source-controller -trimpath main.go;
  92 |
--------------------
error: failed to solve: process "/bin/sh -c export $(cat build/musl/$(xx-info alpine-arch).env | xargs) &&     export LIBRARY_PATH=\"/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64\" &&     export PKG_CONFIG_PATH=\"/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig\" &&     export CGO_LDFLAGS=\"$(pkg-config --static --libs --cflags libssh2 openssl libgit2) -static\" &&     GOARCH=$TARGETARCH go build          -ldflags \"-s -w\"         -tags 'netgo,osusergo,static_build'         -o /source-controller -trimpath main.go;" did not complete successfully: exit code: 2
make: *** [docker-build] Error 1

Docker version:

Client:
 Cloud integration: v1.0.25
 Version:           20.10.16
 API version:       1.41
 Go version:        go1.17.10
 Git commit:        aa7e414
 Built:             Thu May 12 09:20:34 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.9.0 (80466)
 Engine:
  Version:          20.10.16
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.10
  Git commit:       f756502
  Built:            Thu May 12 09:14:19 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.4
  GitCommit:        212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
 runc:
  Version:          1.1.1
  GitCommit:        v1.1.1-0-g52de29d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ciCI related issues and pull requestsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions