Skip to content

Commit 725212b

Browse files
committed
Create scripts that handle building from source automatically
1 parent 997095c commit 725212b

9 files changed

+442
-22
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Sunshine is a Gamestream host for Moonlight
1313

1414
## Linux
1515

16+
If you do not wish to clutter your PC with development files, yet you want the very latest version...
17+
You can use these [build scripts](scripts/README.md)
18+
They make use of docker to handle building Sunshine automatically
19+
1620
### Requirements:
1721

1822
Ubuntu 20.04:
@@ -41,6 +45,7 @@ sudo apt install libwayland-dev
4145

4246
#### Cuda + NvFBC
4347
This requires proprietary software
48+
On Ubuntu 20.04, the cuda compiler will fail since it's version is too old, it's recommended you compile the sources with the [build scripts](scripts/README.md)
4449
```
4550
sudo apt install nvidia-cuda-dev nvidia-cuda-toolkit
4651
```

appveyor.yml

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
image:
2-
- Ubuntu2004
3-
- Visual Studio 2019
1+
services:
2+
- docker
43

54
environment:
65
matrix:
7-
- BUILD_TYPE: Debug
8-
- BUILD_TYPE: Release
6+
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
7+
DOCKERFILE: Dockerfile-2004
8+
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
9+
DOCKERFILE: Dockerfile-2104
10+
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
11+
DOCKERFILE: Dockerfile-debian
12+
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
13+
BUILD_TYPE: Release
914

1015
install:
11-
- sh: sudo apt update --ignore-missing
12-
- sh: sudo apt install -y build-essential fakeroot gcc-10 g++-10 cmake libssl-dev libavdevice-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libpulse-dev libopus-dev libxtst-dev libx11-dev libxrandr-dev libxfixes-dev libevdev-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libdrm-dev libcap-dev software-properties-common wget curl
13-
- sh: sudo apt list --installed
14-
- sh: sudo wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run -O cuda_11.4.2_470.57.02_linux.run
15-
- sh: sudo sh cuda_11.4.2_470.57.02_linux.run --silent --toolkit --no-opengl-libs --no-man-page --no-drm
16-
- sh: export PATH=/usr/local/cuda-11.4/bin${PATH:+:${PATH}}
17-
- sh: export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
18-
# - sh: export APPVEYOR_SSH_BLOCK=true
19-
# - sh: curl -sflL 'https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-ssh.sh' | bash -e -
2016
- cmd: C:\msys64\usr\bin\bash -lc "pacman --needed --noconfirm -S mingw-w64-x86_64-openssl mingw-w64-x86_64-cmake mingw-w64-x86_64-toolchain mingw-w64-x86_64-opus mingw-w64-x86_64-x265 mingw-w64-x86_64-boost git yasm nasm diffutils make"
2117

2218
before_build:
23-
- git submodule update --init --recursive
24-
- mkdir build
25-
- cd build
19+
- cmd: git submodule update --init --recursive
20+
- cmd: mkdir build
21+
- cmd: cd build
22+
- sh: cd scripts
23+
- sh: ./build-container.sh -f $DOCKERFILE
2624

2725
build_script:
2826
- cmd: set OLDPATH=%PATH%
2927
- cmd: set PATH=C:\msys64\mingw64\bin
30-
- sh: cmake -DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSUNSHINE_EXECUTABLE_PATH=sunshine -DSUNSHINE_ASSETS_DIR=/etc/sunshine ..
3128
- cmd: cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSUNSHINE_ASSETS_DIR=assets -G "MinGW Makefiles" ..
32-
- sh: make -j$(nproc)
3329
- cmd: mingw32-make -j2
3430
- cmd: set PATH=%OLDPATH%
31+
- sh: ./build-sunshine.sh -pu
3532

3633
after_build:
37-
- sh: ./gen-deb
3834
- cmd: Del ..\assets\apps_linux.json
3935
- cmd: 7z a Sunshine-Windows.zip ..\assets
4036
- cmd: 7z a Sunshine-Windows.zip sunshine.exe
@@ -44,5 +40,5 @@ after_build:
4440
- cmd: 7z a Sunshine-Windows.zip ..\tools\install-service.bat
4541
- cmd: 7z a Sunshine-Windows.zip ..\tools\uninstall-service.bat
4642
- cmd: appveyor PushArtifact Sunshine-Windows.zip
47-
- sh: appveyor PushArtifact package-deb/sunshine.deb
48-
- sh: appveyor PushArtifact sunshine.service
43+
- sh: appveyor PushArtifact sunshine-build/sunshine.deb
44+

scripts/Dockerfile-2004

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ubuntu:20.04 AS sunshine-2004
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG TZ="Europe/London"
5+
6+
RUN apt-get update -y && \
7+
apt-get install -y \
8+
git wget gcc-10 g++-10 build-essential cmake libssl-dev libavdevice-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libpulse-dev libopus-dev libxtst-dev libx11-dev libxrandr-dev libxfixes-dev libevdev-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libdrm-dev libcap-dev libwayland-dev
9+
10+
RUN cp /usr/bin/gcc-10 /usr/bin/gcc && cp /usr/bin/g++-10 /usr/bin/gcc-10
11+
12+
RUN wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run --progress=bar:force:noscroll -q --show-progress -O /root/cuda.run && chmod a+x /root/cuda.run
13+
RUN /root/cuda.run --silent --toolkit --toolkitpath=/usr --no-opengl-libs --no-man-page --no-drm && rm /root/cuda.run
14+
15+
COPY build-private.sh /root/build.sh
16+
17+
18+
ENTRYPOINT ["/root/build.sh"]

scripts/Dockerfile-2104

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ubuntu:21.04 AS sunshine-2104
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG TZ="Europe/London"
5+
6+
RUN apt-get update -y && \
7+
apt-get install -y \
8+
git build-essential cmake libssl-dev libavdevice-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libpulse-dev libopus-dev libxtst-dev libx11-dev libxrandr-dev libxfixes-dev libevdev-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libdrm-dev libcap-dev libwayland-dev nvidia-cuda-dev nvidia-cuda-toolkit
9+
10+
COPY build-private.sh /root/build.sh
11+
12+
13+
ENTRYPOINT ["/root/build.sh"]

scripts/Dockerfile-debian

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM debian:bullseye AS sunshine-debian
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
ARG TZ="Europe/London"
5+
6+
RUN echo deb http://deb.debian.org/debian/ bullseye main contrib non-free | tee /etc/apt/sources.list.d/non-free.list
7+
RUN apt-get update -y && \
8+
apt-get install -y \
9+
git build-essential cmake libssl-dev libavdevice-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libpulse-dev libopus-dev libxtst-dev libx11-dev libxrandr-dev libxfixes-dev libevdev-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libdrm-dev libcap-dev libwayland-dev nvidia-cuda-dev nvidia-cuda-toolkit
10+
11+
COPY build-private.sh /root/build.sh
12+
13+
14+
ENTRYPOINT ["/root/build.sh"]

scripts/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Introduction
2+
Sunshine is a Gamestream host for Moonlight
3+
4+
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/cgrtw2g3fq9b0b70/branch/master?svg=true)](https://ci.appveyor.com/project/loki-47-6F-64/sunshine/branch/master)
5+
[![Downloads](https://img.shields.io/github/downloads/Loki-47-6F-64/sunshine/total)](https://github.com/Loki-47-6F-64/sunshine/releases)
6+
7+
You may wish to simply build sunshine from source, without bloating your OS with development files.
8+
These scripts will create a docker images that have the necessary packages. As a result, removing the development files after you're done is a single command away.
9+
These scripts use docker under the hood, as such, they can only be used to compile the Linux version
10+
11+
12+
#### Requirements
13+
14+
```
15+
sudo apt install docker
16+
```
17+
18+
#### instructions
19+
20+
You'll require one of the following Dockerfiles:
21+
* Dockerfile-2004 --> Ubuntu 20.04
22+
* Dockerfile-2104 --> Ubuntu 21.04
23+
* Dockerfile-debian --> Debian Bullseye
24+
25+
Depending on your system, the build-* scripts may need root privilleges
26+
27+
First, the docker container needs to be created:
28+
```
29+
cd scripts
30+
./build-container.sh -f Dockerfile-<name>
31+
```
32+
33+
Then, the sources will be compiled and the debian package generated:
34+
```
35+
./build-sunshine -p -s ..
36+
```
37+
You can run `build-sunshine -p -s ..` again as long as the docker container exists.
38+
39+
```
40+
git pull
41+
./build-sunshine -p -s ..
42+
```
43+
44+
Optionally, the docker container can be removed after you're finished:
45+
```
46+
./build-container.sh -c delete
47+
```
48+
49+
Finally install the resulting package:
50+
```
51+
sudo apt install -f sunshine-build/sunshine.deb
52+
```
53+

scripts/build-container.sh

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#/bin/bash -e
2+
3+
function usage {
4+
echo "Usage: $0 [OPTIONS]"
5+
echo " -c: command --> default [build]"
6+
echo " | delete --> Delete the container, Dockerfile isn't mandatory"
7+
echo " | build --> Build the container, Dockerfile is mandatory"
8+
echo " | compile --> Builds the container, then compiles it. Dockerfile is mandatory"
9+
echo ""
10+
echo " -n: name: Docker container name --> default [sunshine]"
11+
echo " --> all: Build/Compile/Delete all available docker containers"
12+
echo " -f: Dockerfile: The name of the docker file"
13+
}
14+
15+
# Attempt to turn relative paths into absolute paths
16+
function absolute_path() {
17+
RELATIVE_PATH=$1
18+
if which realpath >/dev/null 2>/dev/null
19+
then
20+
RELATIVE_PATH=$(realpath $RELATIVE_PATH)
21+
else
22+
echo "Warning: realpath is not installed on your system, ensure [$1] is absolute"
23+
fi
24+
25+
RETURN=$RELATIVE_PATH
26+
}
27+
28+
CONTAINER_NAME=sunshine
29+
COMMAND=BUILD
30+
31+
function build_container() {
32+
CONTAINER_NAME=$1
33+
DOCKER_FILE=$2
34+
35+
if [ ! -f "$DOCKER_FILE" ]
36+
then
37+
echo "Error: $DOCKER_FILE doesn't exist"
38+
exit 7
39+
fi
40+
41+
echo "docker build . -t $CONTAINER_NAME -f $DOCKER_FILE"
42+
docker build . -t "$CONTAINER_NAME" -f "$DOCKER_FILE"
43+
}
44+
45+
function delete() {
46+
CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]')
47+
if [ "$CONTAINER_NAME_UPPER" == "ALL" ]
48+
then
49+
shopt -s nullglob
50+
for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f)
51+
do
52+
CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)"
53+
54+
if docker inspect "$CURRENT_CONTAINER" > /dev/null 2> /dev/null
55+
then
56+
echo "docker rmi $CURRENT_CONTAINER"
57+
docker rmi "$CURRENT_CONTAINER"
58+
fi
59+
done
60+
shopt -u nullglob #revert nullglob back to it's normal default state
61+
else
62+
if docker inspect "$CONTAINER_NAME" > /dev/null 2> /dev/null
63+
then
64+
echo "docker rmi $CONTAINER_NAME"
65+
docker rmi $CONTAINER_NAME
66+
fi
67+
fi
68+
}
69+
70+
function build() {
71+
CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]')
72+
if [ "$CONTAINER_NAME_UPPER" == "ALL" ]
73+
then
74+
shopt -s nullglob
75+
for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f)
76+
do
77+
CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)"
78+
build_container "$CURRENT_CONTAINER" "$file"
79+
done
80+
shopt -u nullglob #revert nullglob back to it's normal default state
81+
else
82+
if [[ -z "$DOCKER_FILE" ]]
83+
then
84+
echo "Error: if container name isn't equal to 'all', you need to specify the Dockerfile"
85+
exit 6
86+
fi
87+
88+
build_container "$CONTAINER_NAME" "$DOCKER_FILE"
89+
fi
90+
}
91+
92+
function abort() {
93+
echo "$1"
94+
exit 10
95+
}
96+
97+
function compile() {
98+
CONTAINER_NAME_UPPER=$(echo "$CONTAINER_NAME" | tr '[:lower:]' '[:upper:]')
99+
if [ "$CONTAINER_NAME_UPPER" == "ALL" ]
100+
then
101+
shopt -s nullglob
102+
103+
# If any docker container doesn't exist, we cannot compile all of them
104+
for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f)
105+
do
106+
CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)"
107+
108+
# If container doesn't exist --> abort.
109+
docker inspect "$CURRENT_CONTAINER" > /dev/null 2> /dev/null || abort "Error: container image [$CURRENT_CONTAINER] doesn't exist"
110+
done
111+
112+
for file in $(find . -maxdepth 1 -iname "Dockerfile-*" -type f)
113+
do
114+
CURRENT_CONTAINER="sunshine-$(echo $file | cut -c 14-)"
115+
116+
echo "$PWD/build-sunshine.sh -p -n $CURRENT_CONTAINER"
117+
"$PWD/build-sunshine.sh" -p -n "$CURRENT_CONTAINER"
118+
done
119+
shopt -u nullglob #revert nullglob back to it's normal default state
120+
else
121+
# If container exists
122+
if docker inspect "$CURRENT_CONTAINER" > /dev/null 2> /dev/null
123+
then
124+
echo "$PWD/build-sunshine.sh -p -n $CONTAINER_NAME"
125+
"$PWD/build-sunshine.sh" -p -n "$CONTAINER_NAME"
126+
else
127+
echo "Error: container image [$CONTAINER_NAME] doesn't exist"
128+
exit 9
129+
fi
130+
fi
131+
}
132+
133+
while getopts ":c:hn:f:" arg; do
134+
case ${arg} in
135+
c)
136+
COMMAND=$(echo $OPTARG | tr '[:lower:]' '[:upper:]')
137+
;;
138+
n)
139+
echo "Container name: $OPTARG"
140+
CONTAINER_NAME="$OPTARG"
141+
;;
142+
f)
143+
echo "Using Dockerfile [$OPTARG]"
144+
DOCKER_FILE="$OPTARG"
145+
;;
146+
h)
147+
usage
148+
exit 0
149+
;;
150+
esac
151+
done
152+
153+
echo "$0 set to $(echo $COMMAND | tr '[:upper:]' '[:lower:]')"
154+
155+
if [[ "$COMMAND" == "BUILD" ]]
156+
then
157+
echo "Start building..."
158+
delete
159+
build
160+
echo "Done."
161+
elif [[ "$COMMAND" == "COMPILE" ]]
162+
then
163+
echo "Start compiling..."
164+
compile
165+
echo "Done."
166+
elif [[ "$COMMAND" == "DELETE" ]]
167+
then
168+
echo "Start deleting..."
169+
delete
170+
echo "Done."
171+
else
172+
echo "Unknown command [$(echo $COMMAND | tr '[:upper:]' '[:lower:]')]"
173+
exit 4
174+
fi

scripts/build-private.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash -e
2+
3+
CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-Release}"
4+
SUNSHINE_EXECUTABLE_PATH="${SUNSHINE_EXECUTABLE_PATH:-/usr/bin/sunshine}"
5+
SUNSHINE_ASSETS_DIR="${SUNSHINE_ASSETS_DIR:-/etc/sunshine}"
6+
7+
8+
SUNSHINE_ROOT="${SUNSHINE_ROOT:-/root/sunshine}"
9+
SUNSHINE_TAG="${SUNSHINE_TAG:-master}"
10+
SUNSHINE_GIT_URL="${SUNSHINE_GIT_URL:-https://github.com/loki-47-6F-64/sunshine.git}"
11+
12+
13+
SUNSHINE_ENABLE_WAYLAND=${SUNSHINE_ENABLE_WAYLAND:-ON}
14+
SUNSHINE_ENABLE_X11=${SUNSHINE_ENABLE_X11:-ON}
15+
SUNSHINE_ENABLE_DRM=${SUNSHINE_ENABLE_DRM:-ON}
16+
SUNSHINE_ENABLE_CUDA=${SUNSHINE_ENABLE_CUDA:-ON}
17+
18+
# For debugging, it would be usefull to have the sources on the host.
19+
if [[ ! -d "$SUNSHINE_ROOT" ]]
20+
then
21+
git clone --depth 1 --branch "$SUNSHINE_TAG" "$SUNSHINE_GIT_URL" --recurse-submodules "$SUNSHINE_ROOT"
22+
fi
23+
24+
if [[ ! -d /root/sunshine-build ]]
25+
then
26+
mkdir -p /root/sunshine-build
27+
fi
28+
cd /root/sunshine-build
29+
30+
cmake "-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" "-DSUNSHINE_EXECUTABLE_PATH=$SUNSHINE_EXECUTABLE_PATH" "-DSUNSHINE_ASSETS_DIR=$SUNSHINE_ASSETS_DIR" "-DSUNSHINE_ENABLE_WAYLAND=$SUNSHINE_ENABLE_WAYLAND" "-DSUNSHINE_ENABLE_X11=$SUNSHINE_ENABLE_X11" "-DSUNSHINE_ENABLE_DRM=$SUNSHINE_ENABLE_DRM" "-DSUNSHINE_ENABLE_CUDA=$SUNSHINE_ENABLE_CUDA" "$SUNSHINE_ROOT"
31+
32+
make -j ${nproc}
33+
34+
./gen-deb

0 commit comments

Comments
 (0)