Skip to content

Commit a79567e

Browse files
cross compile debian
1 parent 2f7ae64 commit a79567e

File tree

2 files changed

+166
-40
lines changed

2 files changed

+166
-40
lines changed

docker/ubuntu-22.04.dockerfile

Lines changed: 140 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
# syntax=docker/dockerfile:1.4
22
# artifacts: true
33
# platforms: linux/amd64,linux/arm64/v8
4-
# platforms_pr: linux/amd64
4+
# platforms_pr: linux/amd64,linux/arm64/v8
55
# no-cache-filters: sunshine-base,artifacts,sunshine
66
ARG BASE=ubuntu
77
ARG TAG=22.04
8-
FROM ${BASE}:${TAG} AS sunshine-base
8+
ARG DIST=jammy
9+
FROM --platform=$BUILDPLATFORM ${BASE}:${TAG} AS sunshine-base
910

1011
ENV DEBIAN_FRONTEND=noninteractive
1112

1213
FROM sunshine-base as sunshine-build
1314

15+
# reused args from base
16+
ARG TAG
17+
ENV TAG=${TAG}
18+
ARG DIST
19+
ENV DIST=${DIST}
20+
21+
ARG BUILDPLATFORM
1422
ARG TARGETPLATFORM
23+
RUN echo "build_platform: ${BUILDPLATFORM}"
1524
RUN echo "target_platform: ${TARGETPLATFORM}"
1625

26+
# args from ci workflow
1727
ARG BRANCH
1828
ARG BUILD_VERSION
1929
ARG COMMIT
@@ -24,47 +34,125 @@ ENV BUILD_VERSION=${BUILD_VERSION}
2434
ENV COMMIT=${COMMIT}
2535

2636
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
37+
# setup env
38+
WORKDIR /env
39+
RUN <<_ENV
40+
#!/bin/bash
41+
set -e
42+
case "${BUILDPLATFORM}" in
43+
linux/amd64)
44+
BUILDARCH=amd64
45+
;;
46+
linux/arm64)
47+
BUILDARCH=arm64
48+
;;
49+
*)
50+
echo "unsupported platform: ${TARGETPLATFORM}";
51+
exit 1
52+
;;
53+
esac
54+
55+
case "${TARGETPLATFORM}" in
56+
linux/amd64)
57+
PACKAGEARCH=amd64
58+
TARGETARCH=x86_64
59+
;;
60+
linux/arm64)
61+
PACKAGEARCH=arm64
62+
TARGETARCH=aarch64
63+
;;
64+
*)
65+
echo "unsupported platform: ${TARGETPLATFORM}";
66+
exit 1
67+
;;
68+
esac
69+
70+
mirror="http://ports.ubuntu.com/ubuntu-ports"
71+
extra_sources=$(cat <<- VAREOF
72+
deb [arch=$PACKAGEARCH] $mirror $DIST main restricted
73+
deb [arch=$PACKAGEARCH] $mirror $DIST-updates main restricted
74+
deb [arch=$PACKAGEARCH] $mirror $DIST universe
75+
deb [arch=$PACKAGEARCH] $mirror $DIST-updates universe
76+
deb [arch=$PACKAGEARCH] $mirror $DIST multiverse
77+
deb [arch=$PACKAGEARCH] $mirror $DIST-updates multiverse
78+
deb [arch=$PACKAGEARCH] $mirror $DIST-backports main restricted universe multiverse
79+
deb [arch=$PACKAGEARCH] $mirror $DIST-security main restricted
80+
deb [arch=$PACKAGEARCH] $mirror $DIST-security universe
81+
deb [arch=$PACKAGEARCH] $mirror $DIST-security multiverse
82+
VAREOF
83+
)
84+
85+
if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
86+
# fix original sources
87+
sed -i -e "s#deb http#deb [arch=$BUILDARCH] http#g" /etc/apt/sources.list
88+
dpkg --add-architecture $PACKAGEARCH
89+
90+
echo "$extra_sources" | tee -a /etc/apt/sources.list
91+
fi
92+
93+
echo PACKAGEARCH=${PACKAGEARCH}; \
94+
echo TARGETARCH=${TARGETARCH}; \
95+
echo TUPLE=${TARGETARCH}-linux-gnu >> ./env
96+
_ENV
97+
2798
# install dependencies
2899
RUN <<_DEPS
29100
#!/bin/bash
30101
set -e
31-
apt-get update -y
32-
apt-get install -y --no-install-recommends \
33-
build-essential \
34-
cmake=3.22.* \
35-
ca-certificates \
36-
git \
37-
libayatana-appindicator3-dev \
38-
libavdevice-dev \
39-
libboost-filesystem-dev=1.74.* \
40-
libboost-locale-dev=1.74.* \
41-
libboost-log-dev=1.74.* \
42-
libboost-program-options-dev=1.74.* \
43-
libcap-dev \
44-
libcurl4-openssl-dev \
45-
libdrm-dev \
46-
libevdev-dev \
47-
libminiupnpc-dev \
48-
libnotify-dev \
49-
libnuma-dev \
50-
libopus-dev \
51-
libpulse-dev \
52-
libssl-dev \
53-
libva-dev \
54-
libvdpau-dev \
55-
libwayland-dev \
56-
libx11-dev \
57-
libxcb-shm0-dev \
58-
libxcb-xfixes0-dev \
59-
libxcb1-dev \
60-
libxfixes-dev \
61-
libxrandr-dev \
62-
libxtst-dev \
63-
wget
64-
if [[ "${TARGETPLATFORM}" == 'linux/amd64' ]]; then
65-
apt-get install -y --no-install-recommends \
66-
libmfx-dev
102+
103+
# shellcheck source=/dev/null
104+
source /env/env
105+
106+
# Initialize an array for packages
107+
packages=(
108+
"build-essential"
109+
"cmake=3.22.*"
110+
"ca-certificates"
111+
"git"
112+
"libayatana-appindicator3-dev"
113+
"libavdevice-dev"
114+
"libboost-filesystem-dev=1.74.*"
115+
"libboost-locale-dev=1.74.*"
116+
"libboost-log-dev=1.74.*"
117+
"libboost-program-options-dev=1.74.*"
118+
"libcap-dev"
119+
"libcurl4-openssl-dev"
120+
"libdrm-dev"
121+
"libevdev-dev"
122+
"libminiupnpc-dev"
123+
"libnotify-dev"
124+
"libnuma-dev"
125+
"libopus-dev"
126+
"libpulse-dev"
127+
"libssl-dev"
128+
"libva-dev"
129+
"libvdpau-dev"
130+
"libwayland-dev"
131+
"libx11-dev"
132+
"libxcb-shm0-dev"
133+
"libxcb-xfixes0-dev"
134+
"libxcb1-dev"
135+
"libxfixes-dev"
136+
"libxrandr-dev"
137+
"libxtst-dev"
138+
"wget"
139+
)
140+
141+
# Conditionally include arch specific packages
142+
if [[ "${TARGETARCH}" == 'x86_64' ]]; then
143+
packages+=(
144+
"libmfx-dev"
145+
)
67146
fi
147+
if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
148+
packages+=(
149+
"g++-${TUPLE}=4:11.2.*"
150+
"gcc-${TUPLE}=4:11.2.*"
151+
)
152+
fi
153+
154+
apt-get update -y
155+
apt-get install -y --no-install-recommends "${packages[@]}"
68156
apt-get clean
69157
rm -rf /var/lib/apt/lists/*
70158
_DEPS
@@ -91,7 +179,7 @@ RUN <<_INSTALL_CUDA
91179
set -e
92180
cuda_prefix="https://developer.download.nvidia.com/compute/cuda/"
93181
cuda_suffix=""
94-
if [[ "${TARGETPLATFORM}" == 'linux/arm64' ]]; then
182+
if [[ "${TARGETARCH}" == 'aarch64' ]]; then
95183
cuda_suffix="_sbsa"
96184
fi
97185
url="${cuda_prefix}${CUDA_VERSION}/local_installers/cuda_${CUDA_VERSION}_${CUDA_BUILD}_linux${cuda_suffix}.run"
@@ -117,8 +205,20 @@ set -e
117205
#Set Node version
118206
source "$HOME/.nvm/nvm.sh"
119207
nvm use 20.9.0
208+
209+
# shellcheck source=/dev/null
210+
source /env/env
211+
212+
TOOLCHAIN_OPTION=""
213+
if [[ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]]; then
214+
export "CCPREFIX=/usr/bin/${TUPLE}-"
215+
216+
TOOLCHAIN_OPTION="-DCMAKE_TOOLCHAIN_FILE=toolchain-${TUPLE}-debian.cmake"
217+
fi
218+
120219
#Actually build
121220
cmake \
221+
"$TOOLCHAIN_OPTION" \
122222
-DCMAKE_CUDA_COMPILER:PATH=/build/cuda/bin/nvcc \
123223
-DCMAKE_BUILD_TYPE=Release \
124224
-DCMAKE_INSTALL_PREFIX=/usr \
@@ -139,7 +239,7 @@ ARG TAG
139239
ARG TARGETARCH
140240
COPY --link --from=sunshine-build /build/sunshine/build/cpack_artifacts/Sunshine.deb /sunshine-${BASE}-${TAG}-${TARGETARCH}.deb
141241

142-
FROM sunshine-base as sunshine
242+
FROM ${BASE}:${TAG} as sunshine
143243

144244
# copy deb from builder
145245
COPY --link --from=artifacts /sunshine*.deb /sunshine.deb
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# the name of the target operating system
2+
SET(CMAKE_SYSTEM_NAME Linux)
3+
4+
# set processor type
5+
SET(CMAKE_SYSTEM_PROCESSOR aarch64)
6+
7+
SET(COMPILER_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu)
8+
9+
# which compilers to use for C and C++
10+
SET(CMAKE_ASM_COMPILER ${COMPILER_PREFIX}-gcc)
11+
SET(CMAKE_ASM-ATT_COMPILER ${COMPILER_PREFIX}-gcc)
12+
SET(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc)
13+
SET(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++)
14+
15+
# here is the target environment located
16+
SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX})
17+
18+
# adjust the default behaviour of the FIND_XXX() commands:
19+
# search headers and libraries in the target environment, search
20+
# programs in the host environment
21+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
22+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
23+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
24+
25+
# packaging
26+
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")

0 commit comments

Comments
 (0)