From 3b833104fbe16931e8fa093ac7b993f081186f00 Mon Sep 17 00:00:00 2001 From: Roman Meier Date: Sat, 21 Mar 2020 16:59:25 +0100 Subject: [PATCH] ci: Port Citra flatpak build to yuzu Port Citra's travis based flatpak build to yuzu's azure build system. --- .../linux-flatpak/azure-ci-flatpak.env | 8 + .ci/scripts/linux-flatpak/azure-ci.env | 14 ++ .ci/scripts/linux-flatpak/docker.sh | 46 +++++ .ci/scripts/linux-flatpak/exec.sh | 6 + .ci/scripts/linux-flatpak/finish.sh | 10 + .ci/scripts/linux-flatpak/generate-data.sh | 182 ++++++++++++++++++ .ci/templates/build-flatpak-single.yml | 35 ++++ .ci/yuzu-flatpak-step2.yml | 39 ++++ keys.tar.enc | 0 9 files changed, 340 insertions(+) create mode 100644 .ci/scripts/linux-flatpak/azure-ci-flatpak.env create mode 100644 .ci/scripts/linux-flatpak/azure-ci.env create mode 100755 .ci/scripts/linux-flatpak/docker.sh create mode 100755 .ci/scripts/linux-flatpak/exec.sh create mode 100755 .ci/scripts/linux-flatpak/finish.sh create mode 100644 .ci/scripts/linux-flatpak/generate-data.sh create mode 100644 .ci/templates/build-flatpak-single.yml create mode 100644 .ci/yuzu-flatpak-step2.yml create mode 100644 keys.tar.enc diff --git a/.ci/scripts/linux-flatpak/azure-ci-flatpak.env b/.ci/scripts/linux-flatpak/azure-ci-flatpak.env new file mode 100644 index 0000000000..93467a2815 --- /dev/null +++ b/.ci/scripts/linux-flatpak/azure-ci-flatpak.env @@ -0,0 +1,8 @@ +# Flatpak specific environment variables +FLATPAK_ENC_IV +FLATPAK_ENC_K +FLATPAK_GPG_PUBLIC_KEY +FLATPAK_SSH_HOSTNAME +FLATPAK_SSH_PORT +FLATPAK_SSH_PUBLIC_KEY +FLATPAK_SSH_USER diff --git a/.ci/scripts/linux-flatpak/azure-ci.env b/.ci/scripts/linux-flatpak/azure-ci.env new file mode 100644 index 0000000000..6c8612d93c --- /dev/null +++ b/.ci/scripts/linux-flatpak/azure-ci.env @@ -0,0 +1,14 @@ +# List of environment variables to be shared with Docker containers +AZURE_BRANCH +AZURE_BUILD_ID +AZURE_BUILD_NUMBER +AZURE_COMMIT +AZURE_COMMIT_RANGE +AZURE_EVENT_TYPE +AZURE_JOB_ID +AZURE_REPO_SLUG +AZURE_TAG + +# yuzu specific flags +ENABLE_COMPATIBILITY_REPORTING +USE_DISCORD_PRESENCE diff --git a/.ci/scripts/linux-flatpak/docker.sh b/.ci/scripts/linux-flatpak/docker.sh new file mode 100755 index 0000000000..3cd5d44d69 --- /dev/null +++ b/.ci/scripts/linux-flatpak/docker.sh @@ -0,0 +1,46 @@ +#!/bin/bash -ex + +# Converts "yuzu-emu/yuzu-release" to "yuzu-release" +REPO_NAME=$(echo $AZURE_REPO_SLUG | cut -d'/' -f 2) +YUZU_SRC_DIR="/yuzu" +BUILD_DIR="$YUZU_SRC_DIR/build" +REPO_DIR="$YUZU_SRC_DIR/repo" +STATE_DIR="$YUZU_SRC_DIR/.flatpak-builder" +KEYS_ARCHIVE="/tmp/keys.tar" +SSH_DIR="/upload" +SSH_KEY="/tmp/ssh.key" +GPG_KEY="/tmp/gpg.key" + +# Generate flatpak Manifest and AppData files (/tmp/appdata.xml and /tmp/org.yuzu.$REPO_NAME.json) +/bin/bash -ex $YUZU_SRC_DIR/.ci/scripts/linux-flatpak/generate-data.sh $1 + +# Extract keys +openssl aes-256-cbc -K $FLATPAK_ENC_K -iv $FLATPAK_ENC_IV -in "$YUZU_SRC_DIR/keys.tar.enc" -out "$KEYS_ARCHIVE" -d +tar -C /tmp -xvf $KEYS_ARCHIVE + +# Configure SSH keys +eval "$(ssh-agent -s)" +chmod -R 600 "$HOME/.ssh" +chown -R root "$HOME/.ssh" +chmod 600 "$SSH_KEY" +ssh-add "$SSH_KEY" +echo "[$FLATPAK_SSH_HOSTNAME]:$FLATPAK_SSH_PORT,[$(dig +short $FLATPAK_SSH_HOSTNAME)]:$FLATPAK_SSH_PORT $FLATPAK_SSH_PUBLIC_KEY" > ~/.ssh/known_hosts + +# Configure GPG keys +gpg2 --import "$GPG_KEY" + +# Mount our flatpak repository +# -o reconnect and -o ServerAliveInterval ensure that +# the share stays active during long flatpak builds +mkdir -p "$REPO_DIR" +sshfs "$FLATPAK_SSH_USER@$FLATPAK_SSH_HOSTNAME:$SSH_DIR" "$REPO_DIR" -C -p "$FLATPAK_SSH_PORT" -o IdentityFile="$SSH_KEY" -o ServerAliveInterval=60 -o "reconnect" -o auto_cache -o no_readahead + + +# setup ccache location +mkdir -p "$STATE_DIR" +ln -sv --force /root/.ccache "$STATE_DIR/ccache" + +# Build the yuzu flatpak +flatpak-builder -v --jobs=4 --ccache --force-clean --state-dir="$STATE_DIR" --gpg-sign="$FLATPAK_GPG_PUBLIC_KEY" --repo="$REPO_DIR" "$BUILD_DIR" "/tmp/org.yuzu.$REPO_NAME.json" +flatpak build-update-repo "$REPO_DIR" -v --generate-static-deltas --gpg-sign="$FLATPAK_GPG_PUBLIC_KEY" + diff --git a/.ci/scripts/linux-flatpak/exec.sh b/.ci/scripts/linux-flatpak/exec.sh new file mode 100755 index 0000000000..73613f60f3 --- /dev/null +++ b/.ci/scripts/linux-flatpak/exec.sh @@ -0,0 +1,6 @@ +#!/bin/bash -ex +mkdir -p "$HOME/.ccache" + +# Configure docker and call the script that generates application data and build scripts +docker run --env-file .ci/scripts/linux-flatpak/azure-ci.env --env-file .ci/scripts/linux-flatpak/azure-ci-flatpak.env -v $(pwd):/yuzu -v "$HOME/.ccache":/root/.ccache -v "$HOME/.ssh":/root/.ssh --privileged yuzuemu/build-environments:linux-flatpak /bin/bash -ex /yuzu/.ci/scripts/linux-flatpak/docker.sh + diff --git a/.ci/scripts/linux-flatpak/finish.sh b/.ci/scripts/linux-flatpak/finish.sh new file mode 100755 index 0000000000..45e543e079 --- /dev/null +++ b/.ci/scripts/linux-flatpak/finish.sh @@ -0,0 +1,10 @@ +#!/bin/bash -ex + +YUZU_SRC_DIR="/yuzu" +REPO_DIR="$YUZU_SRC_DIR/repo" + +# When the script finishes, unmount the repository and delete sensitive files, +# regardless of whether the build passes or fails +umount "$REPO_DIR" || true +rm -rf "$REPO_DIR" "/tmp/*" || true + diff --git a/.ci/scripts/linux-flatpak/generate-data.sh b/.ci/scripts/linux-flatpak/generate-data.sh new file mode 100644 index 0000000000..dbaf0dcd2a --- /dev/null +++ b/.ci/scripts/linux-flatpak/generate-data.sh @@ -0,0 +1,182 @@ +#!/bin/bash -ex +# This script generates the appdata.xml and org.yuzu.$REPO_NAME.json files +# needed to define application metadata and build yuzu + +# Converts "yuzu-emu/yuzu-release" to "yuzu-release" +REPO_NAME=$(echo $AZURE_REPO_SLUG | cut -d'/' -f 2) +# Converts "yuzu-release" to "yuzu Release" +REPO_NAME_FRIENDLY=$(echo $REPO_NAME | sed -e 's/-/ /g' -e 's/\b\(.\)/\u\1/g') + +# Generate the correct appdata.xml for the version of yuzu we're building +cat > /tmp/appdata.xml < + + org.yuzu.$REPO_NAME.desktop + $REPO_NAME_FRIENDLY + Nintendo Switch emulator + CC0-1.0 + GPL-2.0 + +

yuzu is an experimental open-source emulator for the Nintendo Switch from the creators of Citra.

+

It is written in C++ with portability in mind, with builds actively maintained for Windows and Linux. The emulator is currently only useful for homebrew development and research purposes.

+

yuzu only emulates a subset of Switch hardware and therefore is generally only useful for running/debugging homebrew applications. At this time, yuzu cannot play a majority of commercial games without major problems. yuzu can boot some commercial Switch games to varying degrees of success, but your experience may vary between games and for different combinations of host hardware.

+

yuzu is licensed under the GPLv2 (or any later version). Refer to the license.txt file included.

+
+ https://yuzu-emu.org/ + https://yuzu-emu.org/donate/ + https://github.com/yuzu-emu/yuzu/issues + https://yuzu-emu.org/wiki/faq/ + https://yuzu-emu.org/wiki/home/ + https://yuzu-emu.org/images/screenshots/001-Super%20Mario%20Odyssey.png + https://yuzu-emu.org/images/screenshots/004-Super%20Mario%20Odyssey.png + https://yuzu-emu.org/images/screenshots/019-Pokken%20Tournament.png + https://yuzu-emu.org/images/screenshots/052-Pokemon%20Let%27s%20Go.png + + Games + Emulator + +
+EOF + +cat > /tmp/yuzu-wrapper <= 10 +for i in 1 2 3 .. 20 +do + # Spawn a new shell + # This guarantees that a new process is created (unlike with potential bash internals like echo etc.) + bash -c "true" + sleep 0 +done + +# Symlink com.discordapp.Discord ipc pipes if they do not exist yet +for i in {0..9}; do + test -S \$XDG_RUNTIME_DIR/app/com.discordapp.Discord/discord-ipc-\$i && ln -sf {\$XDG_RUNTIME_DIR/app/com.discordapp.Discord,\$XDG_RUNTIME_DIR}/discord-ipc-\$i; +done + +yuzu \$@ +EOF + +# Generate the yuzu flatpak manifest +cat > /tmp/org.yuzu.$REPO_NAME.json <