From d677f72a7a51dd71e18dff02282c018ab48bd0e3 Mon Sep 17 00:00:00 2001 From: jackun Date: Tue, 10 Nov 2020 18:09:45 +0200 Subject: [PATCH] Build script for creating and building in Steam runtime docker --- build-srt.sh | 155 +++++++++++++++++---------------------- build-with-srt-docker.sh | 37 ++++++++++ steamrt.Dockerfile.in | 20 +++++ 3 files changed, 124 insertions(+), 88 deletions(-) create mode 100755 build-with-srt-docker.sh create mode 100644 steamrt.Dockerfile.in diff --git a/build-srt.sh b/build-srt.sh index b8938e8b..572c0e5f 100755 --- a/build-srt.sh +++ b/build-srt.sh @@ -1,24 +1,20 @@ #!/usr/bin/env bash -set -e - # Specialized build script for Steam Runtime SDK docker +set -e -OS_RELEASE_FILES=("/etc/os-release" "/usr/lib/os-release") -XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" -XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" -DATA_DIR="$XDG_DATA_HOME/MangoHud" -CONFIG_DIR="$XDG_CONFIG_HOME/MangoHud" -LAYER="build/release/usr/share/vulkan/implicit_layer.d/mangohud.json" -INSTALL_DIR="build/package/" -IMPLICIT_LAYER_DIR="$XDG_DATA_HOME/vulkan/implicit_layer.d" +IFS=" " read -ra debian_chroot < /etc/debian_chroot +LOCAL_CC=${CC:-gcc-5} +LOCAL_CXX=${CXX:-g++-5} +RUNTIME=${RUNTIME:-${debian_chroot[1]}} +SRT_VERSION=${SRT_VERSION:-${debian_chroot[2]}} VERSION=$(git describe --long --tags --always | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//') dependencies() { - if [[ ! -f build/release/usr/lib64/libMangoHud.so ]]; then + if [[ ! -f build-srt/release/usr/lib/libMangoHud.so ]]; then install() { set +e - for i in $(eval echo $DEPS); do + for i in ${DEPS[@]}; do dpkg-query -s "$i" &> /dev/null if [[ $? == 1 ]]; then INSTALL="$INSTALL""$i " @@ -32,19 +28,26 @@ dependencies() { } echo "# Checking Dependencies" - DEPS="{gcc-5-multilib,g++-5-multilib,unzip}" + DEPS=(${LOCAL_CC}-multilib ${LOCAL_CXX}-multilib unzip) install - # py3.2 is weird - ln -sf python3.5 /usr/bin/python3 + + # use py3.5 with scout, otherwise hope python is new enough + set +e + which python3.5 >/dev/null + if [ $? -eq 0 ]; then + # py3.2 is weird + ln -sf python3.5 /usr/bin/python3 + fi + set -e if [[ ! -f ./bin/get-pip.py ]]; then curl https://bootstrap.pypa.io/get-pip.py -o bin/get-pip.py - python3.5 ./bin/get-pip.py fi + python3 ./bin/get-pip.py - if [[ $(pip3.5 show meson; echo $?) == 1 || $(pip3.5 show mako; echo $?) == 1 ]]; then - pip3.5 install meson mako + if [[ $(pip3 show meson >/dev/null; echo $?) == 1 || $(pip3 show mako >/dev/null; echo $?) == 1 ]]; then + pip3 install meson mako fi if [[ ! -f /usr/include/NVCtrl/NVCtrl.h ]]; then @@ -66,83 +69,49 @@ dependencies() { configure() { dependencies git submodule update --init - if [[ ! -f "build/meson64/build.ninja" ]]; then - export CC="gcc-5" - export CXX="g++-5" - meson build/meson64 --libdir lib/mangohud/lib64 --prefix /usr -Dappend_libdir_mangohud=false ${CONFIGURE_OPTS} + if [[ ! -f "build-srt/meson64/build.ninja" ]]; then + export CC="${LOCAL_CC}" + export CXX="${LOCAL_CXX}" + meson build-srt/meson64 --libdir lib/mangohud/lib --prefix /usr -Dappend_libdir_mangohud=false -Dld_libdir_prefix=true $@ ${CONFIGURE_OPTS} fi - if [[ ! -f "build/meson32/build.ninja" ]]; then - export CC="gcc-5 -m32" - export CXX="g++-5 -m32" + if [[ ! -f "build-srt/meson32/build.ninja" ]]; then + export CC="${LOCAL_CC} -m32" + export CXX="${LOCAL_CXX} -m32" export PKG_CONFIG_PATH="/usr/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:${PKG_CONFIG_PATH_32}" - export LLVM_CONFIG="/usr/bin/llvm-config32" - meson build/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud=false ${CONFIGURE_OPTS} + meson build-srt/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud=false -Dld_libdir_prefix=true $@ ${CONFIGURE_OPTS} fi } build() { - if [[ ! -f "build/meson64/build.ninja" || ! -f "build/meson32/build.ninja" ]]; then + if [[ ! -f "build-srt/meson64/build.ninja" || ! -f "build-srt/meson32/build.ninja" ]]; then configure fi - DESTDIR="$PWD/build/release" ninja -C build/meson32 install - DESTDIR="$PWD/build/release" ninja -C build/meson64 install + DESTDIR="$PWD/build-srt/release" ninja -C build-srt/meson32 install + DESTDIR="$PWD/build-srt/release" ninja -C build-srt/meson64 install } package() { - LIB="build/release/usr/lib/mangohud/lib64/libMangoHud.so" - LIB32="build/release/usr/lib/mangohud/lib32/libMangoHud.so" - if [[ ! -f "$LIB" || "$LIB" -ot "build/meson64/src/libMangoHud.so" ]]; then + LIB="build-srt/release/usr/lib/mangohud/lib/libMangoHud.so" + LIB32="build-srt/release/usr/lib/mangohud/lib32/libMangoHud.so" + if [[ ! -f "$LIB" || "$LIB" -ot "build-srt/meson64/src/libMangoHud.so" ]]; then build fi tar --numeric-owner --owner=0 --group=0 \ - -C build/release -cvf "build/MangoHud-package.tar" . + -C build-srt/release -cvf "build-srt/MangoHud-package.tar" . } release() { - rm build/MangoHud-package.tar - mkdir -p build/MangoHud + rm build-srt/MangoHud-package.tar + mkdir -p build-srt/MangoHud package - cp --preserve=mode bin/mangohud-setup.sh build/MangoHud/mangohud-setup.sh - cp build/MangoHud-package.tar build/MangoHud/MangoHud-package.tar + cp --preserve=mode bin/mangohud-setup.sh build-srt/MangoHud/mangohud-setup.sh + cp build-srt/MangoHud-package.tar build-srt/MangoHud/MangoHud-package.tar tar --numeric-owner --owner=0 --group=0 \ - -C build -czvf build/MangoHud-$VERSION.tar.gz MangoHud -} - -install() { - rm -rf "$HOME/.local/share/MangoHud/" - rm -f "$HOME/.local/share/vulkan/implicit_layer.d/"{mangohud32.json,mangohud64.json} - - [ "$UID" -eq 0 ] || mkdir -pv "${CONFIG_DIR}" - [ "$UID" -eq 0 ] || exec sudo bash "$0" install - - /usr/bin/install -vm644 -D ./build/release/usr/lib/mangohud/lib32/libMangoHud.so /usr/lib/mangohud/lib32/libMangoHud.so - /usr/bin/install -vm644 -D ./build/release/usr/lib/mangohud/lib64/libMangoHud.so /usr/lib/mangohud/lib64/libMangoHud.so - /usr/bin/install -vm644 -D ./build/release/usr/lib/mangohud/lib32/libMangoHud_dlsym.so /usr/lib/mangohud/lib32/libMangoHud_dlsym.so - /usr/bin/install -vm644 -D ./build/release/usr/lib/mangohud/lib64/libMangoHud_dlsym.so /usr/lib/mangohud/lib64/libMangoHud_dlsym.so - /usr/bin/install -vm644 -D ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.x86.json /usr/share/vulkan/implicit_layer.d/MangoHud.x86.json - /usr/bin/install -vm644 -D ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json /usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json - /usr/bin/install -vm644 -D ./build/release/usr/share/doc/mangohud/MangoHud.conf.example /usr/share/doc/mangohud/MangoHud.conf.example - - /usr/bin/install -vm755 ./build/release/usr/bin/mangohud.x86 /usr/bin/mangohud.x86 - /usr/bin/install -vm755 ./build/release/usr/bin/mangohud /usr/bin/mangohud - - echo "MangoHud Installed" + -C build-srt -czvf build-srt/MangoHud-${VERSION}_${RUNTIME}-${SRT_VERSION}.tar.gz MangoHud } clean() { - rm -rf "build" -} - -uninstall() { - [ "$UID" -eq 0 ] || exec sudo bash "$0" uninstall - rm -rfv "/usr/lib/mangohud" - rm -rfv "/usr/share/doc/mangohud" - rm -fv "/usr/share/vulkan/implicit_layer.d/mangohud.json" - rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.json" - rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86.json" - rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json" - rm -fv "/usr/bin/mangohud" - rm -fv "/usr/bin/mangohud.x86" + rm -rf "build-srt/" } usage() { @@ -157,29 +126,39 @@ usage() { echo -e "\tconfigure\tEnsures that dependencies are installed, updates git submodules, and generates files needed for building MangoHud. This is automatically run by the build command" echo -e "\tbuild\t\tIf needed runs configure and then builds (compiles) MangoHud" echo -e "\tpackage\t\tRuns build if needed and then builds a tar package from MangoHud" - echo -e "\tinstall\t\tInstall MangoHud onto your system" echo -e "\tclean\t\tRemoves build directory" - echo -e "\tuninstall\tRemoves installed MangoHud files from your system" echo -e "\trelease\t\tBuilds a MangoHud release tar package" } -for a in $@; do - case $a in - "") build;; - "pull") git pull;; - "configure") configure;; - "build") build;; +if [[ -z $@ ]]; then + usage no-args +fi + +while [ $# -gt 0 ]; do + OPTS=() + arg="$1" + shift + + while [ $# -gt 0 ] ; do + case $1 in + -*) + OPTS+=("$1") + shift + ;; + *) + break + ;; + esac; + done + + echo -e "\e[1mCommand:\e[92m" $arg "\e[94m"${OPTS[@]}"\e[39m\e[0m" + case $arg in + "configure") configure ${OPTS[@]};; + "build") build ${OPTS[@]};; "package") package;; - "install") install;; "clean") clean;; - "uninstall") uninstall;; "release") release;; *) usage esac done - -if [[ -z $@ ]]; then - usage no-args -fi - diff --git a/build-with-srt-docker.sh b/build-with-srt-docker.sh new file mode 100755 index 00000000..b06a86ff --- /dev/null +++ b/build-with-srt-docker.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -u + +if [ $# -eq 2 ]; then + echo Specify runtime version too + exit 1 +fi + +SRCDIR=$PWD +BRANCH="${1:-master}" +# soldier 0.20201022.1 or newer +# scout 0.20201104.0 or newer +RUNTIME="${2:-soldier}" +VERSION="${3:-0.20201022.1}" +IMAGE="steamrt_${RUNTIME}_amd64:mango-${VERSION}" +BASEURL="https://repo.steampowered.com/steamrt-images-${RUNTIME}/snapshots/${VERSION}" + +echo -e "\e[1mBuilding branch \e[92m${BRANCH}\e[39m using \e[92m${RUNTIME}:${VERSION}\e[39m runtime\e[0m" + +if ! docker inspect --type=image ${IMAGE} 2>&1 >/dev/null ; then + rm -fr ./cache/empty + set -e + mkdir -p ./cache/empty + sed "s/%RUNTIME%/${RUNTIME}/g" steamrt.Dockerfile.in > ./cache/steamrt.Dockerfile + + wget -P ./cache -c ${BASEURL}/com.valvesoftware.SteamRuntime.Sdk-amd64,i386-${RUNTIME}-sysroot.tar.gz + cp --reflink=always "./cache/com.valvesoftware.SteamRuntime.Sdk-amd64,i386-${RUNTIME}-sysroot.tar.gz" ./cache/empty/ + docker build -f ./cache/steamrt.Dockerfile -t ${IMAGE} ./cache/empty +fi + +docker run --entrypoint=/bin/sh --rm -i -v "${SRCDIR}/srt-output:/output" ${IMAGE} << EOF +export RUNTIME=${RUNTIME} +export SRT_VERSION=${VERSION} +git clone git://github.com/flightlessmango/MangoHud.git . --branch ${BRANCH} --recurse-submodules --progress +./build-srt.sh clean build package release +cp -v build-srt/MangoHud*tar.gz /output/ +EOF diff --git a/steamrt.Dockerfile.in b/steamrt.Dockerfile.in new file mode 100644 index 00000000..a6ea0ad5 --- /dev/null +++ b/steamrt.Dockerfile.in @@ -0,0 +1,20 @@ +FROM scratch +ADD com.valvesoftware.SteamRuntime.Sdk-amd64,i386-%RUNTIME%-sysroot.tar.gz / +WORKDIR /build +RUN \ +set -e; \ +mkdir -p /run/systemd; \ +echo 'docker' > /run/systemd/container; \ +mkdir -p /prep; cd /prep; \ +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py; \ +if [ ! -f /usr/bin/unzip ]; then apt-get update; apt-get -y install unzip; fi; \ +if [ -f /usr/bin/python3.5 ]; then ln -sf python3.5 /usr/bin/python3; fi; \ +python3 ./get-pip.py; \ +pip3 install meson mako; \ +curl -LO http://mirrors.kernel.org/ubuntu/pool/main/n/nvidia-settings/libxnvctrl0_440.64-0ubuntu1_amd64.deb; \ +curl -LO http://mirrors.kernel.org/ubuntu/pool/main/n/nvidia-settings/libxnvctrl-dev_440.64-0ubuntu1_amd64.deb; \ +dpkg -i libxnvctrl0_440.64-0ubuntu1_amd64.deb libxnvctrl-dev_440.64-0ubuntu1_amd64.deb; \ +cd /; rm -fr /prep; \ +: + +CMD ["/bin/bash"]