Skip to content

Commit

Permalink
Remove all crossbuild stuff, we are building on target archs now
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim committed Oct 25, 2024
1 parent f9e6126 commit 80d3e14
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 173 deletions.
35 changes: 13 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
# Use Debian Bullseye as a base image to link against glibc 2.31
FROM --platform=${BUILDPLATFORM} debian:bullseye-slim AS base
FROM debian:bullseye-slim AS base

ARG TARGETARCH

RUN dpkg --add-architecture ${TARGETARCH} \
&& apt-get update \
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
bash \
curl \
git \
ca-certificates \
crossbuild-essential-${TARGETARCH} \
build-essential \
pkg-config \
libssl-dev \
libstdc++-10-dev:${TARGETARCH}
libstdc++-10-dev

WORKDIR /root

# ==============================================================================

FROM --platform=${BUILDPLATFORM} base AS deps-src
FROM base AS deps-src

COPY versions.sh download-deps.sh ./
RUN ./download-deps.sh

# ==============================================================================

FROM --platform=${BUILDPLATFORM} base AS deps

ARG TARGETARCH
FROM base AS deps

COPY install-rust.sh ./

Expand All @@ -47,10 +42,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
&& python3 -m venv /root/.python \
&& /root/.python/bin/pip install meson ninja packaging

COPY versions.sh build-deps.sh build-bash-profile.sh *.patch cmake_${TARGETARCH}.cmake meson_${TARGETARCH}.ini ./
COPY versions.sh build-deps.sh build-bash-profile.sh *.patch ./
COPY --from=deps-src /root/deps /root/deps

# We need environment variables that based on the TARGETARCH,
# We need environment variables that are based on the uname -m output,
# so we have to use a Bash profile instead of ENV
RUN ./build-bash-profile.sh > /root/.bashrc
ENV BASH_ENV=/root/.bashrc
Expand All @@ -59,21 +54,17 @@ RUN ./build-deps.sh

# ==============================================================================

FROM --platform=${BUILDPLATFORM} base as golang
FROM base AS golang

COPY versions.sh install-go.sh ./
RUN ./install-go.sh

# ==============================================================================

FROM --platform=${TARGETPLATFORM} debian:bullseye-slim AS final
FROM debian:bullseye-slim AS final
LABEL maintainer="Sergey Alexandrovich <darthsim@gmail.com>"

ARG TARGETARCH
ARG BUILDARCH

RUN dpkg --add-architecture ${BUILDARCH} \
&& apt-get update \
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
bash \
curl \
Expand All @@ -87,7 +78,7 @@ RUN dpkg --add-architecture ${BUILDARCH} \
WORKDIR /root

COPY --from=golang /usr/local/go /usr/local/go
ENV PATH $PATH:/usr/local/go/bin
ENV PATH=$PATH:/usr/local/go/bin

COPY --from=deps /opt/imgproxy/lib /opt/imgproxy/lib
COPY --from=deps /opt/imgproxy/include /opt/imgproxy/include
Expand All @@ -97,4 +88,4 @@ COPY --from=deps /root/.bashrc /root/.bashrc
ENV BASH_ENV=/root/.bashrc

WORKDIR /app
CMD bash
CMD ["bash"]
47 changes: 13 additions & 34 deletions build-bash-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,36 @@

set -e

case "$TARGETARCH" in

amd64)
ARCH="x86_64"
case "$(uname -m)" in
x86_64)
ARCH_ENV=$(cat << EOF
export CFLAGS="-mssse3"
EOF
)
;;

arm64)
ARCH="aarch64"
aarch64)
ARCH_ENV=$(cat << EOF
export CFLAGS="-march=armv8.2-a+fp16"
EOF
)
;;

*)
echo "Unknows arch: $TARGETARCH"
echo "Unsupported architecture $(uname -m)"
exit 1
;;
esac

ARCH_ENV=""

if [ "$TARGETARCH" = "amd64" ]; then
ARCH_ENV=$(cat << EOF
export CFLAGS="-mssse3"
EOF
)
fi

if [ "$TARGETARCH" = "arm64" ]; then
ARCH_ENV=$(cat << EOF
export CFLAGS="-march=armv8.2-a+fp16"
EOF
)
fi

cat << EOF
export PATH="/opt/imgproxy/bin:/root/.cargo/bin:/root/.python/bin:\$PATH"
export PKG_CONFIG_LIBDIR=/opt/imgproxy/lib/pkgconfig
export CGO_LDFLAGS_ALLOW="-s|-w"
export CGO_LDFLAGS="-Wl,-rpath,/opt/imgproxy/lib"
$ARCH_ENV
export BUILD=$(uname -m)-linux-gnu
export HOST=$ARCH-linux-gnu
export CC=$ARCH-linux-gnu-gcc
export CXX=$ARCH-linux-gnu-g++
export STRIP=$ARCH-linux-gnu-strip
export CFLAGS="\$CFLAGS -Os -fPIC -D_GLIBCXX_USE_CXX11_ABI=1 -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections"
export CXXFLAGS=\$CFLAGS
export CPPFLAGS="\$CPPFLAGS -I/opt/imgproxy/include"
export LDFLAGS="\$LDFLAGS -L/opt/imgproxy/lib -Wl,--gc-sections -Wl,-rpath,/opt/imgproxy/lib"
export CMAKE_C_COMPILER=\$CC
export CMAKE_CXX_COMPILER=\$CXX
export CMAKE_CROSS_CONFIG="-DCMAKE_TOOLCHAIN_FILE=/root/cmake_$TARGETARCH.cmake"
export MESON_CROSS_CONFIG="--cross-file=/root/meson_$TARGETARCH.ini"
export CARGO_TARGET="$ARCH-unknown-linux-gnu"
export CARGO_CROSS_CONFIG='[target.$ARCH-unknown-linux-gnu]\nlinker = "$ARCH-linux-gnu-gcc"'
EOF
Loading

0 comments on commit 80d3e14

Please sign in to comment.