Created
July 8, 2019 10:11
-
-
Save lancelet/7f705a1cf005822dccf68b312d4e9645 to your computer and use it in GitHub Desktop.
Build and run the Haskell vulkan-triangles example on MacOS.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # | |
| # File: macos-haskell-run-vulkan-triangles.sh | |
| # | |
| # Haskell Vulkan on MacOS example: | |
| # Build and run the vulkan-triangles GLFW example. | |
| # | |
| # The purpose of this script is to automate building and running the | |
| # vulkan-triangles GLFW example. There are some half-baked instructions | |
| # for MacOS available here: | |
| # https://github.com/achirkin/vulkan/blob/ceb537fc66cc429ec3df2cfc1430cbc3741e5538/README-macOS.md | |
| # However, it took me ages to figure out what to actually do to get it | |
| # to work. | |
| # | |
| # This script should (hopefully) help, by simply automating everything. | |
| # Simply place the script in a temporary directory and then execute it. | |
| # "Safe" bash | |
| set -euo pipefail | |
| # The script directory | |
| readonly dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | |
| # Haskell Vulkan bindings | |
| readonly hs_vulkan_dir="${dir}/vulkan" | |
| readonly hs_vulkan_git_repo='https://github.com/achirkin/vulkan.git' | |
| readonly hs_vulkan_git_hash='5bc22748c0799104f1a3201ff8ecd1d0eaefde2d' | |
| # Vulkan SDK for MacOS | |
| readonly vulkan_sdk_version='1.1.108.0' | |
| readonly vulkan_sdk_base_url='https://sdk.lunarg.com/sdk/download' | |
| readonly vulkan_sdk_file="${vulkan_sdk_base_url}/${vulkan_sdk_version}/mac/vulkansdk-macos-${vulkan_sdk_version}.tar.gz?Human=true" | |
| readonly vulkan_sdk_dir="${dir}/vulkansdk-macos-${vulkan_sdk_version}" | |
| # bindings-GLFW for Haskell | |
| readonly hs_bindings_glfw_dir="${dir}/bindings-GLFW" | |
| readonly hs_bindings_glfw_git_repo='https://github.com/cjay/bindings-GLFW.git' | |
| readonly hs_bindings_glfw_git_hash='3b300787078ec12d0ef6ac10ced031ecb2b11e6d' | |
| # GLFW-b for Haskell | |
| readonly hs_glfw_b_dir="${dir}/GLFW-b" | |
| readonly hs_glfw_b_git_repo='https://github.com/cjay/GLFW-b.git' | |
| readonly hs_glfw_b_git_hash='96ae257f7b6b6058d5ff41809757d69fd5a03287' | |
| # Work in the script directory | |
| pushd "${dir}" > /dev/null | |
| # Clone the Haskell vulkan repo if it has not been cloned yet. | |
| if [ ! -d "${hs_vulkan_dir}" ]; then | |
| git clone "${hs_vulkan_git_repo}" "${hs_vulkan_dir}" | |
| # Set commit and apply a small patch. The patch is to use different | |
| # versions of bindings-GLFW and GLFW-b, with Vulkan support. | |
| set +e | |
| read -d "" -r PATCH <<EOF | |
| diff --git a/vulkan-triangles/stack.yaml b/vulkan-triangles/stack.yaml | |
| index 465cb9c..fcdaba5 100644 | |
| --- a/vulkan-triangles/stack.yaml | |
| +++ b/vulkan-triangles/stack.yaml | |
| @@ -12,8 +12,6 @@ flags: | |
| useUnsafeFFIDefault: true | |
| extra-deps: | |
| - - bindings-GLFW-3.2.1.1 | |
| - - GLFW-b-3.2.1.0 | |
| - constraints-deriving-1.0.4.0 | |
| - dimensions-2.0.0.0 | |
| - easytensor-2.0.1.0 | |
| @@ -24,3 +22,7 @@ packages: | |
| - . | |
| - location: ../vulkan-api | |
| extra-dep: true | |
| + - location: ${hs_bindings_glfw_dir} | |
| + extra-dep: true | |
| + - location: ${hs_glfw_b_dir} | |
| + extra-dep: true | |
| EOF | |
| set -e | |
| pushd "${hs_vulkan_dir}" > /dev/null | |
| git reset --hard "${hs_vulkan_git_hash}" | |
| echo "${PATCH}" | git apply - | |
| popd > /dev/null | |
| fi | |
| # Clone the bindings-GLFW repo if it has not yet been cloned. | |
| if [ ! -d "${hs_bindings_glfw_dir}" ]; then | |
| git clone -b 'Upgrade-3.3' "${hs_bindings_glfw_git_repo}" "${hs_bindings_glfw_dir}" | |
| pushd "${hs_bindings_glfw_dir}" > /dev/null | |
| git reset --hard "${hs_bindings_glfw_git_hash}" | |
| popd > /dev/null | |
| fi | |
| # Clone the GLFW-b repo if it has not yet been cloned. | |
| if [ ! -d "${hs_glfw_b_dir}" ]; then | |
| git clone -b 'Upgrade-3.3' "${hs_glfw_b_git_repo}" "${hs_glfw_b_dir}" | |
| pushd "${hs_glfw_b_dir}" > /dev/null | |
| git reset --hard "${hs_glfw_b_git_hash}" | |
| popd > /dev/null | |
| fi | |
| # Download and extract the MacOS Vulkan SDK | |
| echo "Vulkan SDK file: ${vulkan_sdk_file}" | |
| if [ ! -d "${vulkan_sdk_dir}" ]; then | |
| curl "${vulkan_sdk_file}" | tar xvz | |
| fi | |
| # Set environment variables for the Vulkan SDK components | |
| export VULKAN_SDK="${vulkan_sdk_dir}/macOS" | |
| export VK_LAYER_PATH="${VULKAN_SDK}/etc/vulkan/explicit_layer.d" | |
| export VK_ICD_FILENAMES="${VULKAN_SDK}/etc/vulkan/icd.d/MoltenVK_icd.json" | |
| export PATH="${VULKAN_SDK}/bin:${PATH}" | |
| export DYLD_LIBRARY_PATH="${VULKAN_SDK}/lib" | |
| # Build the Vulkan API | |
| pushd "${hs_vulkan_dir}/vulkan-api" > /dev/null | |
| stack build | |
| popd > /dev/null | |
| # Build the Vulkan-Triangles example and run it | |
| pushd "${hs_vulkan_dir}/vulkan-triangles" > /dev/null | |
| install_name_tool -id "${VULKAN_SDK}/lib/libvulkan.1.dylib" "${VULKAN_SDK}/lib/libvulkan.1.dylib" | |
| stack build --extra-lib-dirs="${VULKAN_SDK}/lib" | |
| stack exec vulkan-triangles | |
| popd > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs stack, etc.
Line 32 URL may need to have
?Human=truereplaced with?u=... the site throttles to something like 5 downloads per 24 hours per IP address. I managed to exceed that.