goreleaser / goreleaser-cross

Docker image for Golang cross-compiling with CGO
MIT License
134 stars 23 forks source link

Use Debian Bookworm as base #67

Open gsora opened 4 months ago

gsora commented 4 months ago

Hi!

Due to a third-party dependency, a software I work on needs at least Debian Bookworm to compile correctly (C++ stdlib fails to link otherwise).

Is there a way I could run goreleaser-cross on Bookworm?

Thanks!

nmattia commented 2 months ago

I'm running into a very similar issue! This cpp reference is undefined: std::__throw_bad_array_new_length()

@troian would it be possible to bump bullseye to bookworm here? I'm copying & editing the various dockerfiles to give it a try and see if it solves the issue

troian commented 2 months ago

@gsora you have to use sysroot for that

nmattia commented 2 months ago

@troian I tried to create a new image derived from your (bullseye) image but copying a sysroot from a newer (bookworm) debian:

FROM debian:bookworm as debian-latest

RUN \
    set -x; \
    echo "Starting image build for Debian" \
 && apt-get update \
 && apt-get install --no-install-recommends -y -q \
        wget \
        xz-utils \
        cmake \
        openssl \
        autoconf \
        automake \
        build-essential \
        gcc \
        g++

FROM ghcr.io/goreleaser/goreleaser-cross:v1.21.5

ENV CGO_ENABLED=1

RUN mkdir -p /sysroot/linux/amd64-latest

COPY --from=debian-latest /lib /sysroot/linux/amd64-latest/lib
COPY --from=debian-latest /lib64 /sysroot/linux/amd64-latest/lib64
COPY --from=debian-latest /usr /sysroot/linux/amd64-latest/usr
COPY --from=debian-latest /bin /sysroot/linux/amd64-latest/bin

here's the goreleaser environment I'm using:

builds:
- env:
    - PKG_CONFIG_SYSROOT_DIR=/sysroot/linux/amd64-latest
    - PKG_CONFIG_PATH=/sysroot/linux/amd64-latest/usr/local/lib/pkgconfig
    - CC=/sysroot/linux/amd64-latest/usr/bin/gcc
    - CXX=/sysroot/linux/amd64-latest/usr/bin/g++

still something's off, I need to figure out why /sysroot/linux/amd64-latest/usr/bin/gcc is using the host's libc:

# runtime/cgo
/sysroot/linux/amd64-latest/usr/bin/gcc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.35' not fo
und (required by /sysroot/linux/amd64-latest/usr/bin/gcc)
/sysroot/linux/amd64-latest/usr/bin/gcc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not fo
und (required by /sysroot/linux/amd64-latest/usr/bin/gcc)
/sysroot/linux/amd64-latest/usr/bin/gcc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not fo
und (required by /sysroot/linux/amd64-latest/usr/bin/gcc)
/sysroot/linux/amd64-latest/usr/bin/gcc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not fo
und (required by /sysroot/linux/amd64-latest/usr/bin/gcc)

EDIT: the mistake was to use gcc from the other install. As @troian says below, there's no need to install the compiler into the sysroot.

is this the general direction you were suggesting?

troian commented 2 months ago

My suggestion would be to keep sysroot lets say as git repo and mount it during build process. Also, there is no need to install compiler into sysroot. Tho you can, it's main purpose here to provide libraries and headers.

Take a look at https://github.com/goreleaser/goreleaser-cross-example

nmattia commented 1 month ago

@troian the README says several platforms (darwin x86/arm, linux x86, etc) were verified. Can you share the repos used for verification? The example sysroot repo goreleaser/goreleaser-cross-example-sysroot is missing arm Darwin, Windows, etc.

Then I could just mount that repo/those repos, correct?


EDIT: actually I don't think the sysroot is necessary for Darwin builds; osxcross (installed in the image at /usr/local/osxcross) takes care of everything (including for ARM builds)