VulkanRenderer/build.sh
2025-08-16 08:52:01 +10:00

57 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -eu
if [ -z "$1" ]; then
echo "No output parameter named, please pass the build directory to this script."
exit 1
fi
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
build="$1"
if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc";
elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang";
else echo "Unable to find c++ cpp_compiler"; exit -1; fi;
if [ -x "$(command -v mold)" ]; then linker_cmd="-fuse-ld=mold";
elif [ -x "$(command -v lld)" ]; then linker_cmd="-fuse-ld=lld";
elif [ -x "$(command -v ld)" ]; then linker_cmd="-fuse-ld=ld";
else echo "Unable to find c/c++ linker"; exit -1; fi;
# Build VMA
src="${script_dir}/vma/vma.cpp"
flags="-std=c++20 -D_USE_MATH_DEFINES -Iexternal/vma -c -Wno-everything -static"
out="-o"
obj="${build}/vma.o"
lib="${build}/libvma.a"
if ! [ -f "${build}/libvma.a" ]; then
$cpp_compiler $flags $src $out $obj
ar rcs $lib $obj
rm $obj
fi
# Convert Shader
shader="${script_dir}/convert.comp.glsl"
shader_compiler="glslc"
shader_flags="--target-spv=spv1.5 -std=460 --target-env=vulkan1.3"
shader_out="-o${build}/"
shader_stage="-fshader-stage=comp"
base_name=$(basename -- "$shader" .glsl)
$shader_compiler $shader_flags $shader_stage $shader "${shader_out}${base_name}.spv"
if [ -x "$(command -v ldc2)" ]; then d_compiler="ldc2";
elif [ -x "$(command -v dmd)" ]; then d_compiler="dmd";
else echo "Unable to find D compiler"; exit -1; fi;
codegen_src="${script_dir}/vulkan_codegen.d"
codegen_out="--of=${build}/vulkan_codegen"
$d_compiler $codegen_src $codegen_out
$codegen_out $build/$base_name.spv