-
-
Save Ertain/2c28766dd7ebfe551ececb9928c873f3 to your computer and use it in GitHub Desktop.
Vulkan and Godot engine builder for the Raspberry Pi 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script was written with the assumption that it's run on Raspberry Pi OS. | |
not_keep_sources="" | |
# Arguments for keeping the sources. | |
if [ -n $1 ] && [ "$1" = "-k" ]; then | |
not_keep_sources="yep" | |
fi | |
# Instructions for building the Vulkan drivers found here: https://blogs.igalia.com/apinheiro/2020/06/v3dv-quick-guide-to-build-and-run-some-demos/ | |
# Check for the necessary building software. | |
if [ ! "$(which pip3)" ]; then | |
echo "pip3 is not installed! Now installing pip3." | |
sudo apt install -y python3-pip > /dev/null 2>&1 | |
fi | |
if [ ! "$(which git)" ]; then | |
echo "Git not found! Now installing Git." | |
sudo apt install -y git > /dev/null 2>&1 | |
fi | |
# environmental variable for locating the Vulkan ICD thingy. | |
export VK_ICD_FILENAMES=/home/pi/local-install/share/vulkan/icd.d/broadcom_icd.armv7l.json | |
# The git commit hash used for the code version of the engine that was tested. | |
git_commit_hash="443686d724ce8ac58dcdf09389e9f996aee866c1" | |
function install_devs { | |
sudo apt-get install -y libxcb-randr0-dev libxrandr-dev \ | |
libxcb-xinerama0-dev libxinerama-dev libxcursor-dev \ | |
libxcb-cursor-dev libxkbcommon-dev xutils-dev \ | |
xutils-dev libpthread-stubs0-dev libpciaccess-dev \ | |
libffi-dev x11proto-xext-dev libxcb1-dev libxcb-*dev \ | |
bison flex libssl-dev libgnutls28-dev x11proto-dri2-dev \ | |
x11proto-dri3-dev libx11-dev libxcb-glx0-dev \ | |
libx11-xcb-dev libxext-dev libxdamage-dev libxfixes-dev \ | |
libva-dev x11proto-randr-dev x11proto-present-dev \ | |
libclc-dev libelf-dev git build-essential mesa-utils \ | |
libvulkan-dev ninja-build libvulkan1 python-mako \ | |
libdrm-dev libxshmfence-dev libxxf86vm-dev \ | |
python3-mako libvorbis-dev pkg-config \ | |
libgl1-mesa-dev libglu-dev libasound2-dev \ | |
libpulse-dev libudev-dev libxi-dev yasm llvm clang-8 > /dev/null 2>&1 | |
} | |
function git_and_build_vulkan { | |
# Source of commands: https://blogs.igalia.com/apinheiro/2020/06/v3dv-quick-guide-to-build-and-run-some-demos/ | |
if [ "$not_keep_sources" ]; then | |
if [ -d mesa ]; then | |
echo "Removing old mesa directory." | |
rm -rf mesa | |
fi | |
if [ -d $HOME/local-install ]; then | |
echo "Removing local install of Vulkan drivers." | |
rm -rf $HOME/local-install | |
fi | |
git clone https://gitlab.freedesktop.org/apinheiro/mesa.git mesa > /dev/null 2>&1 | |
else | |
git clone https://gitlab.freedesktop.org/apinheiro/mesa.git mesa > /dev/null 2>&1 | |
fi | |
cd mesa | |
if [ -f vulkan_driver_build.log ]; then | |
rm vulkan_driver_build.log | |
fi | |
git checkout wip/igalia/v3dv > /dev/null 2>&1 | |
"$meson_location" --prefix /home/pi/local-install --libdir lib -Dplatforms=x11,drm -Dvulkan-drivers=broadcom -Ddri-drivers= -Dgallium-drivers=v3d,kmsro,vc4 -Dbuildtype=debug _build >> vulkan_driver_build.log 2>&1 | |
ninja -C _build >> vulkan_driver_build.log 2>&1 | |
ninja -C _build install >> vulkan_driver_build.log 2>&1 | |
# Check that the build succeeded. | |
if [ $? -ne 0 ]; then | |
echo "The build failed!" | |
echo "Check \"vulkan_driver_build.log\" for details." | |
exit 3 | |
fi | |
cd .. | |
} | |
function build_godot_engine { | |
cpu_stuff="-mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -mlittle-endian -munaligned-access" | |
# Check for the "godot-master" directory or whether the user wants to keep the "godot-master" directory. | |
if [ "$not_keep_sources" ] && [ -d godot-master ]; then | |
echo "Removing old godot-master directory." | |
rm -rf godot-master | |
git clone https://github.com/godotengine/godot.git godot-master > /dev/null 2>&1 | |
elif [ ! -d godot-master ]; then | |
git clone https://github.com/godotengine/godot.git godot-master > /dev/null 2>&1 | |
fi | |
cd godot-master | |
if [ -f godot_engine_build.log ]; then | |
rm godot_engine_build.log | |
fi | |
$scons_command -j 4 CCFLAGS="-I/home/pi/local-install/include/ $cpu_stuff" LDLIBS="-lstdc++" LINKFLAGS="-lvorbis" \ | |
tools=yes platform=linuxbsd target=release_debug udev=yes use_llvm=yes >> godot_engine_build.log 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Engine didn't build!" | |
echo "Check \"godot_engine_build.log\" for details." | |
exit 4 | |
fi | |
echo "The resulting binary should be in the \"godot-master/bin\" directory." | |
cd .. | |
} | |
function check_for_meson { | |
# Check for meson. If it's installed, check its version. On an older version, install a newer version via pip3. | |
if [ "$(which meson)" ]; then | |
if [ "$(meson -v)" == "0.49.2" ]; then | |
echo "Removing out of date version of meson and installing newer version." | |
apt remove --purge -y meson > /dev/null 2>&1 | |
pip3 install --user --no-warn-script-location meson | |
meson_location=$HOME/.local/bin/meson | |
else | |
echo "Looks like meson is up to date." | |
meson_location=$(which meson) | |
fi | |
elif [ -e $HOME/.local/bin/meson ]; then | |
echo "Looks like meson is installed." | |
meson_location=$HOME/.local/bin/meson | |
else | |
echo "Installing meson." | |
pip3 install --user --no-warn-script-location meson > /dev/null 2>&1 | |
meson_location=$HOME/.local/bin/meson | |
fi | |
export PATH=$PATH:$meson_location | |
} | |
function check_for_scons { | |
# Check for scons. If it's installed, check the shebang to see whether it uses python3. | |
if [ "$(which scons)" ] && [ "$(head -1 $(which scons) | grep 'python3')" ]; then | |
echo "A necessary version of scons is installed." | |
scons_command=$(which scons) | |
elif [ -e $HOME/.local/bin/scons ]; then | |
echo "The pip3 version of scons is installed." | |
scons_command=$HOME/.local/bin/scons | |
else | |
echo "Installing the Python 3 version of scons." | |
pip3 install --user --no-warn-script-location scons > /dev/null 2>&1 | |
scons_command=$HOME/.local/bin/scons | |
fi | |
export PATH=$PATH:$scons_command | |
} | |
echo "Let's install the necessary software for building the Vulkan driver and the Godot engine." | |
install_devs | |
echo "Let's check for meson." | |
check_for_meson | |
echo "Let's check for scons." | |
check_for_scons | |
echo "Next let's pull down the necessary sources and build the driver." | |
git_and_build_vulkan | |
echo "Now that's finished, let's get the sources for the Godot engine and build it." | |
build_godot_engine | |
echo "All done!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment