Skip to content

Commit 9683060

Browse files
ReenigneArcherchewi
andcommitted
build: cross compile linux
Co-Authored-By: James Le Cuirot <chewi@aura-online.co.uk>
1 parent ec1ae4a commit 9683060

3 files changed

Lines changed: 140 additions & 20 deletions

File tree

docker/fedora-39.dockerfile

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
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/arm64/v8
5+
# todo: add linux/amd64 back to PR platforms
56
# no-cache-filters: sunshine-base,artifacts,sunshine
67
ARG BASE=fedora
78
ARG TAG=39
8-
FROM ${BASE}:${TAG} AS sunshine-base
9+
FROM --platform=$BUILDPLATFORM ${BASE}:${TAG} AS sunshine-base
910

1011
FROM sunshine-base as sunshine-build
1112

13+
# reused args from base
14+
ARG TAG
15+
ENV TAG=${TAG}
16+
1217
ARG TARGETPLATFORM
1318
RUN echo "target_platform: ${TARGETPLATFORM}"
1419

20+
# args from ci workflow
1521
ARG BRANCH
1622
ARG BUILD_VERSION
1723
ARG COMMIT
@@ -22,25 +28,75 @@ ENV BUILD_VERSION=${BUILD_VERSION}
2228
ENV COMMIT=${COMMIT}
2329

2430
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
25-
# install dependencies
31+
# setup env
32+
WORKDIR /env
33+
RUN <<_ENV
34+
#!/bin/bash
35+
set -e
36+
case "${TARGETPLATFORM}" in
37+
linux/amd64)
38+
echo TARGETARCH=x86_64 >> ./env
39+
echo TUPLE=x86_64-linux-gnu >> ./env
40+
;;
41+
linux/arm64)
42+
echo TARGETARCH=aarch64 >> ./env
43+
echo TUPLE=aarch64-linux-gnu >> ./env
44+
;;
45+
*)
46+
echo "unsupported platform: ${TARGETPLATFORM}";
47+
exit 1
48+
;;
49+
esac
50+
_ENV
51+
52+
# reset workdir
53+
WORKDIR /
54+
55+
# install build dependencies
2656
# hadolint ignore=DL3041
27-
RUN <<_DEPS
57+
# shellcheck source=/dev/null
58+
RUN <<_DEPS_A
2859
#!/bin/bash
2960
set -e
61+
source /env/env
62+
3063
dnf -y update
31-
dnf -y group install "Development Tools"
3264
dnf -y install \
33-
boost-devel-1.81.0* \
3465
cmake-3.27.* \
35-
gcc-13.2.* \
36-
gcc-c++-13.2.* \
37-
git \
66+
gcc-"${TARGETARCH}"-linux-gnu-13.2.* \
67+
gcc-c++-"${TARGETARCH}"-linux-gnu-13.2.* \
68+
git-core \
69+
nodejs \
70+
pkgconf-pkg-config \
71+
rpm-build \
72+
wayland-devel \
73+
wget \
74+
which
75+
dnf clean all
76+
_DEPS_A
77+
78+
# install host dependencies
79+
# hadolint ignore=DL3041
80+
# shellcheck source=/dev/null
81+
RUN <<_DEPS_B
82+
#!/bin/bash
83+
set -e
84+
source /env/env
85+
86+
DNF=( dnf -y --installroot /mnt/cross --releasever "${TAG}" --forcearch "${TARGETARCH}" )
87+
"${DNF[@]}" install \
88+
filesystem
89+
"${DNF[@]}" --setopt=tsflags=noscripts install \
90+
$([[ "${TARGETARCH}" == x86_64 ]] && echo intel-mediasdk-devel) \
91+
boost-devel-1.81.0* \
92+
glibc-devel \
3893
libappindicator-gtk3-devel \
3994
libcap-devel \
4095
libcurl-devel \
4196
libdrm-devel \
4297
libevdev-devel \
4398
libnotify-devel \
99+
libstdc++-devel \
44100
libva-devel \
45101
libvdpau-devel \
46102
libX11-devel \
@@ -53,20 +109,13 @@ dnf -y install \
53109
libXtst-devel \
54110
mesa-libGL-devel \
55111
miniupnpc-devel \
56-
nodejs \
57112
numactl-devel \
58113
openssl-devel \
59114
opus-devel \
60115
pulseaudio-libs-devel \
61-
rpm-build \
62-
wget \
63-
which
64-
if [[ "${TARGETPLATFORM}" == 'linux/amd64' ]]; then
65-
dnf -y install intel-mediasdk-devel
66-
fi
67-
dnf clean all
68-
rm -rf /var/cache/yum
69-
_DEPS
116+
wayland-devel
117+
"${DNF[@]}" clean all
118+
_DEPS_B
70119

71120
# todo - enable cuda once it's supported for gcc 13 and fedora 39
72121
## install cuda
@@ -101,12 +150,25 @@ WORKDIR /build/sunshine/build
101150
# cmake and cpack
102151
# todo - add cmake argument back in for cuda support "-DCMAKE_CUDA_COMPILER:PATH=/build/cuda/bin/nvcc \"
103152
# todo - re-enable "DSUNSHINE_ENABLE_CUDA"
153+
# shellcheck source=/dev/null
104154
RUN <<_MAKE
105155
#!/bin/bash
106156
set -e
157+
source /env/env
158+
159+
export \
160+
CXXFLAGS="-isystem $(echo /mnt/cross/usr/include/c++/[0-9]*/) -isystem $(echo /mnt/cross/usr/include/c++/[0-9]*/${TUPLE%%-*}-*/)" \
161+
LDFLAGS="-L$(echo /mnt/cross/usr/lib/gcc/${TUPLE%%-*}-*/[0-9]*/)" \
162+
PKG_CONFIG_LIBDIR=/mnt/cross/usr/lib64/pkgconfig:/mnt/cross/usr/share/pkgconfig \
163+
PKG_CONFIG_SYSROOT_DIR=/mnt/cross \
164+
PKG_CONFIG_SYSTEM_INCLUDE_PATH=/mnt/cross/usr/include \
165+
PKG_CONFIG_SYSTEM_LIBRARY_PATH=/mnt/cross/usr/lib64
166+
107167
cmake \
168+
-DCMAKE_TOOLCHAIN_FILE=toolchain-${TARGETARCH}-linux-gnu.cmake \
108169
-DCMAKE_BUILD_TYPE=Release \
109170
-DCMAKE_INSTALL_PREFIX=/usr \
171+
-DCPACK_RPM_PACKAGE_ARCHITECTURE="${TARGETARCH}" \
110172
-DSUNSHINE_ASSETS_DIR=share/sunshine \
111173
-DSUNSHINE_EXECUTABLE_PATH=/usr/bin/sunshine \
112174
-DSUNSHINE_ENABLE_WAYLAND=ON \
@@ -124,7 +186,7 @@ ARG TAG
124186
ARG TARGETARCH
125187
COPY --link --from=sunshine-build /build/sunshine/build/cpack_artifacts/Sunshine.rpm /sunshine-${BASE}-${TAG}-${TARGETARCH}.rpm
126188

127-
FROM sunshine-base as sunshine
189+
FROM ${BASE}:${TAG} AS sunshine
128190

129191
# copy deb from builder
130192
COPY --link --from=artifacts /sunshine*.rpm /sunshine.rpm

toolchain-aarch64-linux-gnu.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_SYSROOT "/mnt/cross")
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+
set(CMAKE_AR "${COMPILER_PREFIX}-gcc-ar" CACHE FILEPATH "Archive manager" FORCE)
26+
set(CMAKE_RANLIB "${COMPILER_PREFIX}-gcc-ranlib" CACHE FILEPATH "Archive index generator" FORCE)
27+
28+
# packaging
29+
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")

toolchain-x86_64-linux-gnu.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# the name of the target operating system
2+
SET(CMAKE_SYSTEM_NAME Linux)
3+
4+
# set processor type
5+
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
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_SYSROOT "/mnt/cross")
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+
set(CMAKE_AR "${COMPILER_PREFIX}-gcc-ar" CACHE FILEPATH "Archive manager" FORCE)
26+
set(CMAKE_RANLIB "${COMPILER_PREFIX}-gcc-ranlib" CACHE FILEPATH "Archive index generator" FORCE)
27+
28+
# packaging
29+
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")

0 commit comments

Comments
 (0)